e_pochta 0.3.1 → 0.5.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +8 -8
- data/README.md +46 -0
- data/lib/e_pochta.rb +5 -171
- data/lib/e_pochta_base.rb +63 -0
- data/lib/e_pochta_email.rb +23 -0
- data/lib/e_pochta_sms.rb +134 -0
- data/test/e_pochta_spec.rb +146 -0
- data/test/email_methods_spec.rb +88 -0
- data/test/sms_methods_spec.rb +59 -0
- metadata +11 -5
checksums.yaml
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
---
|
2
2
|
!binary "U0hBMQ==":
|
3
3
|
metadata.gz: !binary |-
|
4
|
-
|
4
|
+
NWQ2MmE2Y2IyMGM2YjI0ZjE2NmY1ZTk4OWU4MzlhY2M1N2I0NzQwNg==
|
5
5
|
data.tar.gz: !binary |-
|
6
|
-
|
6
|
+
NWUxMmI5YWQ1NGE4N2MyNmZhM2NiY2U3OTZlMWMyMWQ4NDU4YTE3Yw==
|
7
7
|
!binary "U0hBNTEy":
|
8
8
|
metadata.gz: !binary |-
|
9
|
-
|
10
|
-
|
11
|
-
|
9
|
+
OTI4ZDA0Mjk0MzYwOTlmMTgyY2RlZDU1MGVhMzNkMTMxZmE0NmNiODQxMjRh
|
10
|
+
MDc5ZmYwM2MzNDM5MGYwYjZmZDM5MDYzZTIzODJjMWQyZTNmNTYxMTRhNmQ4
|
11
|
+
NjRjNjcxMzliNDdmNDNlOTVjMTA2MmQwZmM0ZDQ5ODI4YzVmY2Q=
|
12
12
|
data.tar.gz: !binary |-
|
13
|
-
|
14
|
-
|
15
|
-
|
13
|
+
Njk2YTlmMjM0MmNlNWQ4YWJiOGI2ODdhNzVlYjc1Y2IwNmNhYzBkYzMwOTU1
|
14
|
+
NzZmOTkyZjU1NDk3MjM4MWY5NjAwOTIzYmNjM2MxNzMxNmE3ZDQ1OTkwYTY2
|
15
|
+
NzJjNjliZmM4Nzc1YmRlMmVjNjFmY2IwMzYzOGIxZmFlODFhMTE=
|
data/README.md
ADDED
@@ -0,0 +1,46 @@
|
|
1
|
+
#e_pochta
|
2
|
+
This is an API wrapper for online SMS and Email service [E-pochta](http://www.epochta.ru/) and it's API v3.0.
|
3
|
+
You can read about this API [here (russian)] (http://www.epochta.ru/products/sms/v3.php)
|
4
|
+
|
5
|
+
##Usage
|
6
|
+
|
7
|
+
```ruby
|
8
|
+
# provide your user keys
|
9
|
+
epochta = EPochtaService::EPochtaSMS.new(:private_key => 'your_private_key', :public_key => 'your_public_key')
|
10
|
+
# send sms
|
11
|
+
result = epochta.send_sms({
|
12
|
+
# read the api to provide correct arguments
|
13
|
+
'sender' => 'Name',
|
14
|
+
'text' => 'Hello World!',
|
15
|
+
'phone' => '71234567890',
|
16
|
+
'datetime' => '',
|
17
|
+
'sms_lifetime' => 0
|
18
|
+
})
|
19
|
+
|
20
|
+
puts result # sms_id on epochta server
|
21
|
+
```
|
22
|
+
|
23
|
+
##Email
|
24
|
+
From version 0.5.0 gem has new class for EPochta email campaigns.
|
25
|
+
```ruby
|
26
|
+
# provide your user keys
|
27
|
+
epochta = EPochtaService::EPochtaEmail.new(:private_key => 'your_private_key', :public_key => 'your_public_key')
|
28
|
+
# create email campaign
|
29
|
+
campaign = epochta.createCampaign({
|
30
|
+
# read the api to provide correct arguments
|
31
|
+
'name' => 'test campaign',
|
32
|
+
'sender_name' => 'Vasya',
|
33
|
+
'sender_email' => 'example@yandex.ru',
|
34
|
+
'subject' => 'test email',
|
35
|
+
'body' => Base64.encode64("<h2>test</h2> <p>my mail</p>"),
|
36
|
+
'list_id' => @addr_book_id
|
37
|
+
})
|
38
|
+
|
39
|
+
puts campaign['id'] # created campaign id on epochta server
|
40
|
+
```
|
41
|
+
|
42
|
+
You can also install it as a gem.
|
43
|
+
|
44
|
+
```
|
45
|
+
gem install e_pochta
|
46
|
+
```
|
data/lib/e_pochta.rb
CHANGED
@@ -1,177 +1,11 @@
|
|
1
1
|
require 'net/http'
|
2
2
|
require 'digest/md5'
|
3
3
|
require 'json'
|
4
|
+
require 'base64'
|
4
5
|
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
# options hash: public_key, private_key
|
9
|
-
def initialize(options)
|
10
|
-
if options.is_a? Hash
|
11
|
-
self.public_key = options[:public_key]
|
12
|
-
self.private_key = options[:private_key]
|
13
|
-
else
|
14
|
-
raise ArgumentError, "expected Hash argument, got #{options.class}"
|
15
|
-
end
|
16
|
-
end
|
6
|
+
require 'e_pochta_base'
|
7
|
+
require 'e_pochta_sms'
|
8
|
+
require 'e_pochta_email'
|
17
9
|
|
18
|
-
|
19
|
-
result = ''
|
20
|
-
params['key'] = self.public_key
|
21
|
-
#stringify_keys
|
22
|
-
stringified_params = {}
|
23
|
-
params.each {|key, value| stringified_params[key.to_s] = value.to_s}
|
24
|
-
#sort & concatenate all values
|
25
|
-
stringified_params.sort.each { |value| result = result + value[1] }
|
26
|
-
result = result + self.private_key
|
27
|
-
Digest::MD5.hexdigest( result )
|
28
|
-
end
|
10
|
+
include EPochtaService
|
29
11
|
|
30
|
-
def form_request(params, action)
|
31
|
-
params['sum'] = calculate_md5 params
|
32
|
-
self.parameters = params.each {|k,v| v = URI.escape v.to_s }
|
33
|
-
|
34
|
-
url = URI("#{EPochta::URL}#{action}")
|
35
|
-
url.query = URI.encode_www_form params
|
36
|
-
url
|
37
|
-
end
|
38
|
-
|
39
|
-
def exec_command(params, action)
|
40
|
-
uri = form_request(params, action)
|
41
|
-
result = Net::HTTP.post_form(uri, self.parameters)
|
42
|
-
end
|
43
|
-
|
44
|
-
def create_address_book(params)
|
45
|
-
params['action'] = 'addAddressbook'
|
46
|
-
params['version'] = '3.0'
|
47
|
-
result = exec_command(params, 'addAddressbook')
|
48
|
-
result = JSON.parse(result.body)
|
49
|
-
|
50
|
-
if result.has_key? 'error'
|
51
|
-
false
|
52
|
-
else
|
53
|
-
result['result']['addressbook_id']
|
54
|
-
end
|
55
|
-
end
|
56
|
-
|
57
|
-
def get_balance()
|
58
|
-
params = {}
|
59
|
-
params['action'] = 'getUserBalance'
|
60
|
-
params['version'] = '3.0'
|
61
|
-
params['currency'] = 'RUB'
|
62
|
-
result = exec_command(params, 'getUserBalance')
|
63
|
-
result = JSON.parse(result.body)
|
64
|
-
|
65
|
-
if result.has_key? 'error'
|
66
|
-
false
|
67
|
-
else
|
68
|
-
result['result']['balance_currency']
|
69
|
-
end
|
70
|
-
end
|
71
|
-
|
72
|
-
def delete_address_book(params)
|
73
|
-
params['action'] = 'delAddressbook'
|
74
|
-
params['version'] = '3.0'
|
75
|
-
result = exec_command(params, 'delAddressbook')
|
76
|
-
result = JSON.parse(result.body)
|
77
|
-
if result.has_key? 'error'
|
78
|
-
false
|
79
|
-
else
|
80
|
-
true
|
81
|
-
end
|
82
|
-
end
|
83
|
-
|
84
|
-
def add_phones(params)
|
85
|
-
params['action'] = 'addPhoneToAddressBook'
|
86
|
-
params['version'] = '3.0'
|
87
|
-
result = exec_command(params, 'addPhoneToAddressBook')
|
88
|
-
result = JSON.parse(result.body)
|
89
|
-
if result.has_key? 'error'
|
90
|
-
false
|
91
|
-
else
|
92
|
-
true
|
93
|
-
end
|
94
|
-
end
|
95
|
-
|
96
|
-
def send_sms(params)
|
97
|
-
params['action'] = 'sendSMS'
|
98
|
-
params['version'] = '3.0'
|
99
|
-
result = exec_command(params, 'sendSMS')
|
100
|
-
result = JSON.parse(result.body)
|
101
|
-
|
102
|
-
if result.has_key? 'error'
|
103
|
-
false
|
104
|
-
else
|
105
|
-
result['result']['id']
|
106
|
-
end
|
107
|
-
end
|
108
|
-
|
109
|
-
def create_campaign(params)
|
110
|
-
params['action'] = 'createCampaign'
|
111
|
-
params['version'] = '3.0'
|
112
|
-
result = exec_command(params, 'createCampaign')
|
113
|
-
result = JSON.parse(result.body)
|
114
|
-
|
115
|
-
if result.has_key? 'error'
|
116
|
-
false
|
117
|
-
else
|
118
|
-
result['result']['id']
|
119
|
-
end
|
120
|
-
end
|
121
|
-
|
122
|
-
def get_campaign_status(params)
|
123
|
-
params['action'] = 'getCampaignInfo'
|
124
|
-
params['version'] = '3.0'
|
125
|
-
result = exec_command(params, 'getCampaignInfo')
|
126
|
-
result = JSON.parse(result.body)
|
127
|
-
|
128
|
-
if result.has_key? 'error'
|
129
|
-
false
|
130
|
-
else
|
131
|
-
result['result']['status_text'] = get_status_text(result['result']['status'].to_i)
|
132
|
-
result['result']
|
133
|
-
end
|
134
|
-
end
|
135
|
-
|
136
|
-
def campaign_delivery_statuses(params)
|
137
|
-
params['action'] = 'getCampaignDeliveryStats'
|
138
|
-
params['version'] = '3.0'
|
139
|
-
response = exec_command(params, 'getCampaignDeliveryStats')
|
140
|
-
response = JSON.parse(response.body)
|
141
|
-
|
142
|
-
if response.has_key? 'error'
|
143
|
-
false
|
144
|
-
else
|
145
|
-
# makes "phone->status" structure from returned response
|
146
|
-
format_delivery_status_hash(response['result'])
|
147
|
-
end
|
148
|
-
|
149
|
-
end
|
150
|
-
|
151
|
-
private
|
152
|
-
# helpers
|
153
|
-
def get_status_text(code)
|
154
|
-
status_text = case code
|
155
|
-
when 0 then 'pending'
|
156
|
-
when 1 then 'not_enought_money'
|
157
|
-
when 2 then 'in_process'
|
158
|
-
when 3 then 'done'
|
159
|
-
when 4 then 'wrong_numbers'
|
160
|
-
when 5 then 'partialy_done'
|
161
|
-
when 6 then 'spam'
|
162
|
-
when 7 then 'wrong_sender_name'
|
163
|
-
when 8 then 'paused'
|
164
|
-
when 9 then 'planned'
|
165
|
-
when 10 then 'on_moderation'
|
166
|
-
end
|
167
|
-
end
|
168
|
-
|
169
|
-
def format_delivery_status_hash(response)
|
170
|
-
result = {}
|
171
|
-
response['phone'].each_with_index do |client, index|
|
172
|
-
result[client] = response['status'][index]
|
173
|
-
end
|
174
|
-
result
|
175
|
-
end
|
176
|
-
|
177
|
-
end
|
@@ -0,0 +1,63 @@
|
|
1
|
+
module EPochtaService
|
2
|
+
|
3
|
+
class EPochtaBase
|
4
|
+
attr_accessor :public_key, :private_key, :parameters
|
5
|
+
|
6
|
+
# options hash: public_key, private_key
|
7
|
+
def initialize(options)
|
8
|
+
if options.is_a? Hash
|
9
|
+
self.public_key = options[:public_key]
|
10
|
+
self.private_key = options[:private_key]
|
11
|
+
else
|
12
|
+
raise ArgumentError, "expected Hash argument, got #{options.class}"
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
def calculate_md5(params)
|
17
|
+
result = ''
|
18
|
+
params['key'] = self.public_key
|
19
|
+
#stringify_keys
|
20
|
+
stringified_params = {}
|
21
|
+
params.each do |key, value|
|
22
|
+
# This is hack for correct md5 summ calculating
|
23
|
+
# when we have array value in param, we must concatenate with 'Array' string
|
24
|
+
# instead of value of this array =\
|
25
|
+
# because of PHP origin of EPochta engine:
|
26
|
+
|
27
|
+
# this is PHP example of control summ calculating, which is correct
|
28
|
+
|
29
|
+
# ksort($arrayRequest);
|
30
|
+
# $sum = '';
|
31
|
+
# foreach ($arrayRequest as $v)
|
32
|
+
# $sum .= $v; // if $v is Array then it evaluates to 'Array' string value
|
33
|
+
|
34
|
+
if value.is_a?(Array)
|
35
|
+
stringified_params[key.to_s] = 'Array'
|
36
|
+
next
|
37
|
+
end
|
38
|
+
# =========
|
39
|
+
stringified_params[key.to_s] = value.to_s
|
40
|
+
end
|
41
|
+
|
42
|
+
#sort & concatenate all values
|
43
|
+
stringified_params.sort.each {|value| result = result + value[1] }
|
44
|
+
result = result + self.private_key
|
45
|
+
Digest::MD5.hexdigest( result )
|
46
|
+
end
|
47
|
+
|
48
|
+
def form_request(params)
|
49
|
+
params['version'] = '3.0'
|
50
|
+
params['sum'] = calculate_md5 params
|
51
|
+
self.parameters = params.each {|k,v| v = URI.escape v.to_s }
|
52
|
+
|
53
|
+
url = URI("#{self.class::URL}#{params['action']}")
|
54
|
+
url.query = URI.encode_www_form params
|
55
|
+
url
|
56
|
+
end
|
57
|
+
|
58
|
+
def exec_command(params)
|
59
|
+
uri = form_request(params)
|
60
|
+
result = Net::HTTP.post_form(uri, self.parameters)
|
61
|
+
end
|
62
|
+
end
|
63
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
module EPochtaService
|
2
|
+
class EPochtaEmail < EPochtaBase
|
3
|
+
URL = 'http://atompark.com/api/email/3.0/'
|
4
|
+
|
5
|
+
[
|
6
|
+
:addAddressbook, :delAddressbook, :addAddresses,
|
7
|
+
:getAddressbook, :activateEmails, :createCampaign,
|
8
|
+
:delEmail, :getUserBalance, :getCampaignStats
|
9
|
+
].each do |method|
|
10
|
+
define_method(method) do |params|
|
11
|
+
params['action'] = method.to_s
|
12
|
+
result = exec_command(params)
|
13
|
+
result = JSON.parse(result.body)
|
14
|
+
|
15
|
+
if result.has_key? 'error'
|
16
|
+
false
|
17
|
+
else
|
18
|
+
result['result'] || result
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
data/lib/e_pochta_sms.rb
ADDED
@@ -0,0 +1,134 @@
|
|
1
|
+
module EPochtaService
|
2
|
+
class EPochtaSMS < EPochtaBase
|
3
|
+
URL = 'http://atompark.com/api/sms/3.0/'
|
4
|
+
|
5
|
+
def create_address_book(params)
|
6
|
+
params['action'] = 'addAddressbook'
|
7
|
+
|
8
|
+
result = exec_command(params)
|
9
|
+
result = JSON.parse(result.body)
|
10
|
+
|
11
|
+
if result.has_key? 'error'
|
12
|
+
false
|
13
|
+
else
|
14
|
+
result['result']['addressbook_id']
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
def get_balance()
|
19
|
+
params = {}
|
20
|
+
params['action'] = 'getUserBalance'
|
21
|
+
params['currency'] = 'RUB'
|
22
|
+
result = exec_command(params)
|
23
|
+
result = JSON.parse(result.body)
|
24
|
+
|
25
|
+
if result.has_key? 'error'
|
26
|
+
false
|
27
|
+
else
|
28
|
+
result['result']['balance_currency']
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
def delete_address_book(params)
|
33
|
+
params['action'] = 'delAddressbook'
|
34
|
+
result = exec_command(params)
|
35
|
+
result = JSON.parse(result.body)
|
36
|
+
if result.has_key? 'error'
|
37
|
+
false
|
38
|
+
else
|
39
|
+
true
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
def add_phones(params)
|
44
|
+
params['action'] = 'addPhoneToAddressBook'
|
45
|
+
result = exec_command(params)
|
46
|
+
result = JSON.parse(result.body)
|
47
|
+
if result.has_key? 'error'
|
48
|
+
false
|
49
|
+
else
|
50
|
+
true
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
def send_sms(params)
|
55
|
+
params['action'] = 'sendSMS'
|
56
|
+
result = exec_command(params)
|
57
|
+
result = JSON.parse(result.body)
|
58
|
+
|
59
|
+
if result.has_key? 'error'
|
60
|
+
false
|
61
|
+
else
|
62
|
+
result['result']['id']
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
66
|
+
def create_campaign(params)
|
67
|
+
params['action'] = 'createCampaign'
|
68
|
+
result = exec_command(params)
|
69
|
+
result = JSON.parse(result.body)
|
70
|
+
|
71
|
+
if result.has_key? 'error'
|
72
|
+
false
|
73
|
+
else
|
74
|
+
result['result']['id']
|
75
|
+
end
|
76
|
+
end
|
77
|
+
|
78
|
+
# params = {'id' => 12345} campaign_id
|
79
|
+
def get_campaign_status(params)
|
80
|
+
params['action'] = 'getCampaignInfo'
|
81
|
+
result = exec_command(params)
|
82
|
+
result = JSON.parse(result.body)
|
83
|
+
|
84
|
+
if result.has_key? 'error'
|
85
|
+
false
|
86
|
+
else
|
87
|
+
result['result']['status_text'] = get_status_text(result['result']['status'].to_i)
|
88
|
+
result['result']
|
89
|
+
end
|
90
|
+
end
|
91
|
+
|
92
|
+
# params = {'id' => 12345} campaign_id
|
93
|
+
def campaign_delivery_statuses(params)
|
94
|
+
params['action'] = 'getCampaignDeliveryStats'
|
95
|
+
|
96
|
+
response = exec_command(params)
|
97
|
+
response = JSON.parse(response.body)
|
98
|
+
|
99
|
+
if response.has_key? 'error'
|
100
|
+
false
|
101
|
+
else
|
102
|
+
# makes "phone->status" structure from returned response
|
103
|
+
format_delivery_status_hash(response['result'])
|
104
|
+
end
|
105
|
+
|
106
|
+
end
|
107
|
+
|
108
|
+
private
|
109
|
+
# helpers
|
110
|
+
def get_status_text(code)
|
111
|
+
status_text = case code
|
112
|
+
when 0 then 'epochta_pending'
|
113
|
+
when 1 then 'not_enought_money'
|
114
|
+
when 2 then 'in_process'
|
115
|
+
when 3 then 'done'
|
116
|
+
when 4 then 'wrong_numbers'
|
117
|
+
when 5 then 'partialy_done'
|
118
|
+
when 6 then 'spam'
|
119
|
+
when 7 then 'wrong_sender_name'
|
120
|
+
when 8 then 'paused'
|
121
|
+
when 9 then 'planned'
|
122
|
+
when 10 then 'on_moderation'
|
123
|
+
end
|
124
|
+
end
|
125
|
+
|
126
|
+
def format_delivery_status_hash(response)
|
127
|
+
result = {}
|
128
|
+
response['phone'].each_with_index do |client, index|
|
129
|
+
result[client] = {status: response['status'][index], delivery_date: response['donedate'][index] }
|
130
|
+
end
|
131
|
+
result
|
132
|
+
end
|
133
|
+
end
|
134
|
+
end
|
@@ -0,0 +1,146 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
require 'e_pochta'
|
3
|
+
require 'rspec'
|
4
|
+
|
5
|
+
describe EPochtaSMS do
|
6
|
+
|
7
|
+
subject { EPochtaSMS.new(:public_key => '42e461a8affce1cff775b3a603941e8e', :private_key => '89bbb6dab9bed6758aaf137560440e9f') }
|
8
|
+
|
9
|
+
it 'must have constant api url' do
|
10
|
+
EPochtaSMS::URL.should_not be_nil
|
11
|
+
end
|
12
|
+
|
13
|
+
context 'on creation' do
|
14
|
+
it 'should have public and private api key ' do
|
15
|
+
[subject.public_key, subject.private_key].each {|val| val.should_not be_nil}
|
16
|
+
end
|
17
|
+
|
18
|
+
it 'should take options hash ' do
|
19
|
+
expect { EPochtaSMS.new([1,2,3]) }.to raise_error(ArgumentError)
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
describe '.calculate_md5' do
|
24
|
+
it 'should return a string' do
|
25
|
+
params = {b: '123', a: 1, c: 256}
|
26
|
+
result = subject.calculate_md5 params
|
27
|
+
expect(result.class).to eq(String)
|
28
|
+
end
|
29
|
+
|
30
|
+
it 'should return md5 string (32 chars), generated from argument' do
|
31
|
+
params = {b: '123', a: 1, c: 256}
|
32
|
+
result = subject.calculate_md5 params
|
33
|
+
result.length.should == 32
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
describe '.exec_command' do
|
38
|
+
|
39
|
+
context 'responce value' do
|
40
|
+
before(:each) do
|
41
|
+
@addr_book_request = {'action' => 'addAddressbook', 'name' => "test adress book #{Random.rand 1000}", 'description' => 'test book'}
|
42
|
+
@request_result = subject.exec_command(@addr_book_request)
|
43
|
+
end
|
44
|
+
|
45
|
+
it 'should have 200 status: OK' do
|
46
|
+
expect(@request_result.class).to eq(Net::HTTPOK)
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
describe '.form_request' do
|
52
|
+
context 'return value' do
|
53
|
+
before(:each) do
|
54
|
+
@addr_book_request = {'action' => 'addAddressbook', 'name' => "test adress book #{Random.rand 1000}", 'description' => 'test book'}
|
55
|
+
@query_string = subject.form_request(@addr_book_request)
|
56
|
+
end
|
57
|
+
|
58
|
+
it 'should be a URI object' do
|
59
|
+
@query_string.class.should be URI::HTTP
|
60
|
+
end
|
61
|
+
|
62
|
+
it 'should not be empty' do
|
63
|
+
@query_string.to_s.should_not == ''
|
64
|
+
end
|
65
|
+
|
66
|
+
it 'must contain "sum" key' do
|
67
|
+
@query_string.to_s.should =~ /sum/
|
68
|
+
end
|
69
|
+
|
70
|
+
it 'must contain "key" key' do
|
71
|
+
@query_string.to_s.should =~ /key/
|
72
|
+
end
|
73
|
+
end
|
74
|
+
end
|
75
|
+
|
76
|
+
describe '.create_address_book' do
|
77
|
+
before(:each) do
|
78
|
+
@good_params = {'name' => "test adress book", 'description' => 'test book'}
|
79
|
+
end
|
80
|
+
|
81
|
+
context 'return value' do
|
82
|
+
it 'should be ID of created address book' do
|
83
|
+
id = subject.create_address_book(@good_params)
|
84
|
+
expect(id.class).to eq(Fixnum)
|
85
|
+
end
|
86
|
+
|
87
|
+
it 'should not be false' do
|
88
|
+
id = subject.create_address_book(@good_params)
|
89
|
+
expect(id).not_to eq(false)
|
90
|
+
end
|
91
|
+
end
|
92
|
+
end
|
93
|
+
|
94
|
+
describe '.delete_address_book' do
|
95
|
+
before(:each) do
|
96
|
+
address_book_id = subject.create_address_book({'name' => "test delete book"})
|
97
|
+
@good_params = { 'idAddressBook' => address_book_id }
|
98
|
+
@bad_params = { 'idAddressBook' => 123454568 }
|
99
|
+
end
|
100
|
+
|
101
|
+
context 'return value' do
|
102
|
+
it 'should be true' do
|
103
|
+
subject.delete_address_book(@good_params).should be(true)
|
104
|
+
end
|
105
|
+
it 'should be false with bad params' do
|
106
|
+
subject.delete_address_book(@bad_params).should be(false)
|
107
|
+
end
|
108
|
+
end
|
109
|
+
end
|
110
|
+
|
111
|
+
describe '.add_phones' do
|
112
|
+
before do
|
113
|
+
@address_book_id = subject.create_address_book({'name' => "with users"})
|
114
|
+
end
|
115
|
+
|
116
|
+
context 'return value' do
|
117
|
+
before do
|
118
|
+
@good_params = {
|
119
|
+
'idAddressBook' => @address_book_id,
|
120
|
+
'data' => [["89085085077", "Тимур Русланович"], ['89518408051', 'Кристина'] ].to_json }
|
121
|
+
@bad_params = {
|
122
|
+
'idAddressBook' => 1251255,
|
123
|
+
'data' => [["89085085077", "Тимур Русланович"], ['89518408051', 'Кристина'] ].to_json }
|
124
|
+
end
|
125
|
+
|
126
|
+
it 'should be true' do
|
127
|
+
subject.add_phones(@good_params).should be(true)
|
128
|
+
end
|
129
|
+
|
130
|
+
it 'should be false with bad params' do
|
131
|
+
subject.add_phones(@bad_params).should be(false)
|
132
|
+
end
|
133
|
+
end
|
134
|
+
end
|
135
|
+
|
136
|
+
describe '.get_balance' do
|
137
|
+
context 'return value' do
|
138
|
+
it 'should be a number, which represent current account balance' do
|
139
|
+
balance = subject.get_balance()
|
140
|
+
puts balance
|
141
|
+
expect(balance.class).to be(Float)
|
142
|
+
end
|
143
|
+
end
|
144
|
+
end
|
145
|
+
|
146
|
+
end
|
@@ -0,0 +1,88 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
require 'e_pochta'
|
3
|
+
require 'rspec'
|
4
|
+
|
5
|
+
|
6
|
+
describe EPochtaEmail do
|
7
|
+
|
8
|
+
subject { EPochtaEmail.new(:public_key => 'd6029849011e7f86a97792d6e46be1a6', :private_key => '8e564896226d0e02d077cd1f671d6180') }
|
9
|
+
|
10
|
+
describe 'Address book method' do
|
11
|
+
before(:all) do
|
12
|
+
@addr_book_id = subject.addAddressbook({'name' => "My adress book #{Random.rand 1000}"})['addressbook_id']
|
13
|
+
end
|
14
|
+
|
15
|
+
context 'addAddressbook' do
|
16
|
+
it 'return value shoud be an ID of sended message' do
|
17
|
+
@addr_book_id.class.should be(Fixnum)
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
context 'addAddresses' do
|
22
|
+
it 'return value should be 1' do
|
23
|
+
subject.addAddresses('id_list' => @addr_book_id, 'email[]' => ['zxc@zxc.ru', 'asd@asd.ru']).should be_equal(1)
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
context 'getAddressbook' do
|
28
|
+
it 'return value should contain id number' do
|
29
|
+
subject.getAddressbook('id' => @addr_book_id)['id'].should be_equal(@addr_book_id)
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
# context 'activateEmails' do
|
34
|
+
# it 'return value should contain count of numbers, set for activation' do
|
35
|
+
# sleep(5)
|
36
|
+
# subject.activateEmails('id' => @addr_book_id, 'description' => 'sdaad').has_key?('activation_request_qty').should be true
|
37
|
+
# end
|
38
|
+
# end
|
39
|
+
|
40
|
+
context 'delEmail' do
|
41
|
+
it 'return value should be 1' do
|
42
|
+
subject.delEmail('id' => @addr_book_id, 'email' => 'zxc@zxc.ru').should be_equal(1)
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
after(:all) do
|
47
|
+
subject.delAddressbook :id => @addr_book_id
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
describe 'Campaign method' do
|
52
|
+
before(:all) do
|
53
|
+
@addr_book_id = subject.addAddressbook({'name' => "My adress book #{Random.rand 1000}"})['addressbook_id']
|
54
|
+
subject.addAddresses('id_list' => @addr_book_id, 'email[]' => ['timurt1988@gmail.com', 'noodledoomer@rambler.ru'])
|
55
|
+
sleep(6)
|
56
|
+
subject.activateEmails('id' => @addr_book_id, 'description' => 'Моя почта для теста')
|
57
|
+
sleep(6)
|
58
|
+
end
|
59
|
+
|
60
|
+
context 'createCampaign' do
|
61
|
+
it 'return value should contain id of created campaign' do
|
62
|
+
|
63
|
+
campaign = subject.createCampaign({
|
64
|
+
'name' => 'test campaign',
|
65
|
+
'sender_name' => 'Тимур',
|
66
|
+
'sender_email' => 'rouge1988@yandex.ru',
|
67
|
+
'subject' => 'test email',
|
68
|
+
'body' => Base64.encode64("<h2>test</h2> <p>my mail</p>"),
|
69
|
+
'list_id' => @addr_book_id
|
70
|
+
})
|
71
|
+
campaign['id'].class.should be(Fixnum)
|
72
|
+
end
|
73
|
+
end
|
74
|
+
|
75
|
+
context 'getCampaignStats' do
|
76
|
+
it 'return value should have key "statistics"' do
|
77
|
+
subject.getCampaignStats('id' => 20320).has_key?('statistics').should be true
|
78
|
+
end
|
79
|
+
end
|
80
|
+
end
|
81
|
+
|
82
|
+
describe 'getUserBalance method' do
|
83
|
+
it 'should return balance_currency value' do
|
84
|
+
subject.getUserBalance({'currency' => 'RUB'}).has_key?('balance_currency').should be true
|
85
|
+
end
|
86
|
+
end
|
87
|
+
|
88
|
+
end
|
@@ -0,0 +1,59 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
require 'e_pochta'
|
3
|
+
require 'rspec'
|
4
|
+
|
5
|
+
|
6
|
+
describe EPochtaSMS do
|
7
|
+
|
8
|
+
subject { EPochtaSMS.new(:public_key => '42e461a8affce1cff775b3a603941e8e', :private_key => '89bbb6dab9bed6758aaf137560440e9f') }
|
9
|
+
|
10
|
+
describe '.send_sms' do
|
11
|
+
before do
|
12
|
+
@good_params = {
|
13
|
+
'sender' => 'Dealer',
|
14
|
+
'text' => 'Hello Вова!',
|
15
|
+
'phone' => '79085085077',
|
16
|
+
'datetime' => '',
|
17
|
+
'sms_lifetime' => 0
|
18
|
+
}
|
19
|
+
@bad_params = {}
|
20
|
+
end
|
21
|
+
|
22
|
+
context 'return value' do
|
23
|
+
it 'shoud be an ID of sended message' do
|
24
|
+
subject.send_sms(@good_params).class.should be(Fixnum)
|
25
|
+
end
|
26
|
+
|
27
|
+
it 'should be false with bad params' do
|
28
|
+
subject.send_sms(@bad_params).should be(false)
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
describe '.create_campaign' do
|
34
|
+
before do
|
35
|
+
@address_book_id = subject.create_address_book('name' => "campaign 2 test", 'description' => 'for campaign')
|
36
|
+
subject.add_phones({
|
37
|
+
'idAddressBook' => @address_book_id,
|
38
|
+
'data' => [["79085085077", "Юрий Владимирович"], ['79518408051', 'Вова'] ].to_json
|
39
|
+
})
|
40
|
+
|
41
|
+
@good_params = {
|
42
|
+
'sender' => '12345',
|
43
|
+
'list_id' => @address_book_id,
|
44
|
+
'text' => '%1%, представляем Вам CRM Dealerpoint!',
|
45
|
+
'datetime' => '',
|
46
|
+
'batch' => 0,
|
47
|
+
'batchinterval' => 0,
|
48
|
+
'sms_lifetime' => 0,
|
49
|
+
'controlphone' => ''
|
50
|
+
}
|
51
|
+
end
|
52
|
+
context 'return value' do
|
53
|
+
it 'should be an ID of created sms Campaign' do
|
54
|
+
subject.create_campaign(@good_params).class.should be (Fixnum)
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
end
|
metadata
CHANGED
@@ -1,23 +1,29 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: e_pochta
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.5.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Tim Tikijian
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2013-
|
11
|
+
date: 2013-06-01 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
|
-
description:
|
14
|
-
http://www.epochta.ru/
|
13
|
+
description: Ruby gem for EPochta API 3.0 - an email and sms service www.epochta.ru
|
15
14
|
email: timurt1988@gmail.com
|
16
15
|
executables: []
|
17
16
|
extensions: []
|
18
17
|
extra_rdoc_files: []
|
19
18
|
files:
|
19
|
+
- lib/e_pochta_email.rb
|
20
|
+
- lib/e_pochta_base.rb
|
21
|
+
- lib/e_pochta_sms.rb
|
20
22
|
- lib/e_pochta.rb
|
23
|
+
- test/email_methods_spec.rb
|
24
|
+
- test/e_pochta_spec.rb
|
25
|
+
- test/sms_methods_spec.rb
|
26
|
+
- README.md
|
21
27
|
homepage: http://rubygems.org/gems/e_pochta
|
22
28
|
licenses: []
|
23
29
|
metadata: {}
|
@@ -40,5 +46,5 @@ rubyforge_project:
|
|
40
46
|
rubygems_version: 2.0.3
|
41
47
|
signing_key:
|
42
48
|
specification_version: 4
|
43
|
-
summary:
|
49
|
+
summary: Ruby gem for EPochta API 3.0
|
44
50
|
test_files: []
|