Class: Mailgun::Base
- Inherits:
-
Object
- Object
- Mailgun::Base
- Defined in:
- lib/mailgun_api.rb
Instance Attribute Summary collapse
-
#api_key ⇒ Object
Returns the value of attribute api_key.
-
#api_version ⇒ Object
Returns the value of attribute api_version.
-
#domain ⇒ Object
Returns the value of attribute domain.
-
#host ⇒ Object
Returns the value of attribute host.
-
#protocol ⇒ Object
Returns the value of attribute protocol.
-
#response ⇒ Object
Returns the value of attribute response.
-
#test_mode ⇒ Object
Returns the value of attribute test_mode.
Class Method Summary collapse
Instance Method Summary collapse
-
#api_url ⇒ Object
Returns the api url used in all Mailgun API calls.
- #create_list(list_name, options = {}) ⇒ Object
- #create_message(params) ⇒ Object
- #domains ⇒ Object
- #find_domain(domain_name) ⇒ Object
- #find_list(list_name) ⇒ Object
-
#initialize(params = {}) ⇒ Base
constructor
A new instance of Base.
- #lists ⇒ Object
Constructor Details
#initialize(params = {}) ⇒ Base
Returns a new instance of Base.
93 94 95 96 97 98 99 100 101 102 |
# File 'lib/mailgun_api.rb', line 93 def initialize(params={}) raise ArgumentError.new(":api_key is a required argument to initialize Mailgun") if params.fetch(:api_key).nil? @host = params.fetch(:host) @protocol = params.fetch(:protocol) @api_version = params.fetch(:api_version) @test_mode = params.fetch(:test_mode) @api_key = params.fetch(:api_key) @domain = params.fetch(:domain, nil) end |
Instance Attribute Details
#api_key ⇒ Object
Returns the value of attribute api_key.
87 88 89 |
# File 'lib/mailgun_api.rb', line 87 def api_key @api_key end |
#api_version ⇒ Object
Returns the value of attribute api_version.
87 88 89 |
# File 'lib/mailgun_api.rb', line 87 def api_version @api_version end |
#domain ⇒ Object
Returns the value of attribute domain.
87 88 89 |
# File 'lib/mailgun_api.rb', line 87 def domain @domain end |
#host ⇒ Object
Returns the value of attribute host.
87 88 89 |
# File 'lib/mailgun_api.rb', line 87 def host @host end |
#protocol ⇒ Object
Returns the value of attribute protocol.
87 88 89 |
# File 'lib/mailgun_api.rb', line 87 def protocol @protocol end |
#response ⇒ Object
Returns the value of attribute response.
87 88 89 |
# File 'lib/mailgun_api.rb', line 87 def response @response end |
#test_mode ⇒ Object
Returns the value of attribute test_mode.
87 88 89 |
# File 'lib/mailgun_api.rb', line 87 def test_mode @test_mode end |
Class Method Details
.configure {|_self| ... } ⇒ Object
89 90 91 |
# File 'lib/mailgun_api.rb', line 89 def self.configure yield self end |
.fire(method, url, parameters = {}) ⇒ Object
138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 |
# File 'lib/mailgun_api.rb', line 138 def self.fire(method, url, parameters={}) begin parameters = {:params => parameters} if method == :get return JSON(RestClient.send(method, url, parameters)) rescue => e = nil if e.respond_to? :http_body begin = JSON(e.http_body)["message"] rescue raise e end raise Mailgun::Error.new() end raise e end end |
Instance Method Details
#api_url ⇒ Object
Returns the api url used in all Mailgun API calls
133 134 135 |
# File 'lib/mailgun_api.rb', line 133 def api_url "#{protocol}://api:#{api_key}@#{host}/#{api_version}" end |
#create_list(list_name, options = {}) ⇒ Object
122 123 124 |
# File 'lib/mailgun_api.rb', line 122 def create_list(list_name, ={}) Mailgun::List.new(self).create("#{list_name}@#{domain}", ) end |
#create_message(params) ⇒ Object
127 128 129 |
# File 'lib/mailgun_api.rb', line 127 def (params) Mailgun::Message.new(params) end |
#domains ⇒ Object
114 115 116 |
# File 'lib/mailgun_api.rb', line 114 def domains Mailgun::Domain.new(self).list end |
#find_domain(domain_name) ⇒ Object
118 119 120 |
# File 'lib/mailgun_api.rb', line 118 def find_domain(domain_name) Mailgun::Domain.new(self).list(domain_name) end |
#find_list(list_name) ⇒ Object
104 105 106 107 108 |
# File 'lib/mailgun_api.rb', line 104 def find_list(list_name) list = Mailgun::List.new(self) list.find("#{list_name}@#{domain}") list end |
#lists ⇒ Object
110 111 112 |
# File 'lib/mailgun_api.rb', line 110 def lists Mailgun::List.new(self).list end |