responder-api 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (3) hide show
  1. checksums.yaml +7 -0
  2. data/lib/responder-api.rb +219 -0
  3. metadata +44 -0
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 69bd0f5f91a310f3fc2b465e8f59753a1ff3320d
4
+ data.tar.gz: e67d5c0e8a87d7a9d1f1baf3c5cdc4e1582d1ecc
5
+ SHA512:
6
+ metadata.gz: 4eafd01e26270aa818aa63f0ee9780fe4fc7772cafdd255437c2e5847775094456d6b94a1e784c2288d8f13fe41310a6fe1274d35104d4c702927037ec23d5b9
7
+ data.tar.gz: e971c0fcdbf05e4780b5acf865c9621fb84416fbaccbf1c981bac634f78a791465ab2fd67e972b3083a6e7d45d0a4c3437b64700ad6c4205e039ee6f77464b73
@@ -0,0 +1,219 @@
1
+ require 'rubygems'
2
+ require 'oauth'
3
+ require 'json'
4
+ require 'optparse'
5
+ require 'pp'
6
+ require 'uri'
7
+
8
+ # gem class name Responder
9
+ class Responder
10
+ # initialize new Responder Object
11
+ #
12
+ # Example:
13
+ # >> Responder.new(MNFDKRHUI2398RJ2O3R, NF932URH29837RY923JN, NF2983HFOIMNW2983H32, NFG8927RH238RH2)
14
+ #
15
+ # Arguments:
16
+ # client_key: (String) Client Key
17
+ # client_secret: (String) Client Secret
18
+ # user_key: (String) User Key
19
+ # user_secret: (String) User Secret
20
+ def initialize(client_key, client_secret, user_key, user_secret)
21
+ consumer = OAuth::Consumer.new(client_key, client_secret, site: 'http://api.responder.co.il')
22
+ @access_token = OAuth::AccessToken.new(consumer, user_key, user_secret)
23
+ end
24
+
25
+ # <!----------- LISTS -----------!>
26
+
27
+ # get all the lists
28
+ #
29
+ # Example:
30
+ # >> Responder.get_lists()
31
+ # => { "LISTS" => [{}, {}, ... ] }
32
+ #
33
+ def get_lists
34
+ send_request(:get, '', '', [], {})
35
+ end
36
+
37
+ # get list by id
38
+ #
39
+ # Example:
40
+ # >> Responder.get_list(123456)
41
+ # => { "LISTS" => [{}, {}, ... ] }
42
+ #
43
+ # Arguments:
44
+ # id: (int)
45
+ def get_list(id)
46
+ send_request(:get, '', '?', ['list_ids', id.to_s], {})
47
+ end
48
+
49
+ # create new list
50
+ #
51
+ # Example:
52
+ # >> Responder.create_list( {"DESCRIPTION": "Test List", "NAME": "try", ... } )
53
+ # => {"ERRORS"=>[], "LIST_ID"=>123456, "INVALID_EMAIL_NOTIFY"=>[], "INVALID_LIST_IDS"=>[]}
54
+ #
55
+ # Arguments:
56
+ # args: (Hash)
57
+ def create_list(args = {})
58
+ send_request(:post, 'info', '', [], args)
59
+ end
60
+
61
+ # edit list by id
62
+ #
63
+ # Example:
64
+ # >> Responder.edit_list(123456, {"DESCRIPTION": "Test List Edited", "NAME": "try Edited", ... } )
65
+ # => {"ERRORS"=>[], "INVALID_EMAIL_NOTIFY"=>[], "INVALID_LIST_IDS"=>[], "SUCCESS"=>true}
66
+ #
67
+ # Arguments:
68
+ # id: (int)
69
+ # args: (Hash)
70
+ def edit_list(id, args = {})
71
+ send_request(:put, 'info', '/' + id.to_s, [], args)
72
+ end
73
+
74
+ # delete list by id
75
+ #
76
+ # Example:
77
+ # >> Responder.delete_list(123456)
78
+ # => {"DELETED_LIST_ID"=>123456}
79
+ #
80
+ # Arguments:
81
+ # id: (int)
82
+ def delete_list(id)
83
+ send_request(:delete, 'info', '/' + id.to_s, [], {})
84
+ end
85
+
86
+ # <!----------- SUBSCRIBERS -----------!>
87
+
88
+ # get subscribers from specific list
89
+ #
90
+ # Example:
91
+ # >> Responder.get_subscribers(123456)
92
+ # => [{}, {}, ... ]
93
+ #
94
+ # Arguments:
95
+ # id: (int)
96
+ def get_subscribers(id)
97
+ send_request(:get, '', '/' + id.to_s + '/subscribers', [], {})
98
+ end
99
+
100
+ # create new subscribers in specific list
101
+ #
102
+ # Example:
103
+ # >> Responder.create_subscribers(123456, {0 => {'EMAIL': "sub1@email.com", 'NAME': "sub1"}, 1 => {'EMAIL': "sub2@email.com", 'NAME': "sub2"}} )
104
+ # => {"SUBSCRIBERS_CREATED": [], "EMAILS_INVALID": [], "EMAILS_EXISTING": ["johnsmith@gmail.com"], "EMAILS_BANNED": [], "PHONES_INVALID": [], "PHONES_EXISTING": [], "BAD_PERSONAL_FIELDS": {}, "ERRORS" : [] }
105
+ #
106
+ # Arguments:
107
+ # id: (int)
108
+ # args: (Hash)
109
+ def create_subscribers(id, args = {})
110
+ send_request(:post, 'subscribers', '/' + id.to_s + '/subscribers', [], args)
111
+ end
112
+
113
+ # edit subscribers of specific list
114
+ #
115
+ # Example:
116
+ # >> Responder.edit_subscribers(123456, {0 => {'IDENTIFIER': "sub1@email.com", 'NAME': "sub1NewName"}, 1 => {'IDENTIFIER': "sub2", 'NAME': "sub2"}} )
117
+ # => {"SUBSCRIBERS_UPDATED": [], "INVALID_SUBSCRIBER_IDENTIFIERS": [], "EMAILS_INVALID": [], "EMAILS_EXISTED": ["johnsmith@gmail.com"], "EMAILS_BANNED": [], "PHONES_INVALID": [], "PHONES_EXISTING": [], "BAD_PERSONAL_FIELDS": {} }}
118
+ #
119
+ # Arguments:
120
+ # id: (int)
121
+ # args: (Hash)
122
+ def edit_subscribers(id, args)
123
+ send_request(:put, 'subscribers', '/' + id.to_s + '/subscribers', [], args)
124
+ end
125
+
126
+ # delete subscribers of specific list
127
+ #
128
+ # Example:
129
+ # >> Responder.delete_subscribers(123456, {0 => { 'EMAIL': "sub8@email.com" }, 1 => { 'ID': 323715811 }} )
130
+ # => {"INVALID_SUBSCRIBER_IDS": [], "INVALID_SUBSCRIBER_EMAILS": [], "DELETED_SUBSCRIBERS": {} }
131
+ #
132
+ # Arguments:
133
+ # id: (int)
134
+ # args: (Hash)
135
+ def delete_subscribers(id, args)
136
+ send_request(:post, 'subscribers', '/' + id.to_s + '/subscribers?', %w[method delete], args)
137
+ end
138
+
139
+ # <!----------- PERSONAL FIELDS -----------!>
140
+
141
+ # get personal fields from specific list
142
+ #
143
+ # Example:
144
+ # >> Responder.get_personal_fields(123456)
145
+ # => {"LIST_ID": 123456, "PERSONAL_FIELDS": [{"ID": 1234, "NAME": "City", "DEFAULT_VALUE": "Tel Aviv", "DIR": "rtl", "TYPE": 0}, {"ID": 5678, "NAME": "Birth Date", "DEFAULT_VALUE" : "", "DIR": "ltr", "TYPE": 1}] }
146
+ #
147
+ # Arguments:
148
+ # id: (int)
149
+ def get_personal_fields(id)
150
+ send_request(:get, '', '/' + id.to_s + '/personal_fields', [], {})
151
+ end
152
+
153
+ # create new personal fields in specific list
154
+ #
155
+ # Example:
156
+ # >> Responder.create_personal_fields(123456, {0 => {"NAME": "City", "DEFAULT_VALUE": "Tel Aviv", "DIR": "rtl", "TYPE": 0}, 1 => {"NAME": "Date of birth", "TYPE": 1}} )
157
+ # => {"LIST_ID": 123456, "CREATED_PERSONAL_FIELDS": [], "EXISTING_PERSONAL_FIELD_NAMES": []}
158
+ #
159
+ # Arguments:
160
+ # id: (int)
161
+ # args: (Hash)
162
+ def create_personal_fields(id, args = {})
163
+ send_request(:post, 'personal_fields', '/' + id.to_s + '/personal_fields', [], args)
164
+ end
165
+
166
+ # edit personal fields of specific list
167
+ #
168
+ # Example:
169
+ # >> Responder.edit_personal_fields(123456, {0 => {"ID": "1234", "DEFAULT_VALUE": "Tel Aviv-Jaffa"}, 1 => {"ID": "5678", "DIR": "rtl"}})
170
+ # => {"LIST_ID" : 123456, "UPDATED_PERSONAL_FIELDS": [], "INVALID_PERSONAL_FIELD_IDS": [], "EXISTING_PERSONAL_FIELD_NAMES": []}
171
+ #
172
+ # Arguments:
173
+ # id: (int)
174
+ # args: (Hash)
175
+ def edit_personal_fields(id, args)
176
+ send_request(:put, 'personal_fields', '/' + id.to_s + '/personal_fields', [], args)
177
+ end
178
+
179
+ # delete personal fields of specific list
180
+ #
181
+ # Example:
182
+ # >> Responder.delete_personal_fields(123456, {0 => { 'ID': 1234 }, 1 => { 'ID': 5678 }} )
183
+ # => {"DELETED_FIELDS": [], "INVALID_FIELD_IDS" : [] }
184
+ #
185
+ # Arguments:
186
+ # id: (int)
187
+ # args: (Hash)
188
+ def delete_personal_fields(id, args)
189
+ send_request(:post, 'personal_fields', '/' + id.to_s + '/personal_fields?', %w[method delete], args)
190
+ end
191
+
192
+ # privare method
193
+ # common code to send the requests
194
+ #
195
+ # Example:
196
+ # >> send_request(:get, 'info', '?list_ids=123456', {} )
197
+ # => {}
198
+ #
199
+ # Arguments:
200
+ # type: (:get \ :post \ :put \ :delete)
201
+ # object_name: (string) - ('info', 'subscribers', 'personal_fields')
202
+ # query: (string)
203
+ # args: (Hash)
204
+ def send_request(type, object_name = '', path = '', query = [], args = {})
205
+ unless args == {}
206
+ json_obj = { object_name =>
207
+ JSON.generate(args) }
208
+ end
209
+
210
+ path = '/v1.0/lists' + path
211
+ query = [query]
212
+ path_request = query.empty? ? path : path + URI.encode_www_form(query)
213
+ response = @access_token.request(type, path_request, json_obj)
214
+ response = JSON.parse(response.body) unless response.class == String
215
+ response
216
+ end
217
+
218
+ private :send_request
219
+ end
metadata ADDED
@@ -0,0 +1,44 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: responder-api
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ platform: ruby
6
+ authors:
7
+ - Itamar Davidyan
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2018-11-11 00:00:00.000000000 Z
12
+ dependencies: []
13
+ description: Responder API Ruby
14
+ email: itamardavidyan@gmail.com
15
+ executables: []
16
+ extensions: []
17
+ extra_rdoc_files: []
18
+ files:
19
+ - lib/responder-api.rb
20
+ homepage: http://rubygems.org/gems/responder-api
21
+ licenses:
22
+ - MIT
23
+ metadata: {}
24
+ post_install_message:
25
+ rdoc_options: []
26
+ require_paths:
27
+ - lib
28
+ required_ruby_version: !ruby/object:Gem::Requirement
29
+ requirements:
30
+ - - ">="
31
+ - !ruby/object:Gem::Version
32
+ version: '0'
33
+ required_rubygems_version: !ruby/object:Gem::Requirement
34
+ requirements:
35
+ - - ">="
36
+ - !ruby/object:Gem::Version
37
+ version: '0'
38
+ requirements: []
39
+ rubyforge_project:
40
+ rubygems_version: 2.5.2
41
+ signing_key:
42
+ specification_version: 4
43
+ summary: Responder API
44
+ test_files: []