Class: Howitzer::MailgunApi::Client
- Inherits:
-
Object
- Object
- Howitzer::MailgunApi::Client
- Defined in:
- lib/howitzer/mailgun_api/client.rb
Overview
A Mailgun::Client object is used to communicate with the Mailgun API. It is a wrapper around RestClient so you don’t have to worry about the HTTP aspect of communicating with Mailgun API.
Constant Summary collapse
- USER_AGENT =
:nodoc:
'mailgun-sdk-ruby'.freeze
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_user ⇒ Object
readonly
Returns the value of attribute api_user.
-
#api_version ⇒ Object
readonly
Returns the value of attribute api_version.
-
#ssl ⇒ Object
readonly
Returns the value of attribute ssl.
Instance Method Summary collapse
-
#get(resource_path, params: nil, accept: '*/*') ⇒ Mailgun::Response
Generic Mailgun GET Handler.
-
#get_url(resource_url, params: nil, accept: '*/*') ⇒ Mailgun::Response
Extracts data by url in custom way.
-
#initialize(api_user: 'api', api_key: 'key', api_host: 'api.mailgun.net', api_version: 'v3', ssl: true) ⇒ Client
constructor
A new instance of Client.
Constructor Details
#initialize(api_user: 'api', api_key: 'key', api_host: 'api.mailgun.net', api_version: 'v3', ssl: true) ⇒ Client
Returns a new instance of Client.
15 16 17 18 19 20 21 22 |
# File 'lib/howitzer/mailgun_api/client.rb', line 15 def initialize(api_user: 'api', api_key: 'key', api_host: 'api.mailgun.net', api_version: 'v3', ssl: true) @api_user = api_user @api_key = api_key @api_host = api_host @api_version = api_version @ssl = ssl @http_client = ::RestClient::Resource.new(endpoint, user: api_user, password: api_key, user_agent: USER_AGENT) end |
Instance Attribute Details
#api_host ⇒ Object (readonly)
Returns the value of attribute api_host.
13 14 15 |
# File 'lib/howitzer/mailgun_api/client.rb', line 13 def api_host @api_host end |
#api_key ⇒ Object (readonly)
Returns the value of attribute api_key.
13 14 15 |
# File 'lib/howitzer/mailgun_api/client.rb', line 13 def api_key @api_key end |
#api_user ⇒ Object (readonly)
Returns the value of attribute api_user.
13 14 15 |
# File 'lib/howitzer/mailgun_api/client.rb', line 13 def api_user @api_user end |
#api_version ⇒ Object (readonly)
Returns the value of attribute api_version.
13 14 15 |
# File 'lib/howitzer/mailgun_api/client.rb', line 13 def api_version @api_version end |
#ssl ⇒ Object (readonly)
Returns the value of attribute ssl.
13 14 15 |
# File 'lib/howitzer/mailgun_api/client.rb', line 13 def ssl @ssl end |
Instance Method Details
#get(resource_path, params: nil, accept: '*/*') ⇒ Mailgun::Response
Generic Mailgun GET Handler
33 34 35 36 37 38 39 40 |
# File 'lib/howitzer/mailgun_api/client.rb', line 33 def get(resource_path, params: nil, accept: '*/*') http_params = { accept: accept } http_params = http_params.merge(params: params) if params response = http_client[resource_path].get(http_params) Response.new(response) rescue => e raise Howitzer::CommunicationError, e. end |
#get_url(resource_url, params: nil, accept: '*/*') ⇒ Mailgun::Response
This method was introducted because of saving emails to different nodes. As result we can not use #get method, because client holds general api url
Extracts data by url in custom way
53 54 55 56 57 58 59 60 61 62 63 64 65 66 |
# File 'lib/howitzer/mailgun_api/client.rb', line 53 def get_url(resource_url, params: nil, accept: '*/*') response = ::RestClient::Request.execute( method: :get, url: resource_url, user: api_user, password: api_key, user_agent: USER_AGENT, accept: accept, params: params ) Response.new(response) rescue => e raise Howitzer::CommunicationError, e. end |