unisender_api 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore ADDED
@@ -0,0 +1,17 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --color
2
+ --format progress
data/.yardopts ADDED
@@ -0,0 +1,7 @@
1
+ --markup markdown
2
+ --markup-provider redcarpet
3
+ --charset utf-8
4
+ --readme README.md
5
+ -
6
+ README.md
7
+ LICENSE
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+ gem 'addressable'
3
+ # Specify your gem's dependencies in unisender_api.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2013 t0pep0
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,150 @@
1
+ # UnisenderApi
2
+
3
+ Unisender API integration. Ruby gem
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ gem 'unisender_api'
10
+
11
+ And then execute:
12
+
13
+ $ bundle
14
+
15
+ Or install it yourself as:
16
+
17
+ $ gem install unisender_api
18
+
19
+ ## Usage
20
+
21
+ ##How to use?
22
+
23
+ ###1. Create your ruby project
24
+
25
+ ###2. Add "require 'unisender_api'"
26
+
27
+ ###3. Create class
28
+ ```ruby
29
+ api = Unisender::API.new(api_key, locale, test_mode)
30
+ ```
31
+ ```
32
+ api_key - your api key from unisender
33
+ locale - unisender locale 'en' by default. Optional
34
+ test_mode - on/off (true/false) test mode, false (off) by default. Optional
35
+ ```
36
+ ###4. Accepted class in methods
37
+ ```
38
+ Time
39
+ Boolean
40
+ String
41
+ Fixnum
42
+ Bignum
43
+ Float
44
+ Hash - for multi attach emails and other
45
+ Array - for multi adress email and other
46
+ ```
47
+
48
+ ###5. Methods structure
49
+
50
+ ####Unisender::API.lists
51
+
52
+ getLists - return exists lists
53
+
54
+ createList(title, before_subscribe_url = '', after_subscribe_url = '')
55
+
56
+ updateList(list_id, title, before_subscribe_url = '', after_subscribe_url = '')
57
+
58
+ deleteList(list_id)
59
+
60
+ subscribe(list_ids, fields, tags = '', request_ip = '', request_time = '', double_optin = '', confirm_ip = '', confirm_time = '', overwrite = '')
61
+
62
+ importContacts(field_names = 'email', data = 'a@example.com', double_optin = 0, overwrite_tags = 0, overwrite_lists = 0, force_import = 0)
63
+
64
+ example:
65
+ ```
66
+ Unisender::API.new(key).lists.importContacts(['email', 'email_list_ids'], [['a@example.com', '1'],['b@example.com', '2']])
67
+ ```
68
+ or:
69
+ ```
70
+ Unisender::API.new(key).lists.importContacts({0 => 'email', 1 => 'email_list_ids'}, {'[0][0]' => 'a@example.com', '[0][1]' => '1'})
71
+ ```
72
+ exportContacts(list_id, field_names = ['email'], offset = 0, tag = '', email = '', email_status = '', phone = '', phone_status = '', limit = 1000)
73
+ similar to importContacts
74
+ ####Unisender::API.messages
75
+
76
+ createEmailMessage(sender_name, sender_email, subject, body, list_id, text_body = '', generate_text = 0, tag = '', attachments = {}, lang = 'en', series_day = '', series_time = '', wrap_type = 'skip', caregories = '')
77
+
78
+ #####Note: attachments is hash { :file_name1 => content1, :file_name2 => content2 }
79
+
80
+ createSmsMessage(sender, body, list_id, tag = '', series_day = '', series_time = '', categories = '')
81
+
82
+ createCampaign(message_id, start_time = '', timezone = '', track_read = 0, track_links = 0, contacts = '', contacts_url = '', defer = 1, track_ga = 0, payment_limit = 0, payment_currency = '', ga_medium = '', ga_source ='', ga_campaign = '', ga_content = '', ga_term = '')
83
+
84
+ getCampaigns(from = '', to = '')
85
+
86
+ getCampaignStatus(campaign_id)
87
+
88
+ sendSms(phone, sender, text)
89
+
90
+ sendEmail(email, sender_name, sender_email, subject, body, list_id, user_campaign_id, attachments, lang ='en', track_read = 0,track_links = 0, cc = '', headers = '', wrap_type = 'skip', images_as = 'attachments', error_checking = 0)
91
+
92
+ #####Note: field attach_multi is automatic selectable
93
+ #####Note: attachments if one set for all attachments = { :filename1 => content1} else attachments = [{:filename1 => content1}, {:filename2 => content}]
94
+
95
+ checkEmail(email_id)
96
+
97
+ updateOptInEmail(sender_name, sender_email, subject, body, list_id)
98
+
99
+ deleteMessage(message_id)
100
+
101
+ ####Unisender::API.statistics
102
+
103
+ getCampaignDeliveryStats(campaign_id, changed_since = '', field_ids = '')
104
+
105
+ getCampaignAggregateStats(campaign_id)
106
+
107
+ getVisitedLinks(campaign_id, group = false)
108
+
109
+ ####Unisender::API.extends
110
+
111
+ getFields
112
+
113
+ createField(name, type, is_visible = 1, view_pos = 1)
114
+
115
+ updateField(id, name = '', type = '', is_visible = 1, view_pos = 1)
116
+
117
+ getTags
118
+
119
+ deleteTag(id)
120
+
121
+ ####Unisender::API.partners
122
+
123
+ validateSender(email, login = '')
124
+
125
+ register(email, login, password = '', notify = 0, extra = {}, timezone = '', country_code = 'RUS', currency_code = 'RUB', ip = '', api_mode = 'on')
126
+
127
+ checkUserExists(login = '', email = '')
128
+
129
+ getUserInfo(login)
130
+
131
+ getUsers(register_after = '', register_before = '')
132
+
133
+ transferMoney(source_login, target_login, sum, currency)
134
+
135
+ getPayments(login = '', from = '', to = '', only_real_deposit = 0, ids = '', comment_substrings = [], payment_type = '')
136
+
137
+ getTariffs
138
+
139
+ changeTariff(login, tariff_id)
140
+
141
+ ## More API Info
142
+ For more information about actions and returned answers please visit: http://www.unisender.com/help/api/
143
+
144
+ ## Contributing
145
+
146
+ 1. Fork it
147
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
148
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
149
+ 4. Push to the branch (`git push origin my-new-feature`)
150
+ 5. Create new Pull Request
data/Rakefile ADDED
@@ -0,0 +1,5 @@
1
+ require "bundler/gem_tasks"
2
+ require 'yard'
3
+ YARD::Rake::YardocTask.new
4
+ require 'rspec/core/rake_task'
5
+ RSpec::Core::RakeTask.new
Binary file
@@ -0,0 +1,62 @@
1
+ require 'json'
2
+ require 'net/http'
3
+ require 'addressable/uri'
4
+ class ApiCall
5
+ attr_accessor :api_key, :test, :url
6
+
7
+ def initialize(api_key, locale = 'en', test = false)
8
+ self.api_key = api_key
9
+ self.test = test
10
+ self.url = "http://api.unisender.com/#{locale}/api/"
11
+ end
12
+
13
+
14
+ def api_call(method, params)
15
+ url = self.url + method
16
+ params.merge!(:test_mode => '1') if self.test
17
+ params.merge!(:api_key => self.api_key)
18
+ result = JSON.parse(self.post(url, params))
19
+ return result
20
+ end
21
+
22
+
23
+ def gen_hash(param, label)
24
+ hash = Hash.new
25
+
26
+
27
+ case param
28
+ when Time
29
+ hash.merge!("#{label}" => param.strftime("%F %H:%M"))
30
+ when Boolean
31
+ hash.merge!("#{label}" => param.to_s)
32
+ when String
33
+ hash.merge!("#{label}" => param.to_s)
34
+ when Fixnum
35
+ hash.merge!("#{label}" => param.to_s)
36
+ when Bignum
37
+ hash.merge!("#{label}" => param.to_s)
38
+ when Float
39
+ hash.merge!("#{label}" => param.to_s)
40
+ when Hash
41
+ param.each do |key, value|
42
+ hash.merge!(self.gen_hash(value,"#{label}[#{key}]"))
43
+ end
44
+ when Array
45
+ i = 0
46
+ array.each do |value|
47
+ hash.merge!(self.gen_hash(value, "#{label}[#{i}]"))
48
+ i = i+1
49
+ end
50
+ end
51
+ return hash
52
+ end
53
+
54
+ def post(url, param)
55
+ uri = URI.parse(url)
56
+ http = Net::HTTP.new(uri.host, uri.port)
57
+ params = Addressable::URI.new
58
+ params.query_values = param
59
+ http.post(uri.path, params.query).body
60
+ end
61
+
62
+ end
@@ -0,0 +1,41 @@
1
+ class Extends
2
+ attr_accessor :api
3
+
4
+ def initialize(api)
5
+ self.api = api
6
+ end
7
+
8
+ def getFields
9
+ self.api.api_call('getFields', {})
10
+ end
11
+
12
+ def createField(name, type, is_visible = 1, view_pos = 1)
13
+ param = Hash.new
14
+ param.merge!(self.api.gen_hash(name, 'name'))
15
+ param.merge!(self.api.gen_hash(type, 'type'))
16
+ param.merge!(self.api.gen_hash(is_visible, 'is_visible'))
17
+ param.merge!(self.api.gen_hash(view_pos))
18
+ self.api.api_call('createField', param)
19
+ end
20
+
21
+ def updateField(id, name = '', type = '', is_visible = 1, view_pos = 1)
22
+ param = Hash.new
23
+ param.merge!(self.api.gen_hash(id, 'id'))
24
+ param.merge!(self.api.gen_hash(name, 'name')) if name != ''
25
+ param.merge!(self.api.gen_hash(type, 'type')) if type != ''
26
+ param.merge!(self.api.gen_hash(is_visible, 'is_visible'))
27
+ param.merge!(self.api.gen_hash(view_pos, 'view_pos'))
28
+ self.api.api_call('updateField', param)
29
+ end
30
+
31
+ def getTags
32
+ self.api.api_call('getTags', {})
33
+ end
34
+
35
+ def deleteTag(id)
36
+ param = Hash.new
37
+ param.merge!(self.api.gen_hash(id, 'id'))
38
+ self.api.api_call('deleteTag', param)
39
+ end
40
+
41
+ end
@@ -0,0 +1,75 @@
1
+ class Lists
2
+ attr_accessor :api
3
+
4
+ def initialize(api)
5
+ self.api = api
6
+ end
7
+
8
+ def getLists
9
+ self.api.api_call('getLists', {})
10
+ end
11
+
12
+ def createList(title, before_subscribe_url = '', after_subscribe_url = '')
13
+ param = Hash.new
14
+ param.merge!(self.api.gen_hash(title, 'title'))
15
+ param.merge!(self.api.gen_hash(before_subscribe_url,'before_subscribe_url')) if before_subscribe_url != ''
16
+ peram.merge!(self.api.gen_hash(after_subscribe_url, 'after_subscribe_url')) if after_subscribe_url != ''
17
+ self.api.api_call('createList', param)
18
+ end
19
+
20
+ def updateList(list_id, title, before_subscribe_url = '', after_subscribe_url = '')
21
+ param = Hash.new
22
+ param.merge!(self.api.gen_hash(list_id, 'list_id'))
23
+ param.merge!(self.api.gen_hash(title, 'title'))
24
+ param.merge!(self.api.gen_hash(before_subscirbe_url, 'before_subscribe_url')) if before_subscribe_url != ''
25
+ param.merge!(self.api.gen_hash(after_subscribe_url, 'after_subscribe_url')) if after_subscribe_url != ''
26
+ self.api.api_call('updateList', param)
27
+ end
28
+
29
+ def deleteList(list_id)
30
+ param = Hash.new
31
+ param.merge!(self.api.gen_hash(list_id, 'list_id'))
32
+ self.api.api_call('deleteList', param)
33
+ end
34
+
35
+ def subscribe(list_ids, fields, tags = '', request_ip = '', request_time = '', double_optin = '', confirm_ip = '', confirm_time = '', overwrite = '')
36
+ param = Hash.new
37
+ param.merge!(self.api.gen_hash(list_ids, 'list_ids'))
38
+ param.merge!(self.api.gen_hash(fields, 'fields'))
39
+ param.merge!(self.api.gen_hash(tags, 'tags')) if tags != ''
40
+ param.merge!(self.api.gen_hash(request_ip, 'request_ip')) if request_ip != ''
41
+ param.merge!(self.api.gen_hash(request_time, 'request_time')) if request_time != ''
42
+ param.merge!(self.api.gen_hash(double_optin, 'double_optin')) if double_optin != ''
43
+ param.merge!(self.api.gen_hash(confirm_ip, 'confirm_ip')) if confirm_ip != ''
44
+ param.merge!(self.api.gen_hash(confirm_time, 'confirm_time')) if confirm_time != ''
45
+ param.merge!(self.api.gen_hash(overwrite, 'overwrite')) if overwrite != ''
46
+ self.api.api_call('subscribe', param)
47
+ end
48
+
49
+ def importContacts(field_names = 'email', data = 'a@example.com', double_optin = 0, overwrite_tags = 0, overwrite_lists = 0, force_import = 0)
50
+ param = Hash.new
51
+ param.merge!(self.api.gen_hash(field_names, 'field_names'))
52
+ param.merge!(self.api.gen_hash(data, 'data'))
53
+ param.merge!(self.api.gen_hash(double_optin, 'double_optin'))
54
+ param.merge!(self.api.gen_hash(overwrite_tags, 'overwrite_tags'))
55
+ param.merge!(self.api.gen_hash(overwrite_lists, 'overwrite_lists'))
56
+ param.merge!(self.api.gen_hash(force_import, 'force_import'))
57
+ self.api.api_call('importContacts', param)
58
+ end
59
+
60
+ def exportContacts(list_id, field_names = ['email'], offset = 0, tag = '', email = '', email_status = '', phone = '', phone_status = '', limit = 1000)
61
+ param = Hash.new
62
+ param.merge!(self.api.gen_hash(list_id, 'list_id'))
63
+ param.merge!(self.api.gen_hash(field_names, 'field_names'))
64
+ param.merge!(self.api.gen_hash(offset, 'offset'))
65
+ param.merge!(self.api.gen_hash(tag, 'tag')) if tag != ''
66
+ param.merge!(self.api.gen_hash(email, 'email')) if email != ''
67
+ param.merge!(self.api.gen_hash(email_status, 'email_status')) if email_status != ''
68
+ param.merge!(self.api.gen_hash(phone, 'phone')) if phone != ''
69
+ param.merge!(self.api.gen_hash(phone_status, 'phone_status')) if phone_status != ''
70
+ param.merge!(self.api.gen_hash(limit, 'limit'))
71
+ self.api.api_call('exportContacts', param)
72
+ end
73
+
74
+
75
+ end
@@ -0,0 +1,133 @@
1
+ class Messages
2
+ attr_accessor :api
3
+
4
+ def initialize(api)
5
+ self.api = api
6
+ end
7
+
8
+ def createEmailMessage(sender_name, sender_email, subject, body, list_id, text_body = '', generate_text = 0, tag = '', attachments = {}, lang = 'en', series_day = '', series_time = '', wrap_type = 'skip', caregories = '')
9
+ param = Hash.new
10
+ param.merge!(self.api.gen_hash(sender_name, 'sender_name'))
11
+ param.merge!(self.api.gen_hash(sender_email, 'sender_email'))
12
+ param.merge!(self.api.gen_hash(subject, 'subject'))
13
+ param.merge!(self.api.gen_hash(body, 'body'))
14
+ param.merge!(self.api.gen_hash(list_id, 'list-id'))
15
+ param.merge!(self.api.gen_hash(text_body, 'text_body')) if text_body != ''
16
+ param.merge!(self.api.gen_hash(generate_text, 'generate_text'))
17
+ param.merge!(self.api.gen_hash(tag, 'tag')) if tag != ''
18
+ if !attachments.empty?
19
+ param.merge!(self.api.gen_hash(arrachments, 'attachments'))
20
+ end
21
+ param.merge!(self.api.gen_hash(lang, 'lang'))
22
+ param.merge!(self.api.gen_hash(series_day, 'series_day')) if series_day != ''
23
+ param.merge!(self.api.gen_hash(series_time, 'series_time')) if series_time != ''
24
+ param.merge!(self.api.gen_hash(wrap_type, 'wrap_type'))
25
+ param.merge!(self.api.gen_hash(categories, 'categories')) if categories != ''
26
+ self.api.api_call('createEmailMessage', param)
27
+ end
28
+
29
+ def createSmsMessage(sender, body, list_id, tag = '', series_day = '', series_time = '', categories = '')
30
+ param = Hash.new
31
+ param.merge!(self.api.gen_hash(sender, 'sender'))
32
+ param.merge!(self.api.gen_hash(body, 'body'))
33
+ param.merge!(self.api.gen_hash(list_id, 'list_id'))
34
+ param.merge!(self.api.gen_hash(tag, 'tag')) if tag != ''
35
+ param.merge!(self.api.gen_hash(series_day, 'series_day')) if series_day != ''
36
+ param.merge!(self.api.gen_hash(series_time, 'series_time')) if series_time != ''
37
+ param.merge!(self.api.gen_hash(categories, 'categories')) if categories != ''
38
+ self.api.api_call('createSmsMessage', param)
39
+ end
40
+
41
+ def createCampaign(message_id, start_time = '', timezone = '', track_read = 0, track_links = 0, contacts = '', contacts_url = '', defer = 1, track_ga = 0, payment_limit = 0, payment_currency = '', ga_medium = '', ga_source ='', ga_campaign = '', ga_content = '', ga_term = '')
42
+ param = Hash.new
43
+ param.merge!(self.api.gen_hash(message_id, 'message_id'))
44
+ param.merge!(self.api.gen_hash(start_time, 'start_time')) if start_time != ''
45
+ param.merge!(self.api.gen_hash(timezone, 'timezone')) if timezone != ''
46
+ param.merge!(self.api.gen_hash(track_read, 'track_read'))
47
+ param.merge!(self.api.gen_hash(track_links, 'track_links'))
48
+ param.merge!(self.api.gen_hash(contacts, 'contacts')) if contacts != ''
49
+ param.merge!(self.api.gen_hash(contacts_url, 'contacts_url')) if contacts_url != ''
50
+ param.merge!(self.api.gen_hash(defer, 'defer'))
51
+ param.merge!(self.api.gen_hash(track_ga, 'track_ga.to_s'))
52
+ param.merge!(self.api.gen_hash(payment_limit, 'payment_limit'))
53
+ param.merge!(self.api.gen_hash(payment_currency, 'payment_currency')) if payment_currenct != ''
54
+ param.merge!(self.api.gen_hash(ga_medium, 'ga_medium')) if ga_medium != ''
55
+ param.merge!(self.api.gen_hash(ga_source, 'ga_source')) if ga_source != ''
56
+ param.merge!(self.api.gen_hash(ga_campaign, 'ga_campaign')) if ga_campaign != ''
57
+ param.merge!(self.api.gen_hash(ga_content, 'ga_content')) if ga_content != ''
58
+ param.merge!(self.api.gen_hash(ga_term, 'ga_term')) if ga_term != ''
59
+ self.api.api_call('createCampaign', param)
60
+ end
61
+
62
+ def getCampaigns(from = '', to = '')
63
+ param = Hash.new
64
+ param.merge!(self.api.gen_hash(from, 'from')) if from != ''
65
+ param.merge!(self.api.gen_hash(to, 'to')) if to != ''
66
+ self.api.api_call('getCampaigns', param)
67
+ end
68
+
69
+ def getCampaignStatus(campaign_id)
70
+ param = Hash.new
71
+ param.merge!(self.api.gen_hash(campaign_id, 'campaign_id'))
72
+ self.api.api_call('getCampaignStatus', param)
73
+ end
74
+
75
+ def sendSms(phone, sender, text)
76
+ param = Hash.new
77
+ param.merge!(self.api.gen_hash(phone, 'phone'))
78
+ param.merge!(self.api.gen_hash(sender, 'sender'))
79
+ param.merge!(self.api.gen_hash(text, 'text'))
80
+ self.api.api_call('sendSms', param)
81
+ end
82
+
83
+ def checkSms(sms_id)
84
+ param = Hash.new
85
+ param.merge!(self.api.gen_hash(sms_id, 'sms_id'))
86
+ self.api.api_call('checkSms', param)
87
+ end
88
+
89
+ def sendEmail(email, sender_name, sender_email, subject, body, list_id, user_campaign_id, attachments, lang ='en', track_read = 0,track_links = 0, cc = '', headers = '', wrap_type = 'skip', images_as = 'attachments', error_checking = 0)
90
+ param = Hash.new
91
+ param.merge!(self.api.gen_hash(email, 'email'))
92
+ param.merge!(self.api.gen_hash(sender_name, 'sender_name'))
93
+ param.merge!(self.api.gen_hash(sender_email, 'sender_email'))
94
+ param.merge!(self.api.gen_hash(subject, 'subject'))
95
+ param.merge!(self.api.gen_hash(body, 'body'))
96
+ param.merge!(self.api.gen_hash(list_id, 'list_id'))
97
+ param.merge!(self.api.gen_hash(user_campaign_id, 'user_campaign_id'))
98
+ param.merge!(:attach_multi => '1') if attachments.is_a? Array
99
+ param.merge!(self.api.gen_hash(attachments, 'attachments'))
100
+ param.merge!(self.api.gen_hash(lang, 'lang'))
101
+ param.merge!(self.api.gen_hash(track_read, 'track_read'))
102
+ param.merge!(self.api.gen_hash(track_links, 'track_links'))
103
+ param.merge!(self.api.gen_hash(cc, 'cc')) if cc != ''
104
+ param.merge!(self.api.gen_hash(headers, 'headers')) if headers != ''
105
+ param.merge!(self.api.gen_hash(wrap_type, 'wrap_type'))
106
+ param.merge!(self.api.gen_hash(images_as, 'images_as'))
107
+ param.merge!(self.api.gen_hash(error_checking, 'error_checking'))
108
+ self.api.api_call('sendEmail', param)
109
+ end
110
+
111
+ def checkEmail(email_id)
112
+ param = Hash.new
113
+ param.merge!(self.api.gen_hash(email_id, 'email_id'))
114
+ self.api.api_call('checkEmail', param)
115
+ end
116
+
117
+ def updateOptInEmail(sender_name, sender_email, subject, body, list_id)
118
+ param = Hash.new
119
+ param.merge!(self.api.gen_hash(sender_name, 'sender_name'))
120
+ param.merge!(self.api.gen_hash(sender_eamil, 'sender_email'))
121
+ param.merge!(self.api.gen_hash(subject, 'subject'))
122
+ param.merge!(self.api.gen_hash(body, 'body'))
123
+ param.merge!(self.api.gen_hash(list_id, 'list_id'))
124
+ self.api.api_call('updateOptInEmail', param)
125
+ end
126
+
127
+ def deleteMessage(message_id)
128
+ param = Hash.new
129
+ param.merge!(self.api.gen_hash(message_id, 'message_id'))
130
+ self.api.api_call('deleteMessage', param)
131
+ end
132
+
133
+ end
@@ -0,0 +1,82 @@
1
+ class Partners
2
+ attr_accessor :api
3
+
4
+ def initialize(api)
5
+ self.api = api
6
+ end
7
+
8
+ def validateSender(email, login = '')
9
+ param = Hash.new
10
+ param.merge!(self.api.gen_hash(email, 'email'))
11
+ param.merge!(self.api.gen_hash(login, 'login')) if login != ''
12
+ self.api.api_call('validateSender', param)
13
+ end
14
+
15
+ def register(email, login, password = '', notify = 0, extra = {}, timezone = '', country_code = 'RUS', currency_code = 'RUB', ip = '', api_mode = 'on')
16
+ param = Hash.new
17
+ param.merge!(self.api.gen_hash(email, 'email'))
18
+ param.merge!(self.api.gen_hash(login, 'login'))
19
+ param.merge!(self.api.gen_hash(password, 'password')) if password != ''
20
+ param.merge!(self.api.gen_hash(notify, 'notify'))
21
+ param.merge!(self.api.gen_hash(extra, 'extra')) unless extra.empty?
22
+ param.merge!(self.api.gen_hash(timezone, 'timezone')) if timezone != ''
23
+ param.merge!(self.api.gen_hash(country_code, 'country_code'))
24
+ param.merge!(self.api.gen_hash(currency_code, 'currence_code'))
25
+ param.merge!(self.api.gen_hash(ip, 'ip')) if ip != ''
26
+ param.merge!(self.api.gen_hash(api_mode, 'api_mode'))
27
+ self.api.api_call('register', param)
28
+ end
29
+
30
+ def checkUserExists(login = '', email = '')
31
+ param = Hash.new
32
+ param.merge!(self.api.gen_hash(login, 'login')) if login != ''
33
+ param.merge!(self.api.gen_hash(email, 'email')) if email != ''
34
+ self.api.api_call('checkUserExists', param)
35
+ end
36
+
37
+ def getUserInfo(login)
38
+ param = Hash.new
39
+ param.merge!(self.api.gen_hash(login, 'login'))
40
+ self.api.api_call('getUserInfo', param)
41
+ end
42
+
43
+ def getUsers(register_after = '', register_before = '')
44
+ param = Hash.new
45
+ param.merge!(self.api.gen_hash(register_after, 'register_after')) if register_after != ''
46
+ param.merge!(self.api.gen_hash(register_before, 'register_before')) if register_before != ''
47
+ self.api.api_call('getUsers', param)
48
+ end
49
+
50
+ def transferMoney(source_login, target_login, sum, currency)
51
+ param = Hash.new
52
+ param.merge!(self.api.gen_hash(source_login, 'source_login'))
53
+ param.merge!(self.api.gen_hash(target_login, 'target_login'))
54
+ param.merge!(self.api.gen_hash(sum, 'sum'))
55
+ param.merge!(self.api.gen_hash(currency, 'currency'))
56
+ self.api.api_call('transferMoney', param)
57
+ end
58
+
59
+ def getPayments(login = '', from = '', to = '', only_real_deposit = 0, ids = '', comment_substrings = [], payment_type = '')
60
+ param = Hash.new
61
+ param.merge!(self.api.gen_hash(login, 'login')) if login != ''
62
+ param.merge!(self.api.gen_hash(from, 'from')) if from != ''
63
+ param.merge!(self.api.gen_hash(to, 'to')) if to != ''
64
+ param.merge!(self.api.gen_hash(only_real_deposit, 'only_real_deposit'))
65
+ param.merge!(self.api.gen_hash(ids, 'ids')) if ids != ''
66
+ param.merge!(self.api.gen_hash(comment_substrings, 'comment_substrings')) unless comment_substrings.empty?
67
+ param.merge!(self.api.gen_hash(payment_type, 'payment_type')) if payment_type != ''
68
+ self.api.api_call('getPayments', param)
69
+ end
70
+
71
+ def getTariffs
72
+ self.api.api_call('getTariffs', {})
73
+ end
74
+
75
+ def changeTariff(login, tariff_id)
76
+ param = Hash.new
77
+ param.merge!(self.api.gen_hash(login, 'login'))
78
+ param.merge!(self.api.gen_hash(tariff_id, 'tarrif_id'))
79
+ self.api.api_call('changeTariff', param)
80
+ end
81
+
82
+ end
@@ -0,0 +1,29 @@
1
+ class Statistics
2
+ attr_accessor :api
3
+
4
+ def initialize(api)
5
+ self.api = api
6
+ end
7
+
8
+ def getCampaignDeliveryStats(campaign_id, changed_since = '', field_ids = '')
9
+ param = Hash.new
10
+ param.merge!(self.api.gen_hash(campaign_id, 'campaign_id'))
11
+ param.merge!(self.api.gen_hash(changed_since, 'changed_since')) if changed_since != ''
12
+ param.merge!(self.api.gen_hash(field_ids, 'field_ids')) if field_ids != ''
13
+ self.api.api_call('getCampaignDeliveryStats', param)
14
+ end
15
+
16
+ def getCampaignAggregateStats(campaign_id)
17
+ param = Hash.new
18
+ param.merge!(self.api.gen_hash(campaign_id, 'campaign_id'))
19
+ self.api.api_call('getCampaignDeliveryStats', param)
20
+ end
21
+
22
+ def getVisitedLinks(campaign_id, group = false)
23
+ param = Hash.new
24
+ param.merge!(self.api.gen_hash(campaign_id, 'campaign_id'))
25
+ param.merge!(self.api.gen_hash(group, 'group'))
26
+ self.api.api_call('getVisitedLinks', param)
27
+ end
28
+
29
+ end
@@ -0,0 +1,3 @@
1
+ module UnisenderApi
2
+ VERSION = "0.0.1"
3
+ end
@@ -0,0 +1,48 @@
1
+ require "unisender_api/version"
2
+ require "unisender_api/api_call"
3
+ require "unisender_api/extends"
4
+ require "unisender_api/lists"
5
+ require "unisender_api/message"
6
+ require "unisender_api/partners"
7
+ require "unisender_api/statistics"
8
+
9
+
10
+ module Unisender
11
+
12
+ class API
13
+
14
+ attr_accessor :api, :lists, :messages, :statistics, :extends, :partners
15
+
16
+ def initialize(api_key, locale = 'en', test = false)
17
+ self.api = ApiCall.new(api_key, locale, test)
18
+ @lists = Lists.new(self.api)
19
+ @messages = Messages.new(self.api)
20
+ @statistics = Statistics.new(self.api)
21
+ @extends = Extends.new(self.api)
22
+ @partners = Partners.new(self.api)
23
+ end
24
+
25
+ def lists
26
+ @lists
27
+ end
28
+
29
+ def messages
30
+ @messages
31
+ end
32
+
33
+ def statistics
34
+ @statistics
35
+ end
36
+
37
+ def extends
38
+ @extends
39
+ end
40
+
41
+ def partners
42
+ @partners
43
+ end
44
+
45
+ end
46
+
47
+
48
+ end
@@ -0,0 +1,34 @@
1
+ require "unisender_api/version"
2
+
3
+ module Unisender
4
+
5
+
6
+ class Api
7
+ attr_accessor :api_key, :test, :url
8
+
9
+ def initialize(api_key, locale = 'en', test = false)
10
+ self.api_key = api_key
11
+ self.test = test
12
+ self.url = "http://api.unisender.com/#{locale}/api/"
13
+ end
14
+
15
+
16
+ def api_call(method, params)
17
+ url = self.url + method
18
+ params.merge!(:test_mode => '1') if self.test
19
+ params.merge!(:api_key => self.api_key)
20
+ result = JSON.parse(self.post(url, params))
21
+ return result
22
+ end
23
+
24
+ def post(url, param)
25
+ uri = URI.parse(url)
26
+ https = Net::HTTP.new(uri.host, uri.port)
27
+ https.use_ssl = true
28
+ params = Addressable::URI.new
29
+ params.query_values = param
30
+ https.post(uri.path, params.query).body
31
+ end
32
+
33
+ end
34
+ end
@@ -0,0 +1,18 @@
1
+ # This file was generated by the `rspec --init` command. Conventionally, all
2
+ # specs live under a `spec` directory, which RSpec adds to the `$LOAD_PATH`.
3
+ # Require this file using `require "spec_helper"` to ensure that it is only
4
+ # loaded once.
5
+ #
6
+ # See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration
7
+ RSpec.configure do |config|
8
+ config.treat_symbols_as_metadata_keys_with_true_values = true
9
+ config.run_all_when_everything_filtered = true
10
+ config.filter_run :focus
11
+ config.mock_with :rr
12
+
13
+ # Run specs in random order to surface order dependencies. If you find an
14
+ # order dependency and want to debug it, you can fix the order by providing
15
+ # the seed, which is printed after each run.
16
+ # --seed 1234
17
+ config.order = 'random'
18
+ end
@@ -0,0 +1,28 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'unisender_api/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "unisender_api"
8
+ spec.version = UnisenderApi::VERSION
9
+ spec.authors = ["t0pep0"]
10
+ spec.email = ["t0pep0.gentoo@gmail.com"]
11
+ spec.description = "Unisender api library"
12
+ spec.summary = "unisender api library"
13
+ spec.homepage = "https://github.com/t0pep0/unisender_api"
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files`.split($/)
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_development_dependency "bundler", "~> 1.3"
22
+ spec.add_development_dependency "rake"
23
+ spec.add_development_dependency "redcarpet"
24
+ spec.add_development_dependency "yard"
25
+ spec.add_development_dependency "rspec-core"
26
+ spec.add_development_dependency "rspec-expectations"
27
+ spec.add_development_dependency "rr"
28
+ end
metadata ADDED
@@ -0,0 +1,179 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: unisender_api
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - t0pep0
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2013-12-24 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: bundler
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ~>
20
+ - !ruby/object:Gem::Version
21
+ version: '1.3'
22
+ type: :development
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ~>
28
+ - !ruby/object:Gem::Version
29
+ version: '1.3'
30
+ - !ruby/object:Gem::Dependency
31
+ name: rake
32
+ requirement: !ruby/object:Gem::Requirement
33
+ none: false
34
+ requirements:
35
+ - - ! '>='
36
+ - !ruby/object:Gem::Version
37
+ version: '0'
38
+ type: :development
39
+ prerelease: false
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ! '>='
44
+ - !ruby/object:Gem::Version
45
+ version: '0'
46
+ - !ruby/object:Gem::Dependency
47
+ name: redcarpet
48
+ requirement: !ruby/object:Gem::Requirement
49
+ none: false
50
+ requirements:
51
+ - - ! '>='
52
+ - !ruby/object:Gem::Version
53
+ version: '0'
54
+ type: :development
55
+ prerelease: false
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ! '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ - !ruby/object:Gem::Dependency
63
+ name: yard
64
+ requirement: !ruby/object:Gem::Requirement
65
+ none: false
66
+ requirements:
67
+ - - ! '>='
68
+ - !ruby/object:Gem::Version
69
+ version: '0'
70
+ type: :development
71
+ prerelease: false
72
+ version_requirements: !ruby/object:Gem::Requirement
73
+ none: false
74
+ requirements:
75
+ - - ! '>='
76
+ - !ruby/object:Gem::Version
77
+ version: '0'
78
+ - !ruby/object:Gem::Dependency
79
+ name: rspec-core
80
+ requirement: !ruby/object:Gem::Requirement
81
+ none: false
82
+ requirements:
83
+ - - ! '>='
84
+ - !ruby/object:Gem::Version
85
+ version: '0'
86
+ type: :development
87
+ prerelease: false
88
+ version_requirements: !ruby/object:Gem::Requirement
89
+ none: false
90
+ requirements:
91
+ - - ! '>='
92
+ - !ruby/object:Gem::Version
93
+ version: '0'
94
+ - !ruby/object:Gem::Dependency
95
+ name: rspec-expectations
96
+ requirement: !ruby/object:Gem::Requirement
97
+ none: false
98
+ requirements:
99
+ - - ! '>='
100
+ - !ruby/object:Gem::Version
101
+ version: '0'
102
+ type: :development
103
+ prerelease: false
104
+ version_requirements: !ruby/object:Gem::Requirement
105
+ none: false
106
+ requirements:
107
+ - - ! '>='
108
+ - !ruby/object:Gem::Version
109
+ version: '0'
110
+ - !ruby/object:Gem::Dependency
111
+ name: rr
112
+ requirement: !ruby/object:Gem::Requirement
113
+ none: false
114
+ requirements:
115
+ - - ! '>='
116
+ - !ruby/object:Gem::Version
117
+ version: '0'
118
+ type: :development
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ none: false
122
+ requirements:
123
+ - - ! '>='
124
+ - !ruby/object:Gem::Version
125
+ version: '0'
126
+ description: Unisender api library
127
+ email:
128
+ - t0pep0.gentoo@gmail.com
129
+ executables: []
130
+ extensions: []
131
+ extra_rdoc_files: []
132
+ files:
133
+ - .gitignore
134
+ - .rspec
135
+ - .yardopts
136
+ - Gemfile
137
+ - LICENSE.txt
138
+ - README.md
139
+ - Rakefile
140
+ - lib/.unisender_api.rb.swp
141
+ - lib/unisender_api.rb
142
+ - lib/unisender_api.rb~
143
+ - lib/unisender_api/api_call.rb
144
+ - lib/unisender_api/extends.rb
145
+ - lib/unisender_api/lists.rb
146
+ - lib/unisender_api/message.rb
147
+ - lib/unisender_api/partners.rb
148
+ - lib/unisender_api/statistics.rb
149
+ - lib/unisender_api/version.rb
150
+ - spec/spec_helper.rb
151
+ - unisender_api.gemspec
152
+ homepage: https://github.com/t0pep0/unisender_api
153
+ licenses:
154
+ - MIT
155
+ post_install_message:
156
+ rdoc_options: []
157
+ require_paths:
158
+ - lib
159
+ required_ruby_version: !ruby/object:Gem::Requirement
160
+ none: false
161
+ requirements:
162
+ - - ! '>='
163
+ - !ruby/object:Gem::Version
164
+ version: '0'
165
+ required_rubygems_version: !ruby/object:Gem::Requirement
166
+ none: false
167
+ requirements:
168
+ - - ! '>='
169
+ - !ruby/object:Gem::Version
170
+ version: '0'
171
+ requirements: []
172
+ rubyforge_project:
173
+ rubygems_version: 1.8.23
174
+ signing_key:
175
+ specification_version: 3
176
+ summary: unisender api library
177
+ test_files:
178
+ - spec/spec_helper.rb
179
+ has_rdoc: