class Sendable::Client

Attributes

api_key[R]

Public Class Methods

new(api_key) click to toggle source
# File lib/sendable/client.rb, line 9
def initialize(api_key)
  @api_key = api_key
end

Public Instance Methods

email(params = {}) click to toggle source
# 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 = {}) click to toggle source
# 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