expresspigeon-ruby 0.0.9 → 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.gitignore +0 -4
- data/Gemfile.lock +2 -2
- data/README.md +1 -22
- data/expresspigeon-ruby.gemspec +2 -2
- data/lib/expresspigeon-ruby.rb +28 -15
- data/lib/expresspigeon-ruby/auto_responders.rb +6 -41
- data/lib/expresspigeon-ruby/campaigns.rb +0 -8
- data/lib/expresspigeon-ruby/contacts.rb +0 -1
- data/lib/expresspigeon-ruby/lists.rb +0 -7
- data/lib/expresspigeon-ruby/messages.rb +6 -91
- data/lib/expresspigeon-ruby/version.rb +1 -1
- data/spec/campaigns_spec.rb +46 -68
- data/spec/contacts_spec.rb +38 -38
- data/spec/lists_spec.rb +32 -50
- data/spec/messages_spec.rb +9 -42
- data/spec/pigeon_helper.rb +2 -0
- data/spec/templates_spec.rb +2 -2
- data/test/send.rb +5 -15
- metadata +5 -16
- data/spec/autoresponders_spec.rb +0 -46
- data/test/README +0 -25
- data/test/attachments/example.ics +0 -32
- data/test/attachments/smile.pdf +0 -0
- data/test/send_with_attachments.rb +0 -22
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d3531f1f4bb4e7b172a5529c14fb7ff4135fae0f
|
4
|
+
data.tar.gz: 7656345b121e756d514a4827815d917d4f9015a3
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e523bae70bab3fb65377dd6336bba0542ad8ac0780b62e240187bd1153f277aefca9b55c6992fcb45f54515642311f775b14e1d4ca310bbb8a76da85599dfddd
|
7
|
+
data.tar.gz: a7b7c9626ea4a95469d8b3b9ab6a07c647c1a5fa50c5cbab530fab6a4f4e249a6544283467a0b1b03c516cba41b56a49768bb3b4c8cbd814558693567fa689c8
|
data/.gitignore
CHANGED
data/Gemfile.lock
CHANGED
data/README.md
CHANGED
@@ -16,7 +16,7 @@ Or install it yourself as:
|
|
16
16
|
|
17
17
|
$ gem install expresspigeon-ruby
|
18
18
|
|
19
|
-
##
|
19
|
+
## Usage
|
20
20
|
|
21
21
|
Sending a transactional message is easy:
|
22
22
|
|
@@ -40,27 +40,6 @@ sleep 5
|
|
40
40
|
puts MESSAGES.report message_response.id
|
41
41
|
```
|
42
42
|
|
43
|
-
## Sending a message with attachments
|
44
|
-
|
45
|
-
```ruby
|
46
|
-
MESSAGES = ExpressPigeon::API.messages.auth_key(ENV['AUTH_KEY'])
|
47
|
-
|
48
|
-
attachments = %W{attachments/attachment1.txt attachments/smile.pdf attachments/example.ics}
|
49
|
-
|
50
|
-
puts MESSAGES.send_message(
|
51
|
-
123, # template_id
|
52
|
-
'john@doe.com', #to
|
53
|
-
'jane@doe.com', #reply_to
|
54
|
-
"Jane Doe", #from_name
|
55
|
-
"Want to get out for a dinner?", #subject
|
56
|
-
{first_name: 'John', main_course: 'stake'}, #merge_fields
|
57
|
-
false, #view_online
|
58
|
-
true, #click_tracking
|
59
|
-
true, #suppress_address
|
60
|
-
attachments #file paths to upload as attachments
|
61
|
-
)
|
62
|
-
|
63
|
-
```
|
64
43
|
|
65
44
|
## Contributing
|
66
45
|
|
data/expresspigeon-ruby.gemspec
CHANGED
@@ -17,7 +17,7 @@ Gem::Specification.new do |gem|
|
|
17
17
|
gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
|
18
18
|
gem.require_paths = ["lib"]
|
19
19
|
|
20
|
-
gem.add_runtime_dependency 'rest-client', '~> 1.8'
|
20
|
+
gem.add_runtime_dependency 'rest-client', '~> 1.8.0'
|
21
|
+
|
21
22
|
gem.add_development_dependency "rspec", "~> 2.6"
|
22
|
-
gem.licenses = ['MIT']
|
23
23
|
end
|
data/lib/expresspigeon-ruby.rb
CHANGED
@@ -8,9 +8,7 @@ require 'rest_client'
|
|
8
8
|
module ExpressPigeon
|
9
9
|
|
10
10
|
AUTH_KEY = ENV['EXPRESSPIGEON_AUTH_KEY']
|
11
|
-
|
12
|
-
# EXPRESSPIGEON_ROOT env var is used to point to testenv
|
13
|
-
ROOT = ENV.has_key?('EXPRESSPIGEON_ROOT') ? ENV['EXPRESSPIGEON_ROOT'] : 'https://api.expresspigeon.com/'
|
11
|
+
ROOT = 'https://api.expresspigeon.com/'
|
14
12
|
USE_SSL = true
|
15
13
|
|
16
14
|
module API
|
@@ -21,6 +19,14 @@ module ExpressPigeon
|
|
21
19
|
self
|
22
20
|
end
|
23
21
|
|
22
|
+
def open_timeout=(timeout)
|
23
|
+
@open_timeout = timeout
|
24
|
+
end
|
25
|
+
|
26
|
+
def read_timeout=(timeout)
|
27
|
+
@read_timeout = timeout
|
28
|
+
end
|
29
|
+
|
24
30
|
def root(root)
|
25
31
|
@root = root
|
26
32
|
self
|
@@ -47,7 +53,13 @@ module ExpressPigeon
|
|
47
53
|
end
|
48
54
|
|
49
55
|
if block_given?
|
50
|
-
Net::HTTP.start(
|
56
|
+
Net::HTTP.start(
|
57
|
+
uri.host,
|
58
|
+
uri.port,
|
59
|
+
:use_ssl => USE_SSL,
|
60
|
+
:read_timeout => @read_timeout,
|
61
|
+
:open_timeout => @open_timeout,
|
62
|
+
) do |http|
|
51
63
|
http.request req do |res|
|
52
64
|
res.read_body do |seg|
|
53
65
|
yield seg
|
@@ -55,19 +67,20 @@ module ExpressPigeon
|
|
55
67
|
end
|
56
68
|
end
|
57
69
|
else
|
58
|
-
resp = Net::HTTP.start(
|
70
|
+
resp = Net::HTTP.start(
|
71
|
+
uri.host,
|
72
|
+
uri.port,
|
73
|
+
:use_ssl => USE_SSL,
|
74
|
+
:read_timeout => @read_timeout,
|
75
|
+
:open_timeout => @open_timeout,
|
76
|
+
) do |http|
|
59
77
|
http.request req
|
60
78
|
end
|
61
|
-
|
62
|
-
if
|
63
|
-
parsed
|
64
|
-
if parsed.kind_of? Hash
|
65
|
-
MetaResponse.new parsed
|
66
|
-
else
|
67
|
-
parsed
|
68
|
-
end
|
79
|
+
parsed = JSON.parse(resp.body)
|
80
|
+
if parsed.kind_of? Hash
|
81
|
+
MetaResponse.new parsed
|
69
82
|
else
|
70
|
-
|
83
|
+
parsed
|
71
84
|
end
|
72
85
|
end
|
73
86
|
end
|
@@ -108,7 +121,7 @@ module ExpressPigeon
|
|
108
121
|
Messages.new
|
109
122
|
end
|
110
123
|
|
111
|
-
def self.
|
124
|
+
def self.auto_responders
|
112
125
|
AutoResponders.new
|
113
126
|
end
|
114
127
|
|
@@ -12,8 +12,10 @@ module ExpressPigeon
|
|
12
12
|
#
|
13
13
|
# Returns an array of autoresponders.
|
14
14
|
#
|
15
|
+
# Docs: https://expresspigeon.com/api#auto_responders_get_all
|
16
|
+
#
|
15
17
|
def all
|
16
|
-
get
|
18
|
+
get endpoint
|
17
19
|
end
|
18
20
|
|
19
21
|
# Start for a contact
|
@@ -23,9 +25,10 @@ module ExpressPigeon
|
|
23
25
|
# :param auto_responder_id: autoresponder id to be started for a contact
|
24
26
|
# :param email: contact email
|
25
27
|
#
|
28
|
+
# Docs: https://expresspigeon.com/api#auto_responders_start
|
26
29
|
#
|
27
30
|
def start(auto_responder_id, email)
|
28
|
-
post "#{
|
31
|
+
post "#{endpoint}/#{auto_responder_id}/start", email: email
|
29
32
|
end
|
30
33
|
|
31
34
|
# Stop for a contact
|
@@ -38,45 +41,7 @@ module ExpressPigeon
|
|
38
41
|
# Docs: https://expresspigeon.com/api#auto_responders_stop
|
39
42
|
#
|
40
43
|
def stop(auto_responder_id, email)
|
41
|
-
post "#{
|
42
|
-
end
|
43
|
-
|
44
|
-
# Reports for a single responder
|
45
|
-
#
|
46
|
-
# :param auto_responder_id: autoresponder id to be stopped for a contact
|
47
|
-
# :param email: contact email
|
48
|
-
#
|
49
|
-
def report(auto_responder_id)
|
50
|
-
get "#{@endpoint}/#{auto_responder_id}"
|
51
|
-
end
|
52
|
-
|
53
|
-
|
54
|
-
# Reports bounces for autoresponder part
|
55
|
-
#
|
56
|
-
# :param auto_responder_id: autoresponder id to be stopped for a contact
|
57
|
-
# :param auto_responder_part_id: id of the autoresponder part in questions
|
58
|
-
#
|
59
|
-
def bounced(auto_responder_id, autoresponder_part_id)
|
60
|
-
get "#{@endpoint}/#{auto_responder_id}/#{autoresponder_part_id}/bounced"
|
61
|
-
end
|
62
|
-
|
63
|
-
# Reports unsubscribed for autoresponder part
|
64
|
-
#
|
65
|
-
# :param auto_responder_id: autoresponder id to be stopped for a contact
|
66
|
-
# :param auto_responder_part_id: id of the autoresponder part in questions
|
67
|
-
#
|
68
|
-
def unsubscribed(auto_responder_id, autoresponder_part_id)
|
69
|
-
get "#{@endpoint}/#{auto_responder_id}/#{autoresponder_part_id}/unsubscribed"
|
70
|
-
end
|
71
|
-
|
72
|
-
|
73
|
-
# Get spam reports for autoresponder part
|
74
|
-
#
|
75
|
-
# :param auto_responder_id: autoresponder id to be stopped for a contact
|
76
|
-
# :param auto_responder_part_id: id of the autoresponder part in questions
|
77
|
-
#
|
78
|
-
def spam(auto_responder_id, autoresponder_part_id)
|
79
|
-
get "#{@endpoint}/#{auto_responder_id}/#{autoresponder_part_id}/spam"
|
44
|
+
post "#{endpoint}/#{auto_responder_id}/stop", email: email
|
80
45
|
end
|
81
46
|
end
|
82
47
|
end
|
@@ -14,14 +14,6 @@ module ExpressPigeon
|
|
14
14
|
get "#{@endpoint}/#{campaign_id}"
|
15
15
|
end
|
16
16
|
|
17
|
-
def opened(campaign_id)
|
18
|
-
get "#{@endpoint}/#{campaign_id}/opened"
|
19
|
-
end
|
20
|
-
|
21
|
-
def clicked(campaign_id)
|
22
|
-
get "#{@endpoint}/#{campaign_id}/clicked"
|
23
|
-
end
|
24
|
-
|
25
17
|
def bounced(campaign_id)
|
26
18
|
get "#{@endpoint}/#{campaign_id}/bounced"
|
27
19
|
end
|
@@ -33,13 +33,6 @@ module ExpressPigeon
|
|
33
33
|
end
|
34
34
|
|
35
35
|
|
36
|
-
#
|
37
|
-
#:returns: status of upload
|
38
|
-
#
|
39
|
-
def upload_status(list_id)
|
40
|
-
get "#{@endpoint}/upload_status/#{list_id}"
|
41
|
-
end
|
42
|
-
|
43
36
|
##
|
44
37
|
# Removes a list with a given id. A list must be enabled and has no dependent subscriptions and/or scheduled campaigns.
|
45
38
|
#
|
@@ -7,43 +7,19 @@ module ExpressPigeon
|
|
7
7
|
@endpoint = 'messages'
|
8
8
|
end
|
9
9
|
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
# * +to+ - destination email address
|
14
|
-
# * +reply_to+ - return email address
|
15
|
-
# * +from_name+ - name of sender
|
16
|
-
# * +subject+ - subject of email
|
17
|
-
# * +merge fields+ - hash with dynamic values to merge into a template
|
18
|
-
# * +view_online+ - generate "view online" link in the template
|
19
|
-
# * +click_tracking+ - enable/disable click tracking (and URL rewriting)
|
20
|
-
# * +suppress_address+ - enable/disable display of physical address at the bottom of newsletter.
|
21
|
-
# * +attachments+ - array of file paths to attach to email. Size limit: 1k per attachment, maximum 3 attachments.
|
22
|
-
# * +headers+ - hash with headers to include into the message. The header 'Sender' will override a standard behavior of the platform.
|
23
|
-
def send_message(template_id, to, reply_to, from_name, subject, merge_fields = nil, view_online = false,
|
24
|
-
click_tracking = true, suppress_address = false, attachments = nil, headers = nil)
|
25
|
-
if attachments
|
26
|
-
upload(template_id, to, reply_to, from_name, subject, merge_fields, view_online, click_tracking,
|
27
|
-
suppress_address, attachments, headers)
|
28
|
-
else
|
29
|
-
post @endpoint, params = {template_id: template_id, to: to, reply_to: reply_to, from: from_name,
|
30
|
-
subject: subject, merge_fields: merge_fields, view_online: view_online,
|
31
|
-
click_tracking: click_tracking, suppress_address: suppress_address, headers: headers}
|
32
|
-
end
|
10
|
+
def send_message(template_id, to, reply_to, from_name, subject, merge_fields = nil, view_online = false, click_tracking = true)
|
11
|
+
post @endpoint, params = {template_id: template_id, :to => to, reply_to: reply_to, :from => from_name, :subject => subject,
|
12
|
+
:merge_fields => merge_fields, :view_online => view_online, :click_tracking => click_tracking}
|
33
13
|
end
|
34
14
|
|
35
|
-
|
36
|
-
# Retrieve report for a single message.
|
37
|
-
#
|
38
|
-
# * +message_id+ - ID of a message sent previously
|
39
15
|
def report(message_id)
|
40
16
|
get "#{@endpoint}/#{message_id}"
|
41
17
|
end
|
42
18
|
|
43
|
-
# Report for a group of messages in a given time period.
|
44
19
|
#
|
45
|
-
#
|
46
|
-
#
|
20
|
+
#
|
21
|
+
# start_date is instance of Time
|
22
|
+
# end_date is instance of Time
|
47
23
|
def reports(from_id, start_date = nil, end_date = nil)
|
48
24
|
params = []
|
49
25
|
|
@@ -70,68 +46,7 @@ module ExpressPigeon
|
|
70
46
|
end
|
71
47
|
|
72
48
|
get query
|
73
|
-
end
|
74
|
-
|
75
|
-
|
76
|
-
# Sends a transactional message with attachments using ExpressPigeon Rest API.
|
77
|
-
# This method is not used directly, instead use +send_message()+
|
78
|
-
#
|
79
|
-
# * +template_id+ - ID of a template to use for sending
|
80
|
-
# * +to+ - destination email address
|
81
|
-
# * +reply_to+ - return email address
|
82
|
-
# * +from_name+ - name of sender
|
83
|
-
# * +subject+ - subject of email
|
84
|
-
# * +merge fields+ - hash with dynamic values to merge into a template
|
85
|
-
# * +view_online+ - generate "view online" link in the template
|
86
|
-
# * +click_tracking+ - enable/disable click tracking (and URL rewriting)
|
87
|
-
# * +suppress_address+ - enable/disable display of physical address at the bottom of newsletter.
|
88
|
-
# * +attachments+ - array of file paths to attach to email. Size limit: 1k per attachment, maximum 3 attachments.
|
89
|
-
def upload(template_id, to, reply_to, from_name, subject, merge_fields, view_online, click_tracking, suppress_address, attachments, headers)
|
90
|
-
path = "#{@root ? @root : ROOT}/#{@endpoint}"
|
91
|
-
begin
|
92
|
-
payload = prepare_payload(template_id, to, reply_to, from_name, subject, merge_fields, view_online, click_tracking, suppress_address, attachments, headers)
|
93
|
-
request = RestClient::Request.new(
|
94
|
-
:method => :post,
|
95
|
-
:headers => {:'X-auth-key' => get_auth_key},
|
96
|
-
:url => path,
|
97
|
-
:payload => payload)
|
98
|
-
resp = request.execute
|
99
|
-
res = resp.body
|
100
|
-
rescue RestClient::ExceptionWithResponse => err
|
101
|
-
res = err.response
|
102
|
-
end
|
103
|
-
|
104
|
-
parsed = JSON.parse(res)
|
105
|
-
if parsed.kind_of? Hash
|
106
|
-
MetaResponse.new parsed
|
107
|
-
else
|
108
|
-
parsed
|
109
|
-
end
|
110
|
-
end
|
111
|
-
|
112
|
-
|
113
|
-
def prepare_payload(template_id, to, reply_to, from, subject, merge_fields, view_online, click_tracking, suppress_address, attachments, headers)
|
114
|
-
payload = { multipart: true }
|
115
|
-
payload[:template_id] = template_id
|
116
|
-
payload[:to] = to
|
117
|
-
payload[:reply_to] = reply_to
|
118
|
-
payload[:subject] = subject
|
119
|
-
payload[:from] = from
|
120
|
-
payload[:merge_fields] = merge_fields.to_json
|
121
|
-
payload[:headers] = headers.to_json
|
122
|
-
payload[:view_online] = view_online
|
123
|
-
payload[:click_tracking] = click_tracking
|
124
|
-
payload[:suppress_address] = suppress_address
|
125
49
|
|
126
|
-
attachments.each { |attachment|
|
127
|
-
if File.file?(attachment)
|
128
|
-
file = File.basename(attachment)
|
129
|
-
payload[file] = File.new attachment
|
130
|
-
else
|
131
|
-
raise "File #{attachment} does not exist"
|
132
|
-
end
|
133
|
-
}
|
134
|
-
payload
|
135
50
|
end
|
136
51
|
end
|
137
52
|
end
|
data/spec/campaigns_spec.rb
CHANGED
@@ -6,55 +6,55 @@ describe 'campaigns integration test' do
|
|
6
6
|
include PigeonSpecHelper
|
7
7
|
|
8
8
|
it 'should return more than 0 campaign ids' do
|
9
|
-
res =
|
9
|
+
res = PIGEON.campaigns.all
|
10
10
|
res.class.should == Array
|
11
11
|
res.size.should > 0
|
12
12
|
end
|
13
13
|
|
14
14
|
it 'cannot send with missing parameters' do
|
15
|
-
res =
|
16
|
-
|
17
|
-
|
15
|
+
res = PIGEON.campaigns.send(:template_id => 15233, :name => 'API Test campaign',
|
16
|
+
:from_name => 'Igor Polevoy', :reply_to => 'igor@polevoy.org',
|
17
|
+
:subject => 'API test', :google_analytics => true)
|
18
18
|
validate_response res, 400, 'error', /required parameters: list_id, template_id, name, from_name, reply_to, subject, google_analytics/
|
19
19
|
end
|
20
20
|
|
21
21
|
it 'cannot send with bad reply_to' do
|
22
|
-
res =
|
23
|
-
|
22
|
+
res = PIGEON.campaigns.send(:list_id => -1, :template_id => -1, :name => 'My Campaign', :from_name => 'John', :reply_to => 'j',
|
23
|
+
:subject => 'Hi', :google_analytics => false)
|
24
24
|
validate_response res, 400, 'error', /reply_to should be valid email address/
|
25
25
|
end
|
26
26
|
|
27
27
|
it 'cannot send with non-existing template' do
|
28
|
-
res =
|
29
|
-
|
30
|
-
|
28
|
+
res = PIGEON.campaigns.send(:list_id => -1, :template_id => -1, :name => 'My Campaign', :from_name => 'John',
|
29
|
+
:reply_to => 'j@j.j',
|
30
|
+
:subject => 'Hi', :google_analytics => false)
|
31
31
|
validate_response res, 400, 'error', /template=-1 is not found/
|
32
32
|
end
|
33
33
|
|
34
34
|
it 'cannot send to non-existing list' do
|
35
|
-
res =
|
36
|
-
|
37
|
-
|
35
|
+
res = PIGEON.campaigns.send(:list_id => -1, :template_id => TEMPLATE_ID, :name => 'My Campaign', :from_name => 'John',
|
36
|
+
:reply_to => 'j@j.j',
|
37
|
+
:subject => 'Hi', :google_analytics => false)
|
38
38
|
validate_response res, 400, 'error', /list=-1 is not found/
|
39
39
|
end
|
40
40
|
|
41
41
|
it 'cannot send to disabled list' do
|
42
|
-
res =
|
43
|
-
|
44
|
-
|
42
|
+
res = PIGEON.campaigns.send(:list_id => LIST_ID, :template_id => TEMPLATE_ID, :name => 'My Campaign', :from_name => 'John',
|
43
|
+
:reply_to => 'j@j.j',
|
44
|
+
:subject => 'Hi', :google_analytics => false)
|
45
45
|
validate_response res, 400, 'error', /list=#{DISABLED_LIST} is disabled/
|
46
46
|
end
|
47
47
|
|
48
48
|
it 'should create new list, add contact and send successful campaign' do
|
49
49
|
|
50
|
-
list_resp =
|
50
|
+
list_resp = PIGEON.lists.create('My list', 'John', API_USER)
|
51
51
|
list_id = list_resp.list.id
|
52
|
-
|
53
|
-
resp =
|
54
|
-
|
55
|
-
|
52
|
+
PIGEON.contacts.upsert(list_id, {:email => API_USER})
|
53
|
+
resp = PIGEON.campaigns.send(:list_id => list_id, :template_id => TEMPLATE_ID, :name => 'My Campaign', :from_name => 'John',
|
54
|
+
:reply_to => API_USER,
|
55
|
+
:subject => 'Hi', :google_analytics => false)
|
56
56
|
validate_response resp, 200, 'success', /new campaign created successfully/
|
57
|
-
report =
|
57
|
+
report = PIGEON.campaigns.report(resp.campaign_id)
|
58
58
|
(report.delivered == 0 or report.delivered == 1).should be_true
|
59
59
|
report.clicked.should eq 0
|
60
60
|
report.opened.should eq 0
|
@@ -62,45 +62,45 @@ describe 'campaigns integration test' do
|
|
62
62
|
(report.in_transit == 0 or report.in_transit == 1).should be_true
|
63
63
|
report.unsubscribed.should eq 0
|
64
64
|
report.bounced.should eq 0
|
65
|
-
bounced =
|
66
|
-
unsubscribed =
|
67
|
-
spam =
|
65
|
+
bounced = PIGEON.campaigns.bounced(resp.campaign_id)
|
66
|
+
unsubscribed = PIGEON.campaigns.unsubscribed(resp.campaign_id)
|
67
|
+
spam = PIGEON.campaigns.spam(resp.campaign_id)
|
68
68
|
|
69
69
|
bounced.size.should eq 0
|
70
70
|
unsubscribed.size.should eq 0
|
71
71
|
spam.size.should eq 0
|
72
72
|
|
73
|
-
resp =
|
73
|
+
resp = PIGEON.contacts.delete(API_USER)
|
74
74
|
validate_response resp, 200, 'success', /contact=non@non.non deleted successfully/
|
75
75
|
|
76
|
-
resp =
|
76
|
+
resp = PIGEON.contacts.find_by_email(API_USER)
|
77
77
|
validate_response resp, 404, 'error', /contact=non@non.non not found/
|
78
78
|
|
79
|
-
resp =
|
79
|
+
resp = PIGEON.lists.delete(list_id)
|
80
80
|
validate_response resp, 200, 'success', /deleted successfully/
|
81
81
|
end
|
82
82
|
|
83
83
|
|
84
84
|
it 'cannot send campaign if scheduling with bad date' do
|
85
85
|
|
86
|
-
list_resp =
|
87
|
-
resp =
|
86
|
+
list_resp = PIGEON.lists.create "My list", "John", API_USER
|
87
|
+
resp = PIGEON.campaigns.schedule :list_id => list_resp.list.id, :template_id => TEMPLATE_ID, :name => 'My Campaign',
|
88
88
|
|
89
|
-
|
90
|
-
|
91
|
-
|
89
|
+
:from_name => 'John',
|
90
|
+
:reply_to => API_USER, :subject => 'Hi',
|
91
|
+
:google_analytics => false, :schedule_for => "2013-05-28"
|
92
92
|
|
93
93
|
validate_response resp, 400, 'error', /schedule_for is not in ISO date format, example: 2013-05-28T17:19:50.779/
|
94
|
-
resp =
|
94
|
+
resp = PIGEON.lists.delete(list_resp.list.id)
|
95
95
|
validate_response resp, 200, 'success', /deleted successfully/
|
96
96
|
end
|
97
97
|
|
98
98
|
it 'should not schedule campaign with date in the past' do
|
99
|
-
list_resp =
|
100
|
-
resp =
|
101
|
-
|
102
|
-
|
103
|
-
|
99
|
+
list_resp = PIGEON.lists.create('My list', 'John', API_USER)
|
100
|
+
resp = PIGEON.campaigns.schedule :list_id => list_resp.list.id, :template_id => TEMPLATE_ID, :name => 'My Campaign',
|
101
|
+
:from_name => 'John',
|
102
|
+
:reply_to => API_USER, :subject => 'Hi',
|
103
|
+
:google_analytics => false, :schedule_for => '2010-05-28T17:19:50.779+0300'
|
104
104
|
|
105
105
|
validate_response resp, 400, 'error', /schedule_for should be in the future/
|
106
106
|
end
|
@@ -108,48 +108,26 @@ describe 'campaigns integration test' do
|
|
108
108
|
|
109
109
|
|
110
110
|
it 'should delete scheduled campaign' do
|
111
|
-
list_resp =
|
112
|
-
resp =
|
113
|
-
|
114
|
-
|
115
|
-
|
111
|
+
list_resp = PIGEON.lists.create('My list', 'John', API_USER)
|
112
|
+
resp = PIGEON.campaigns.schedule :list_id => list_resp.list.id, :template_id => TEMPLATE_ID, :name => 'My Campaign',
|
113
|
+
:from_name => 'John',
|
114
|
+
:reply_to => API_USER, :subject => 'Hi',
|
115
|
+
:google_analytics => false, :schedule_for => '2030-05-28T17:19:50.779+0300'
|
116
116
|
|
117
117
|
validate_response resp, 200, 'success', /new campaign created successfully/
|
118
118
|
campaign_id = resp.campaign_id
|
119
|
-
resp =
|
119
|
+
resp = PIGEON.campaigns.delete campaign_id
|
120
120
|
resp.message.should eq "campaign #{campaign_id} was deleted"
|
121
121
|
end
|
122
122
|
|
123
123
|
|
124
124
|
# This test uses account ep.api.tester@expresspigeon.com and expects two specific campaign there.
|
125
125
|
it 'should list campaigns from account' do
|
126
|
-
campaigns =
|
126
|
+
campaigns = PIGEON.campaigns.all
|
127
127
|
campaigns.size.should eq 4
|
128
|
-
campaigns =
|
128
|
+
campaigns = PIGEON.campaigns.all from_id: 53853
|
129
129
|
campaigns.size.should eq 3
|
130
130
|
end
|
131
131
|
|
132
|
-
|
133
|
-
it 'should get opened from campaign' do
|
134
|
-
opened = ExpressPigeon::API.campaigns.opened 441663
|
135
|
-
|
136
|
-
puts opened
|
137
|
-
|
138
|
-
end
|
139
|
-
|
140
|
-
it 'should get clicked from campaign' do
|
141
|
-
clicked = ExpressPigeon::API.campaigns.clicked 441663
|
142
|
-
|
143
|
-
puts clicked
|
144
|
-
|
145
|
-
end
|
146
|
-
|
147
|
-
it 'should get unsubs from campaign' do
|
148
|
-
unsubscribed = ExpressPigeon::API.campaigns.unsubscribed 441663
|
149
|
-
|
150
|
-
puts unsubscribed
|
151
|
-
|
152
|
-
end
|
153
|
-
|
154
132
|
end
|
155
133
|
|
data/spec/contacts_spec.rb
CHANGED
@@ -6,24 +6,24 @@ describe 'contacts integration test' do
|
|
6
6
|
include PigeonSpecHelper
|
7
7
|
|
8
8
|
it 'should not create contact without contact data' do
|
9
|
-
resp =
|
9
|
+
resp = PIGEON.contacts.upsert(-1, {})
|
10
10
|
validate_response resp, 400, 'error', /email is required/
|
11
11
|
end
|
12
12
|
|
13
13
|
it 'should not create contact without email' do
|
14
|
-
resp =
|
14
|
+
resp = PIGEON.contacts.upsert -1, :email => '', :first_name => 'Marylin', :last_name => 'Monroe'
|
15
15
|
validate_response resp, 400, 'error', /email is required/
|
16
16
|
end
|
17
17
|
|
18
18
|
it 'should not add contact with too many custom fields' do
|
19
19
|
custom_fields = {}
|
20
20
|
(1..25).each { |n| custom_fields["custom_field_#{n}"] = n }
|
21
|
-
resp =
|
21
|
+
resp = PIGEON.contacts.upsert -1, :email => "mary@e.e", :custom_fields => custom_fields
|
22
22
|
validate_response resp, 400, 'error', /You cannot create more than 20 custom fields. Use one of the 'custom_fields'./
|
23
23
|
end
|
24
24
|
|
25
25
|
it 'should not create new contact without list_id' do
|
26
|
-
resp =
|
26
|
+
resp = PIGEON.contacts.upsert '', :email => 'ee@e.e', :first_name => 'Marylin', :last_name => 'Monroe'
|
27
27
|
# TODO: this is a pretty crappy message from API https://redmine.expresspigeon.com/issues/5479
|
28
28
|
validate_response resp, 400, 'error', /failed to convert: '' to Long/
|
29
29
|
end
|
@@ -34,21 +34,21 @@ describe 'contacts integration test' do
|
|
34
34
|
# end
|
35
35
|
|
36
36
|
it 'cannot upsert into non-existent_list' do
|
37
|
-
resp =
|
37
|
+
resp = PIGEON.contacts.upsert -123, :email => "e@e.e"
|
38
38
|
# TODO: uncomment after: https://redmine.expresspigeon.com/issues/5478
|
39
39
|
validate_response resp, 404, 'error', /contact=e@e.e not found/
|
40
40
|
end
|
41
41
|
|
42
42
|
it 'creates list with contacts' do
|
43
|
-
list_response =
|
43
|
+
list_response = PIGEON.lists.create 'My List', 'John Doe', 'john@doe.com'
|
44
44
|
list_id = list_response.list.id
|
45
|
-
resp =
|
46
|
-
|
45
|
+
resp = PIGEON.contacts.upsert list_id, email: "mary@e.e",
|
46
|
+
:custom_fields => {:custom_field_1 => "custom_value_1", }
|
47
47
|
validate_response resp, 200, 'success', /contacts created\/updated successfully/
|
48
48
|
|
49
|
-
resp =
|
49
|
+
resp = PIGEON.contacts.find_by_email "mary@e.e"
|
50
50
|
|
51
|
-
|
51
|
+
PIGEON.lists.delete(list_id)
|
52
52
|
|
53
53
|
resp.custom_fields.custom_field_1 eq "custom_value_1"
|
54
54
|
resp.email.should eq 'mary@e.e'
|
@@ -56,16 +56,16 @@ describe 'contacts integration test' do
|
|
56
56
|
end
|
57
57
|
|
58
58
|
it 'creates list non-existent custom field' do
|
59
|
-
list_response =
|
59
|
+
list_response = PIGEON.lists.create 'My List', 'John Doe', 'a@a.a'
|
60
60
|
list_id = list_response.list.id
|
61
|
-
resp =
|
62
|
-
|
61
|
+
resp = PIGEON.contacts.upsert(list_id, {:email => "mary@e.e", :custom_fields => {:c => "c", }})
|
62
|
+
PIGEON.lists.delete(list_id)
|
63
63
|
validate_response resp, 200, 'success', nil
|
64
64
|
end
|
65
65
|
|
66
66
|
it 'cannot export contacts from list without list_id' do
|
67
67
|
content = ''
|
68
|
-
|
68
|
+
PIGEON.lists.csv "-1" do |c|
|
69
69
|
content << c
|
70
70
|
end
|
71
71
|
resp = JSON.parse(content)
|
@@ -76,7 +76,7 @@ describe 'contacts integration test' do
|
|
76
76
|
|
77
77
|
it 'should get contacts from suppressed list' do
|
78
78
|
content =''
|
79
|
-
|
79
|
+
PIGEON.lists.csv "suppress_list" do |c|
|
80
80
|
content += c
|
81
81
|
end
|
82
82
|
resp = content.split /\n/
|
@@ -87,13 +87,13 @@ describe 'contacts integration test' do
|
|
87
87
|
end
|
88
88
|
|
89
89
|
it 'should get single contact' do
|
90
|
-
resp =
|
90
|
+
resp = PIGEON.contacts.find_by_email 'suppressed@e.e'
|
91
91
|
# TODO: have these on account before checking.
|
92
92
|
# resp.email.should eq 'suppressed@e.e'
|
93
93
|
end
|
94
94
|
|
95
95
|
it 'should not find non existent contact' do
|
96
|
-
resp =
|
96
|
+
resp = PIGEON.contacts.find_by_email 'a@a.a'
|
97
97
|
# TODO: have these on account before checking.
|
98
98
|
|
99
99
|
# validate_response resp, 404, 'error', /contact=a@a.a not found/
|
@@ -103,56 +103,56 @@ describe 'contacts integration test' do
|
|
103
103
|
|
104
104
|
|
105
105
|
|
106
|
-
list_response =
|
106
|
+
list_response = PIGEON.lists.create('My List', 'John Doe', "a@a.a")
|
107
107
|
|
108
108
|
# PIGEON.contacts.find_by_email("mary@e.e").last_name.should eq 'Doe'
|
109
109
|
|
110
|
-
resp =
|
111
|
-
|
110
|
+
resp = PIGEON.contacts.upsert list_response.list.id,
|
111
|
+
:email => 'mary@e.e', :first_name => 'Mary', :last_name => 'Johns'
|
112
112
|
validate_response resp, 200, 'success', /contacts created\/updated successfully/
|
113
|
-
|
114
|
-
|
113
|
+
PIGEON.contacts.find_by_email("mary@e.e").last_name.should eq 'Johns'
|
114
|
+
PIGEON.lists.delete list_response.list.id
|
115
115
|
end
|
116
116
|
|
117
117
|
it 'cannot delete contact with non-existent email' do
|
118
|
-
res =
|
118
|
+
res = PIGEON.contacts.delete("g@g.g")
|
119
119
|
validate_response res, 404, 'error', /contact=g@g.g not found/
|
120
120
|
end
|
121
121
|
|
122
122
|
it 'should not delete suppressed contact' do
|
123
|
-
res =
|
123
|
+
res = PIGEON.contacts.delete("suppressed@e.e")
|
124
124
|
|
125
125
|
# TODO: add this to the account at setup.
|
126
126
|
# validate_response res, 400, 'error', /contact=suppressed@e.e is in suppress list/
|
127
127
|
end
|
128
128
|
|
129
129
|
it 'should delete single contact from all lists' do
|
130
|
-
list_response =
|
131
|
-
|
132
|
-
res =
|
130
|
+
list_response = PIGEON.lists.create 'My List', 'Jane Doe', 'a@a.a'
|
131
|
+
PIGEON.contacts.upsert list_response.list.id, :email => 'mary@e.e'
|
132
|
+
res = PIGEON.contacts.delete 'mary@e.e'
|
133
133
|
validate_response res, 200, 'success', /contact=mary@e.e deleted successfully/
|
134
|
-
|
134
|
+
PIGEON.lists.delete list_response.list.id
|
135
135
|
end
|
136
136
|
|
137
137
|
it 'deletes single contact from single list' do
|
138
|
-
list_response =
|
139
|
-
list_response_2 =
|
140
|
-
|
141
|
-
|
138
|
+
list_response = PIGEON.lists.create 'My List', 'John D.', 'a@a.a'
|
139
|
+
list_response_2 = PIGEON.lists.create('My List2', "Jane D.", 'a@a.a')
|
140
|
+
PIGEON.contacts.upsert(list_response.list.id, {:email => 'mary@e.e'})
|
141
|
+
PIGEON.contacts.upsert(list_response_2.list.id, {:email => 'mary@e.e'})
|
142
142
|
|
143
|
-
res =
|
143
|
+
res = PIGEON.contacts.delete 'mary@e.e', list_response.list.id
|
144
144
|
|
145
145
|
validate_response res, 200, 'success', /contact=mary@e.e deleted successfully/
|
146
146
|
|
147
147
|
contacts_exported = ''
|
148
|
-
|
148
|
+
PIGEON.lists.csv list_response.list.id do |c|
|
149
149
|
contacts_exported << c
|
150
150
|
end
|
151
151
|
contacts_exported = contacts_exported.split /\n/
|
152
152
|
contacts_exported.size.should eq 1
|
153
153
|
|
154
154
|
contacts_exported_2 = ''
|
155
|
-
|
155
|
+
PIGEON.lists.csv list_response_2.list.id do |c|
|
156
156
|
contacts_exported_2 << c
|
157
157
|
end
|
158
158
|
|
@@ -160,9 +160,9 @@ describe 'contacts integration test' do
|
|
160
160
|
contacts_exported_2.size.should eq 2
|
161
161
|
contacts_exported_2[1].should =~ /"mary@e.e"/
|
162
162
|
|
163
|
-
|
164
|
-
|
165
|
-
|
163
|
+
PIGEON.lists.delete(list_response.list.id)
|
164
|
+
PIGEON.lists.delete(list_response_2.list.id)
|
165
|
+
PIGEON.contacts.delete('mary@e.e')
|
166
166
|
end
|
167
167
|
end
|
168
168
|
|
data/spec/lists_spec.rb
CHANGED
@@ -6,39 +6,39 @@ describe 'lists integration test' do
|
|
6
6
|
include PigeonSpecHelper
|
7
7
|
|
8
8
|
it 'test_create_and_delete_new_list(self):' do
|
9
|
-
contact_list =
|
9
|
+
contact_list = PIGEON.lists.create 'Active customers', 'Bob', 'bob@acmetools.com'
|
10
10
|
validate_response contact_list, 200, 'success', /list=#{contact_list.list.id} created\/updated successfully/
|
11
11
|
contact_list.list.name.should eq "Active customers"
|
12
12
|
contact_list.list.from_name.should eq "Bob"
|
13
13
|
contact_list.list.reply_to.should eq "bob@acmetools.com"
|
14
14
|
contact_list.list.contact_count.should eq 0
|
15
|
-
res =
|
15
|
+
res = PIGEON.lists.delete contact_list.list.id
|
16
16
|
validate_response res, 200, 'success', /list=#{contact_list.list.id} deleted successfully/
|
17
17
|
end
|
18
18
|
|
19
19
|
it 'should update existing list' do
|
20
|
-
contact_list =
|
21
|
-
res =
|
20
|
+
contact_list = PIGEON.lists.create("Update", "Bob", "bob@acmetools.com")
|
21
|
+
res = PIGEON.lists.update contact_list.list.id, :name => 'Updated Name', :from_name => 'Bob', :reply_to => 'Frank@zappa.com'
|
22
22
|
validate_response res, 200, 'success', /list=#{res.list.id} created\/updated successfully/
|
23
23
|
res.list.name.should eq "Updated Name"
|
24
24
|
res.list.from_name.should eq 'Bob'
|
25
|
-
res =
|
25
|
+
res = PIGEON.lists.delete(contact_list.list.id)
|
26
26
|
validate_response res, 200, 'success', /list=#{contact_list.list.id} deleted successfully/
|
27
27
|
end
|
28
28
|
|
29
29
|
|
30
30
|
it 'should upload contacts as CSV file' do
|
31
31
|
list_name = "Upload_#{Kernel.rand(9999).to_s}"
|
32
|
-
list_resp =
|
32
|
+
list_resp = PIGEON.lists.create(list_name, 'Bob', 'bob@acmetools.com')
|
33
33
|
begin
|
34
|
-
resp =
|
34
|
+
resp = PIGEON.lists.upload(list_resp.list.id, 'spec/resources/upload.csv')
|
35
35
|
validate_response resp, 200, 'success', /file uploaded successfully/
|
36
|
-
res =
|
36
|
+
res = PIGEON.contacts.find_by_email 'x@x.x'
|
37
37
|
res.lists[0]['id'].should eq list_resp.list.id
|
38
38
|
ensure
|
39
|
-
res =
|
39
|
+
res = PIGEON.lists.delete(list_resp.list.id)
|
40
40
|
validate_response res, 200, 'success', /list=#{list_resp.list.id} deleted successfully/
|
41
|
-
|
41
|
+
PIGEON.contacts.find_by_email('x@x.x').message.should eq 'contact=x@x.x not found'
|
42
42
|
end
|
43
43
|
end
|
44
44
|
|
@@ -72,19 +72,11 @@ describe 'lists integration test' do
|
|
72
72
|
# self.assertEqual(res.code, 404)
|
73
73
|
# self.assertEqual(res.message, "list=-1 not found")
|
74
74
|
#
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
begin
|
82
|
-
puts ExpressPigeon::API.lists.upload_status list_response.list.id
|
83
|
-
ensure
|
84
|
-
ExpressPigeon::API.lists.delete list_response.list.id
|
85
|
-
end
|
86
|
-
|
87
|
-
end
|
75
|
+
# def test_upload_status_without_upload_id(self):
|
76
|
+
# res = self.api.lists.upload_status("")
|
77
|
+
# self.assertEqual(res.code, 400)
|
78
|
+
# self.assertEqual(res.status, "error")
|
79
|
+
# self.assertEqual(res.message, "you must provide upload id")
|
88
80
|
#
|
89
81
|
# def test_enabled_list_removal(self):
|
90
82
|
# list_resp = self.api.lists.create("My list", "John", os.environ['EXPRESSPIGEON_API_USER'])
|
@@ -110,32 +102,22 @@ describe 'lists integration test' do
|
|
110
102
|
# "could not delete list={0}, it has dependent subscriptions and/or scheduled campaigns".format(
|
111
103
|
# list_resp.list.id))
|
112
104
|
#
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
# '"custom_field_12", "custom_field_13", "custom_field_18", "custom_field_19", "custom_field_2", ' \
|
131
|
-
# '"custom_field_20", "custom_field_21", "custom_field_22", "custom_field_23", "custom_field_24", ' \
|
132
|
-
# '"custom_field_3", "custom_field_4", "custom_field_5", "custom_field_6", "custom_field_7", ' \
|
133
|
-
# '"custom_field_8", "custom_field_9"'
|
134
|
-
# self.assertEquals(res[0], headers)
|
135
|
-
# self.assertEquals(res[1], '"mary@a.a",,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,')
|
136
|
-
#
|
137
|
-
# self.api.lists.delete(list_response.list.id)
|
138
|
-
# self.api.contacts.delete("mary@a.a")
|
139
|
-
end
|
105
|
+
# def test_export_csv(self):
|
106
|
+
# list_response = self.api.lists.create("My List", "a@a.a", "a@a.a")
|
107
|
+
# self.api.contacts.upsert(list_response.list.id, {"email": "mary@a.a"})
|
108
|
+
#
|
109
|
+
# res = self.api.lists.csv(list_response.list.id).split("\n")
|
110
|
+
# self.assertEquals(len(res), 2)
|
111
|
+
# headers = '"Email", "First name", "Last name", "City", "Phone", "Company", "Title", "Address 1", "Address 2", ' \
|
112
|
+
# '"State", "Zip", "Country", "Date of birth", "custom_field_1", "custom_field_10", "custom_field_11", ' \
|
113
|
+
# '"custom_field_12", "custom_field_13", "custom_field_18", "custom_field_19", "custom_field_2", ' \
|
114
|
+
# '"custom_field_20", "custom_field_21", "custom_field_22", "custom_field_23", "custom_field_24", ' \
|
115
|
+
# '"custom_field_3", "custom_field_4", "custom_field_5", "custom_field_6", "custom_field_7", ' \
|
116
|
+
# '"custom_field_8", "custom_field_9"'
|
117
|
+
# self.assertEquals(res[0], headers)
|
118
|
+
# self.assertEquals(res[1], '"mary@a.a",,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,')
|
119
|
+
#
|
120
|
+
# self.api.lists.delete(list_response.list.id)
|
121
|
+
# self.api.contacts.delete("mary@a.a")
|
140
122
|
|
141
123
|
end
|
data/spec/messages_spec.rb
CHANGED
@@ -32,10 +32,10 @@ describe 'transactional messages integration test' do
|
|
32
32
|
|
33
33
|
#TODO: complete the spec
|
34
34
|
it 'sends a single transactional message' do
|
35
|
-
message_response =
|
36
|
-
|
35
|
+
message_response = PIGEON.messages.send_message 115, ENV['TARGET_EMAIL'], ENV['TARGET_EMAIL'], "Team ExpressPigeon", "Hi there!",
|
36
|
+
:first_name => "Igor"
|
37
37
|
validate_response message_response, 200, 'success', /email queued/
|
38
|
-
report =
|
38
|
+
report = PIGEON.messages.report(message_response.id)
|
39
39
|
report.id.should eq message_response.id
|
40
40
|
end
|
41
41
|
|
@@ -90,23 +90,23 @@ describe 'transactional messages integration test' do
|
|
90
90
|
# self.assertEquals(report2.email, os.environ['EXPRESSPIGEON_API_USER'])
|
91
91
|
# self.assertTrue(report2.in_transit is not None)
|
92
92
|
#
|
93
|
-
it '
|
93
|
+
it 'test_sending_multiple_messages_and_get_reports_for_today(self):' do
|
94
94
|
|
95
95
|
start = Time.now.utc - 60 # one minute ago
|
96
96
|
|
97
|
-
message_response =
|
98
|
-
|
97
|
+
message_response = PIGEON.messages.send_message 4905, ENV['TARGET_EMAIL'], ENV['TARGET_EMAIL'],
|
98
|
+
'Team EP', "Hi, there!", :first_name => "Bob"
|
99
99
|
|
100
100
|
validate_response message_response, 200, 'success', /email queued/
|
101
101
|
message_response.id should_not be_nil
|
102
102
|
|
103
|
-
message_response2 =
|
104
|
-
|
103
|
+
message_response2 = PIGEON.messages.send_message 4905, ENV['TARGET_EMAIL'], ENV['TARGET_EMAIL'],
|
104
|
+
'Team EP', "Hi, there!", :first_name => "Bob"
|
105
105
|
validate_response message_response2, 200, 'success', /email queued/
|
106
106
|
message_response2.id should_not be_nil
|
107
107
|
|
108
108
|
finish = start + 120 # two minutes after start
|
109
|
-
reports =
|
109
|
+
reports = PIGEON.messages.reports (message_response.id - 1), start, finish
|
110
110
|
|
111
111
|
reports.size.should eq 2
|
112
112
|
reports[0]['id'].should eq message_response.id
|
@@ -115,8 +115,6 @@ describe 'transactional messages integration test' do
|
|
115
115
|
reports[0]['email'].should eq ENV['TARGET_EMAIL']
|
116
116
|
reports[1]['email'].should eq ENV['TARGET_EMAIL']
|
117
117
|
end
|
118
|
-
|
119
|
-
|
120
118
|
#
|
121
119
|
#def __get_report_by_id__(self, message_id, start_date=None, end_date=None):
|
122
120
|
# reports = self.api.messages.reports() if start_date is None and end_date is None else \
|
@@ -126,35 +124,4 @@ describe 'transactional messages integration test' do
|
|
126
124
|
# return report[0]
|
127
125
|
|
128
126
|
|
129
|
-
it 'should prepare payload hash' do
|
130
|
-
|
131
|
-
payload = ExpressPigeon::API.messages.prepare_payload(123, #template_id
|
132
|
-
'john@doe.com',
|
133
|
-
'jane@doe.com',
|
134
|
-
'Jane Doe',
|
135
|
-
'Hello, Dolly!',
|
136
|
-
{eye_color: 'blue', body_shape:'pear'},
|
137
|
-
false, true, false,
|
138
|
-
%w(spec/resources/attachment1.txt spec/resources/attachment2.txt), {})
|
139
|
-
|
140
|
-
payload[:multipart].should eq true
|
141
|
-
payload[:template_id].should eq 123
|
142
|
-
payload[:to].should eq 'john@doe.com'
|
143
|
-
payload[:reply_to].should eq 'jane@doe.com'
|
144
|
-
payload[:from].should eq 'Jane Doe'
|
145
|
-
payload[:subject].should eq 'Hello, Dolly!'
|
146
|
-
payload[:template_id].should eq 123
|
147
|
-
payload[:view_online].should eq false
|
148
|
-
payload[:click_tracking].should eq true
|
149
|
-
payload[:suppress_address].should eq false
|
150
|
-
payload['attachment1.txt'].class.should eq File
|
151
|
-
|
152
|
-
payload[:merge_fields].class.should eq String
|
153
|
-
merge_fields = JSON.parse payload[:merge_fields]
|
154
|
-
merge_fields['eye_color'].should eq "blue"
|
155
|
-
merge_fields['body_shape'].should eq "pear"
|
156
|
-
|
157
|
-
File.basename(payload['attachment1.txt']).should eq 'attachment1.txt'
|
158
|
-
File.basename(payload['attachment2.txt']).should eq 'attachment2.txt'
|
159
|
-
end
|
160
127
|
end
|
data/spec/pigeon_helper.rb
CHANGED
data/spec/templates_spec.rb
CHANGED
@@ -6,10 +6,10 @@ describe 'templates integration test' do
|
|
6
6
|
include PigeonSpecHelper
|
7
7
|
|
8
8
|
it 'should copy template and delete template' do
|
9
|
-
template_response =
|
9
|
+
template_response = PIGEON.templates.copy 34830, "new template", :content => "Hello Template World!"
|
10
10
|
template_response.message.should eq 'template copied successfully'
|
11
11
|
template_id = template_response.template_id
|
12
|
-
delete_response =
|
12
|
+
delete_response = PIGEON.templates.delete template_id
|
13
13
|
delete_response.message.should eq 'template deleted successfully'
|
14
14
|
end
|
15
15
|
end
|
data/test/send.rb
CHANGED
@@ -1,19 +1,9 @@
|
|
1
|
+
require '../lib/expresspigeon-ruby.rb'
|
1
2
|
|
2
|
-
require_relative '../lib/expresspigeon-ruby.rb'
|
3
3
|
|
4
|
-
MESSAGES = ExpressPigeon::API.messages
|
4
|
+
MESSAGES = ExpressPigeon::API.messages
|
5
|
+
MESSAGES.open_timeout = 1000
|
6
|
+
|
7
|
+
puts MESSAGES.send_message 565452, 'igor@expresspigeon.com', 'igor@polevoy.org', "Igor Polevoy", "Transactional message test", {first_name: 'Igor', img1: "https://cdn.pioneer.pgsitecore.com/en-us/-/media/Charmin/Images/Editorials/charmin_tipsarticles_howtopottytrainagirl_image1.jpg"}
|
5
8
|
|
6
9
|
|
7
|
-
puts MESSAGES.send_message(
|
8
|
-
390243, # template_id
|
9
|
-
'igor@polevoy.org', #to
|
10
|
-
'igor@polevoy.org', #reply_to
|
11
|
-
"Igor Polevoy", #from_name
|
12
|
-
"Hi there! Sending with a heades", #subject
|
13
|
-
{first_name: 'Igor', eye_color: 'brown'}, #merge_fields
|
14
|
-
false, #view_online
|
15
|
-
true, #click_tracking
|
16
|
-
true, #suppress_address
|
17
|
-
{}, #file paths to upload as attachments
|
18
|
-
{Sender: 'Vasya Pupkin <vasya@polevoy.org>'}
|
19
|
-
)
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: expresspigeon-ruby
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0
|
4
|
+
version: 0.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- ipolevoy
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2018-04-30 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rest-client
|
@@ -16,14 +16,14 @@ dependencies:
|
|
16
16
|
requirements:
|
17
17
|
- - "~>"
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version:
|
19
|
+
version: 1.8.0
|
20
20
|
type: :runtime
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
24
|
- - "~>"
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version:
|
26
|
+
version: 1.8.0
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: rspec
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
@@ -63,7 +63,6 @@ files:
|
|
63
63
|
- lib/expresspigeon-ruby/meta_response.rb
|
64
64
|
- lib/expresspigeon-ruby/templates.rb
|
65
65
|
- lib/expresspigeon-ruby/version.rb
|
66
|
-
- spec/autoresponders_spec.rb
|
67
66
|
- spec/campaigns_spec.rb
|
68
67
|
- spec/contacts_spec.rb
|
69
68
|
- spec/lists_spec.rb
|
@@ -71,14 +70,9 @@ files:
|
|
71
70
|
- spec/pigeon_helper.rb
|
72
71
|
- spec/resources/upload.csv
|
73
72
|
- spec/templates_spec.rb
|
74
|
-
- test/README
|
75
|
-
- test/attachments/example.ics
|
76
|
-
- test/attachments/smile.pdf
|
77
73
|
- test/send.rb
|
78
|
-
- test/send_with_attachments.rb
|
79
74
|
homepage: https://github.com/expresspigeon/expresspigeon-ruby
|
80
|
-
licenses:
|
81
|
-
- MIT
|
75
|
+
licenses: []
|
82
76
|
metadata: {}
|
83
77
|
post_install_message:
|
84
78
|
rdoc_options: []
|
@@ -101,7 +95,6 @@ signing_key:
|
|
101
95
|
specification_version: 4
|
102
96
|
summary: ExpressPigeon API Ruby Wrapper
|
103
97
|
test_files:
|
104
|
-
- spec/autoresponders_spec.rb
|
105
98
|
- spec/campaigns_spec.rb
|
106
99
|
- spec/contacts_spec.rb
|
107
100
|
- spec/lists_spec.rb
|
@@ -109,8 +102,4 @@ test_files:
|
|
109
102
|
- spec/pigeon_helper.rb
|
110
103
|
- spec/resources/upload.csv
|
111
104
|
- spec/templates_spec.rb
|
112
|
-
- test/README
|
113
|
-
- test/attachments/example.ics
|
114
|
-
- test/attachments/smile.pdf
|
115
105
|
- test/send.rb
|
116
|
-
- test/send_with_attachments.rb
|
data/spec/autoresponders_spec.rb
DELETED
@@ -1,46 +0,0 @@
|
|
1
|
-
require './lib/expresspigeon-ruby'
|
2
|
-
require 'pigeon_helper'
|
3
|
-
|
4
|
-
describe 'autoresponders integration test' do
|
5
|
-
|
6
|
-
include PigeonSpecHelper
|
7
|
-
|
8
|
-
it 'should return all autoresponders' do
|
9
|
-
res = ExpressPigeon::API.autoresponders.all
|
10
|
-
res.class.should == Array
|
11
|
-
res.size.should > 0
|
12
|
-
puts res
|
13
|
-
end
|
14
|
-
|
15
|
-
it 'should start autoresponder by id' do
|
16
|
-
res = ExpressPigeon::API.autoresponders.start 672, 'igor@polevoy.org'
|
17
|
-
puts res
|
18
|
-
end
|
19
|
-
|
20
|
-
it 'should stop autoresponder by id' do
|
21
|
-
res = ExpressPigeon::API.autoresponders.stop 672, 'igor@polevoy.org'
|
22
|
-
puts res
|
23
|
-
end
|
24
|
-
|
25
|
-
it 'should get single report' do
|
26
|
-
res = ExpressPigeon::API.autoresponders.report 672
|
27
|
-
puts res
|
28
|
-
end
|
29
|
-
|
30
|
-
it 'should get bounces for autoresponder part' do
|
31
|
-
res = ExpressPigeon::API.autoresponders.bounced 672, 746
|
32
|
-
puts res
|
33
|
-
end
|
34
|
-
|
35
|
-
it 'should get spam for autoresponder part' do
|
36
|
-
res = ExpressPigeon::API.autoresponders.spam 672, 746
|
37
|
-
puts res
|
38
|
-
end
|
39
|
-
|
40
|
-
it 'should get unsubscribed for autoresponder part' do
|
41
|
-
res = ExpressPigeon::API.autoresponders.unsubscribed 672, 746
|
42
|
-
puts res
|
43
|
-
end
|
44
|
-
|
45
|
-
end
|
46
|
-
|
data/test/README
DELETED
@@ -1,25 +0,0 @@
|
|
1
|
-
h2. Intro
|
2
|
-
|
3
|
-
This directory contains Ruby scripts for manual testing some features.
|
4
|
-
|
5
|
-
In order to point to test env and set the auth_key, you need need to source the file called set_env (ignored)
|
6
|
-
|
7
|
-
h2. Curl example
|
8
|
-
|
9
|
-
|
10
|
-
```
|
11
|
-
curl -X POST https://api.expresspigeon.com/messages \
|
12
|
-
-H "Content-type: multipart/form-data" \
|
13
|
-
-H "X-auth-key: XXX"\
|
14
|
-
-F template_id=123\
|
15
|
-
-F reply_to='john@doe.com'\
|
16
|
-
-F from='John Doe'\
|
17
|
-
-F to='jane@doe.com'\
|
18
|
-
-F subject='Lets go out tonight?'\
|
19
|
-
-F view_online=true\
|
20
|
-
-F suppress_address=true\
|
21
|
-
-F click_tracking=true\
|
22
|
-
-F merge_fields='{"first_name": "Jane"}'\
|
23
|
-
-F attachment=@attachments/attachment1.txt\
|
24
|
-
-F attachment=@attachments/attachment2.txt
|
25
|
-
```
|
@@ -1,32 +0,0 @@
|
|
1
|
-
BEGIN:VCALENDAR
|
2
|
-
VERSION:2.0
|
3
|
-
CALSCALE:GREGORIAN
|
4
|
-
BEGIN:VEVENT
|
5
|
-
SUMMARY:Access-A-Ride Pickup
|
6
|
-
DTSTART;TZID=America/New_York:20130802T103400
|
7
|
-
DTEND;TZID=America/New_York:20130802T110400
|
8
|
-
LOCATION:1000 Broadway Ave.\, Brooklyn
|
9
|
-
DESCRIPTION: Access-A-Ride trip to 900 Jay St.\, Brooklyn
|
10
|
-
STATUS:CONFIRMED
|
11
|
-
SEQUENCE:3
|
12
|
-
BEGIN:VALARM
|
13
|
-
TRIGGER:-PT10M
|
14
|
-
DESCRIPTION:Pickup Reminder
|
15
|
-
ACTION:DISPLAY
|
16
|
-
END:VALARM
|
17
|
-
END:VEVENT
|
18
|
-
BEGIN:VEVENT
|
19
|
-
SUMMARY:Access-A-Ride Pickup
|
20
|
-
DTSTART;TZID=America/New_York:20250802T200000
|
21
|
-
DTEND;TZID=America/New_York:20250802T203000
|
22
|
-
LOCATION:900 Jay St.\, Brooklyn
|
23
|
-
DESCRIPTION: Access-A-Ride trip to 1000 Broadway Ave.\, Brooklyn
|
24
|
-
STATUS:CONFIRMED
|
25
|
-
SEQUENCE:3
|
26
|
-
BEGIN:VALARM
|
27
|
-
TRIGGER:-PT10M
|
28
|
-
DESCRIPTION:Pickup Reminder
|
29
|
-
ACTION:DISPLAY
|
30
|
-
END:VALARM
|
31
|
-
END:VEVENT
|
32
|
-
END:VCALENDAR
|
data/test/attachments/smile.pdf
DELETED
Binary file
|
@@ -1,22 +0,0 @@
|
|
1
|
-
|
2
|
-
require_relative '../lib/expresspigeon-ruby.rb'
|
3
|
-
|
4
|
-
MESSAGES = ExpressPigeon::API.messages.auth_key(ENV['AUTH_KEY'])
|
5
|
-
|
6
|
-
#attachments = %W{attachments/attachment1.txt attachments/smile.pdf attachments/example.ics}
|
7
|
-
#attachments = %W{/home/igor/tmp/The-Definitive-Guide-To-Mobile-Marketing-Marketo.pdf}
|
8
|
-
attachments = %W{/home/igor/tmp/Express-Pigeon-PropertyRadar-MSA-12-13-15.pdf}
|
9
|
-
|
10
|
-
puts MESSAGES.send_message(
|
11
|
-
390243, # template_id
|
12
|
-
'igor@polevoy.org', #to
|
13
|
-
'igor@polevoy.org', #reply_to
|
14
|
-
"Igor Polevoy", #from_name
|
15
|
-
"Hi there! Attachments and header", #subject
|
16
|
-
{first_name: 'Igor', eye_color: 'blue'}, #merge_fields
|
17
|
-
false, #view_online
|
18
|
-
true, #click_tracking
|
19
|
-
true, #suppress_address
|
20
|
-
attachments, #file paths to upload as attachments
|
21
|
-
{Sender: 'Vasya Pupkin <vasya@polevoy.org>'}
|
22
|
-
)
|