Module: MarketingConnection
- Defined in:
- lib/marketing_connection.rb,
lib/marketing_connection/gun.rb,
lib/marketing_connection/list.rb,
lib/marketing_connection/error.rb,
lib/marketing_connection/version.rb,
lib/marketing_connection/delivery.rb,
lib/marketing_connection/template.rb
Defined Under Namespace
Classes: Base, Delivery, Error, Gun, List, Template
Constant Summary collapse
- VERSION =
"0.0.2"
Class Attribute Summary collapse
-
.api_key ⇒ Object
Returns the value of attribute api_key.
-
.api_secret ⇒ Object
Returns the value of attribute api_secret.
-
.api_url ⇒ Object
Returns the value of attribute api_url.
-
.mode ⇒ Object
Returns the value of attribute mode.
Class Method Summary collapse
- .base_url ⇒ Object
- .config {|_self| ... } ⇒ Object
-
.submit(method, target_url, parameters = {}) ⇒ Object
Submits the API call to the Mailgun server.
Class Attribute Details
.api_key ⇒ Object
Returns the value of attribute api_key.
38 39 40 |
# File 'lib/marketing_connection.rb', line 38 def api_key @api_key end |
.api_secret ⇒ Object
Returns the value of attribute api_secret.
38 39 40 |
# File 'lib/marketing_connection.rb', line 38 def api_secret @api_secret end |
.api_url ⇒ Object
Returns the value of attribute api_url.
38 39 40 |
# File 'lib/marketing_connection.rb', line 38 def api_url @api_url end |
.mode ⇒ Object
Returns the value of attribute mode.
38 39 40 |
# File 'lib/marketing_connection.rb', line 38 def mode @mode end |
Class Method Details
.base_url ⇒ Object
69 70 71 |
# File 'lib/marketing_connection.rb', line 69 def base_url "http://#{self.api_key}:#{self.api_secret}@#{self.api_url}/api/v1/" end |
.config {|_self| ... } ⇒ Object
73 74 75 76 |
# File 'lib/marketing_connection.rb', line 73 def config yield self true end |
.submit(method, target_url, parameters = {}) ⇒ Object
Submits the API call to the Mailgun server
49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 |
# File 'lib/marketing_connection.rb', line 49 def submit(method, target_url, parameters={}) url = base_url + target_url puts url 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 MarketingConnection::Error.new() end raise e end end |