Class: Sendable::Client
- Inherits:
-
Object
- Object
- Sendable::Client
- Defined in:
- lib/sendable/client.rb
Instance Attribute Summary collapse
-
#api_key ⇒ Object
readonly
Returns the value of attribute api_key.
Instance Method Summary collapse
- #email(params = {}) ⇒ Object
-
#initialize(api_key) ⇒ Client
constructor
A new instance of Client.
- #render(params = {}) ⇒ Object
Constructor Details
#initialize(api_key) ⇒ Client
Returns a new instance of Client.
9 10 11 |
# File 'lib/sendable/client.rb', line 9 def initialize(api_key) @api_key = api_key end |
Instance Attribute Details
#api_key ⇒ Object (readonly)
Returns the value of attribute api_key.
7 8 9 |
# File 'lib/sendable/client.rb', line 7 def api_key @api_key end |
Instance Method Details
#email(params = {}) ⇒ Object
26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/sendable/client.rb', line 26 def email(params = {}) uri = URI('https://api.sendable.io/v1/email') http = Net::HTTP.new(uri.host, uri.port) http.use_ssl = true request = Net::HTTP::Post.new(uri.request_uri) request.basic_auth(api_key, '') request.body = params.respond_to?(:to_json) ? params.to_json : JSON.dump(params) response = http.request(request) JSON.parse(response.body) end |
#render(params = {}) ⇒ Object
13 14 15 16 17 18 19 20 21 22 23 24 |
# File 'lib/sendable/client.rb', line 13 def render(params = {}) uri = URI('https://api.sendable.io/v1/render') http = Net::HTTP.new(uri.host, uri.port) http.use_ssl = true request = Net::HTTP::Post.new(uri.request_uri) request.basic_auth(api_key, '') request.body = params.respond_to?(:to_json) ? params.to_json : JSON.dump(params) response = http.request(request) JSON.parse(response.body) end |