expresspigeon-ruby 0.0.5 → 0.0.6
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +4 -0
- data/Gemfile.lock +10 -7
- data/README.md +22 -2
- data/expresspigeon-ruby.gemspec +2 -2
- data/lib/expresspigeon-ruby.rb +3 -1
- data/lib/expresspigeon-ruby/messages.rb +86 -7
- data/lib/expresspigeon-ruby/meta_response.rb +4 -0
- data/lib/expresspigeon-ruby/version.rb +1 -1
- data/spec/messages_spec.rb +26 -0
- data/test/README +5 -0
- data/test/attachments/example.ics +32 -0
- data/test/attachments/smile.pdf +0 -0
- data/test/send_with_attachments.rb +18 -0
- metadata +14 -6
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: fe5c068844c9be4409e579ec341e7adb9e793330
|
4
|
+
data.tar.gz: 25738ba898a979110728640539677250bd15ce80
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9cce412e917134f9f04acb97e2a109992cdf767c65265df219892b23f73c0d19e6c5be77349c7d6ca9534c53853c3ebd7f0b1c7c3c38ab9b0fd5909e8d447f61
|
7
|
+
data.tar.gz: da1dc1d7d89ab9bc1dbcedb07c2cee5394bd3d756db5fbf5dc5b4863f9780e153d4ed5e01c4afa724f593e388cb3d06366e6dc66cb6b351a246b308e24bbcde5
|
data/.gitignore
CHANGED
data/Gemfile.lock
CHANGED
@@ -1,19 +1,19 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
expresspigeon-ruby (0.0.
|
5
|
-
rest-client (~> 1.8
|
4
|
+
expresspigeon-ruby (0.0.6)
|
5
|
+
rest-client (~> 1.8)
|
6
6
|
|
7
7
|
GEM
|
8
8
|
remote: https://rubygems.org/
|
9
9
|
specs:
|
10
10
|
diff-lcs (1.2.5)
|
11
|
-
domain_name (0.5.
|
11
|
+
domain_name (0.5.20161021)
|
12
12
|
unf (>= 0.0.5, < 1.0.0)
|
13
|
-
http-cookie (1.0.
|
13
|
+
http-cookie (1.0.3)
|
14
14
|
domain_name (~> 0.5)
|
15
|
-
mime-types (
|
16
|
-
netrc (0.
|
15
|
+
mime-types (2.99.3)
|
16
|
+
netrc (0.11.0)
|
17
17
|
rest-client (1.8.0)
|
18
18
|
http-cookie (>= 1.0.2, < 2.0)
|
19
19
|
mime-types (>= 1.16, < 3.0)
|
@@ -28,7 +28,7 @@ GEM
|
|
28
28
|
rspec-mocks (2.14.3)
|
29
29
|
unf (0.1.4)
|
30
30
|
unf_ext
|
31
|
-
unf_ext (0.0.7.
|
31
|
+
unf_ext (0.0.7.2)
|
32
32
|
|
33
33
|
PLATFORMS
|
34
34
|
ruby
|
@@ -36,3 +36,6 @@ PLATFORMS
|
|
36
36
|
DEPENDENCIES
|
37
37
|
expresspigeon-ruby!
|
38
38
|
rspec (~> 2.6)
|
39
|
+
|
40
|
+
BUNDLED WITH
|
41
|
+
1.13.6
|
data/README.md
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
# Expresspigeon::Ruby
|
2
2
|
|
3
|
-
|
3
|
+
This is a Ruby library for convenince access to [ExpressPigeon API](https://expresspigeon.com/api).
|
4
4
|
|
5
5
|
## Installation
|
6
6
|
|
@@ -16,7 +16,7 @@ Or install it yourself as:
|
|
16
16
|
|
17
17
|
$ gem install expresspigeon-ruby
|
18
18
|
|
19
|
-
##
|
19
|
+
## Sending a simple message
|
20
20
|
|
21
21
|
Sending a transactional message is easy:
|
22
22
|
|
@@ -40,6 +40,26 @@ 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: 'Igor', eye_color: 'blue'}, #merge_fields
|
57
|
+
false, #view_online
|
58
|
+
true, #click_tracking
|
59
|
+
attachments #file paths to upload as attachments
|
60
|
+
)
|
61
|
+
|
62
|
+
```
|
43
63
|
|
44
64
|
## Contributing
|
45
65
|
|
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
|
21
|
-
|
20
|
+
gem.add_runtime_dependency 'rest-client', '~> 1.8'
|
22
21
|
gem.add_development_dependency "rspec", "~> 2.6"
|
22
|
+
gem.licenses = ['MIT']
|
23
23
|
end
|
data/lib/expresspigeon-ruby.rb
CHANGED
@@ -8,7 +8,9 @@ require 'rest_client'
|
|
8
8
|
module ExpressPigeon
|
9
9
|
|
10
10
|
AUTH_KEY = ENV['EXPRESSPIGEON_AUTH_KEY']
|
11
|
-
|
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/'
|
12
14
|
USE_SSL = true
|
13
15
|
|
14
16
|
module API
|
@@ -7,19 +7,37 @@ module ExpressPigeon
|
|
7
7
|
@endpoint = 'messages'
|
8
8
|
end
|
9
9
|
|
10
|
-
|
11
|
-
|
12
|
-
|
10
|
+
# Sends a transactional message using ExpressPigeon Rest API
|
11
|
+
#
|
12
|
+
# * +template_id+ - ID of a template to use for sending
|
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
|
+
# * +attachments+ - array of file paths to attach to email. Size limit: 1k per attachment, maximum 3 attachments.
|
21
|
+
def send_message(template_id, to, reply_to, from_name, subject, merge_fields = nil, view_online = false, click_tracking = true, attachments = nil)
|
22
|
+
if attachments
|
23
|
+
upload(template_id, to, reply_to, from_name, subject, merge_fields, view_online, click_tracking, attachments)
|
24
|
+
else
|
25
|
+
post @endpoint, params = {template_id: template_id, :to => to, reply_to: reply_to, :from => from_name, :subject => subject,
|
26
|
+
:merge_fields => merge_fields, :view_online => view_online, :click_tracking => click_tracking}
|
27
|
+
end
|
13
28
|
end
|
14
29
|
|
30
|
+
# Retrieve report for a single message.
|
31
|
+
#
|
32
|
+
# * +message_id+ - ID of a message sent previously
|
15
33
|
def report(message_id)
|
16
34
|
get "#{@endpoint}/#{message_id}"
|
17
35
|
end
|
18
36
|
|
37
|
+
# Report for a group of messages in a given time period.
|
19
38
|
#
|
20
|
-
#
|
21
|
-
#
|
22
|
-
# end_date is instance of Time
|
39
|
+
# * +start_date+ is instance of Time
|
40
|
+
# * +end_date+ is instance of Time
|
23
41
|
def reports(from_id, start_date = nil, end_date = nil)
|
24
42
|
params = []
|
25
43
|
|
@@ -45,9 +63,70 @@ module ExpressPigeon
|
|
45
63
|
query << params.join('&')
|
46
64
|
end
|
47
65
|
|
48
|
-
puts "calling: #{query}"
|
49
66
|
get query
|
67
|
+
end
|
68
|
+
|
69
|
+
|
70
|
+
# Sends a transactional message with attachments using ExpressPigeon Rest API.
|
71
|
+
# This method is not used directly, instead use +send_message()+
|
72
|
+
#
|
73
|
+
# * +template_id+ - ID of a template to use for sending
|
74
|
+
# * +to+ - destination email address
|
75
|
+
# * +reply_to+ - return email address
|
76
|
+
# * +from_name+ - name of sender
|
77
|
+
# * +subject+ - subject of email
|
78
|
+
# * +merge fields+ - hash with dynamic values to merge into a template
|
79
|
+
# * +view_online+ - generate "view online" link in the template
|
80
|
+
# * +click_tracking+ - enable/disable click tracking (and URL rewriting)
|
81
|
+
# * +attachments+ - array of file paths to attach to email. Size limit: 1k per attachment, maximum 3 attachments.
|
82
|
+
def upload(template_id, to, reply_to, from_name, subject, merge_fields, view_online, click_tracking, attachments)
|
83
|
+
|
84
|
+
path = "#{@root ? @root : ROOT}/#{@endpoint}"
|
85
|
+
|
86
|
+
puts "sending to #{path}"
|
87
|
+
|
88
|
+
begin
|
89
|
+
payload = prepare_payload(template_id, to, reply_to, from_name, subject, merge_fields, view_online, click_tracking, attachments)
|
90
|
+
request = RestClient::Request.new(
|
91
|
+
:method => :post,
|
92
|
+
:headers => {:'X-auth-key' => get_auth_key},
|
93
|
+
:url => path,
|
94
|
+
:payload => payload)
|
95
|
+
resp = request.execute
|
96
|
+
res = resp.body
|
97
|
+
rescue RestClient::ExceptionWithResponse => err
|
98
|
+
res = err.response
|
99
|
+
end
|
100
|
+
|
101
|
+
parsed = JSON.parse(res)
|
102
|
+
if parsed.kind_of? Hash
|
103
|
+
MetaResponse.new parsed
|
104
|
+
else
|
105
|
+
parsed
|
106
|
+
end
|
107
|
+
end
|
108
|
+
|
109
|
+
|
110
|
+
def prepare_payload(template_id, to, reply_to, from, subject, merge_fields, view_online, click_tracking, attachments)
|
111
|
+
payload = { multipart: true }
|
112
|
+
payload[:template_id] = template_id
|
113
|
+
payload[:to] = to
|
114
|
+
payload[:reply_to] = reply_to
|
115
|
+
payload[:subject] = subject
|
116
|
+
payload[:from] = from
|
117
|
+
payload[:merge_fields] = merge_fields
|
118
|
+
payload[:view_online] = view_online
|
119
|
+
payload[:click_tracking] = click_tracking
|
50
120
|
|
121
|
+
attachments.each { |attachment|
|
122
|
+
if File.file?(attachment)
|
123
|
+
file = File.basename(attachment)
|
124
|
+
payload[file] = File.new attachment
|
125
|
+
else
|
126
|
+
raise "File #{attachment} does not exist"
|
127
|
+
end
|
128
|
+
}
|
129
|
+
payload
|
51
130
|
end
|
52
131
|
end
|
53
132
|
end
|
data/spec/messages_spec.rb
CHANGED
@@ -124,4 +124,30 @@ describe 'transactional messages integration test' do
|
|
124
124
|
# return report[0]
|
125
125
|
|
126
126
|
|
127
|
+
it 'should from payload hash' do
|
128
|
+
|
129
|
+
payload = PIGEON.messages.prepare_payload(123, #template_id
|
130
|
+
'john@doe.com',
|
131
|
+
'jane@doe.com',
|
132
|
+
'Jane Doe',
|
133
|
+
'Hello, Dolly!',
|
134
|
+
{eye_color: 'blue', body_shape:'pear'},
|
135
|
+
false, true,
|
136
|
+
%w(spec/resources/attachment1.txt spec/resources/attachment2.txt))
|
137
|
+
|
138
|
+
payload[:multipart].should eq true
|
139
|
+
payload[:template_id].should eq 123
|
140
|
+
payload[:to].should eq 'john@doe.com'
|
141
|
+
payload[:reply_to].should eq 'jane@doe.com'
|
142
|
+
payload[:from].should eq 'Jane Doe'
|
143
|
+
payload[:subject].should eq 'Hello, Dolly!'
|
144
|
+
payload[:template_id].should eq 123
|
145
|
+
payload[:merge_fields][:eye_color].should eq 'blue'
|
146
|
+
payload[:merge_fields][:body_shape].should eq 'pear'
|
147
|
+
payload[:view_online].should eq false
|
148
|
+
payload[:click_tracking].should eq true
|
149
|
+
payload['attachment1.txt'].class.should eq File
|
150
|
+
File.basename(payload['attachment1.txt']).should eq 'attachment1.txt'
|
151
|
+
File.basename(payload['attachment2.txt']).should eq 'attachment2.txt'
|
152
|
+
end
|
127
153
|
end
|
data/test/README
ADDED
@@ -0,0 +1,32 @@
|
|
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
|
Binary file
|
@@ -0,0 +1,18 @@
|
|
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
|
+
|
8
|
+
puts MESSAGES.send_message(
|
9
|
+
1527, # template_id
|
10
|
+
'igor@expresspigeon.com', #to
|
11
|
+
'igor@polevoy.org', #reply_to
|
12
|
+
"Igor Polevoy", #from_name
|
13
|
+
"Hi there! Two attachments and a calendar - Ruby", #subject
|
14
|
+
{first_name: 'Igor', eye_color: 'blue'}, #merge_fields
|
15
|
+
false, #view_online
|
16
|
+
true, #click_tracking
|
17
|
+
attachments #file paths to upload as attachments
|
18
|
+
)
|
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.0.6
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- ipolevoy
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-
|
11
|
+
date: 2016-11-15 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: 1.8
|
19
|
+
version: '1.8'
|
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: 1.8
|
26
|
+
version: '1.8'
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: rspec
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
@@ -70,8 +70,13 @@ files:
|
|
70
70
|
- spec/pigeon_helper.rb
|
71
71
|
- spec/resources/upload.csv
|
72
72
|
- spec/templates_spec.rb
|
73
|
+
- test/README
|
74
|
+
- test/attachments/example.ics
|
75
|
+
- test/attachments/smile.pdf
|
76
|
+
- test/send_with_attachments.rb
|
73
77
|
homepage: https://github.com/expresspigeon/expresspigeon-ruby
|
74
|
-
licenses:
|
78
|
+
licenses:
|
79
|
+
- MIT
|
75
80
|
metadata: {}
|
76
81
|
post_install_message:
|
77
82
|
rdoc_options: []
|
@@ -101,4 +106,7 @@ test_files:
|
|
101
106
|
- spec/pigeon_helper.rb
|
102
107
|
- spec/resources/upload.csv
|
103
108
|
- spec/templates_spec.rb
|
104
|
-
|
109
|
+
- test/README
|
110
|
+
- test/attachments/example.ics
|
111
|
+
- test/attachments/smile.pdf
|
112
|
+
- test/send_with_attachments.rb
|