class Paubox::Client
Attributes
api_host[R]
api_key[R]
api_protocol[R]
api_user[R]
api_version[R]
Public Class Methods
new(args = {})
click to toggle source
# File lib/paubox/client.rb, line 10 def initialize(args = {}) args = defaults.merge(args) @api_key = args[:api_key] @api_user = args[:api_user] @api_host = args[:api_host] @api_protocol = args[:api_protocol] @api_version = args[:api_version] @test_mode = args[:test_mode] @api_base_endpoint = api_base_endpoint end
Public Instance Methods
api_status()
click to toggle source
# File lib/paubox/client.rb, line 21 def api_status url = request_endpoint('status') RestClient.get(url, accept: :json) end
email_disposition(source_tracking_id)
click to toggle source
# File lib/paubox/client.rb, line 46 def email_disposition(source_tracking_id) url = "#{request_endpoint('message_receipt')}?sourceTrackingId=#{source_tracking_id}" response = RestClient.get(url, auth_header) email_disposition = Paubox::EmailDisposition.new(JSON.parse(response.body)) end
Also aliased as: message_receipt
send_mail(mail)
click to toggle source
# File lib/paubox/client.rb, line 26 def send_mail(mail) case mail when Mail::Message allow_non_tls = mail.allow_non_tls.nil? ? false : mail.allow_non_tls payload = MailToMessage.new(mail, allow_non_tls: allow_non_tls) .send_message_payload when Hash payload = Message.new(mail).send_message_payload when Paubox::Message payload = mail.send_message_payload end url = request_endpoint('messages') response = RestClient.post(url, payload, auth_header) if mail.class == Mail::Message mail.source_tracking_id = JSON.parse(response.body)['sourceTrackingId'] end JSON.parse(response.body) end
Also aliased as: deliver_mail
Private Instance Methods
api_base_endpoint()
click to toggle source
# File lib/paubox/client.rb, line 61 def api_base_endpoint "#{api_protocol}#{api_host}/#{api_version}/#{api_user}" end
auth_header()
click to toggle source
# File lib/paubox/client.rb, line 55 def auth_header { accept: :json, content_type: :json, Authorization: "Token token=#{@api_key}" } end
defaults()
click to toggle source
# File lib/paubox/client.rb, line 69 def defaults { api_key: Paubox.configuration.api_key, api_user: Paubox.configuration.api_user, api_host: 'api.paubox.net', api_protocol: 'https://', api_version: 'v1', test_mode: false } end
request_endpoint(endpoint)
click to toggle source
# File lib/paubox/client.rb, line 65 def request_endpoint(endpoint) "#{api_base_endpoint}/#{endpoint}" end
to_open_struct(hash)
click to toggle source
recursively converts a nested Hash into OpenStruct
# File lib/paubox/client.rb, line 79 def to_open_struct(hash) OpenStruct.new(hash.each_with_object({}) do |(key, val), memo| memo[key] = val.is_a?(Hash) ? to_open_struct(val) : val end) end