rav-meser-api 1.0.1

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.
Files changed (3) hide show
  1. checksums.yaml +7 -0
  2. data/lib/rav-meser-api.rb +219 -0
  3. metadata +44 -0
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: a78f6ed21d2d1def473b5da89e7c8b3d9627e57d
4
+ data.tar.gz: 052c6cef00f54c69fd60cbff0e2513479f65da98
5
+ SHA512:
6
+ metadata.gz: 0d74aa433d7aa90d9f2b78ab900e560745b8777b53f531c62d1485b9b2f459a9385faec28c5a427c2cb42846946d637d8531e7e72a07e5fd1856760612ce261a
7
+ data.tar.gz: ce3ecb1fbf81983f0a18d90f0422de0324ab08545953b540474c7098c65e0d62565bfd7f12a01e6f6a3065acde10c7445239956c9978a0b948d9ba3e585f6f5f
@@ -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 RavMeser
9
+ class RavMeser
10
+ # initialize new RavMeser Object
11
+ #
12
+ # Example:
13
+ # >> RavMeser.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
+ # >> ה.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
+ # >> RavMeser.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
+ # >> RavMeser.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
+ # >> RavMeser.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
+ # >> RavMeser.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
+ # >> RavMeser.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
+ # >> RavMeser.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
+ # >> RavMeser.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
+ # >> RavMeser.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
+ # >> RavMeser.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
+ # >> RavMeser.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
+ # >> RavMeser.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
+ # >> RavMeser.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: rav-meser-api
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Itamar Davidyan
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2018-11-25 00:00:00.000000000 Z
12
+ dependencies: []
13
+ description: Rav Meser API Ruby
14
+ email: itamardavidyan@gmail.com
15
+ executables: []
16
+ extensions: []
17
+ extra_rdoc_files: []
18
+ files:
19
+ - lib/rav-meser-api.rb
20
+ homepage: http://rubygems.org/gems/rav-meser-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: Rav Meser API
44
+ test_files: []