Qore MewsRestClient Module Reference 1.0
Loading...
Searching...
No Matches
MewsRestClient::MewsRestClient Class Reference

this class provides the REST client API for communication with Mews servers More...

#include <MewsRestClient.qm.dox.h>

Inheritance diagram for MewsRestClient::MewsRestClient:
[legend]

Public Member Methods

 constructor (hash< auto > opts, *softbool do_not_connect)
 creates the object with the given options
 
hash< auto > doMewsRequest (string path, *hash< auto > body, *reference< hash< auto > > info, *hash< auto > hdr)
 Makes a POST request to the server with the required tokens and returns the response.
 
auto preprocessRequestBody (auto body)
 Adds authorization keys to the request body.
 

Public Attributes

const DefaultClient = sprintf("Qore %s", Qore::VersionString)
 Default client value.
 
const DefaultUriPathPrefix = "api/connector/v1"
 Connector REST API path prefix.
 

Private Member Methods

 checkLogin (*reference< hash< auto > > info)
 Checks if a login is necessary; if so, then the login is performed.
 

Static Private Member Methods

static hash< auto > getOptions (hash< auto > opts)
 returns options for MewsRestClient::MewsRestClient::constructor()
 

Private Attributes

string access_token
 Mews access token.
 
string client = DefaultClient
 Mews client values.
 
string client_token
 Mews client token.
 

Detailed Description

this class provides the REST client API for communication with Mews servers

You must use an OAuth2 token by setting the token and oauth2_refresh_token options; the following options need to be set as well:

  • oauth2_client_id: the OAuth2 client ID
  • oauth2_client_secret: the OAuth2 client secret

Then an external program has to guide the user through using the authorization_grant flow to get a token to use; this module does not implement that flow.

Member Function Documentation

◆ constructor()

MewsRestClient::MewsRestClient::constructor ( hash< auto >  opts,
*softbool  do_not_connect 
)

creates the object with the given options

Example:
MewsRestClient rest(opts);
Parameters
optsvalid options are all the options for the RestClient class
do_not_connectif False (the default), then a connection will be immediately established to the remote server
Exceptions
RESTCLIENT-ERRORinvalid option passed to constructor, unsupported data serialization, etc

◆ doMewsRequest()

hash< auto > MewsRestClient::MewsRestClient::doMewsRequest ( string  path,
*hash< auto >  body,
*reference< hash< auto > >  info,
*hash< auto >  hdr 
)

Makes a POST request to the server with the required tokens and returns the response.

Parameters
paththe URI path to add (will be appended to any root path given in the constructor)
bodyan optional message body to be included in the request; this will have the AccessToken, ClientToken, as well as the Client value added to it automatically before sending with JSON serialization
infoan optional reference to a hash that will be used as an output variable giving a hash of request headers and other information about the HTTP request
Returns
A hash of headers received from the HTTP server with all key names converted to lower-case; if any message body is included in the response, it will be deserialized to Qore data and assigned to the value of the "body" key
Exceptions
REST-RESPONSE-ERRORif this exception is thrown by the Qore::HTTPClient::send() call in case of an HTTP response code < 100 or >= 300, the message body is still deserialized if possible and the response information can be retrieved in the info hash output keys as follows:
  • "response-code": the HTTP response code given
  • "response-headers": a hash of processed response headers
  • "response-headers-raw": a hash of raw unprocessed response headers
  • "response-body": the decoded response body
Note that this exception is not raised for HTTP status codes indicating an error if the error_passthru option is set to True

Other exceptions can be thrown by the Qore::HTTPClient::send() call used to make the HTTP request.