Module: MaropostApi

Includes:
HTTParty, URI
Defined in:
lib/maropost-api.rb,
lib/maropost_api/reports.rb,
lib/maropost_api/version.rb,
lib/maropost_api/contacts.rb,
lib/maropost_api/journeys.rb,
lib/maropost_api/campaigns.rb,
lib/maropost_api/ab_test_campaigns.rb,
lib/maropost_api/relational_tables.rb,
lib/maropost_api/products_and_revenue.rb,
lib/maropost_api/transactional_campaigns.rb

Overview

This package provides programmatic access to several Maropost services. It consists of eight services within the MaropostApi namespace. Each service consists of one or more functions that perform an operation against your Maropost account. These methods return a result object indicating success/failure, any Exceptions thrown, and the resulting data. The detailed documentation of the api can be found in api.maropost.com/api

Defined Under Namespace

Classes: AbTestCampaigns, Campaigns, Contacts, Error, Journeys, ProductsAndRevenue, RelationalTableRows, Reports, TransactionalCampaigns

Constant Summary collapse

VERSION =
"0.2.1"

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Attribute Details

#accountObject

Returns the value of attribute account.



28
29
30
# File 'lib/maropost-api.rb', line 28

def 
  @account
end

#api_keyObject

Returns the value of attribute api_key.



27
28
29
# File 'lib/maropost-api.rb', line 27

def api_key
  @api_key
end

Class Method Details

.delete_result(path, query_params, body = {}) ⇒ Object



58
59
60
61
62
63
64
# File 'lib/maropost-api.rb', line 58

def self.delete_result(path, query_params, body={})
  raise ArgumentError "path and query_params cannot be nil" if path.nil? || query_params.nil?
  full_path = path << ".#{format.to_s}"
  result = delete(full_path, :headers => {"Content-Type" => 'application/json'}, :query => query_params[:query], :body => body.to_json)
  
  OperationResult.new(result)
end

.get_result(path, options) ⇒ Object



32
33
34
35
36
37
# File 'lib/maropost-api.rb', line 32

def self.get_result(path, options)
  full_path = path << ".#{format.to_s}"
  result = get(full_path, options)
  
  OperationResult.new(result)
end

.post_result(path, form_body) ⇒ Object



39
40
41
42
43
44
45
46
47
# File 'lib/maropost-api.rb', line 39

def self.post_result(path, form_body)
  raise ArgumentError "path and form_body cannot be nil" if path.nil? || form_body.nil?
  full_path = path << ".#{format.to_s}"
  # set auth_token manually due to 400 error when sent via parameters
  full_path = full_path << "?auth_token=#{@api_key}"
  result = post(full_path, :body => form_body.to_json, :headers => {"Content-Type" => 'application/json'})
  
  OperationResult.new(result)
end

.put_result(path, form_body = {}, query_params = {}) ⇒ Object



49
50
51
52
53
54
55
56
# File 'lib/maropost-api.rb', line 49

def self.put_result(path, form_body = {}, query_params = {})
  raise ArgumentError "path and form_body cannot be nil" if path.nil? || form_body.nil?
  full_path = path << ".#{format.to_s}"
  query_params = set_query_params if query_params.empty?
  result = put(full_path, :body => form_body.to_json, :headers => {"Content-Type" => 'application/json', 'Accept' => 'application/json'}, :query => query_params[:query])
  
  OperationResult.new(result)
end

.set_query_params(query_params = {}) ⇒ Object



66
67
68
69
70
71
72
73
74
75
76
# File 'lib/maropost-api.rb', line 66

def self.set_query_params(query_params = {})
  return nil if query_params.class != Hash
  @query_params ||= {
    query: {auth_token: @api_key}
  }
  additional_params = { query: query_params }
  
  @query_params.merge(additional_params) do |key, qp_val, ap_val|
    qp_val.merge ap_val
  end
end