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

Class Method Summary collapse

Class Attribute Details

.api_keyObject

Returns the value of attribute api_key.



38
39
40
# File 'lib/marketing_connection.rb', line 38

def api_key
  @api_key
end

.api_secretObject

Returns the value of attribute api_secret.



38
39
40
# File 'lib/marketing_connection.rb', line 38

def api_secret
  @api_secret
end

.api_urlObject

Returns the value of attribute api_url.



38
39
40
# File 'lib/marketing_connection.rb', line 38

def api_url
  @api_url
end

.modeObject

Returns the value of attribute mode.



38
39
40
# File 'lib/marketing_connection.rb', line 38

def mode
  @mode
end

Class Method Details

.base_urlObject



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

Yields:

  • (_self)

Yield Parameters:



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
    error_message = nil
    if e.respond_to? :http_body
      begin
        error_message = JSON(e.http_body)["message"]
      rescue
        raise e
      end
      raise MarketingConnection::Error.new(error_message)
    end
    raise e
  end
end