sailthru-client 1.14 → 1.15
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 +83 -0
- data/lib/sailthru.rb +38 -5
- metadata +3 -3
data/README.md
CHANGED
@@ -8,6 +8,7 @@ By default, it will make request in `JSON` format.
|
|
8
8
|
It can make requests to following [API calls](http://docs.sailthru.com/api):
|
9
9
|
|
10
10
|
* [email](http://docs.sailthru.com/api/email)
|
11
|
+
* [user](http://docs.sailthru.com/api/user)
|
11
12
|
* [send](http://docs.sailthru.com/api/send)
|
12
13
|
* [blast](http://docs.sailthru.com/api/blast)
|
13
14
|
* [template](http://docs.sailthru.com/api/template)
|
@@ -32,6 +33,40 @@ api_key = "api_key";
|
|
32
33
|
api_secret = 'secret';
|
33
34
|
api_url = "https://api.sailthru.com";
|
34
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
|
+
|
35
70
|
```
|
36
71
|
|
37
72
|
### [send](http://docs.sailthru.com/api/send)
|
@@ -60,6 +95,54 @@ options = {'test' => 1}
|
|
60
95
|
response = sailthru.multi_send(template_name, emails, vars, options)
|
61
96
|
```
|
62
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
|
+
|
63
146
|
### [email](http://docs.sailthru.com/api/email)
|
64
147
|
``` ruby
|
65
148
|
#get email
|
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 = '1.
|
12
|
+
Version = VERSION = '1.15'
|
13
13
|
|
14
14
|
class SailthruClientException < Exception
|
15
15
|
end
|
@@ -529,8 +529,7 @@ module Sailthru
|
|
529
529
|
# sets horizon data
|
530
530
|
def set_horizon(email, tags)
|
531
531
|
data = {}
|
532
|
-
data[
|
533
|
-
:email] = email
|
532
|
+
data[:email] = email
|
534
533
|
data[:tags] = (tags.class == Array) ? tags.join(',') : tags
|
535
534
|
api_post(:horizon, data)
|
536
535
|
end
|
@@ -609,7 +608,7 @@ module Sailthru
|
|
609
608
|
data['emails'] = Array(emails).join(',')
|
610
609
|
process_job(:import, data, report_email, postback_url)
|
611
610
|
end
|
612
|
-
|
611
|
+
|
613
612
|
# implementation for import job using file upload
|
614
613
|
def process_import_job_from_file(list, file_path, report_email = nil, postback_url = nil)
|
615
614
|
data = {}
|
@@ -618,6 +617,13 @@ module Sailthru
|
|
618
617
|
process_job(:import, data, report_email, postback_url, 'file')
|
619
618
|
end
|
620
619
|
|
620
|
+
# implementation for update job using file upload
|
621
|
+
def process_update_job_from_file(file_path, report_email = nil, postback_url = nil)
|
622
|
+
data = {}
|
623
|
+
data['file'] = file_path
|
624
|
+
process_job(:update, data, report_email, postback_url, 'file')
|
625
|
+
end
|
626
|
+
|
621
627
|
# implementation for snapshot job
|
622
628
|
def process_snapshot_job(query = {}, report_email = nil, postback_url = nil)
|
623
629
|
data = {}
|
@@ -637,6 +643,33 @@ module Sailthru
|
|
637
643
|
api_get(:job, {'job_id' => job_id})
|
638
644
|
end
|
639
645
|
|
646
|
+
# Get user by Sailthru ID
|
647
|
+
def get_user_by_sid(id, fields = {})
|
648
|
+
api_get(:user, {'id' => id, 'fields' => fields})
|
649
|
+
end
|
650
|
+
|
651
|
+
# Get user by specified key
|
652
|
+
def get_user_by_key(id, key, fields = {})
|
653
|
+
data = {
|
654
|
+
'id' => id,
|
655
|
+
'key' => key,
|
656
|
+
'fields' => fields
|
657
|
+
}
|
658
|
+
api_get(:user, data)
|
659
|
+
end
|
660
|
+
|
661
|
+
# Creates new user
|
662
|
+
def create_new_user(options = {})
|
663
|
+
options.delete('id')
|
664
|
+
api_post(:user, options)
|
665
|
+
end
|
666
|
+
|
667
|
+
# Save existing user
|
668
|
+
def save_user(id, options = {})
|
669
|
+
data = options
|
670
|
+
data['id'] = id
|
671
|
+
api_post(:user, data)
|
672
|
+
end
|
640
673
|
|
641
674
|
# Perform API GET request
|
642
675
|
def api_get(action, data)
|
@@ -764,7 +797,7 @@ module Sailthru
|
|
764
797
|
def prepare_json_payload(data)
|
765
798
|
payload = {
|
766
799
|
:api_key => @api_key,
|
767
|
-
:format => 'json',
|
800
|
+
:format => 'json', #<3 XML
|
768
801
|
:json => data.to_json
|
769
802
|
}
|
770
803
|
payload[:sig] = get_signature_hash(payload, @secret)
|
metadata
CHANGED
@@ -4,8 +4,8 @@ version: !ruby/object:Gem::Version
|
|
4
4
|
prerelease: false
|
5
5
|
segments:
|
6
6
|
- 1
|
7
|
-
-
|
8
|
-
version: "1.
|
7
|
+
- 15
|
8
|
+
version: "1.15"
|
9
9
|
platform: ruby
|
10
10
|
authors:
|
11
11
|
- Prajwal Tuladhar
|
@@ -13,7 +13,7 @@ autorequire:
|
|
13
13
|
bindir: bin
|
14
14
|
cert_chain: []
|
15
15
|
|
16
|
-
date: 2012-
|
16
|
+
date: 2012-05-31 00:00:00 -04:00
|
17
17
|
default_executable:
|
18
18
|
dependencies:
|
19
19
|
- !ruby/object:Gem::Dependency
|