expresspigeon-ruby 0.0.2 → 0.0.3

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 219e88febc4f6de2dec7d8688366a8ad687b8928
4
- data.tar.gz: a060f8c93df2f5dc6329ea4b098eed97da24e310
3
+ metadata.gz: fefbb9b811e6290f8bee711c7999eee4863fbf2c
4
+ data.tar.gz: 226ce044ad36fc9e040765166957e60b55a86310
5
5
  SHA512:
6
- metadata.gz: d24f13e62161c083a61437e14474f24552c37d64606e23adc3c0d0016837e08f004296af4ac1230f54bad9c0a1f85fe7415c9b19484823980417d122a7d75913
7
- data.tar.gz: 84e93e5168cbfc8df275cc564e9b2b72feebc413a238a06b314f16de037530848c88b7de577a8a0ddacd70a4b6b6be6c2badc0f60a0c204f8552fe130c0ff094
6
+ metadata.gz: afddd1061ee740fbfaf728021ac668adf13fa9dcdc4da1b009a9cdfc5c5c04238c7a8e82a206820374bd08ac61494b0f19ecdb246688fce3f9da1b1e923d629a
7
+ data.tar.gz: f049b418b5e84d7664ad8e2d721d02b7fa7de7b3a2d2e14b069fd53188f854b5374389e01d46672b50a0da784c055fc971695991d24adcbc33f3444b5aa07d03
data/.gitignore CHANGED
@@ -5,3 +5,5 @@
5
5
 
6
6
  rspec.sh
7
7
  set_env
8
+
9
+ *.txt
data/.rvmrc CHANGED
@@ -3,6 +3,6 @@ USER_RVMRC='.rvmrc.local'
3
3
  if [ -f $USER_RVMRC ]; then
4
4
  source $USER_RVMRC
5
5
  else
6
- rvm use 2.1.5 --create
6
+ rvm use 2.1.1 --create
7
7
  fi
8
8
 
data/Gemfile.lock CHANGED
@@ -1,12 +1,23 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- expresspigeon-ruby (0.0.1)
4
+ expresspigeon-ruby (0.0.2)
5
+ rest-client (~> 1.8.0)
5
6
 
6
7
  GEM
7
8
  remote: https://rubygems.org/
8
9
  specs:
9
10
  diff-lcs (1.2.5)
11
+ domain_name (0.5.24)
12
+ unf (>= 0.0.5, < 1.0.0)
13
+ http-cookie (1.0.2)
14
+ domain_name (~> 0.5)
15
+ mime-types (1.25.1)
16
+ netrc (0.7.9)
17
+ rest-client (1.8.0)
18
+ http-cookie (>= 1.0.2, < 2.0)
19
+ mime-types (>= 1.16, < 3.0)
20
+ netrc (~> 0.7)
10
21
  rspec (2.14.1)
11
22
  rspec-core (~> 2.14.0)
12
23
  rspec-expectations (~> 2.14.0)
@@ -15,6 +26,9 @@ GEM
15
26
  rspec-expectations (2.14.3)
16
27
  diff-lcs (>= 1.1.3, < 2.0)
17
28
  rspec-mocks (2.14.3)
29
+ unf (0.1.4)
30
+ unf_ext
31
+ unf_ext (0.0.7.1)
18
32
 
19
33
  PLATFORMS
20
34
  ruby
data/README.md CHANGED
@@ -38,6 +38,8 @@ sleep 5
38
38
 
39
39
  # get a report for a specific message
40
40
  puts MESSAGES.report message_response.id
