sms_centre 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +17 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +90 -0
- data/Rakefile +1 -0
- data/TODO.md +1 -0
- data/lib/sms_centre.rb +106 -0
- data/lib/sms_centre/api.rb +81 -0
- data/lib/sms_centre/configuration.rb +45 -0
- data/lib/sms_centre/locales/ru.yml +30 -0
- data/lib/sms_centre/provider.rb +72 -0
- data/lib/sms_centre/result.rb +30 -0
- data/lib/sms_centre/status.rb +36 -0
- data/lib/sms_centre/version.rb +3 -0
- data/sms_centre.gemspec +25 -0
- metadata +101 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 888f04fa711bf759a971c6c83db68de98d5efac5
|
4
|
+
data.tar.gz: 9aeca8e1672f7ef79d1c7f2c3c535a9efbf9a009
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 3b823ef4321cd2e9650a29055a70f6137ea5840b00e3d2370e8ea809e8919e957ede8a9549eabaac059f854548abb0f00b8c816e2bc35faccdb04eb5dc385071
|
7
|
+
data.tar.gz: 6090666a27660b3ed16cdc263bf7d0445c2f0d6a018e5ffcd5f1b1a9f392884ef16ca46b0ea164e142623eb4fe25b8bb826b6cdb4294c3b898fbe843c39d7e3c
|
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2014 Maxim Andryunin, Sybis Technology
|
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,90 @@
|
|
1
|
+
# SMSCentre
|
2
|
+
|
3
|
+
Send SMS via [SMS Centre](http://smscentre.com) gateway
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
gem 'sms_centre'
|
10
|
+
|
11
|
+
And then execute:
|
12
|
+
|
13
|
+
$ bundle
|
14
|
+
|
15
|
+
Or install it yourself as:
|
16
|
+
|
17
|
+
$ gem install sms_centre
|
18
|
+
|
19
|
+
## Usage
|
20
|
+
|
21
|
+
1. Register at [http://smscentre.com](http://smscentre.com)
|
22
|
+
2. Create api object:
|
23
|
+
|
24
|
+
```ruby
|
25
|
+
api = SMSCentre::API.new('your_login', 'your_password')
|
26
|
+
```
|
27
|
+
|
28
|
+
3. Send sms:
|
29
|
+
|
30
|
+
```ruby
|
31
|
+
# Single phone
|
32
|
+
result = api.broadcast('PHONENUMBER1', 'This is message text')
|
33
|
+
|
34
|
+
# Multiple phones
|
35
|
+
result = api.broadcast(['PHONENUMBER1', ...], 'This is message text')
|
36
|
+
|
37
|
+
# Optional, you can set sender name and message id (can be used for status check)
|
38
|
+
result = api.broadcast('PHONENUMBER1', 'This is message text', params: {sender: 'SENDER NAME', id: 'MESSAGE_ID'}
|
39
|
+
|
40
|
+
# Get phone status code
|
41
|
+
result.status_for 'PHONENUMBER1'
|
42
|
+
|
43
|
+
# Or get localized status string (only russian supported yet)
|
44
|
+
result.human_status_for 'PHONENUMBER1'
|
45
|
+
```
|
46
|
+
|
47
|
+
4. Get sms status by phone number and message id:
|
48
|
+
|
49
|
+
```ruby
|
50
|
+
status = api.status('MESSAGE_ID', 'PHONENUMBER1')
|
51
|
+
|
52
|
+
# Get status code
|
53
|
+
status.status
|
54
|
+
|
55
|
+
# Get get localized status string
|
56
|
+
status.human_status
|
57
|
+
|
58
|
+
# More generic status checks
|
59
|
+
status.delivered? # Is message delivered?
|
60
|
+
status.pending? # Is message in queue yet?
|
61
|
+
status.failed? # Is message delivery failed for some reason?
|
62
|
+
```
|
63
|
+
|
64
|
+
5. Check your balance:
|
65
|
+
|
66
|
+
```
|
67
|
+
api.balance
|
68
|
+
# => '999.99'
|
69
|
+
|
70
|
+
## Configure
|
71
|
+
|
72
|
+
Paste this code in some file, load it before send sms (rails hint: initializer is the best place to do it)
|
73
|
+
|
74
|
+
```
|
75
|
+
SMSCentre.configure.do |config|
|
76
|
+
# For example, disable SSL
|
77
|
+
config.use_ssl = false
|
78
|
+
end
|
79
|
+
```
|
80
|
+
|
81
|
+
See options list in [source code](lib/sms_centre/configuration.rb)
|
82
|
+
|
83
|
+
|
84
|
+
## Contributing
|
85
|
+
|
86
|
+
1. Fork it
|
87
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
88
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
89
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
90
|
+
5. Create new Pull Request
|
data/Rakefile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require "bundler/gem_tasks"
|
data/TODO.md
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
* Find optimum value for max_phones_per_request option
|
data/lib/sms_centre.rb
ADDED
@@ -0,0 +1,106 @@
|
|
1
|
+
require 'json'
|
2
|
+
require 'logger'
|
3
|
+
require 'net/http'
|
4
|
+
require 'i18n'
|
5
|
+
|
6
|
+
require 'sms_centre/version'
|
7
|
+
|
8
|
+
I18n.load_path += Dir[File.expand_path('..', __FILE__) + '/sms_centre/locales/*.yml']
|
9
|
+
|
10
|
+
module SMSCentre
|
11
|
+
ERRORS = {
|
12
|
+
(ERROR_PARAMS = 1) => 'error.parameters',
|
13
|
+
(ERROR_AUTH = 2) => 'error.auth',
|
14
|
+
(ERROR_BALANCE = 3) => 'error.balance',
|
15
|
+
(ERROR_FLOOD = 4) => 'error.flood',
|
16
|
+
(ERROR_DATE_FORMAT = 5) => 'error.data_format',
|
17
|
+
(ERROR_FORBIDDEN_MESSAGE = 6) => 'error.forbidden_message',
|
18
|
+
(ERROR_PHONE_FORMAT = 7) => 'error.phone_format',
|
19
|
+
(ERROR_IMPOSSIBLE = 8) => 'error.impossible',
|
20
|
+
(ERROR_REPEATED_REQUEST = 9) => 'error.repeated_request',
|
21
|
+
}
|
22
|
+
|
23
|
+
MESSAGE_STATUSES = {
|
24
|
+
(MESSAGE_STATUS_PENDING = -1) => 'message_status.pending',
|
25
|
+
(MESSAGE_STATUS_OPERATOR = 0 ) => 'message_status.operator',
|
26
|
+
(MESSAGE_STATUS_DELIVERED = 1 ) => 'message_status.delivered',
|
27
|
+
(MESSAGE_STATUS_EXPIRED = 3 ) => 'message_status.expired',
|
28
|
+
(MESSAGE_STATUS_ERROR_IMPOSSIBLE = 20) => 'message_status.impossible',
|
29
|
+
(MESSAGE_STATUS_ERROR_PHONE_FORMAT = 22) => 'message_status.phone_format_error',
|
30
|
+
(MESSAGE_STATUS_ERROR_FORBIDDEN_MESSAGE = 23) => 'message_status.forbidden_message_error',
|
31
|
+
(MESSAGE_STATUS_ERROR_BALANCE = 24) => 'message_status.balance_error',
|
32
|
+
(MESSAGE_STATUS_UNAVAILABLE = 25) => 'message_status.unavailable'
|
33
|
+
}
|
34
|
+
|
35
|
+
STATUS_ERRORS = {
|
36
|
+
(STATUS_ERROR_PARAMS = 1) => 'status_error.parameters',
|
37
|
+
(STATUS_ERROR_AUTH = 2) => 'status_error.auth',
|
38
|
+
(STATUS_ERROR_NOT_FOUND = 3) => 'status_error.not_found',
|
39
|
+
(STATUS_ERROR_IP_BANNED = 4) => 'status_error.ip_banned',
|
40
|
+
(STATUS_ERROR_REPEATED_REQUEST = 9) => 'status_error.repeated_request'
|
41
|
+
}
|
42
|
+
|
43
|
+
autoload :API, 'sms_centre/api'
|
44
|
+
autoload :Configuration, 'sms_centre/configuration'
|
45
|
+
autoload :Provider, 'sms_centre/provider'
|
46
|
+
autoload :Result, 'sms_centre/result'
|
47
|
+
autoload :Status, 'sms_centre/status'
|
48
|
+
|
49
|
+
Error = Class.new(StandardError)
|
50
|
+
ConnectionError = Class.new(Error)
|
51
|
+
ServerError = Class.new(Error)
|
52
|
+
|
53
|
+
class ClientError < Error
|
54
|
+
attr_reader :error_code
|
55
|
+
|
56
|
+
def initialize(error)
|
57
|
+
if Fixnum === error
|
58
|
+
@error_code = error
|
59
|
+
super(ERRORS[error])
|
60
|
+
else
|
61
|
+
super(error)
|
62
|
+
end
|
63
|
+
end
|
64
|
+
|
65
|
+
def human_message
|
66
|
+
if @error_code
|
67
|
+
SMSCentre.human_error(@error_code)
|
68
|
+
else
|
69
|
+
message
|
70
|
+
end
|
71
|
+
end
|
72
|
+
end
|
73
|
+
|
74
|
+
class << self
|
75
|
+
attr_writer :configuration
|
76
|
+
|
77
|
+
def configuration
|
78
|
+
@configuration ||= Configuration.new
|
79
|
+
end
|
80
|
+
|
81
|
+
def reset
|
82
|
+
@configuration = Configuration.new
|
83
|
+
end
|
84
|
+
|
85
|
+
def configure
|
86
|
+
yield(configuration)
|
87
|
+
end
|
88
|
+
|
89
|
+
def logger
|
90
|
+
configuration.logger
|
91
|
+
end
|
92
|
+
|
93
|
+
def human_error(error_code)
|
94
|
+
I18n.t('sms_centre.' + ERRORS[error_code])
|
95
|
+
end
|
96
|
+
|
97
|
+
def human_message_status(message_status_code)
|
98
|
+
I18n.t('sms_centre.' + MESSAGE_STATUSES[message_status_code])
|
99
|
+
end
|
100
|
+
|
101
|
+
def human_status_error(status_error_code)
|
102
|
+
I18n.t('sms_centre.' + STATUS_ERRORS[status_error_code])
|
103
|
+
end
|
104
|
+
end
|
105
|
+
|
106
|
+
end
|
@@ -0,0 +1,81 @@
|
|
1
|
+
module SMSCentre
|
2
|
+
class API
|
3
|
+
def initialize(login, password)
|
4
|
+
@provider = Provider.new(login, password)
|
5
|
+
end
|
6
|
+
|
7
|
+
def balance
|
8
|
+
resp = @provider.request(path: '/sys/balance.php')
|
9
|
+
|
10
|
+
if resp.key?("balance")
|
11
|
+
resp["balance"]
|
12
|
+
else
|
13
|
+
raise ServerError.new("unexpected response: 'balance' key not found")
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
def broadcast(phones, message, opts = {})
|
18
|
+
opts = {path: '/sys/send.php'}.merge(opts)
|
19
|
+
phones = [phones] if phones.kind_of? String
|
20
|
+
|
21
|
+
if phones.length > SMSCentre.configuration.max_phones_per_request
|
22
|
+
raise ClientError.new("too much phone numbers per request")
|
23
|
+
end
|
24
|
+
|
25
|
+
params = {
|
26
|
+
phones: phones.join(','),
|
27
|
+
mes: message,
|
28
|
+
err: 1, # Show errors for each phone
|
29
|
+
cost: 3 # Return request cost and result balance
|
30
|
+
}
|
31
|
+
|
32
|
+
params.merge!(opts.delete(:params) || {})
|
33
|
+
|
34
|
+
resp = @provider.request(opts.merge(params: params))
|
35
|
+
|
36
|
+
if resp.key?("error_code")
|
37
|
+
global_error = case resp["error_code"]
|
38
|
+
when ERROR_IMPOSSIBLE
|
39
|
+
MESSAGE_STATUS_ERROR_IMPOSSIBLE
|
40
|
+
when ERROR_PHONE_FORMAT
|
41
|
+
MESSAGE_STATUS_ERROR_PHONE_FORMAT
|
42
|
+
when ERROR_FORBIDDEN_MESSAGE
|
43
|
+
MESSAGE_STATUS_ERROR_FORBIDDEN_MESSAGE
|
44
|
+
when ERROR_BALANCE
|
45
|
+
MESSAGE_STATUS_ERROR_BALANCE
|
46
|
+
else
|
47
|
+
raise ClientError.new(resp['error_code'])
|
48
|
+
end
|
49
|
+
|
50
|
+
errors = {}
|
51
|
+
phones.each { |p| errors[p] = global_error }
|
52
|
+
|
53
|
+
Result.new(errors, resp['id'])
|
54
|
+
else
|
55
|
+
Result.new(resp['errors'] || {}, resp['id'], cost: resp['cost'], balance: resp['balance'])
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
def status(message_id, phone, opts = {})
|
60
|
+
opts = {path: '/sys/status.php', all: 2}.merge(opts)
|
61
|
+
params = {
|
62
|
+
phone: phone,
|
63
|
+
id: message_id
|
64
|
+
}
|
65
|
+
|
66
|
+
params.merge!(opts.delete(:params) || {})
|
67
|
+
|
68
|
+
resp = @provider.request(opts.merge(params: params))
|
69
|
+
|
70
|
+
if resp.key?('error_code')
|
71
|
+
raise ClientError.new(resp['error_code'])
|
72
|
+
end
|
73
|
+
|
74
|
+
Status.new(phone, message_id, resp["status"],
|
75
|
+
err: resp["err"],
|
76
|
+
last_date: resp["last_date"],
|
77
|
+
last_timestamp: resp["last_timestamp"],
|
78
|
+
)
|
79
|
+
end
|
80
|
+
end
|
81
|
+
end
|
@@ -0,0 +1,45 @@
|
|
1
|
+
module SMSCentre
|
2
|
+
class Configuration
|
3
|
+
# @return [Boolean] use HTTPS by default.
|
4
|
+
# Defaults to false.
|
5
|
+
attr_accessor :ssl
|
6
|
+
|
7
|
+
# @return [String] SMS Centre gateway API host.
|
8
|
+
# Defaults to "smsc.ru".
|
9
|
+
attr_accessor :host
|
10
|
+
|
11
|
+
# @return [Fixnum] SMS Centre gateway API port.
|
12
|
+
# Defaults to 80 or 443, depends on 'ssl' option.
|
13
|
+
def port
|
14
|
+
@port ||= ssl ? 443 : 80
|
15
|
+
end
|
16
|
+
|
17
|
+
attr_writer :port
|
18
|
+
|
19
|
+
# @return [String] Default sender name.
|
20
|
+
# Defaults to nil.
|
21
|
+
attr_accessor :sender
|
22
|
+
|
23
|
+
# @return [Fixnum] Default timeout for single API call.
|
24
|
+
# Defaults to 0 (no timeout).
|
25
|
+
attr_accessor :timeout
|
26
|
+
|
27
|
+
# @return [Logger] Logger instance, should be compatible with ruby logger.
|
28
|
+
# Defaults to Logger.new(STDOUT).
|
29
|
+
attr_accessor :logger
|
30
|
+
|
31
|
+
# @return [Fixnum] Maximum phones count for single API call.
|
32
|
+
# Defaults to 10.
|
33
|
+
attr_accessor :max_phones_per_request
|
34
|
+
|
35
|
+
def initialize
|
36
|
+
@ssl = true
|
37
|
+
@host = "smsc.ru"
|
38
|
+
@timeout = 0
|
39
|
+
@max_phones_per_request = 10
|
40
|
+
|
41
|
+
@logger ||= Logger.new(STDOUT)
|
42
|
+
@logger.level = Logger::DEBUG
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
@@ -0,0 +1,30 @@
|
|
1
|
+
ru:
|
2
|
+
sms_centre:
|
3
|
+
error:
|
4
|
+
parameters: Ошибка в параметрах
|
5
|
+
auth: Неверный логин или пароль
|
6
|
+
balance: Недостаточно средств на счете клиента
|
7
|
+
flood: IP-адрес временно заблокирован из-за частых ошибок в запросах
|
8
|
+
data_format: Неверный формат даты
|
9
|
+
forbidden_message: Сообщение запрещено (по тексту или по имени отправителя)
|
10
|
+
phone_format: Неверный формат номера телефона
|
11
|
+
impossible: Сообщение на указанный номер не может быть доставлено
|
12
|
+
repeated_request: Отправка более одного одинакового запроса на передачу SMS-сообщения либо более пяти одинаковых запросов на получение стоимости сообщения в течение минут
|
13
|
+
|
14
|
+
message_status:
|
15
|
+
pending: Ожидает отправки
|
16
|
+
operator: Передано оператору
|
17
|
+
delivered: Доставлено
|
18
|
+
expired: Просрочено
|
19
|
+
impossible: Невозможно доставить
|
20
|
+
phone_format_error: Неверный номер
|
21
|
+
forbidden_message_error: Запрещено
|
22
|
+
balance_error: Недостаточно средств
|
23
|
+
unavailable: Недоступный номер
|
24
|
+
|
25
|
+
status_error:
|
26
|
+
parameters: Ошибка в параметрах
|
27
|
+
auth: Неверный логин или пароль
|
28
|
+
not_found: Сообщение не найдено
|
29
|
+
ip_banned: IP-адрес временно заблокирован
|
30
|
+
repeated_request: Попытка отправки более пяти запросов на получение статуса одного и того же сообщения в течение минуты
|
@@ -0,0 +1,72 @@
|
|
1
|
+
module SMSCentre
|
2
|
+
class Provider
|
3
|
+
def initialize(login, password)
|
4
|
+
@login = login
|
5
|
+
@password = password
|
6
|
+
end
|
7
|
+
|
8
|
+
# Perform API call
|
9
|
+
#
|
10
|
+
# @option opts [Fixnum] :timeout Timeout for API call
|
11
|
+
# @option opts [String] :path ('sys/send.php') Remote script path
|
12
|
+
# @option opts [String] :host SMS Centre gateway API host
|
13
|
+
# @option opts [Boolean] :ssl Use HTTPS for API call
|
14
|
+
def request(opts = {})
|
15
|
+
opts = default_opts.merge(opts)
|
16
|
+
params = default_params.merge(opts.fetch(:params, {}))
|
17
|
+
data = URI.encode_www_form(params)
|
18
|
+
|
19
|
+
resp = perform_request(opts, data)
|
20
|
+
JSON.parse(resp.body || '')
|
21
|
+
rescue Errno::ECONNREFUSED => e
|
22
|
+
raise ConnectionError.new(e.message)
|
23
|
+
rescue JSON::ParserError => e
|
24
|
+
raise ServerError.new("response json parsing failed: #{e.message}")
|
25
|
+
end
|
26
|
+
|
27
|
+
private
|
28
|
+
|
29
|
+
def default_params
|
30
|
+
params = {
|
31
|
+
login: @login, # Login
|
32
|
+
psw: @password, # Password
|
33
|
+
fmt: 3, # Use JSON format for response
|
34
|
+
charset: 'utf-8' # Message charset
|
35
|
+
}
|
36
|
+
|
37
|
+
unless SMSCentre.configuration.sender.nil?
|
38
|
+
params[:sender] = SMSCentre.sender
|
39
|
+
end
|
40
|
+
|
41
|
+
params
|
42
|
+
end
|
43
|
+
|
44
|
+
def default_opts
|
45
|
+
{
|
46
|
+
timeout: SMSCentre.configuration.timeout,
|
47
|
+
ssl: SMSCentre.configuration.ssl,
|
48
|
+
host: SMSCentre.configuration.host,
|
49
|
+
port: SMSCentre.configuration.port
|
50
|
+
}
|
51
|
+
end
|
52
|
+
|
53
|
+
def perform_request(opts, data)
|
54
|
+
Timeout.timeout(opts[:timeout]) do
|
55
|
+
uri = opts[:ssl] ? "https://" : "http://"
|
56
|
+
uri += opts[:host]
|
57
|
+
uri += ":#{opts[:port]}"
|
58
|
+
uri += opts[:path]
|
59
|
+
|
60
|
+
SMSCentre.logger.debug "call: POST #{uri}; Data: '#{data}'"
|
61
|
+
|
62
|
+
resp = Net::HTTP.start(opts[:host], opts[:port], use_ssl: opts[:ssl]) do |http|
|
63
|
+
http.post(opts[:path], data)
|
64
|
+
end
|
65
|
+
|
66
|
+
SMSCentre.logger.debug "resp: (#{resp.code}) #{resp.body.inspect}"
|
67
|
+
|
68
|
+
resp
|
69
|
+
end
|
70
|
+
end
|
71
|
+
end
|
72
|
+
end
|
@@ -0,0 +1,30 @@
|
|
1
|
+
module SMSCentre
|
2
|
+
class Result
|
3
|
+
attr_reader :message_id
|
4
|
+
attr_reader :cost
|
5
|
+
attr_reader :balance
|
6
|
+
|
7
|
+
def initialize(phones, message_id, opts = {})
|
8
|
+
@phones = phones
|
9
|
+
@message_id = message_id
|
10
|
+
@cost = opts[:cost]
|
11
|
+
@balance = opts[:balance]
|
12
|
+
end
|
13
|
+
|
14
|
+
def status_for(phone)
|
15
|
+
@phones[phone] || MESSAGE_STATUS_PENDING
|
16
|
+
end
|
17
|
+
|
18
|
+
def human_status_for(phone)
|
19
|
+
SMSCentre.human_message_status(status_for(phone))
|
20
|
+
end
|
21
|
+
|
22
|
+
def succeed?(phone)
|
23
|
+
!@phones.key?(phone)
|
24
|
+
end
|
25
|
+
|
26
|
+
def failed?(phone)
|
27
|
+
@phones.key?(phone)
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
@@ -0,0 +1,36 @@
|
|
1
|
+
module SMSCentre
|
2
|
+
class Status
|
3
|
+
attr_reader :message_id
|
4
|
+
attr_reader :phone
|
5
|
+
attr_reader :status
|
6
|
+
attr_reader :err
|
7
|
+
attr_reader :last_date
|
8
|
+
attr_reader :last_timestamp
|
9
|
+
|
10
|
+
def initialize(phone, message_id, status, opts = {})
|
11
|
+
@phone = phone
|
12
|
+
@message_id = message_id
|
13
|
+
@status = status
|
14
|
+
|
15
|
+
@err = opts[:err]
|
16
|
+
@last_date = opts[:last_date]
|
17
|
+
@last_timestamp = opts[:last_timestamp]
|
18
|
+
end
|
19
|
+
|
20
|
+
def delivered?
|
21
|
+
@status == MESSAGE_STATUS_DELIVERED
|
22
|
+
end
|
23
|
+
|
24
|
+
def pending?
|
25
|
+
[MESSAGE_STATUS_PENDING, MESSAGE_STATUS_OPERATOR].include?(@status)
|
26
|
+
end
|
27
|
+
|
28
|
+
def failed?
|
29
|
+
!(delivered? || pending?)
|
30
|
+
end
|
31
|
+
|
32
|
+
def human_status
|
33
|
+
SMSCentre.human_message_status(status)
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
data/sms_centre.gemspec
ADDED
@@ -0,0 +1,25 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'sms_centre/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "sms_centre"
|
8
|
+
spec.version = SMSCentre::VERSION
|
9
|
+
spec.authors = ["Maxim Andryunin"]
|
10
|
+
spec.email = ["maxim.andryunin@gmail.com"]
|
11
|
+
spec.description = %q{HTTP-API wrapper for smscentre.com}
|
12
|
+
spec.summary = %q{Send SMS via smscentre.com gateway}
|
13
|
+
spec.homepage = "https://github.com/sybis/sms_centre"
|
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
|
+
|
24
|
+
spec.add_dependency "i18n"
|
25
|
+
end
|
metadata
ADDED
@@ -0,0 +1,101 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: sms_centre
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Maxim Andryunin
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2014-09-30 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ~>
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.3'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ~>
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.3'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - '>='
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - '>='
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: i18n
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - '>='
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :runtime
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - '>='
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
description: HTTP-API wrapper for smscentre.com
|
56
|
+
email:
|
57
|
+
- maxim.andryunin@gmail.com
|
58
|
+
executables: []
|
59
|
+
extensions: []
|
60
|
+
extra_rdoc_files: []
|
61
|
+
files:
|
62
|
+
- .gitignore
|
63
|
+
- Gemfile
|
64
|
+
- LICENSE.txt
|
65
|
+
- README.md
|
66
|
+
- Rakefile
|
67
|
+
- TODO.md
|
68
|
+
- lib/sms_centre.rb
|
69
|
+
- lib/sms_centre/api.rb
|
70
|
+
- lib/sms_centre/configuration.rb
|
71
|
+
- lib/sms_centre/locales/ru.yml
|
72
|
+
- lib/sms_centre/provider.rb
|
73
|
+
- lib/sms_centre/result.rb
|
74
|
+
- lib/sms_centre/status.rb
|
75
|
+
- lib/sms_centre/version.rb
|
76
|
+
- sms_centre.gemspec
|
77
|
+
homepage: https://github.com/sybis/sms_centre
|
78
|
+
licenses:
|
79
|
+
- MIT
|
80
|
+
metadata: {}
|
81
|
+
post_install_message:
|
82
|
+
rdoc_options: []
|
83
|
+
require_paths:
|
84
|
+
- lib
|
85
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - '>='
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '0'
|
90
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
91
|
+
requirements:
|
92
|
+
- - '>='
|
93
|
+
- !ruby/object:Gem::Version
|
94
|
+
version: '0'
|
95
|
+
requirements: []
|
96
|
+
rubyforge_project:
|
97
|
+
rubygems_version: 2.0.3
|
98
|
+
signing_key:
|
99
|
+
specification_version: 4
|
100
|
+
summary: Send SMS via smscentre.com gateway
|
101
|
+
test_files: []
|