Class: RavMeser
- Inherits:
-
Object
- Object
- RavMeser
- Defined in:
- lib/rav-meser-api.rb
Overview
gem class name RavMeser
Instance Method Summary collapse
-
#create_and_send_message(id, msg) ⇒ Object
create and send message of specific list.
-
#create_list(args = {}) ⇒ Object
create new list.
-
#create_message(id, args) ⇒ Object
create new message to specific list.
-
#create_personal_fields(id, args = {}) ⇒ Object
create new personal fields in specific list.
-
#create_subscribers(id, args = {}) ⇒ Object
create new subscribers in specific list.
-
#delete_list(id) ⇒ Object
delete list by id.
-
#delete_personal_fields(id, args) ⇒ Object
delete personal fields of specific list.
-
#delete_subscribers(id, args) ⇒ Object
delete subscribers of specific list.
-
#edit_list(id, args = {}) ⇒ Object
edit list by id.
-
#edit_personal_fields(id, args) ⇒ Object
edit personal fields of specific list.
-
#edit_subscribers(id, args) ⇒ Object
edit subscribers of specific list.
-
#get_list(id) ⇒ Object
get list by id.
-
#get_lists ⇒ Object
get all the lists.
-
#get_personal_fields(id) ⇒ Object
get personal fields from specific list.
-
#get_subscribers(id) ⇒ Object
get subscribers from specific list.
-
#initialize(client_key, client_secret, user_key, user_secret) ⇒ RavMeser
constructor
initialize new RavMeser Object.
-
#send_message(list_id, msg_id) ⇒ Object
send message of specific list.
-
#upsert_subscriber(id, args = {}) ⇒ Object
create new subscriber in specific list - update the subscriber if already exists.
-
#upsert_subscribers(id, args = {}) ⇒ Object
create new subscribers in specific list and update subscribers that exists.
Constructor Details
#initialize(client_key, client_secret, user_key, user_secret) ⇒ RavMeser
initialize new RavMeser Object
Example:
>> RavMeser.new(MNFDKRHUI2398RJ2O3R, NF932URH29837RY923JN, NF2983HFOIMNW2983H32, NFG8927RH238RH2)
Arguments:
client_key: (String) Client Key
client_secret: (String) Client Secret
user_key: (String) User Key
user_secret: (String) User Secret
21 22 23 24 |
# File 'lib/rav-meser-api.rb', line 21 def initialize(client_key, client_secret, user_key, user_secret) consumer = OAuth::Consumer.new(client_key, client_secret, site: 'http://api.responder.co.il') @access_token = OAuth::AccessToken.new(consumer, user_key, user_secret) end |
Instance Method Details
#create_and_send_message(id, msg) ⇒ Object
create and send message of specific list
Example:
>> RavMeser.create_and_send_message(123456, {'TYPE' => 1, 'BODY_TYPE' => 0, 'SUBJECT' => 'subject2', 'BODY' => 'message HTML body'})
=> {"MESSAGE_SENT"=>true}
Arguments:
list_id: (int)
args: (Hash)
281 282 283 284 |
# File 'lib/rav-meser-api.rb', line 281 def (id, msg) res = (id, msg) (id, res['MESSAGE_ID']) end |
#create_list(args = {}) ⇒ Object
create new list
Example:
>> RavMeser.create_list( {"DESCRIPTION": "Test List", "NAME": "try", ... } )
=> {"ERRORS"=>[], "LIST_ID"=>123456, "INVALID_EMAIL_NOTIFY"=>[], "INVALID_LIST_IDS"=>[]}
Arguments:
args: (Hash)
58 59 60 |
# File 'lib/rav-meser-api.rb', line 58 def create_list(args = {}) send_request(:post, 'info', '', [], args) end |
#create_message(id, args) ⇒ Object
create new message to specific list
Example:
>> RavMeser.create_message(123456, {'TYPE' => 1, 'BODY_TYPE' => 0, 'SUBJECT' => 'subject2', 'BODY' => 'message HTML body'} )
=> {"ERRORS"=>[], "MESSAGE_ID"=>3586177}
Arguments:
id: (int)
args: (Hash)
255 256 257 |
# File 'lib/rav-meser-api.rb', line 255 def (id, args) send_request(:post, 'info', '/' + id.to_s + '/messages', [], args) end |
#create_personal_fields(id, args = {}) ⇒ Object
create new personal fields in specific list
Example:
>> RavMeser.create_personal_fields(123456, {0 => {"NAME": "City", "DEFAULT_VALUE": "Tel Aviv", "DIR": "rtl", "TYPE": 0}, 1 => {"NAME": "Date of birth", "TYPE": 1}} )
=> {"LIST_ID": 123456, "CREATED_PERSONAL_FIELDS": [], "EXISTING_PERSONAL_FIELD_NAMES": []}
Arguments:
id: (int)
args: (Hash)
216 217 218 |
# File 'lib/rav-meser-api.rb', line 216 def create_personal_fields(id, args = {}) send_request(:post, 'personal_fields', '/' + id.to_s + '/personal_fields', [], args) end |
#create_subscribers(id, args = {}) ⇒ Object
create new subscribers in specific list
Example:
>> RavMeser.create_subscribers(123456, {0 => {'EMAIL': "[email protected]", 'NAME': "sub1"}, 1 => {'EMAIL': "[email protected]", 'NAME': "sub2"}} )
=> {"SUBSCRIBERS_CREATED": [112233], "EMAILS_INVALID": [], "EMAILS_EXISTING": ["[email protected]"], "EMAILS_BANNED": [], "PHONES_INVALID": [], "PHONES_EXISTING": [], "BAD_PERSONAL_FIELDS": {}, "ERRORS" : [] }
Arguments:
id: (int)
args: (Hash)
110 111 112 |
# File 'lib/rav-meser-api.rb', line 110 def create_subscribers(id, args = {}) send_request(:post, 'subscribers', '/' + id.to_s + '/subscribers', [], args) end |
#delete_list(id) ⇒ Object
delete list by id
Example:
>> RavMeser.delete_list(123456)
=> {"DELETED_LIST_ID"=>123456}
Arguments:
id: (int)
83 84 85 |
# File 'lib/rav-meser-api.rb', line 83 def delete_list(id) send_request(:delete, 'info', '/' + id.to_s, [], {}) end |
#delete_personal_fields(id, args) ⇒ Object
delete personal fields of specific list
Example:
>> RavMeser.delete_personal_fields(123456, {0 => { 'ID': 1234 }, 1 => { 'ID': 5678 }} )
=> {"DELETED_FIELDS": [], "INVALID_FIELD_IDS" : [] }
Arguments:
id: (int)
args: (Hash)
242 243 244 |
# File 'lib/rav-meser-api.rb', line 242 def delete_personal_fields(id, args) send_request(:post, 'personal_fields', '/' + id.to_s + '/personal_fields?', %w[method delete], args) end |
#delete_subscribers(id, args) ⇒ Object
delete subscribers of specific list
Example:
>> RavMeser.delete_subscribers(123456, {0 => { 'EMAIL': "[email protected]" }, 1 => { 'ID': 323715811 }} )
=> {"INVALID_SUBSCRIBER_IDS": [], "INVALID_SUBSCRIBER_EMAILS": [], "DELETED_SUBSCRIBERS": {} }
Arguments:
id: (int)
args: (Hash)
136 137 138 |
# File 'lib/rav-meser-api.rb', line 136 def delete_subscribers(id, args) send_request(:post, 'subscribers', '/' + id.to_s + '/subscribers?', %w[method delete], args) end |
#edit_list(id, args = {}) ⇒ Object
edit list by id
Example:
>> RavMeser.edit_list(123456, {"DESCRIPTION": "Test List Edited", "NAME": "try Edited", ... } )
=> {"ERRORS"=>[], "INVALID_EMAIL_NOTIFY"=>[], "INVALID_LIST_IDS"=>[], "SUCCESS"=>true}
Arguments:
id: (int)
args: (Hash)
71 72 73 |
# File 'lib/rav-meser-api.rb', line 71 def edit_list(id, args = {}) send_request(:put, 'info', '/' + id.to_s, [], args) end |
#edit_personal_fields(id, args) ⇒ Object
edit personal fields of specific list
Example:
>> RavMeser.edit_personal_fields(123456, {0 => {"ID": "1234", "DEFAULT_VALUE": "Tel Aviv-Jaffa"}, 1 => {"ID": "5678", "DIR": "rtl"}})
=> {"LIST_ID" : 123456, "UPDATED_PERSONAL_FIELDS": [], "INVALID_PERSONAL_FIELD_IDS": [], "EXISTING_PERSONAL_FIELD_NAMES": []}
Arguments:
id: (int)
args: (Hash)
229 230 231 |
# File 'lib/rav-meser-api.rb', line 229 def edit_personal_fields(id, args) send_request(:put, 'personal_fields', '/' + id.to_s + '/personal_fields', [], args) end |
#edit_subscribers(id, args) ⇒ Object
edit subscribers of specific list
Example:
>> RavMeser.edit_subscribers(123456, {0 => {'IDENTIFIER': "[email protected]", 'NAME': "sub1NewName"}, 1 => {'IDENTIFIER': "sub2", 'NAME': "sub2"}} )
=> {"SUBSCRIBERS_UPDATED": [112233], "INVALID_SUBSCRIBER_IDENTIFIERS": ["[email protected]"], "EMAILS_INVALID": [], "EMAILS_EXISTED": [], "EMAILS_BANNED": [], "PHONES_INVALID": [], "PHONES_EXISTING": [], "BAD_PERSONAL_FIELDS": {} }
Arguments:
id: (int)
args: (Hash)
123 124 125 |
# File 'lib/rav-meser-api.rb', line 123 def edit_subscribers(id, args) send_request(:put, 'subscribers', '/' + id.to_s + '/subscribers', [], args) end |
#get_list(id) ⇒ Object
get list by id
Example:
>> RavMeser.get_list(123456)
=> { "LISTS" => [{}, {}, ... ] }
Arguments:
id: (int)
46 47 48 |
# File 'lib/rav-meser-api.rb', line 46 def get_list(id) send_request(:get, '', '?', ['list_ids', id.to_s], {}) end |
#get_lists ⇒ Object
get all the lists
Example:
>> RavMeser.get_lists()
=> { "LISTS" => [{}, {}, ... ] }
34 35 36 |
# File 'lib/rav-meser-api.rb', line 34 def get_lists send_request(:get, '', '', [], {}) end |
#get_personal_fields(id) ⇒ Object
get personal fields from specific list
Example:
>> RavMeser.get_personal_fields(123456)
=> {"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}] }
Arguments:
id: (int)
203 204 205 |
# File 'lib/rav-meser-api.rb', line 203 def get_personal_fields(id) send_request(:get, '', '/' + id.to_s + '/personal_fields', [], {}) end |
#get_subscribers(id) ⇒ Object
get subscribers from specific list
Example:
>> RavMeser.get_subscribers(123456)
=> [{}, {}, ... ]
Arguments:
id: (int)
97 98 99 |
# File 'lib/rav-meser-api.rb', line 97 def get_subscribers(id) send_request(:get, '', '/' + id.to_s + '/subscribers', [], {}) end |
#send_message(list_id, msg_id) ⇒ Object
send message of specific list
Example:
>> RavMeser.send_message(123456, 565656)
=> {"MESSAGE_SENT"=>true}
Arguments:
list_id: (int)
msg_id: (int)
268 269 270 |
# File 'lib/rav-meser-api.rb', line 268 def (list_id, msg_id) send_request(:post, '', '/' + list_id.to_s + '/messages/' + msg_id.to_s , [], {} ) end |
#upsert_subscriber(id, args = {}) ⇒ Object
create new subscriber in specific list - update the subscriber if already exists
Example:
>> RavMeser.upsert_subscriber(123456, {0 => {'EMAIL': "[email protected]", 'NAME': "sub1"} )
=> [{"SUBSCRIBERS_CREATED": [], "EMAILS_INVALID": [], "EMAILS_EXISTING": ["[email protected]"], "EMAILS_BANNED": [], "PHONES_INVALID": [], "PHONES_EXISTING": [], "BAD_PERSONAL_FIELDS": {}, "ERRORS" : [] },
{"SUBSCRIBERS_UPDATED": [223344], "INVALID_SUBSCRIBER_IDENTIFIERS": [], "EMAILS_INVALID": [], "EMAILS_EXISTED": [], "EMAILS_BANNED": [], "PHONES_INVALID": [], "PHONES_EXISTING": [], "BAD_PERSONAL_FIELDS": {} }]
Arguments:
id: (int)
args: (Hash)
178 179 180 181 182 183 184 185 186 187 188 189 190 191 |
# File 'lib/rav-meser-api.rb', line 178 def upsert_subscriber(id, args = {}) raise 'Too many subscribers' unless args.length == 1 edit_response = {} create_response = send_request(:post, 'subscribers', '/' + id.to_s + '/subscribers', [], args) raise "ERRORS: #{create_response['ERRORS']}" unless create_response['ERRORS'].empty? if create_response['EMAILS_EXISTING'].length == 1 args[0][:IDENTIFIER] = args[0].delete(:EMAIL) edit_response = send_request(:put, 'subscribers', '/' + id.to_s + '/subscribers', [], args) end [create_response, edit_response] end |
#upsert_subscribers(id, args = {}) ⇒ Object
create new subscribers in specific list and update subscribers that exists
Example:
>> RavMeser.upsert_subscribers(123456, {0 => {'EMAIL': "[email protected]", 'NAME': "sub1"}, 1 => {'EMAIL': "[email protected]", 'NAME': "sub2"}} )
=> [{"SUBSCRIBERS_CREATED": [112233], "EMAILS_INVALID": [], "EMAILS_EXISTING": ["[email protected]"], "EMAILS_BANNED": [], "PHONES_INVALID": [], "PHONES_EXISTING": [], "BAD_PERSONAL_FIELDS": {}, "ERRORS" : [] },
{"SUBSCRIBERS_UPDATED": [223344], "INVALID_SUBSCRIBER_IDENTIFIERS": [], "EMAILS_INVALID": [], "EMAILS_EXISTED": [], "EMAILS_BANNED": [], "PHONES_INVALID": [], "PHONES_EXISTING": [], "BAD_PERSONAL_FIELDS": {} }]
Arguments:
id: (int)
args: (Hash)
150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 |
# File 'lib/rav-meser-api.rb', line 150 def upsert_subscribers(id, args = {}) raise 'Too few subscribers' if args.length.zero? create_response = send_request(:post, 'subscribers', '/' + id.to_s + '/subscribers', [], args) raise "ERRORS: #{create_response['ERRORS']}" unless create_response['ERRORS'].empty? edit_response = {} unless create_response['EMAILS_EXISTING'].empty? update_args = {} create_response['EMAILS_EXISTING'].each_with_index do |email, index| update_args[index] = get_subscriber_args_and_set_identifier(args, email) end edit_response = send_request(:put, 'subscribers', '/' + id.to_s + '/subscribers', [], update_args) end [create_response, edit_response] end |