41
+ ```
42
+
41
43
 
42
44
  ## Contributing
43
45
 
Binary file
@@ -7,8 +7,8 @@ Gem::Specification.new do |gem|
7
7
  gem.name = "expresspigeon-ruby"
8
8
  gem.version = Expresspigeon::API::VERSION
9
9
  gem.authors = ["ipolevoy"]
10
- gem.email = ["ipolevoy@groupon.com"]
11
- gem.description = %q{ExpressPigeon Ruby API for sending transactional messages, manipulating lists, contacts nad more}
10
+ gem.email = ["igor@expresspigeon.com"]
11
+ gem.description = %q{ExpressPigeon Ruby API for sending transactional messages, manipulating lists, contacts and more}
12
12
  gem.summary = %q{ExpressPigeon API Ruby Wrapper}
13
13
  gem.homepage = "https://github.com/expresspigeon/expresspigeon-ruby"
14
14
 
@@ -16,5 +16,8 @@ Gem::Specification.new do |gem|
16
16
  gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
17
17
  gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
18
18
  gem.require_paths = ["lib"]
19
+
20
+ gem.add_runtime_dependency 'rest-client', '~> 1.8.0'
21
+
19
22
  gem.add_development_dependency "rspec", "~> 2.6"
20
23
  end
@@ -0,0 +1,47 @@
1
+ module ExpressPigeon
2
+ class AutoResponders
3
+ include ExpressPigeon::API
4
+
5
+ def initialize
6
+ @endpoint = 'auto_responders'
7
+ end
8
+
9
+ attr_reader :endpoint
10
+
11
+ # Get all autoresponders
12
+ #
13
+ # Returns an array of autoresponders.
14
+ #
15
+ # Docs: https://expresspigeon.com/api#auto_responders_get_all
16
+ #
17
+ def all
18
+ get endpoint
19
+ end
20
+
21
+ # Start for a contact
22
+ #
23
+ # This call starts an autoresponder for a contact.
24
+ #
25
+ # :param auto_responder_id: autoresponder id to be started for a contact
26
+ # :param email: contact email
27
+ #
28
+ # Docs: https://expresspigeon.com/api#auto_responders_start
29
+ #
30
+ def start(auto_responder_id, email)
31
+ post "#{endpoint}/#{auto_responder_id}/start", email: email
32
+ end
33
+
34
+ # Stop for a contact
35
+ #
36
+ # This call stops an autoresponder for a contact.
37
+ #
38
+ # :param auto_responder_id: autoresponder id to be stopped for a contact
39
+ # :param email: contact email
40
+ #
41
+ # Docs: https://expresspigeon.com/api#auto_responders_stop
42
+ #
43
+ def stop(auto_responder_id, email)
44
+ post "#{endpoint}/#{auto_responder_id}/stop", email: email
45
+ end
46
+ end
47
+ end
@@ -3,6 +3,7 @@ require "expresspigeon-ruby/version"
3
3
  require 'net/http'
4
4
  require 'json'
5
5
  require 'uri'
6
+ require 'rest_client'
6
7
 
7
8
  module ExpressPigeon
8
9
 
@@ -25,16 +26,22 @@ module ExpressPigeon
25
26
 
26
27
  def http(path, method, params = {})
27
28
  root = @root ? @root : ROOT
29
+
30
+ if params and !params.empty? and method == 'Get'
31
+ query = URI.encode_www_form(params)
32
+ path = "#{path}?#{query}"
33
+ end
34
+
35
+
28
36
  uri = URI.parse "#{root}#{path}"
29
37
  req = Net::HTTP.const_get("#{method}").new "#{ROOT}#{path}"
30
- unless AUTH_KEY || @auth_key
31
- raise("Must set either EXPRESSPIGEON_AUTH_KEY as environment variable, or ExpressPigeon::AUTH_KEY in code")
32
- end
33
38
 
34
- req['X-auth-key'] = AUTH_KEY ? AUTH_KEY : @auth_key
39
+ req['X-auth-key'] = get_auth_key
35
40
  if params
36
- req.body = params.to_json
37
- req['Content-type'] = 'application/json'
41
+ if method != 'Get'
42
+ req.body = params.to_json
43
+ req['Content-type'] = 'application/json'
44
+ end
38
45
  end
39
46
 
40
47
  if block_given?
@@ -58,8 +65,16 @@ module ExpressPigeon
58
65
  end
59
66
  end
60
67
 
61
- def get(path, &block)
62
- http path, 'Get', nil, &block
68
+ def get_auth_key
69
+ unless AUTH_KEY || @auth_key
70
+ raise("Must set authentication key either using environment variable EXPRESSPIGEON_AUTH_KEY, or using auth_key() method in code")
71
+ end
72
+
73
+ @auth_key ? @auth_key : AUTH_KEY
74
+ end
75
+
76
+ def get(path, params = {}, &block)
77
+ http path, 'Get', params, &block
63
78
  end
64
79
 
65
80
  def post(path, params = {})
@@ -85,234 +100,23 @@ module ExpressPigeon
85
100
  def self.messages
86
101
  Messages.new
87
102
  end
88
- end
89
-
90
- end
91
103
 
92
- class MetaHash < Hash
93
-
94
- def initialize(delegate)
95
- super
96
- @delegate = delegate
97
- @delegate.each_key do |k|
98
- v = @delegate[k] # lets go only one level down for now
99
- if v.kind_of? Hash
100
- @delegate[k] = MetaHash.new(v)
101
- end
104
+ def self.auto_responders
105
+ AutoResponders.new
102
106
  end
103
- end
104
-
105
- def method_missing(m, *args, &block)
106
- @delegate[m.to_s]
107
- end
108
-
109
- def to_s
110
- @delegate.to_s
111
- end
112
-
113
- end
114
-
115
- class Lists
116
-
117
- include ExpressPigeon::API
118
-
119
- def initialize
120
- @endpoint = 'lists'
121
- end
122
-
123
- def create(list_name, from_name, reply_to)
124
- post @endpoint, {:name => list_name, :from_name => from_name, :reply_to => reply_to}
125
- end
126
-
127
-
128
- # Query all lists.
129
- # returns: array of hashes each representing a list for this user
130
- def all
131
- get @endpoint
132
- end
133
-
134
-
135
- #Updates existing list
136
- #
137
- #:param list_id: Id of list to be updated
138
- #:type list_id: int
139
- #
140
- #:param params: JSON object represents a list to be updated
141
107
 
142
- #
143
- #:returns: EpResponse with status, code, message, and updated list
144
- #:rtype: EpResponse
145
- #TODO: resolve API on Python side, then implement this
146
- #def update(list_id, params = {})
147
- # params['id'] = list_id
148
- # return self.ep.put(self.endpoint, params=params)
149
- #end
150
-
151
-
152
- # Removes a list with a given id. A list must be enabled and has no dependent subscriptions and/or scheduled campaigns.
153
- #
154
- # param list_id: Id of list to be removed.
155
- # returns response hash with status, code, and message
156
- def delete(list_id)
157
- del "#{@endpoint}/#{list_id}"
158
- end
159
-
160
- def csv(list_id, &block)
161
- get "#{@endpoint}/#{list_id}/csv", &block
162
- end
163
-
164
-
165
- end
166
-
167
- class Campaigns
168
- include ExpressPigeon::API
169
-
170
- def initialize
171
- @endpoint = 'campaigns'
172
- end
173
-
174
- def all
175
- get @endpoint
176
- end
177
-
178
- def report(campaign_id)
179
- get "#{@endpoint}/#{campaign_id}"
180
- end
181
-
182
- def bounced(campaign_id)
183
- get "#{@endpoint}/#{campaign_id}/bounced"
184
- end
185
-
186
- def unsubscribed(campaign_id)
187
- get "#{@endpoint}/#{campaign_id}/unsubscribed"
188
- end
189
-
190
- def spam(campaign_id)
191
- get "#{@endpoint}/#{campaign_id}/spam"
192
- end
193
-
194
- #
195
- # Schedules a new campaign to be sent.
196
- # Parameters:
197
- # * *list_id* - id of list to send to
198
- # * *template_id* - id of template to send
199
- # * *name* - name of a newly created campaign
200
- # * *from_name* - from name
201
- # * *reply_to* - reply to
202
- # * *subject* - subject of campaign
203
- # * *google_analytics* - true to turn Google Analytics on
204
- def send(params = {})
205
- post @endpoint, params
206
- end
207
-
208
- #
209
- # Schedules a new campaign to be sent.
210
- # Parameters:
211
- # * *list_id* - id of list to send to
212
- # * *template_id* - id of template to send
213
- # * *name* - name of a newly created campaign
214
- # * *from_name* - from name
215
- # * *reply_to* - reply to
216
- # * *subject* - subject of campaign
217
- # * *google_analytics* - true to turn Google Analytics on
218
- # * *schedule_for* - Specifies what time a campaign should be sent. If it is provided the campaign will
219
- # be scheduled to this time, otherwise campaign is sent immediately. The schedule_for
220
- # must be in ISO date format and should be in the future.
221
- def schedule(params = {})
222
- post @endpoint, params
223
- end
224
- end
225
-
226
-
227
- class Contacts
228
- include ExpressPigeon::API
229
-
230
- def initialize
231
- @endpoint = 'contacts'
232
- end
233
-
234
- def find_by_email(email)
235
- get "#{@endpoint}?email=#{email}"
236
- end
237
-
238
-
239
- # JSON document represents a contact to be created or updated.
240
- # The email field is required.
241
- # When updating a contact, list_id is optional,
242
- # since the contact is uniquely identified by email across all lists.
243
- #
244
- # :param list_id: Contact list ID (Fixnum) the contact will be added to
245
- #
246
- # :param contact: Hash describes new contact. The "email" field is required.
247
- #
248
- # :returns: representation of a contact
249
- #
250
- def upsert(list_id, contact)
251
- post @endpoint, params = {:list_id => list_id, :contact => contact}
252
- end
253
-
254
- # Delete single contact. If list_id is not provided, contact will be deleted from system.
255
- # :param email: contact email to be deleted.
256
- # :param list_id: list id to remove contact from, if not provided, contact will be deleted from system.
257
- def delete(email, list_id = nil)
258
- if list_id
259
- query = "email=#{email}&list_id=#{list_id}"
260
- else
261
- query = "email=#{email}"
108
+ def self.templates
109
+ Templates.new
262
110
  end
263
- del "#{@endpoint}?#{query}", nil
264
111
  end
265
112
 
266
-
267
113
  end
268
- class Messages
269
-
270
- include ExpressPigeon::API
271
-
272
- def initialize
273
- @endpoint = 'messages'
274
- end
275
-
276
- def send_message(template_id, to, reply_to, from_name, subject, merge_fields = nil, view_online = false, click_tracking = true)
277
- post @endpoint, params = {template_id: template_id, :to => to, reply_to: reply_to, :from => from_name, :subject => subject,
278
- :merge_fields => merge_fields, :view_online => view_online, :click_tracking => click_tracking}
279
- end
280
-
281
- def report(message_id)
282
- get "#{@endpoint}/#{message_id}"
283
- end
284
-
285
- #
286
- #
287
- # start_date is instance of Time
288
- # end_date is instance of Time
289
- def reports(from_id, start_date = nil, end_date = nil)
290
- params = []
291
114
 
292
- if from_id
293
- params << "from_id=#{from_id}"
294
- end
295
-
296
- if start_date and not end_date
297
- raise 'must include both start_date and end_date'
298
- end
299
- if end_date and not start_date
300
- raise 'must include both start_date and end_date'
301
- end
302
-
303
- if start_date and end_date
304
- params << "start_date=#{start_date.strftime('%FT%T.%L%z')}"
305
- params << "end_date=#{end_date.strftime('%FT%T.%L%z')}"
306
- end
115
+ require_relative 'expresspigeon-ruby/meta_hash'
116
+ require_relative 'expresspigeon-ruby/lists'
117
+ require_relative 'expresspigeon-ruby/campaigns'
118
+ require_relative 'expresspigeon-ruby/contacts'
119
+ require_relative 'expresspigeon-ruby/messages'
120
+ require_relative 'expresspigeon-ruby/templates'
307
121
 
308
- query = "#{@endpoint}?"
309
-
310
- if params.size > 0
311
- query << params.join('&')
312
- end
313
-
314
- puts "calling: #{query}"
315
- get query
316
-
317
- end
318
- end
122
+ require_relative 'express_pigeon/auto_responders'
@@ -0,0 +1,64 @@
1
+ module ExpressPigeon
2
+ class Campaigns
3
+ include ExpressPigeon::API
4
+
5
+ def initialize
6
+ @endpoint = 'campaigns'
7
+ end
8
+
9
+ def all (params ={})
10
+ get @endpoint, params
11
+ end
12
+
13
+ def report(campaign_id)
14
+ get "#{@endpoint}/#{campaign_id}"
15
+ end
16
+
17
+ def bounced(campaign_id)
18
+ get "#{@endpoint}/#{campaign_id}/bounced"
19
+ end
20
+
21
+ def unsubscribed(campaign_id)
22
+ get "#{@endpoint}/#{campaign_id}/unsubscribed"
23
+ end
24
+
25
+ def spam(campaign_id)
26
+ get "#{@endpoint}/#{campaign_id}/spam"
27
+ end
28
+
29
+ #
30
+ # Schedules a new campaign to be sent.
31
+ # Parameters:
32
+ # * *list_id* - id of list to send to
33
+ # * *template_id* - id of template to send
34
+ # * *name* - name of a newly created campaign
35
+ # * *from_name* - from name
36
+ # * *reply_to* - reply to
37
+ # * *subject* - subject of campaign
38
+ # * *google_analytics* - true to turn Google Analytics on
39
+ def send(params = {})
40
+ post @endpoint, params
41
+ end
42
+
43
+ #
44
+ # Schedules a new campaign to be sent.
45
+ # Parameters:
46
+ # * *list_id* - id of list to send to
47
+ # * *template_id* - id of template to send
48
+ # * *name* - name of a newly created campaign
49
+ # * *from_name* - from name
50
+ # * *reply_to* - reply to
51
+ # * *subject* - subject of campaign
52
+ # * *google_analytics* - true to turn Google Analytics on
53
+ # * *schedule_for* - Specifies what time a campaign should be sent. If it is provided the campaign will
54
+ # be scheduled to this time, otherwise campaign is sent immediately. The schedule_for
55
+ # must be in ISO date format and should be in the future.
56
+ def schedule(params = {})
57
+ post @endpoint, params
58
+ end
59
+
60
+ def delete(campaign_id)
61
+ del "#{@endpoint}/#{campaign_id}"
62
+ end
63
+ end
64
+ end