Class: Paubox::Client
- Inherits:
-
Object
- Object
- Paubox::Client
- Defined in:
- lib/paubox/client.rb
Overview
Client sends API requests to Paubox API
Instance Attribute Summary collapse
-
#api_host ⇒ Object
readonly
Returns the value of attribute api_host.
-
#api_key ⇒ Object
readonly
Returns the value of attribute api_key.
-
#api_protocol ⇒ Object
readonly
Returns the value of attribute api_protocol.
-
#api_user ⇒ Object
readonly
Returns the value of attribute api_user.
-
#api_version ⇒ Object
readonly
Returns the value of attribute api_version.
Instance Method Summary collapse
- #api_status ⇒ Object
- #email_disposition(source_tracking_id) ⇒ Object (also: #message_receipt)
-
#initialize(args = {}) ⇒ Client
constructor
A new instance of Client.
- #send_mail(mail) ⇒ Object (also: #deliver_mail)
Constructor Details
#initialize(args = {}) ⇒ Client
Returns a new instance of Client.
10 11 12 13 14 15 16 17 18 19 |
# 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 |
Instance Attribute Details
#api_host ⇒ Object (readonly)
Returns the value of attribute api_host.
8 9 10 |
# File 'lib/paubox/client.rb', line 8 def api_host @api_host end |
#api_key ⇒ Object (readonly)
Returns the value of attribute api_key.
8 9 10 |
# File 'lib/paubox/client.rb', line 8 def api_key @api_key end |
#api_protocol ⇒ Object (readonly)
Returns the value of attribute api_protocol.
8 9 10 |
# File 'lib/paubox/client.rb', line 8 def api_protocol @api_protocol end |
#api_user ⇒ Object (readonly)
Returns the value of attribute api_user.
8 9 10 |
# File 'lib/paubox/client.rb', line 8 def api_user @api_user end |
#api_version ⇒ Object (readonly)
Returns the value of attribute api_version.
8 9 10 |
# File 'lib/paubox/client.rb', line 8 def api_version @api_version end |
Instance Method Details
#api_status ⇒ Object
21 22 23 24 |
# 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) ⇒ Object Also known as: message_receipt
46 47 48 49 50 |
# 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 |
#send_mail(mail) ⇒ Object Also known as: deliver_mail
26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 |
# 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) . when Hash payload = Message.new(mail). when Paubox::Message payload = mail. 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 |