Class: Customerio::APIClient
- Inherits:
-
Object
- Object
- Customerio::APIClient
- Defined in:
- lib/customerio/api.rb
Instance Method Summary collapse
-
#initialize(app_key, options = {}) ⇒ APIClient
constructor
A new instance of APIClient.
- #send_email(req) ⇒ Object
- #send_push(req) ⇒ Object
- #send_sms(req) ⇒ Object
Constructor Details
#initialize(app_key, options = {}) ⇒ APIClient
Returns a new instance of APIClient.
6 7 8 9 10 11 12 |
# File 'lib/customerio/api.rb', line 6 def initialize(app_key, = {}) [:region] = Customerio::Regions::US if [:region].nil? raise "region must be an instance of Customerio::Regions::Region" unless [:region].is_a?(Customerio::Regions::Region) [:url] = [:region].api_url if [:url].nil? || [:url].empty? @client = Customerio::BaseClient.new({ app_key: app_key }, ) end |
Instance Method Details
#send_email(req) ⇒ Object
14 15 16 17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/customerio/api.rb', line 14 def send_email(req) raise "request must be an instance of Customerio::SendEmailRequest" unless req.is_a?(Customerio::SendEmailRequest) response = @client.request(:post, send_email_path, req.) case response when Net::HTTPSuccess then JSON.parse(response.body) when Net::HTTPBadRequest then json = JSON.parse(response.body) raise Customerio::InvalidResponse.new(response.code, json['meta']['error'], response) else raise InvalidResponse.new(response.code, response.body) end end |
#send_push(req) ⇒ Object
29 30 31 32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/customerio/api.rb', line 29 def send_push(req) raise "request must be an instance of Customerio::SendPushRequest" unless req.is_a?(Customerio::SendPushRequest) response = @client.request(:post, send_push_path, req.) case response when Net::HTTPSuccess then JSON.parse(response.body) when Net::HTTPBadRequest then json = JSON.parse(response.body) raise Customerio::InvalidResponse.new(response.code, json['meta']['error'], response) else raise InvalidResponse.new(response.code, response.body) end end |
#send_sms(req) ⇒ Object
44 45 46 47 48 49 50 51 52 53 54 55 56 57 |
# File 'lib/customerio/api.rb', line 44 def send_sms(req) raise "request must be an instance of Customerio::SendSMSRequest" unless req.is_a?(Customerio::SendSMSRequest) response = @client.request(:post, send_sms_path, req.) case response when Net::HTTPSuccess then JSON.parse(response.body) when Net::HTTPBadRequest then json = JSON.parse(response.body) raise Customerio::InvalidResponse.new(response.code, json['meta']['error'], response) else raise InvalidResponse.new(response.code, response.body) end end |