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
Deprecated: api_user is no longer used for authentication or URLs.
-
#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)
- #send_request(method: :get, payload: {}, path: '') ⇒ Object
Constructor Details
#initialize(args = {}) ⇒ Client
Returns a new instance of Client.
14 15 16 17 18 19 20 21 22 23 |
# File 'lib/paubox/client.rb', line 14 def initialize(args = {}) args = defaults.merge(args) @api_key = args[:api_key] @api_user = args[:api_user] # deprecated no-op, kept for backward compatibility @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)
Deprecated: api_user is no longer used for authentication or URLs. It is kept only for backward compatibility and has no effect on requests.
12 13 14 |
# File 'lib/paubox/client.rb', line 12 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
25 26 27 28 |
# File 'lib/paubox/client.rb', line 25 def api_status url = request_endpoint('status') RestClient.get(url, accept: :json) end |
#email_disposition(source_tracking_id) ⇒ Object Also known as: message_receipt
50 51 52 53 54 |
# File 'lib/paubox/client.rb', line 50 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
30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/paubox/client.rb', line 30 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, Paubox::TemplatedMessage payload = mail. end url = request_endpoint(mail.is_a?(Paubox::TemplatedMessage) ? 'templated_messages' : '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 |
#send_request(method: :get, payload: {}, path: '') ⇒ Object
57 58 59 60 61 |
# File 'lib/paubox/client.rb', line 57 def send_request(method: :get, payload: {}, path: '') url = request_endpoint(path) RestClient::Request.execute(method: method, url: url, payload: payload, headers: auth_header) end |