maropost-api 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +11 -0
- data/.rspec +3 -0
- data/.travis.yml +7 -0
- data/Gemfile +6 -0
- data/README.md +1 -0
- data/Rakefile +6 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/lib/maropost-api.rb +78 -0
- data/lib/maropost_api/ab_test_campaigns.rb +48 -0
- data/lib/maropost_api/campaigns.rb +148 -0
- data/lib/maropost_api/contacts.rb +312 -0
- data/lib/maropost_api/custom_types/operation_result.rb +17 -0
- data/lib/maropost_api/custom_types/order_item.rb +24 -0
- data/lib/maropost_api/journeys.rb +137 -0
- data/lib/maropost_api/products_and_revenue.rb +140 -0
- data/lib/maropost_api/relational_tables.rb +91 -0
- data/lib/maropost_api/reports.rb +176 -0
- data/lib/maropost_api/transactional_campaigns.rb +80 -0
- data/lib/maropost_api/version.rb +3 -0
- data/maropost_api.gemspec +43 -0
- metadata +124 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 6c8b9f2f1503cbd2b23c828357d4098e86c97cb5
|
4
|
+
data.tar.gz: feba6fc5c7543817116193751fce70161e3450ef
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 79feafdbae51a52c30f3ab2aa7768480238c5ba5e82bac7d4aecc121b1970d4636a6657dee5f47ca7f4ca6ba021ade3b8c10c88d2bf39cad307715def930004a
|
7
|
+
data.tar.gz: f2fa7ff178b79dff8658fe36603874ef60a57f6989e25581eaf4914d661a12e2aa669f7f34cb7c7cf0d940d0a72f936a358f6808049477affb2502aa09bc8219
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/README.md
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
# marketing-ruby
|
data/Rakefile
ADDED
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "maropost_api"
|
5
|
+
|
6
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
7
|
+
# with your gem easier. You can also use a different console, if you like.
|
8
|
+
|
9
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
10
|
+
# require "pry"
|
11
|
+
# Pry.start
|
12
|
+
|
13
|
+
require "irb"
|
14
|
+
IRB.start(__FILE__)
|
data/bin/setup
ADDED
data/lib/maropost-api.rb
ADDED
@@ -0,0 +1,78 @@
|
|
1
|
+
require "maropost_api/version"
|
2
|
+
require 'uri'
|
3
|
+
require "maropost_api/campaigns"
|
4
|
+
require "maropost_api/contacts"
|
5
|
+
require "maropost_api/journeys"
|
6
|
+
require "maropost_api/products_and_revenue"
|
7
|
+
require "maropost_api/custom_types/operation_result"
|
8
|
+
require "maropost_api/ab_test_campaigns"
|
9
|
+
require "maropost_api/reports"
|
10
|
+
require "maropost_api/relational_tables"
|
11
|
+
require "maropost_api/transactional_campaigns"
|
12
|
+
require "httparty"
|
13
|
+
|
14
|
+
##
|
15
|
+
# This package provides programmatic access to several Maropost services. It consists of eight services within the MaropostApi
|
16
|
+
# namespace. Each service consists of one or more functions that perform an operation against your Maropost account. These methods
|
17
|
+
# return a result object indicating success/failure, any Exceptions thrown, and the resulting data. The detailed documentation of the
|
18
|
+
# api can be found in http://api.maropost.com/api
|
19
|
+
#
|
20
|
+
module MaropostApi
|
21
|
+
include HTTParty
|
22
|
+
# debug_output $stdout
|
23
|
+
include URI
|
24
|
+
format :json
|
25
|
+
base_uri 'https://api.maropost.com'
|
26
|
+
|
27
|
+
attr_accessor :api_key
|
28
|
+
attr_accessor :account
|
29
|
+
|
30
|
+
class Error < StandardError; end
|
31
|
+
|
32
|
+
def self.get_result(path, options)
|
33
|
+
full_path = path << ".#{format.to_s}"
|
34
|
+
result = get(full_path, options)
|
35
|
+
|
36
|
+
OperationResult.new(result)
|
37
|
+
end
|
38
|
+
|
39
|
+
def self.post_result(path, form_body)
|
40
|
+
raise ArgumentError "path and form_body cannot be nil" if path.nil? || form_body.nil?
|
41
|
+
full_path = path << ".#{format.to_s}"
|
42
|
+
# set auth_token manually due to 400 error when sent via parameters
|
43
|
+
full_path = full_path << "?auth_token=#{@api_key}"
|
44
|
+
result = post(full_path, :body => form_body.to_json, :headers => {"Content-Type" => 'application/json'})
|
45
|
+
|
46
|
+
OperationResult.new(result)
|
47
|
+
end
|
48
|
+
|
49
|
+
def self.put_result(path, form_body = {}, query_params = {})
|
50
|
+
raise ArgumentError "path and form_body cannot be nil" if path.nil? || form_body.nil?
|
51
|
+
full_path = path << ".#{format.to_s}"
|
52
|
+
query_params = set_query_params if query_params.empty?
|
53
|
+
result = put(full_path, :body => form_body.to_json, :headers => {"Content-Type" => 'application/json', 'Accept' => 'application/json'}, :query => query_params[:query])
|
54
|
+
|
55
|
+
OperationResult.new(result)
|
56
|
+
end
|
57
|
+
|
58
|
+
def self.delete_result(path, query_params, body={})
|
59
|
+
raise ArgumentError "path and query_params cannot be nil" if path.nil? || query_params.nil?
|
60
|
+
full_path = path << ".#{format.to_s}"
|
61
|
+
result = delete(full_path, :headers => {"Content-Type" => 'application/json'}, :query => query_params[:query], :body => body.to_json)
|
62
|
+
|
63
|
+
OperationResult.new(result)
|
64
|
+
end
|
65
|
+
|
66
|
+
def self.set_query_params(query_params = {})
|
67
|
+
return nil if query_params.class != Hash
|
68
|
+
@query_params ||= {
|
69
|
+
query: {auth_token: @api_key}
|
70
|
+
}
|
71
|
+
additional_params = { query: query_params }
|
72
|
+
|
73
|
+
@query_params.merge(additional_params) do |key, qp_val, ap_val|
|
74
|
+
qp_val.merge ap_val
|
75
|
+
end
|
76
|
+
end
|
77
|
+
|
78
|
+
end
|
@@ -0,0 +1,48 @@
|
|
1
|
+
module MaropostApi
|
2
|
+
|
3
|
+
class AbTestCampaigns
|
4
|
+
|
5
|
+
def initialize(account = ENV["ACCOUNT"], api_key = ENV["API_KEY"])
|
6
|
+
MaropostApi.instance_variable_set(:@api_key, api_key)
|
7
|
+
MaropostApi.instance_variable_set(:@account, account)
|
8
|
+
end
|
9
|
+
|
10
|
+
def create_ab_test(
|
11
|
+
name:,
|
12
|
+
from_email:,
|
13
|
+
address:,
|
14
|
+
language:,
|
15
|
+
campaign_groups_attributes:,
|
16
|
+
commit:,
|
17
|
+
sendAt:,
|
18
|
+
brand_id: nil,
|
19
|
+
suppressed_list_ids: [],
|
20
|
+
suppressed_journey_ids: [],
|
21
|
+
suppressed_segment_ids: [],
|
22
|
+
email_preview_link: nil,
|
23
|
+
decided_by: nil,
|
24
|
+
lists: [],
|
25
|
+
ctags: [],
|
26
|
+
segments: []
|
27
|
+
)
|
28
|
+
args = method(__method__).parameters
|
29
|
+
body = {:ab_test => {}}
|
30
|
+
args.each do |arg|
|
31
|
+
k = arg[1].to_s
|
32
|
+
v = eval(k)
|
33
|
+
body[:ab_test][k] = v unless v.nil?
|
34
|
+
end
|
35
|
+
|
36
|
+
full_path = full_resource_path('/ab_test')
|
37
|
+
|
38
|
+
MaropostApi.post_result(full_path, :body => {campaign: body[:ab_test]})
|
39
|
+
end
|
40
|
+
|
41
|
+
private
|
42
|
+
|
43
|
+
def full_resource_path(specifics = '', root_resource = "campaigns")
|
44
|
+
account = MaropostApi.instance_variable_get(:@account)
|
45
|
+
"/accounts/#{account}/#{root_resource}" << specifics
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
@@ -0,0 +1,148 @@
|
|
1
|
+
module MaropostApi
|
2
|
+
|
3
|
+
##
|
4
|
+
# Contains methods that get various Campaign Reports based on provided parameters.
|
5
|
+
# The method names themselves reveal the type of reports they are getting.
|
6
|
+
class Campaigns
|
7
|
+
##
|
8
|
+
# Creates a new instance of Reports class.
|
9
|
+
# @param account [Integer] is authentic user account id (Integer) provided by maropost.com
|
10
|
+
# @param api_key [String] is the auth token (String) that is validated on the server to authenticate the user
|
11
|
+
def initialize(account = ENV["ACCOUNT"], api_key = ENV["API_KEY"])
|
12
|
+
MaropostApi.instance_variable_set(:@api_key, api_key)
|
13
|
+
MaropostApi.instance_variable_set(:@account, account)
|
14
|
+
end
|
15
|
+
|
16
|
+
##
|
17
|
+
# gets all the campaigns grouped by
|
18
|
+
# @param page (Integer) number that determines which page of the result to retrieve
|
19
|
+
def get(page)
|
20
|
+
full_path = full_resource_path('')
|
21
|
+
query_params = MaropostApi.set_query_params({page: page})
|
22
|
+
|
23
|
+
MaropostApi.get_result(full_path, query_params)
|
24
|
+
end
|
25
|
+
|
26
|
+
##
|
27
|
+
# gets a campaign determined by the provided
|
28
|
+
# @param campaign_id [Integer] Unique identifier of campaigns
|
29
|
+
def get_campaign(campaign_id)
|
30
|
+
full_path = full_resource_path("/#{campaign_id}")
|
31
|
+
query_params = MaropostApi.set_query_params()
|
32
|
+
|
33
|
+
MaropostApi.get_result(full_path, query_params)
|
34
|
+
end
|
35
|
+
|
36
|
+
##
|
37
|
+
# gets bounce reports for the provided
|
38
|
+
# @param campaign_id [Integer] Unique id of campaign
|
39
|
+
# @param page [Integer] number that decides which page of result to get
|
40
|
+
def get_bounce_reports(campaign_id, page)
|
41
|
+
full_path = full_resource_path("/#{campaign_id}/bounce_report")
|
42
|
+
query_params = MaropostApi.set_query_params({page:page})
|
43
|
+
|
44
|
+
MaropostApi.get_result(full_path, query_params)
|
45
|
+
end
|
46
|
+
|
47
|
+
##
|
48
|
+
# gets click reports for the provided
|
49
|
+
# @param campaign_id [Integer] Unique id of campaign
|
50
|
+
# @param page [Integer] number that decides which page of result to get
|
51
|
+
# @param unique [Boolean] decides whether to retrive unique reports or not
|
52
|
+
def get_click_reports(campaign_id, page, unique = nil)
|
53
|
+
full_path = full_resource_path("/#{campaign_id}/click_report")
|
54
|
+
query_params = MaropostApi.set_query_params({page: page})
|
55
|
+
query_params[:query][:unique] = unique unless unique.nil?
|
56
|
+
|
57
|
+
MaropostApi.get_result(full_path, query_params)
|
58
|
+
end
|
59
|
+
|
60
|
+
##
|
61
|
+
# gets complaint reports for the provided
|
62
|
+
# @param campaign_id [Integer] Unique id of campaign
|
63
|
+
# param page [Integer] number that decides which page of result to get
|
64
|
+
def get_complaint_reports(campaign_id, page)
|
65
|
+
full_path = full_resource_path("/#{campaign_id}/complaint_report")
|
66
|
+
query_params = MaropostApi.set_query_params({page: page})
|
67
|
+
|
68
|
+
MaropostApi.get_result(full_path, query_params)
|
69
|
+
end
|
70
|
+
|
71
|
+
##
|
72
|
+
# gets delivered reports for the provided
|
73
|
+
# @param campaign_id [Integer] Unique id of campaign
|
74
|
+
# param page [Integer] number that decides which page of result to get
|
75
|
+
def get_delivered_reports(campaign_id, page)
|
76
|
+
full_path = full_resource_path("/#{campaign_id}/delivered_report")
|
77
|
+
query_params = MaropostApi.set_query_params({page: page})
|
78
|
+
|
79
|
+
MaropostApi.get_result(full_path, query_params)
|
80
|
+
end
|
81
|
+
|
82
|
+
##
|
83
|
+
# gets hard bounce reports for the provided
|
84
|
+
# @param campaign_id [Integer] Unique id of campaign
|
85
|
+
# param page [Integer] number that decides which page of result to get
|
86
|
+
def get_hard_bounce_reports(campaign_id, page)
|
87
|
+
full_path = full_resource_path("/#{campaign_id}/hard_bounce_report")
|
88
|
+
query_params = MaropostApi.set_query_params({page: page})
|
89
|
+
|
90
|
+
MaropostApi.get_result(full_path, query_params)
|
91
|
+
end
|
92
|
+
|
93
|
+
##
|
94
|
+
# gets soft bounce reports for the provided
|
95
|
+
# @param campaign_id [Integer] Unique id of campaign
|
96
|
+
# param page [Integer] number that decides which page of result to get
|
97
|
+
def get_soft_bounce_reports(campaign_id, page)
|
98
|
+
full_path = full_resource_path("/#{campaign_id}/soft_bounce_report")
|
99
|
+
query_params = MaropostApi.set_query_params({page: page})
|
100
|
+
|
101
|
+
MaropostApi.get_result(full_path, query_params)
|
102
|
+
end
|
103
|
+
|
104
|
+
##
|
105
|
+
# gets open reports for the provided
|
106
|
+
# @param campaign_id [Integer] Unique id of campaign
|
107
|
+
# param page [Integer] number that decides which page of result to get
|
108
|
+
# @param unique [Boolean] decides whether to retrive unique reports or not
|
109
|
+
def get_open_reports(campaign_id, page, unique = nil)
|
110
|
+
full_path = full_resource_path("/#{campaign_id}/open_report")
|
111
|
+
query_params = MaropostApi.set_query_params({page: page})
|
112
|
+
query_params[:query][:unique] = unique unless unique.nil?
|
113
|
+
|
114
|
+
MaropostApi.get_result(full_path, query_params)
|
115
|
+
end
|
116
|
+
|
117
|
+
##
|
118
|
+
# gets unsubscribe reports for the provided
|
119
|
+
# @param campaign_id [Integer] Unique id of campaign
|
120
|
+
# param page [Integer] number that decides which page of result to get
|
121
|
+
def get_unsubscribe_reports(campaign_id, page)
|
122
|
+
full_path = full_resource_path("/#{campaign_id}/unsubscribe_report")
|
123
|
+
query_params = MaropostApi.set_query_params({page: page})
|
124
|
+
|
125
|
+
MaropostApi.get_result(full_path, query_params)
|
126
|
+
end
|
127
|
+
|
128
|
+
##
|
129
|
+
# gets link reports for the provided
|
130
|
+
# @param campaign_id [Integer] Unique id of campaign
|
131
|
+
# param page [Integer] number that decides which page of result to get
|
132
|
+
def get_link_reports(campaign_id, page, unique = nil)
|
133
|
+
full_path = full_resource_path("/#{campaign_id}/link_report")
|
134
|
+
query_params = MaropostApi.set_query_params({page: page})
|
135
|
+
query_params[:query][:unique] = unique unless unique.nil?
|
136
|
+
|
137
|
+
MaropostApi.get_result(full_path, query_params)
|
138
|
+
end
|
139
|
+
|
140
|
+
private
|
141
|
+
|
142
|
+
def full_resource_path(specifics = '')
|
143
|
+
account = MaropostApi.instance_variable_get(:@account)
|
144
|
+
"/accounts/#{account}/campaigns" << specifics
|
145
|
+
end
|
146
|
+
end
|
147
|
+
|
148
|
+
end
|
@@ -0,0 +1,312 @@
|
|
1
|
+
module MaropostApi
|
2
|
+
##
|
3
|
+
# Contains methods that get Contacts based on provided parameters.
|
4
|
+
# The method names themselves reveal the type of reports they are getting.
|
5
|
+
class Contacts
|
6
|
+
##
|
7
|
+
# Creates a new instance of Reports class.
|
8
|
+
# @param account [Integer] is authentic user account id (Integer) provided by maropost.com
|
9
|
+
# @param api_key [String] is the auth token (String) that is validated on the server to authenticate the user
|
10
|
+
def initialize(account = ENV["ACCOUNT"], api_key = ENV["API_KEY"])
|
11
|
+
MaropostApi.instance_variable_set(:@api_key, api_key)
|
12
|
+
MaropostApi.instance_variable_set(:@account, account)
|
13
|
+
end
|
14
|
+
|
15
|
+
##
|
16
|
+
# gets contact for the provided
|
17
|
+
# @param email [String] must be an email
|
18
|
+
def get_for_email(email)
|
19
|
+
full_path = full_resource_path("/email")
|
20
|
+
query_params = MaropostApi.set_query_params({"contact[email]" => email})
|
21
|
+
|
22
|
+
MaropostApi.get_result(full_path, query_params)
|
23
|
+
end
|
24
|
+
|
25
|
+
##
|
26
|
+
# gets opens for the provided
|
27
|
+
# @param contact_id [Integer] unique id of the contact
|
28
|
+
# @param page [Integer] number that decides which page or result to retrieve
|
29
|
+
def get_opens(contact_id, page)
|
30
|
+
full_path = full_resource_path("/#{contact_id}/open_report")
|
31
|
+
query_params = MaropostApi.set_query_params({page: page})
|
32
|
+
|
33
|
+
MaropostApi.get_result(full_path, query_params)
|
34
|
+
end
|
35
|
+
|
36
|
+
##
|
37
|
+
# gets clicks for the provided
|
38
|
+
# @param contact_id [Integer] unique id of the contact
|
39
|
+
# @param page [Integer] number that decides which page or result to retrieve
|
40
|
+
def get_clicks(contact_id, page)
|
41
|
+
full_path = full_resource_path("/#{contact_id}/click_report")
|
42
|
+
query_params = MaropostApi.set_query_params({page: page})
|
43
|
+
|
44
|
+
MaropostApi.get_result(full_path, query_params)
|
45
|
+
end
|
46
|
+
|
47
|
+
##
|
48
|
+
# gets contacts for the provided
|
49
|
+
# @param list_id [Integer] unique id of the list
|
50
|
+
# @param page [Integer] number that decides which page or result to retrieve
|
51
|
+
def get_for_list(list_id, page)
|
52
|
+
full_path = full_resource_path("/#{list_id}/contacts", 'lists')
|
53
|
+
query_params = MaropostApi.set_query_params({page: page})
|
54
|
+
|
55
|
+
MaropostApi.get_result(full_path, query_params)
|
56
|
+
end
|
57
|
+
|
58
|
+
##
|
59
|
+
# gets contacts for the provided
|
60
|
+
# @param list_id [Integer] unique id of the list
|
61
|
+
# @param contact_id [Integer] unique contact id
|
62
|
+
def get_contact_for_list(list_id, contact_id)
|
63
|
+
full_path = full_resource_path("/#{list_id}/contacts/#{contact_id}", 'lists')
|
64
|
+
query_params = MaropostApi.set_query_params
|
65
|
+
|
66
|
+
MaropostApi.get_result(full_path, query_params)
|
67
|
+
end
|
68
|
+
|
69
|
+
##
|
70
|
+
# creates a contact
|
71
|
+
# @param email [String] must be an email
|
72
|
+
# @param first_name [String] Contact First Name
|
73
|
+
# @param last_name [String] Contact Last Name
|
74
|
+
# @param phone [String] Contact's phone number
|
75
|
+
# @param fax [String] Contacts' fax number
|
76
|
+
# @param uid [String] Unique identifier
|
77
|
+
# @param custom_field [Hash] list of custom_fields addable for the new contact
|
78
|
+
# @param add_tags [Array] list of tags to be added to the contact
|
79
|
+
# @param remove_tags [Array] list of tags to be removed from the contact
|
80
|
+
# @param remove_from_dnm [Boolean] decides whether to remove contact from dnm or not
|
81
|
+
# @param options [Hash] Key value pairs containing other different properties for the new contact
|
82
|
+
def create_contact(
|
83
|
+
email,
|
84
|
+
first_name,
|
85
|
+
last_name,
|
86
|
+
phone,
|
87
|
+
fax,
|
88
|
+
uid = nil,
|
89
|
+
custom_field = {},
|
90
|
+
add_tags = [],
|
91
|
+
remove_tags = [],
|
92
|
+
remove_from_dnm = false,
|
93
|
+
**options
|
94
|
+
)
|
95
|
+
args = method(__method__).parameters
|
96
|
+
body = {contact: {}}
|
97
|
+
args.each do |arg|
|
98
|
+
k = arg[1].to_s
|
99
|
+
v = eval(k)
|
100
|
+
body[:contact][k] = v unless v.nil?
|
101
|
+
end
|
102
|
+
# p body
|
103
|
+
path = full_resource_path()
|
104
|
+
|
105
|
+
MaropostApi.post_result(path, body)
|
106
|
+
end
|
107
|
+
|
108
|
+
##
|
109
|
+
# creates a contact
|
110
|
+
# @param list_id [Integer] id of the list for which to update/create contact
|
111
|
+
# @param email [String] must be an email
|
112
|
+
# @param first_name [String] Contact First Name
|
113
|
+
# @param last_name [String] Contact Last Name
|
114
|
+
# @param phone [String] Contact's phone number
|
115
|
+
# @param fax [String] Contacts' fax number
|
116
|
+
# @param uid [String] Unique identifier
|
117
|
+
# @param custom_field [Hash] list of custom_fields addable for the new contact
|
118
|
+
# @param add_tags [Array] list of tags to be added to the contact
|
119
|
+
# @param remove_tags [Array] list of tags to be removed from the contact
|
120
|
+
# @param remove_from_dnm [Boolean] decides whether to remove contact from dnm or not
|
121
|
+
# @param subscribe [Boolean] Flags the new contact as subscribed
|
122
|
+
def create_or_update_for_list(
|
123
|
+
list_id,
|
124
|
+
email,
|
125
|
+
first_name,
|
126
|
+
last_name,
|
127
|
+
phone,
|
128
|
+
fax,
|
129
|
+
uid = nil,
|
130
|
+
custom_field = {},
|
131
|
+
add_tags = [],
|
132
|
+
remove_tags = [],
|
133
|
+
remove_from_dnm = true,
|
134
|
+
subscribe = true
|
135
|
+
)
|
136
|
+
args = method(__method__).parameters
|
137
|
+
body = {contact: {}}
|
138
|
+
args.each do |arg|
|
139
|
+
k = arg[1].to_s
|
140
|
+
next if k == "list_id"
|
141
|
+
v = eval(k)
|
142
|
+
body[:contact][k] = v unless v.nil?
|
143
|
+
end
|
144
|
+
|
145
|
+
email_existence = get_for_email(email)
|
146
|
+
if email_existence.success
|
147
|
+
contact_id = email_existence.data["id"]
|
148
|
+
full_path = full_resource_path("/#{list_id}/contacts/#{contact_id}", "lists")
|
149
|
+
|
150
|
+
MaropostApi.put_result(full_path, body)
|
151
|
+
else
|
152
|
+
full_path = full_resource_path("/#{list_id}/contacts", "lists")
|
153
|
+
|
154
|
+
MaropostApi.post_result(full_path, body)
|
155
|
+
end
|
156
|
+
|
157
|
+
end
|
158
|
+
|
159
|
+
##
|
160
|
+
# creates a contact
|
161
|
+
# @param email [String] must be an email
|
162
|
+
# @param first_name [String] Contact First Name
|
163
|
+
# @param last_name [String] Contact Last Name
|
164
|
+
# @param phone [String] Contact's phone number
|
165
|
+
# @param fax [String] Contacts' fax number
|
166
|
+
# @param uid [String] Unique identifier
|
167
|
+
# @param custom_field [Hash] list of custom_fields addable for the new contact
|
168
|
+
# @param add_tags [Array] list of tags to be added to the contact
|
169
|
+
# @param remove_tags [Array] list of tags to be removed from the contact
|
170
|
+
# @param remove_from_dnm [Boolean] decides whether to remove contact from dnm or not
|
171
|
+
# @param options [Hash] Key value pairs containing other different properties for the new contact
|
172
|
+
def create_or_update_for_lists_and_workflows(
|
173
|
+
email,
|
174
|
+
first_name,
|
175
|
+
last_name,
|
176
|
+
phone,
|
177
|
+
fax,
|
178
|
+
uid = nil,
|
179
|
+
custom_field = {},
|
180
|
+
add_tags = [],
|
181
|
+
remove_tags = [],
|
182
|
+
remove_from_dnm = true,
|
183
|
+
**options
|
184
|
+
)
|
185
|
+
args = method(__method__).parameters
|
186
|
+
body = {contact: {}}
|
187
|
+
args.each do |arg|
|
188
|
+
k = arg[1].to_s
|
189
|
+
v = eval(k)
|
190
|
+
body[:contact][k] = v unless v.nil?
|
191
|
+
end
|
192
|
+
|
193
|
+
email_existence = get_for_email email
|
194
|
+
if email_existence.success
|
195
|
+
contact_id = email_existence.data["id"]
|
196
|
+
full_path = full_resource_path("/#{contact_id}")
|
197
|
+
body[:contact].delete("options")
|
198
|
+
body[:contact]["subscribe"] = options[:subscribe] if options.has_key? :subscribe
|
199
|
+
|
200
|
+
MaropostApi.put_result(full_path, body)
|
201
|
+
else
|
202
|
+
full_path = full_resource_path
|
203
|
+
|
204
|
+
MaropostApi.post_result(full_path, body)
|
205
|
+
end
|
206
|
+
|
207
|
+
end
|
208
|
+
|
209
|
+
##
|
210
|
+
# creates a contact
|
211
|
+
# @param list_id [Integer] id of the list for which to update/create contact
|
212
|
+
# @param email [String] must be an email
|
213
|
+
# @param first_name [String] Contact First Name
|
214
|
+
# @param last_name [String] Contact Last Name
|
215
|
+
# @param phone [String] Contact's phone number
|
216
|
+
# @param fax [String] Contacts' fax number
|
217
|
+
# @param uid [String] Unique identifier
|
218
|
+
# @param custom_field [Hash] list of custom_fields addable for the new contact
|
219
|
+
# @param add_tags [Array] list of tags to be added to the contact
|
220
|
+
# @param remove_tags [Array] list of tags to be removed from the contact
|
221
|
+
# @param remove_from_dnm [Boolean] decides whether to remove contact from dnm or not
|
222
|
+
# @param subscribe [Boolean] Flags the new contact as subscribed
|
223
|
+
def update_for_list_and_contact(
|
224
|
+
list_id,
|
225
|
+
contact_id,
|
226
|
+
email,
|
227
|
+
first_name,
|
228
|
+
last_name,
|
229
|
+
phone,
|
230
|
+
fax,
|
231
|
+
uid = nil,
|
232
|
+
custom_field = {},
|
233
|
+
add_tags = [],
|
234
|
+
remove_tags = [],
|
235
|
+
remove_from_dnm = true,
|
236
|
+
subscribe = true
|
237
|
+
)
|
238
|
+
args = method(__method__).parameters
|
239
|
+
body = {contact: {}}
|
240
|
+
args.each do |arg|
|
241
|
+
k = arg[1].to_s
|
242
|
+
next if ["list_id", "contact_id"].include? k
|
243
|
+
v = eval(k)
|
244
|
+
body[:contact][k] = v unless v.nil?
|
245
|
+
end
|
246
|
+
|
247
|
+
full_path = full_resource_path("/#{list_id}/contacts/#{contact_id}", "lists")
|
248
|
+
|
249
|
+
MaropostApi.put_result(full_path, body)
|
250
|
+
end
|
251
|
+
|
252
|
+
##
|
253
|
+
# unsubscribes all those contacts matching
|
254
|
+
# @param contact_field_value [String|Integer] the value of the contact field name
|
255
|
+
# @param contact_field_name [String|Integer] the name of the field to query the contact for
|
256
|
+
def unsubscribe_all(contact_field_value, contact_field_name)
|
257
|
+
full_path = full_resource_path('/unsubscribe_all')
|
258
|
+
query_params = MaropostApi.set_query_params({"contact[#{contact_field_name}]" => contact_field_value})
|
259
|
+
|
260
|
+
MaropostApi.put_result(full_path, {}, query_params)
|
261
|
+
end
|
262
|
+
|
263
|
+
##
|
264
|
+
# deletes contact from all the lists
|
265
|
+
# @param email [String] gets deleted if matches the value provided
|
266
|
+
def delete_from_all_lists(email)
|
267
|
+
full_path = full_resource_path('/delete_all')
|
268
|
+
query_params = MaropostApi.set_query_params({"contact[email]" => email})
|
269
|
+
|
270
|
+
MaropostApi.delete_result(full_path, query_params)
|
271
|
+
end
|
272
|
+
|
273
|
+
##
|
274
|
+
# deletes contact from list
|
275
|
+
# @param contact_id [Integer] Contact id to delete
|
276
|
+
# @param list_to_delete_from [Integer] List id
|
277
|
+
def delete_from_lists(contact_id, lists_to_delete_from)
|
278
|
+
full_path = full_resource_path("/#{contact_id}")
|
279
|
+
query_params = MaropostApi.set_query_params({'list_ids' => lists_to_delete_from.join(',')})
|
280
|
+
|
281
|
+
MaropostApi.delete_result(full_path, query_params)
|
282
|
+
end
|
283
|
+
|
284
|
+
##
|
285
|
+
# deletes contact for uid
|
286
|
+
# @param uid [String] unique identifier
|
287
|
+
def delete_contact_for_uid(uid)
|
288
|
+
full_path = full_resource_path("/delete_all")
|
289
|
+
query_params = MaropostApi.set_query_params({"uid" => uid})
|
290
|
+
|
291
|
+
MaropostApi.delete_result(full_path, query_params)
|
292
|
+
end
|
293
|
+
|
294
|
+
##
|
295
|
+
# deletes list for the given contact
|
296
|
+
# @param list_id [Integer] List ID
|
297
|
+
# @param contact_id [Integer] Contact ID
|
298
|
+
def delete_list_contact(list_id, contact_id)
|
299
|
+
full_path = full_resource_path("/#{list_id}/contacts/#{contact_id}", "lists")
|
300
|
+
query_params = MaropostApi.set_query_params
|
301
|
+
|
302
|
+
MaropostApi.delete_result(full_path, query_params)
|
303
|
+
end
|
304
|
+
|
305
|
+
private
|
306
|
+
|
307
|
+
def full_resource_path(specifics = '', root_resource = 'contacts')
|
308
|
+
account = MaropostApi.instance_variable_get(:@account)
|
309
|
+
"/accounts/#{account}/#{root_resource}" << specifics
|
310
|
+
end
|
311
|
+
end
|
312
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
class OperationResult
|
2
|
+
attr_accessor :errors, :success, :data
|
3
|
+
def initialize(result)
|
4
|
+
if (200..206).to_a.include? result.code
|
5
|
+
@success = true
|
6
|
+
@errors = nil
|
7
|
+
@data = JSON.parse([result.body].to_json).first
|
8
|
+
@data = JSON.parse(@data) if @data.kind_of? String and @data.start_with?("{", "[")
|
9
|
+
@data = nil if @data == ""
|
10
|
+
else
|
11
|
+
@success = false
|
12
|
+
@errors = JSON.parse(JSON.parse([result.body].to_json).first) if result.code != 404
|
13
|
+
@errors = nil if @errors == ""
|
14
|
+
@errors['message'] = 'Page not found!' if result.code == 404
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|