Class: CustomerioAPI::Resource
- Inherits:
-
Object
- Object
- CustomerioAPI::Resource
show all
- Defined in:
- lib/customerio_api/resource.rb
Instance Attribute Summary collapse
Instance Method Summary
collapse
Constructor Details
#initialize(client) ⇒ Resource
Returns a new instance of Resource.
7
8
9
|
# File 'lib/customerio_api/resource.rb', line 7
def initialize(client)
@client = client
end
|
Instance Attribute Details
Returns the value of attribute client.
5
6
7
|
# File 'lib/customerio_api/resource.rb', line 5
def client
@client
end
|
Instance Method Details
#get_request(url, params: {}, headers: {}) ⇒ Object
11
12
13
|
# File 'lib/customerio_api/resource.rb', line 11
def get_request(url, params: {}, headers: {})
handle_response client.connection.get(url, params, )
end
|
#handle_response(response) ⇒ Object
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
|
# File 'lib/customerio_api/resource.rb', line 23
def handle_response(response)
error_message = response.body
case response.status
when 400
raise Error, "A bad request or a validation exception has occurred. #{error_message}"
when 401
raise AuthenticationError, "Invalid authorization credentials. #{error_message}"
when 403
raise WhiteListError, "IP address is not white listed. #{error_message}"
when 404
raise NotFoundError, "The resource you have specified cannot be found. #{error_message}"
when 429
raise RateLimitError, "The API rate limit for your application has been exceeded. #{error_message}"
when 500
raise ServerError, "An unhandled error with the Customer.io API. #{error_message}"
end
response
end
|
#post_request(url, body:, headers: {}) ⇒ Object
15
16
17
|
# File 'lib/customerio_api/resource.rb', line 15
def post_request(url, body:, headers: {})
handle_response client.connection.post(url, body, )
end
|
#put_request(url, body:, headers: {}) ⇒ Object
19
20
21
|
# File 'lib/customerio_api/resource.rb', line 19
def put_request(url, body:, headers: {})
handle_response client.connection.put(url, body, )
end
|