sailthru-client 1.15 → 2.0.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.
- data/README.md +4 -311
- data/lib/sailthru.rb +206 -54
- metadata +96 -76
data/README.md
CHANGED
@@ -1,320 +1,13 @@
|
|
1
1
|
sailthru-ruby-client
|
2
2
|
====================
|
3
3
|
|
4
|
-
|
4
|
+
For installation instructions, documentation, and examples please visit:
|
5
|
+
[http://getstarted.sailthru.com/developers/api-libraries/ruby](http://getstarted.sailthru.com/developers/api-libraries/ruby)
|
5
6
|
|
6
|
-
|
7
|
-
|
8
|
-
It can make requests to following [API calls](http://docs.sailthru.com/api):
|
7
|
+
A simple client library to remotely access the `Sailthru REST API` as per [http://getstarted.sailthru.com/api](http://getstarted.sailthru.com/developers/api)
|
9
8
|
|
10
|
-
|
11
|
-
* [user](http://docs.sailthru.com/api/user)
|
12
|
-
* [send](http://docs.sailthru.com/api/send)
|
13
|
-
* [blast](http://docs.sailthru.com/api/blast)
|
14
|
-
* [template](http://docs.sailthru.com/api/template)
|
15
|
-
* [list](http://docs.sailthru.com/api/list)
|
16
|
-
* [contacts](http://docs.sailthru.com/api/contacts)
|
17
|
-
* [content](http://docs.sailthru.com/api/content)
|
18
|
-
* [alert](http://docs.sailthru.com/api/alert)
|
19
|
-
* [stats](http://docs.sailthru.com/api/stats)
|
20
|
-
* [purchase](http://docs.sailthru.com/api/purchase)
|
21
|
-
* [horizon](http://docs.sailthru.com/api/horizon)
|
9
|
+
By default, it will make request in `JSON` format.
|
22
10
|
|
23
11
|
### Installing from rubygems.org (Tested with Ruby 1.8.7)
|
24
12
|
$ gem install sailthru-client
|
25
13
|
|
26
|
-
Examples
|
27
|
-
--------
|
28
|
-
|
29
|
-
``` ruby
|
30
|
-
require 'sailthru' #if using as gem
|
31
|
-
|
32
|
-
api_key = "api_key";
|
33
|
-
api_secret = 'secret';
|
34
|
-
api_url = "https://api.sailthru.com";
|
35
|
-
sailthru = Sailthru::SailthruClient.new(api_key, api_secret, api_url)
|
36
|
-
|
37
|
-
# GET http://docs.sailthru.com/api/user API call
|
38
|
-
user_key = 'email'
|
39
|
-
email = 'praj@sailthru.com'
|
40
|
-
fields = {'vars' => 1, 'lists' => 1}
|
41
|
-
data = {
|
42
|
-
'id' => email,
|
43
|
-
'key' => user_key,
|
44
|
-
'fields' => fields
|
45
|
-
}
|
46
|
-
response = sailthru.api_get('user', data)
|
47
|
-
|
48
|
-
# POST http://docs.sailthru.com/api/user API call
|
49
|
-
user_sid = '4e2879472d7acd6d97144f9e' #sailthru ID
|
50
|
-
lists = {
|
51
|
-
"list-A" => 1,
|
52
|
-
"list-B" => 1,
|
53
|
-
"list-C" => 0 #optout of this list
|
54
|
-
}
|
55
|
-
vars = {
|
56
|
-
'name' => 'Prajwal Tuladhar',
|
57
|
-
'address' => {
|
58
|
-
'city': 'New York',
|
59
|
-
'state': 'NY',
|
60
|
-
'zipcode': 10011
|
61
|
-
}
|
62
|
-
}
|
63
|
-
data = {
|
64
|
-
'id' => user_sid,
|
65
|
-
'lists' => lists,
|
66
|
-
'vars' => vars
|
67
|
-
}
|
68
|
-
response = sailthru.api_post('user', data)
|
69
|
-
|
70
|
-
```
|
71
|
-
|
72
|
-
### [send](http://docs.sailthru.com/api/send)
|
73
|
-
``` ruby
|
74
|
-
#send
|
75
|
-
template_name = 'my-template'
|
76
|
-
email = 'praj@sailthru.com'
|
77
|
-
vars = {'name' => 'Prajwal Tuladhar', "myvar" => [1111,2,3]}
|
78
|
-
options = {'test' => 1}
|
79
|
-
schedule_time = '+3 hours'
|
80
|
-
response = sailthru.send(template_name, email, vars, options, schedule_time)
|
81
|
-
|
82
|
-
#get send
|
83
|
-
send_id = '6363'
|
84
|
-
response = sailthru.get_send(send_id)
|
85
|
-
|
86
|
-
#cancel send
|
87
|
-
send_id = '236236sbs'
|
88
|
-
response = sailthru.cancel_send(send_id)
|
89
|
-
|
90
|
-
#multi send
|
91
|
-
template_name = 'my-template'
|
92
|
-
emails = 'praj@sailthru.com, ian@sailthru.com'
|
93
|
-
vars = {'name' => 'Prajwal Tuladhar', "myvar" => [1111,2,3]}
|
94
|
-
options = {'test' => 1}
|
95
|
-
response = sailthru.multi_send(template_name, emails, vars, options)
|
96
|
-
```
|
97
|
-
|
98
|
-
### [user](http://docs.sailthru.com/api/user)
|
99
|
-
```ruby
|
100
|
-
#create new user profile
|
101
|
-
options = {
|
102
|
-
'vars' => {
|
103
|
-
'name' => 'Prajwal Tuladhar',
|
104
|
-
'address' => 'New York, NY'
|
105
|
-
}
|
106
|
-
}
|
107
|
-
response = sailthru.create_new_user(options)
|
108
|
-
|
109
|
-
#update existing user by Sailthru ID
|
110
|
-
options = {
|
111
|
-
'keys' => {
|
112
|
-
'email' => 'praj@sailthru.com',
|
113
|
-
'twitter' => 'infynyxx',
|
114
|
-
'fb' => 726310296
|
115
|
-
},
|
116
|
-
'lists' => {
|
117
|
-
'list-1' => 1,
|
118
|
-
'list-2' => 1,
|
119
|
-
}
|
120
|
-
}
|
121
|
-
response = sailthru.save_user('4e2879472d7acd6d97144f9e', options)
|
122
|
-
|
123
|
-
#update existing user by email
|
124
|
-
options = {
|
125
|
-
'key' => 'email',
|
126
|
-
'lists' => {
|
127
|
-
'list-1' => 0
|
128
|
-
}
|
129
|
-
}
|
130
|
-
response = sailthru.save_user('praj@sailthru.com', options)
|
131
|
-
|
132
|
-
#get user by Sailthru ID
|
133
|
-
fields = {
|
134
|
-
'keys' => 1,
|
135
|
-
'vars' => 1,
|
136
|
-
'activity' => 1
|
137
|
-
}
|
138
|
-
response = sailthru.get_user_by_sid('4e2879472d7acd6d97144f9e')
|
139
|
-
|
140
|
-
#get user by Custom key
|
141
|
-
response = sailthru.get_user_by_key('praj@sailthru.com', 'email', fields)
|
142
|
-
|
143
|
-
```
|
144
|
-
|
145
|
-
|
146
|
-
### [email](http://docs.sailthru.com/api/email)
|
147
|
-
``` ruby
|
148
|
-
#get email
|
149
|
-
email = 'praj@sailthru.com'
|
150
|
-
response = sailthru.get_email(email)
|
151
|
-
|
152
|
-
#set email
|
153
|
-
email = 'praj@sailthru.com'
|
154
|
-
response = sailthru.set_email(email)
|
155
|
-
```
|
156
|
-
|
157
|
-
### [blast](http://docs.sailthru.com/api/blast)
|
158
|
-
``` ruby
|
159
|
-
#schedule blast
|
160
|
-
blast_name = 'My blast name'
|
161
|
-
template = 'my-template'
|
162
|
-
schedule_time = '+5 hours'
|
163
|
-
from_name = 'prajwal tuladhar'
|
164
|
-
from_email = 'praj@sailthru.com'
|
165
|
-
subject = "What's up!"
|
166
|
-
html = '<p>Lorem ispum is great</p>'
|
167
|
-
text = 'Lorem ispum is great'
|
168
|
-
response = sailthru.schedule_blast(blast_name, template, schedule_time, from_name, from_email, subject, html, text)
|
169
|
-
|
170
|
-
#schedule blast from template
|
171
|
-
template = 'default'
|
172
|
-
list = 'default'
|
173
|
-
schedule_time = 'now'
|
174
|
-
response = sailthru.schedule_blast_from_template(template, list, schedule_time)
|
175
|
-
|
176
|
-
#schedule blast from previous blast
|
177
|
-
blast_id = 67535
|
178
|
-
schedule_time ='now'
|
179
|
-
vars = {
|
180
|
-
'my_var' => '3y6366546363',
|
181
|
-
'my_var2' => [7,8,9],
|
182
|
-
'my_var3' => {'president' => 'obama', 'nested' => {'vp' => 'palin'}}
|
183
|
-
}
|
184
|
-
options = {:vars => vars}
|
185
|
-
response = sailthru.schedule_blast_from_blast(blast_id, "now", options)
|
186
|
-
|
187
|
-
#update blast
|
188
|
-
blast_id = 7886
|
189
|
-
name = 'prajwal tuladhar 64'
|
190
|
-
response = sailthru.update_blast(blast_id, name = name)
|
191
|
-
|
192
|
-
#get blast info
|
193
|
-
blast_id = 7886
|
194
|
-
response = sailthru.get_blast(blast_id)
|
195
|
-
|
196
|
-
#cancel blast
|
197
|
-
blast_id = 7886
|
198
|
-
response = sailthru.cancel_blast(blast_id)
|
199
|
-
|
200
|
-
#delete blast
|
201
|
-
blast_id = 7886
|
202
|
-
response = sailthru.delete_blast(blast_id)
|
203
|
-
```
|
204
|
-
|
205
|
-
### [list](http://docs.sailthru.com/api/list)
|
206
|
-
|
207
|
-
Get information about a list, or create a list.
|
208
|
-
|
209
|
-
``` ruby
|
210
|
-
#save list
|
211
|
-
list_name = 'my-list'
|
212
|
-
options = {
|
213
|
-
'primary' => 1,
|
214
|
-
}
|
215
|
-
response = sailthru.save_list(list_name, options)
|
216
|
-
|
217
|
-
#get list information
|
218
|
-
list_name = 'my-list'
|
219
|
-
response = sailthru.get_list(list_name)
|
220
|
-
|
221
|
-
#get all lists
|
222
|
-
response = sailthru.get_lists()
|
223
|
-
|
224
|
-
#delete list
|
225
|
-
list_name = 'my-list'
|
226
|
-
response = sailthru.delete_list(list_name)
|
227
|
-
```
|
228
|
-
|
229
|
-
### [content](http://docs.sailthru.com/api/content)
|
230
|
-
``` ruby
|
231
|
-
#push content
|
232
|
-
title = 'hello world'
|
233
|
-
url = 'http://example.com/product-url'
|
234
|
-
response = sailthru.push_content(title, url)
|
235
|
-
|
236
|
-
#another push content exammple
|
237
|
-
title = 'hello world'
|
238
|
-
url = 'http://example.com/product-url'
|
239
|
-
tags = ["blue", "red", "green"]
|
240
|
-
vars = {'vars' => ['price' => 17299]}
|
241
|
-
date = nil
|
242
|
-
response = sailthru.push_content(title, url, date, tags = tags, vars = vars)
|
243
|
-
```
|
244
|
-
|
245
|
-
### [alert](http://docs.sailthru.com/api/alert)
|
246
|
-
``` ruby
|
247
|
-
#get alert info
|
248
|
-
email = 'praj@sailthru.com'
|
249
|
-
response = sailthru.get_alert(email)
|
250
|
-
|
251
|
-
#save alert
|
252
|
-
email = 'praj@sailthru.com'
|
253
|
-
type = 'daily'
|
254
|
-
_when = '+5 hours'
|
255
|
-
extras = {'tags' => ['red', 'blue'], 'match' => {'type' => 'yellow'}}
|
256
|
-
response = sailthru.save_alert(email, type, _when, extras)
|
257
|
-
|
258
|
-
#delete alert
|
259
|
-
email = 'praj@sailthru.com'
|
260
|
-
alert_id = '4d4b17a36763d930210007ba'
|
261
|
-
response = sailthru.delete_alert(email, alert_id)
|
262
|
-
``` ruby
|
263
|
-
|
264
|
-
### [purchase](http://docs.sailthru.com/api/purchase)
|
265
|
-
``` ruby
|
266
|
-
#purchase API call
|
267
|
-
email = 'praj@sailthru.com'
|
268
|
-
items = [{"price"=>1099, "qty"=>22, "title"=>"High-Impact Water Bottle", "url"=>"http://example.com/234/high-impact-water-bottle", "id"=>"234"}, {"price"=>500, "qty"=>2, "title"=>"Lorem Ispum", "url"=>"http://example.com/2304/lorem-ispum", "id"=>"2304"}]
|
269
|
-
response = sailthru.purchase(email, items)
|
270
|
-
```
|
271
|
-
|
272
|
-
### [stats](http://docs.sailthru.com/api/stats)
|
273
|
-
``` ruby
|
274
|
-
#stats list
|
275
|
-
response = sailthru.stats_list()
|
276
|
-
|
277
|
-
#stats blast
|
278
|
-
blast_id = 42382
|
279
|
-
response = sailthru.stats_blast(blast_id)
|
280
|
-
```
|
281
|
-
|
282
|
-
### [horizon](http://docs.sailthru.com/api/horizon)
|
283
|
-
``` ruby
|
284
|
-
#get horizon user info
|
285
|
-
email = 'praj@sailthru.com'
|
286
|
-
response = sailthru.get_horizon(email)
|
287
|
-
|
288
|
-
#set horizon data
|
289
|
-
email = 'praj@sailthru.com'
|
290
|
-
tags = ['red', 'blue']
|
291
|
-
response = sailthru.set_horizon(email, tags)
|
292
|
-
```
|
293
|
-
|
294
|
-
|
295
|
-
### [job] (http://docs.sailthru.com/api/job)
|
296
|
-
``` ruby
|
297
|
-
# get status of job id
|
298
|
-
job_id = '4dd58f036803fa3b5500000b'
|
299
|
-
response = sailthru.get_job_status(job_id)
|
300
|
-
|
301
|
-
# process import job for email string
|
302
|
-
list = 'test-list'
|
303
|
-
emails = 'a@a.com,b@b.com'
|
304
|
-
response = sailthru.process_import_job(list, emails)
|
305
|
-
|
306
|
-
# process import job from CSV or text file
|
307
|
-
list = 'test-list'
|
308
|
-
source_file = '/home/praj/Desktop/emails.txt'
|
309
|
-
response = sailthru.process_import_job(list, source_file)
|
310
|
-
|
311
|
-
# process snapshot job
|
312
|
-
query = {}
|
313
|
-
report_email = 'praj@sailthru.com'
|
314
|
-
postback_url = 'http://example.com/reports/snapshot_postback'
|
315
|
-
response = sailthru.process_snapshot_job(query)
|
316
|
-
|
317
|
-
# process export list job
|
318
|
-
list = 'test-list'
|
319
|
-
response = sailthru.process_export_list_job(list)
|
320
|
-
```
|
data/lib/sailthru.rb
CHANGED
@@ -9,7 +9,7 @@ require 'net/http/post/multipart'
|
|
9
9
|
|
10
10
|
module Sailthru
|
11
11
|
|
12
|
-
Version = VERSION = '
|
12
|
+
Version = VERSION = '2.0.0'
|
13
13
|
|
14
14
|
class SailthruClientException < Exception
|
15
15
|
end
|
@@ -118,9 +118,27 @@ module Sailthru
|
|
118
118
|
# options, Hash
|
119
119
|
# replyto: override Reply-To header
|
120
120
|
# test: send as test email (subject line will be marked, will not count towards stats)
|
121
|
+
# schedule_time, Date
|
121
122
|
# returns:
|
122
123
|
# Hash, response data from server
|
124
|
+
#
|
125
|
+
# Send a transactional email, or schedule one for the near future
|
126
|
+
# http://docs.sailthru.com/api/send
|
123
127
|
def send(template_name, email, vars={}, options = {}, schedule_time = nil)
|
128
|
+
warn "[DEPRECATION] `send` is deprecated. Please use `send_email` instead."
|
129
|
+
send_email(template_name, email, vars={}, options = {}, schedule_time = nil)
|
130
|
+
end
|
131
|
+
|
132
|
+
# params:
|
133
|
+
# template_name, String
|
134
|
+
# email, String
|
135
|
+
# vars, Hash
|
136
|
+
# options, Hash
|
137
|
+
# replyto: override Reply-To header
|
138
|
+
# test: send as test email (subject line will be marked, will not count towards stats)
|
139
|
+
# returns:
|
140
|
+
# Hash, response data from server
|
141
|
+
def send_email(template_name, email, vars={}, options = {}, schedule_time = nil)
|
124
142
|
post = {}
|
125
143
|
post[:template] = template_name
|
126
144
|
post[:email] = email
|
@@ -250,12 +268,14 @@ module Sailthru
|
|
250
268
|
|
251
269
|
# params:
|
252
270
|
# blast_id, Fixnum | String
|
271
|
+
# options, hash
|
253
272
|
# returns:
|
254
273
|
# Hash, response data from server
|
255
274
|
#
|
256
275
|
# Get information on a previously scheduled email blast
|
257
|
-
def get_blast(blast_id)
|
258
|
-
|
276
|
+
def get_blast(blast_id, options={})
|
277
|
+
options[:blast_id] = blast_id.to_s
|
278
|
+
api_get(:blast, options)
|
259
279
|
end
|
260
280
|
|
261
281
|
# params:
|
@@ -288,18 +308,35 @@ module Sailthru
|
|
288
308
|
# email, String
|
289
309
|
# vars, Hash
|
290
310
|
# lists, Hash mapping list name => 1 for subscribed, 0 for unsubscribed
|
311
|
+
# options, Hash mapping optional parameters
|
291
312
|
# returns:
|
292
313
|
# Hash, response data from server
|
293
314
|
#
|
294
315
|
# Set replacement vars and/or list subscriptions for an email address.
|
295
|
-
def set_email(email, vars = {}, lists = {}, templates = {})
|
296
|
-
data =
|
316
|
+
def set_email(email, vars = {}, lists = {}, templates = {}, options = {})
|
317
|
+
data = options
|
318
|
+
data[:email] = email
|
297
319
|
data[:vars] = vars unless vars.empty?
|
298
320
|
data[:lists] = lists unless lists.empty?
|
299
321
|
data[:templates] = templates unless templates.empty?
|
300
322
|
self.api_post(:email, data)
|
301
323
|
end
|
302
|
-
|
324
|
+
|
325
|
+
# params:
|
326
|
+
# new_email, String
|
327
|
+
# old_email, String
|
328
|
+
# options, Hash mapping optional parameters
|
329
|
+
# returns:
|
330
|
+
# Hash of response data.
|
331
|
+
#
|
332
|
+
# change a user's email address.
|
333
|
+
def change_email(new_email, old_email, options = {})
|
334
|
+
data = options
|
335
|
+
data[:email] = new_email
|
336
|
+
data[:change_email] = old_email
|
337
|
+
self.api_post(:email, data)
|
338
|
+
end
|
339
|
+
|
303
340
|
# params:
|
304
341
|
# template_name, String
|
305
342
|
# returns:
|
@@ -346,8 +383,7 @@ module Sailthru
|
|
346
383
|
|
347
384
|
return false unless params[:action] == :verify
|
348
385
|
|
349
|
-
sig = params
|
350
|
-
params.delete(:sig)
|
386
|
+
sig = params.delete(:sig)
|
351
387
|
return false unless sig == get_signature_hash(params, @secret)
|
352
388
|
|
353
389
|
_send = self.get_send(params[:send_id])
|
@@ -361,6 +397,44 @@ module Sailthru
|
|
361
397
|
end
|
362
398
|
end
|
363
399
|
|
400
|
+
# params:
|
401
|
+
# params, Hash
|
402
|
+
# request, String
|
403
|
+
# returns:
|
404
|
+
# TrueClass or FalseClass, Returns true if the incoming request is an authenticated optout post.
|
405
|
+
def receive_optout_post(params, request)
|
406
|
+
if request.post?
|
407
|
+
[:action, :email, :sig].each { |key| return false unless params.has_key?(key) }
|
408
|
+
|
409
|
+
return false unless params[:action] == 'optout'
|
410
|
+
|
411
|
+
sig = params.delete(:sig)
|
412
|
+
return false unless sig == get_signature_hash(params, @secret)
|
413
|
+
return true
|
414
|
+
else
|
415
|
+
return false
|
416
|
+
end
|
417
|
+
end
|
418
|
+
|
419
|
+
# params:
|
420
|
+
# params, Hash
|
421
|
+
# request, String
|
422
|
+
# returns:
|
423
|
+
# TrueClass or FalseClass, Returns true if the incoming request is an authenticated hardbounce post.
|
424
|
+
def receive_hardbounce_post(params, request)
|
425
|
+
if request.post?
|
426
|
+
[:action, :email, :sig].each { |key| return false unless params.has_key?(key) }
|
427
|
+
|
428
|
+
return false unless params[:action] == 'hardbounce'
|
429
|
+
|
430
|
+
sig = params.delete(:sig)
|
431
|
+
return false unless sig == get_signature_hash(params, @secret)
|
432
|
+
return true
|
433
|
+
else
|
434
|
+
return false
|
435
|
+
end
|
436
|
+
end
|
437
|
+
|
364
438
|
# params:
|
365
439
|
# email, String
|
366
440
|
# items, String
|
@@ -416,7 +490,6 @@ module Sailthru
|
|
416
490
|
data[:date] = date
|
417
491
|
end
|
418
492
|
data[:stat] = 'list'
|
419
|
-
|
420
493
|
stats(data)
|
421
494
|
end
|
422
495
|
|
@@ -445,6 +518,30 @@ module Sailthru
|
|
445
518
|
stats(data)
|
446
519
|
end
|
447
520
|
|
521
|
+
# params
|
522
|
+
# template, String
|
523
|
+
# start_date, String
|
524
|
+
# end_date, String
|
525
|
+
# options, Hash
|
526
|
+
#
|
527
|
+
# returns:
|
528
|
+
# hash, response from server
|
529
|
+
# Retrieve information about a particular blast or aggregated information from all of blasts over a specified date range
|
530
|
+
def stats_send(template = nil, start_date = nil, end_date = nil, options = {})
|
531
|
+
data = options
|
532
|
+
if template != nil
|
533
|
+
data[:template] = template
|
534
|
+
end
|
535
|
+
if start_date != nil
|
536
|
+
data[:start_date] = start_date
|
537
|
+
end
|
538
|
+
if end_date != nil
|
539
|
+
data[:end_date] = end_date
|
540
|
+
end
|
541
|
+
data[:stat] = 'send'
|
542
|
+
stats(data)
|
543
|
+
end
|
544
|
+
|
448
545
|
|
449
546
|
# params
|
450
547
|
# title, String
|
@@ -452,11 +549,12 @@ module Sailthru
|
|
452
549
|
# date, String
|
453
550
|
# tags, Array or Comma separated string
|
454
551
|
# vars, Hash
|
552
|
+
# options, Hash
|
455
553
|
#
|
456
554
|
# Push a new piece of content to Sailthru, triggering any applicable alerts.
|
457
555
|
# http://docs.sailthru.com/api/content
|
458
|
-
def push_content(title, url, date = nil, tags = nil, vars = {})
|
459
|
-
data =
|
556
|
+
def push_content(title, url, date = nil, tags = nil, vars = {}, options = {})
|
557
|
+
data = options
|
460
558
|
data[:title] = title
|
461
559
|
data[:url] = url
|
462
560
|
if date != nil
|
@@ -507,33 +605,6 @@ module Sailthru
|
|
507
605
|
api_delete(:list, {:list => list})
|
508
606
|
end
|
509
607
|
|
510
|
-
# params
|
511
|
-
# email, String
|
512
|
-
# hid_only, Boolean
|
513
|
-
#
|
514
|
-
# gets horizon data
|
515
|
-
def get_horizon(email, hid_only = false)
|
516
|
-
data = {}
|
517
|
-
data[:email] = email
|
518
|
-
if hid_only == true
|
519
|
-
data[:hid_only] = 1
|
520
|
-
end
|
521
|
-
api_get(:horizon, data)
|
522
|
-
end
|
523
|
-
|
524
|
-
|
525
|
-
# params
|
526
|
-
# email, String
|
527
|
-
# tags, String | Array
|
528
|
-
#
|
529
|
-
# sets horizon data
|
530
|
-
def set_horizon(email, tags)
|
531
|
-
data = {}
|
532
|
-
data[:email] = email
|
533
|
-
data[:tags] = (tags.class == Array) ? tags.join(',') : tags
|
534
|
-
api_post(:horizon, data)
|
535
|
-
end
|
536
|
-
|
537
608
|
# params
|
538
609
|
# email, String
|
539
610
|
#
|
@@ -658,19 +729,83 @@ module Sailthru
|
|
658
729
|
api_get(:user, data)
|
659
730
|
end
|
660
731
|
|
661
|
-
#
|
662
|
-
def create_new_user(options = {})
|
663
|
-
options.delete('id')
|
664
|
-
api_post(:user, options)
|
665
|
-
end
|
666
|
-
|
667
|
-
# Save existing user
|
732
|
+
# Create new user, or update existing user
|
668
733
|
def save_user(id, options = {})
|
669
734
|
data = options
|
670
735
|
data['id'] = id
|
671
736
|
api_post(:user, data)
|
672
737
|
end
|
673
738
|
|
739
|
+
# params
|
740
|
+
# Get an existing trigger
|
741
|
+
def get_triggers()
|
742
|
+
api_get(:trigger, {})
|
743
|
+
end
|
744
|
+
|
745
|
+
# params
|
746
|
+
# template, String
|
747
|
+
# trigger_id, String
|
748
|
+
# Get an existing trigger
|
749
|
+
def get_trigger_by_template(template, trigger_id = nil)
|
750
|
+
data = {}
|
751
|
+
data['template'] = template
|
752
|
+
if trigger_id != nil then data['trigger_id'] = trigger_id end
|
753
|
+
api_get(:trigger, data)
|
754
|
+
end
|
755
|
+
|
756
|
+
# params
|
757
|
+
# event, String
|
758
|
+
# Get an existing trigger
|
759
|
+
def get_trigger_by_event(event)
|
760
|
+
data = {}
|
761
|
+
data['event'] = event
|
762
|
+
api_get(:trigger, data)
|
763
|
+
end
|
764
|
+
|
765
|
+
# params
|
766
|
+
# template, String
|
767
|
+
# time, String
|
768
|
+
# time_unit, String
|
769
|
+
# event, String
|
770
|
+
# zephyr, String
|
771
|
+
# Create or update a trigger
|
772
|
+
def post_template_trigger(template, time, time_unit, event, zephyr)
|
773
|
+
data = {}
|
774
|
+
data['template'] = template
|
775
|
+
data['time'] = time
|
776
|
+
data['time_unit'] = time_unit
|
777
|
+
data['event'] = event
|
778
|
+
data['zephyr'] = zephyr
|
779
|
+
api_post(:trigger, data)
|
780
|
+
end
|
781
|
+
|
782
|
+
# params
|
783
|
+
# template, String
|
784
|
+
# time, String
|
785
|
+
# time_unit, String
|
786
|
+
# zephyr, String
|
787
|
+
# Create or update a trigger
|
788
|
+
def post_event_trigger(event, time, time_unit, zephyr)
|
789
|
+
data = {}
|
790
|
+
data['time'] = time
|
791
|
+
data['time_unit'] = time_unit
|
792
|
+
data['event'] = event
|
793
|
+
data['zephyr'] = zephyr
|
794
|
+
api_post(:trigger, data)
|
795
|
+
end
|
796
|
+
|
797
|
+
# params
|
798
|
+
# id, String
|
799
|
+
# event, String
|
800
|
+
# options, Hash (Can contain vars, Hash and/or key)
|
801
|
+
# Notify Sailthru of an Event
|
802
|
+
def post_event(id, event, options = {})
|
803
|
+
data = options
|
804
|
+
data['id'] = id
|
805
|
+
data['event'] = event
|
806
|
+
api_post(:event, data)
|
807
|
+
end
|
808
|
+
|
674
809
|
# Perform API GET request
|
675
810
|
def api_get(action, data)
|
676
811
|
api_request(action, data, 'GET')
|
@@ -728,6 +863,28 @@ module Sailthru
|
|
728
863
|
return _result
|
729
864
|
end
|
730
865
|
|
866
|
+
# set up our post request
|
867
|
+
def set_up_post_request(uri, data, headers, binary_key = nil)
|
868
|
+
if (!binary_key.nil?)
|
869
|
+
binary_data = data[binary_key]
|
870
|
+
|
871
|
+
if binary_data.is_a?(StringIO)
|
872
|
+
data[binary_key] = UploadIO.new(
|
873
|
+
binary_data, "text/plain"
|
874
|
+
)
|
875
|
+
else
|
876
|
+
data[binary_key] = UploadIO.new(
|
877
|
+
File.open(binary_data), "text/plain"
|
878
|
+
)
|
879
|
+
end
|
880
|
+
|
881
|
+
req = Net::HTTP::Post::Multipart.new(uri.path, data)
|
882
|
+
else
|
883
|
+
req = Net::HTTP::Post.new(uri.path, headers)
|
884
|
+
req.set_form_data(data)
|
885
|
+
end
|
886
|
+
req
|
887
|
+
end
|
731
888
|
|
732
889
|
# params:
|
733
890
|
# uri, String
|
@@ -748,14 +905,9 @@ module Sailthru
|
|
748
905
|
_uri = URI.parse(uri)
|
749
906
|
|
750
907
|
if method == 'POST'
|
751
|
-
|
752
|
-
|
753
|
-
|
754
|
-
req = Net::HTTP::Post::Multipart.new(_uri.path, data)
|
755
|
-
else
|
756
|
-
req = Net::HTTP::Post.new(_uri.path, headers)
|
757
|
-
req.set_form_data(data)
|
758
|
-
end
|
908
|
+
req = self.set_up_post_request(
|
909
|
+
_uri, data, headers, binary_key
|
910
|
+
)
|
759
911
|
|
760
912
|
else
|
761
913
|
request_uri = "#{_uri.path}?#{_uri.query}"
|
@@ -779,7 +931,7 @@ module Sailthru
|
|
779
931
|
}
|
780
932
|
|
781
933
|
rescue Exception => e
|
782
|
-
raise SailthruClientException.new("Unable to open stream: #{_uri}\n
|
934
|
+
raise SailthruClientException.new(["Unable to open stream: #{_uri}", e.inspect, e.backtrace].join("\n"));
|
783
935
|
end
|
784
936
|
|
785
937
|
if response.body
|
metadata
CHANGED
@@ -1,110 +1,130 @@
|
|
1
|
-
--- !ruby/object:Gem::Specification
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
2
|
name: sailthru-client
|
3
|
-
version: !ruby/object:Gem::Version
|
4
|
-
|
5
|
-
|
6
|
-
- 1
|
7
|
-
- 15
|
8
|
-
version: "1.15"
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 2.0.0
|
5
|
+
prerelease:
|
9
6
|
platform: ruby
|
10
|
-
authors:
|
7
|
+
authors:
|
11
8
|
- Prajwal Tuladhar
|
9
|
+
- Dennis Yu
|
12
10
|
autorequire:
|
13
11
|
bindir: bin
|
14
12
|
cert_chain: []
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
dependencies:
|
19
|
-
- !ruby/object:Gem::Dependency
|
13
|
+
date: 2013-09-06 00:00:00.000000000 Z
|
14
|
+
dependencies:
|
15
|
+
- !ruby/object:Gem::Dependency
|
20
16
|
name: json
|
21
|
-
|
22
|
-
|
23
|
-
requirements:
|
24
|
-
- -
|
25
|
-
- !ruby/object:Gem::Version
|
26
|
-
|
27
|
-
- 0
|
28
|
-
version: "0"
|
17
|
+
requirement: !ruby/object:Gem::Requirement
|
18
|
+
none: false
|
19
|
+
requirements:
|
20
|
+
- - ! '>='
|
21
|
+
- !ruby/object:Gem::Version
|
22
|
+
version: '0'
|
29
23
|
type: :runtime
|
30
|
-
version_requirements: *id001
|
31
|
-
- !ruby/object:Gem::Dependency
|
32
|
-
name: multipart-post
|
33
24
|
prerelease: false
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
25
|
+
version_requirements: !ruby/object:Gem::Requirement
|
26
|
+
none: false
|
27
|
+
requirements:
|
28
|
+
- - ! '>='
|
29
|
+
- !ruby/object:Gem::Version
|
30
|
+
version: '0'
|
31
|
+
- !ruby/object:Gem::Dependency
|
32
|
+
name: multipart-post
|
33
|
+
requirement: !ruby/object:Gem::Requirement
|
34
|
+
none: false
|
35
|
+
requirements:
|
36
|
+
- - ! '>='
|
37
|
+
- !ruby/object:Gem::Version
|
38
|
+
version: '0'
|
41
39
|
type: :runtime
|
42
|
-
version_requirements: *id002
|
43
|
-
- !ruby/object:Gem::Dependency
|
44
|
-
name: fakeweb
|
45
40
|
prerelease: false
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
41
|
+
version_requirements: !ruby/object:Gem::Requirement
|
42
|
+
none: false
|
43
|
+
requirements:
|
44
|
+
- - ! '>='
|
45
|
+
- !ruby/object:Gem::Version
|
46
|
+
version: '0'
|
47
|
+
- !ruby/object:Gem::Dependency
|
48
|
+
name: fakeweb
|
49
|
+
requirement: !ruby/object:Gem::Requirement
|
50
|
+
none: false
|
51
|
+
requirements:
|
52
|
+
- - ! '>='
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
53
55
|
type: :development
|
54
|
-
|
55
|
-
|
56
|
+
prerelease: false
|
57
|
+
version_requirements: !ruby/object:Gem::Requirement
|
58
|
+
none: false
|
59
|
+
requirements:
|
60
|
+
- - ! '>='
|
61
|
+
- !ruby/object:Gem::Version
|
62
|
+
version: '0'
|
63
|
+
- !ruby/object:Gem::Dependency
|
56
64
|
name: shoulda
|
65
|
+
requirement: !ruby/object:Gem::Requirement
|
66
|
+
none: false
|
67
|
+
requirements:
|
68
|
+
- - ! '>='
|
69
|
+
- !ruby/object:Gem::Version
|
70
|
+
version: '0'
|
71
|
+
type: :development
|
57
72
|
prerelease: false
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
73
|
+
version_requirements: !ruby/object:Gem::Requirement
|
74
|
+
none: false
|
75
|
+
requirements:
|
76
|
+
- - ! '>='
|
77
|
+
- !ruby/object:Gem::Version
|
78
|
+
version: '0'
|
79
|
+
- !ruby/object:Gem::Dependency
|
80
|
+
name: mocha
|
81
|
+
requirement: !ruby/object:Gem::Requirement
|
82
|
+
none: false
|
83
|
+
requirements:
|
84
|
+
- - ! '>='
|
85
|
+
- !ruby/object:Gem::Version
|
86
|
+
version: '0'
|
65
87
|
type: :development
|
66
|
-
|
88
|
+
prerelease: false
|
89
|
+
version_requirements: !ruby/object:Gem::Requirement
|
90
|
+
none: false
|
91
|
+
requirements:
|
92
|
+
- - ! '>='
|
93
|
+
- !ruby/object:Gem::Version
|
94
|
+
version: '0'
|
67
95
|
description:
|
68
96
|
email: praj@sailthru.com
|
69
97
|
executables: []
|
70
|
-
|
71
98
|
extensions: []
|
72
|
-
|
73
|
-
extra_rdoc_files:
|
99
|
+
extra_rdoc_files:
|
74
100
|
- README.md
|
75
|
-
files:
|
101
|
+
files:
|
76
102
|
- README.md
|
77
103
|
- lib/sailthru.rb
|
78
|
-
has_rdoc: true
|
79
104
|
homepage: http://docs.sailthru.com
|
80
105
|
licenses: []
|
81
|
-
|
82
106
|
post_install_message:
|
83
|
-
rdoc_options:
|
107
|
+
rdoc_options:
|
84
108
|
- --main
|
85
109
|
- README.md
|
86
|
-
require_paths:
|
110
|
+
require_paths:
|
87
111
|
- lib
|
88
|
-
required_ruby_version: !ruby/object:Gem::Requirement
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
requirements:
|
97
|
-
- -
|
98
|
-
- !ruby/object:Gem::Version
|
99
|
-
|
100
|
-
- 0
|
101
|
-
version: "0"
|
112
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
113
|
+
none: false
|
114
|
+
requirements:
|
115
|
+
- - ! '>='
|
116
|
+
- !ruby/object:Gem::Version
|
117
|
+
version: '0'
|
118
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
119
|
+
none: false
|
120
|
+
requirements:
|
121
|
+
- - ! '>='
|
122
|
+
- !ruby/object:Gem::Version
|
123
|
+
version: '0'
|
102
124
|
requirements: []
|
103
|
-
|
104
125
|
rubyforge_project:
|
105
|
-
rubygems_version: 1.
|
126
|
+
rubygems_version: 1.8.25
|
106
127
|
signing_key:
|
107
128
|
specification_version: 3
|
108
129
|
summary: A simple client library to remotely access the Sailthru REST API.
|
109
130
|
test_files: []
|
110
|
-
|