Class: InContactClient::Connection
- Inherits:
-
Object
- Object
- InContactClient::Connection
- Defined in:
- lib/incontact_client/connection.rb
Constant Summary collapse
- TIMEOUT =
60
- OPEN_TIMEOUT =
10
- MAX_TRIES =
2
- RETRY_SLEEP =
1
- API_PATH_PREFIX =
"services/v8.0/"
Instance Attribute Summary collapse
-
#authorization ⇒ Object
readonly
Returns the value of attribute authorization.
-
#default_data_model ⇒ Object
readonly
Returns the value of attribute default_data_model.
-
#url ⇒ Object
readonly
Returns the value of attribute url.
Instance Method Summary collapse
- #get(path, params = {}) ⇒ Object
-
#initialize(url, authorization, options = {}) ⇒ Connection
constructor
A new instance of Connection.
- #post(path, payload = "", params = {}) ⇒ Object
- #request(type, path, params = {}, body = nil) ⇒ Object
Constructor Details
#initialize(url, authorization, options = {}) ⇒ Connection
Returns a new instance of Connection.
13 14 15 16 17 |
# File 'lib/incontact_client/connection.rb', line 13 def initialize(url, , = {}) @url = url @authorization = @default_data_model = [:default_data_model] || OpenStruct end |
Instance Attribute Details
#authorization ⇒ Object (readonly)
Returns the value of attribute authorization.
10 11 12 |
# File 'lib/incontact_client/connection.rb', line 10 def @authorization end |
#default_data_model ⇒ Object (readonly)
Returns the value of attribute default_data_model.
11 12 13 |
# File 'lib/incontact_client/connection.rb', line 11 def default_data_model @default_data_model end |
#url ⇒ Object (readonly)
Returns the value of attribute url.
9 10 11 |
# File 'lib/incontact_client/connection.rb', line 9 def url @url end |
Instance Method Details
#get(path, params = {}) ⇒ Object
19 20 21 |
# File 'lib/incontact_client/connection.rb', line 19 def get(path, params = {}) request :get, path, params end |
#post(path, payload = "", params = {}) ⇒ Object
23 24 25 |
# File 'lib/incontact_client/connection.rb', line 23 def post(path, payload = "", params = {}) request :post, path, params, payload end |
#request(type, path, params = {}, body = nil) ⇒ Object
27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/incontact_client/connection.rb', line 27 def request(type, path, params = {}, body=nil) timeout_override = params.delete :timeout open_timeout_override = params.delete :open_timeout data_model_override = params.delete :data_model_override response = Retryable.retryable((params)) do request_with_exception_handling do connection.send(type) do |req| req.path = API_PATH_PREFIX + path unless path.blank? req.[:timeout] = timeout_override || TIMEOUT req.[:open_timeout] = open_timeout_override || OPEN_TIMEOUT req.params = params req.body = body.to_json unless body.blank? end end end raise_response_errors(response) parse_response(response, data_model_override) end |