Class: Mailgun::Client

Inherits:
Object
  • Object
show all
Defined in:
lib/howitzer/mailgun/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 our API.

Instance Method Summary collapse

Constructor Details

#initialize(api_key, api_host = "api.mailgun.net", api_version = "v2", ssl = true) ⇒ Client


14
15
16
17
18
19
20
# File 'lib/howitzer/mailgun/client.rb', line 14

def initialize(api_key, api_host="api.mailgun.net", api_version="v2", ssl=true)
  endpoint = endpoint_generator(api_host, api_version, ssl)
  @http_client = RestClient::Resource.new(endpoint,
                                          :user => "api",
                                          :password => api_key,
                                          :user_agent => "mailgun-sdk-ruby/1.0.1")
end

Instance Method Details

#get(resource_path, params = nil, accept = "*/*") ⇒ Mailgun::Response

Generic Mailgun GET Handler

with. Be sure to include your domain, where necessary. containing required parameters for the requested resource.


30
31
32
33
34
35
36
37
# File 'lib/howitzer/mailgun/client.rb', line 30

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
  log.error Howitzer::CommunicationError, e.message
end