smstraffic 0.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/.gitignore +10 -0
- data/.travis.yml +4 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +21 -0
- data/README.md +74 -0
- data/Rakefile +1 -0
- data/bin/console +14 -0
- data/bin/setup +7 -0
- data/lib/smstraffic.rb +2 -0
- data/lib/smstraffic/sms.rb +164 -0
- data/lib/smstraffic/version.rb +3 -0
- data/smstraffic.gemspec +26 -0
- metadata +112 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: ddee4c65ffc196512fc9bc85516dc8a5553e771c
|
4
|
+
data.tar.gz: bc5693ed526ec602dd624a8d0fb417494a4b665d
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 2b8894959e656d5752a0b0f427eac76e95b9ca9479ff834317637bc80706bdb59a9faf270ca996e872be8a2ef6e1a8fd365ba26c5623410938f0751430b4aa2b
|
7
|
+
data.tar.gz: 741c6932baa618044b1c816247fa0e4e1a365f2cdf1d834009019eee0f9854c6efcb3ef5fff0cc397801e2c585b9499d39d6591f17531f29281af6bf3cbe309a
|
data/.gitignore
ADDED
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2015 Neodelf
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,74 @@
|
|
1
|
+
# Smstraffic
|
2
|
+
|
3
|
+
Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/smstraffic`. To experiment with that code, run `bin/console` for an interactive prompt.
|
4
|
+
|
5
|
+
TODO: Delete this and the text above, and describe your gem
|
6
|
+
|
7
|
+
## Installation
|
8
|
+
|
9
|
+
Add this line to your application's Gemfile:
|
10
|
+
|
11
|
+
```ruby
|
12
|
+
gem 'smstraffic'
|
13
|
+
```
|
14
|
+
|
15
|
+
And then execute:
|
16
|
+
|
17
|
+
$ bundle
|
18
|
+
|
19
|
+
Or install it yourself as:
|
20
|
+
|
21
|
+
$ gem install smstraffic
|
22
|
+
|
23
|
+
## Usage
|
24
|
+
|
25
|
+
|
26
|
+
Define settings:
|
27
|
+
|
28
|
+
Smstraffic::SMS.settings = {
|
29
|
+
login: login,
|
30
|
+
password: password,
|
31
|
+
server: server,
|
32
|
+
translit: true # default is false
|
33
|
+
}
|
34
|
+
|
35
|
+
Initialize sms:
|
36
|
+
|
37
|
+
sms = Smstraffic::SMS.new('phone','title','text') # initialize sms
|
38
|
+
sms = Smstraffic::SMS.new('phone','title','text',false) # last parameter overrides 'translit' option
|
39
|
+
|
40
|
+
Send it and get sent sms id and dispatch code:
|
41
|
+
|
42
|
+
sms.send # send sms. returns sms id or dispatch code if something went wrong
|
43
|
+
sms.id # get sms id
|
44
|
+
|
45
|
+
Get current sms status and update it:
|
46
|
+
|
47
|
+
sms.status # get sms delivery status
|
48
|
+
sms.update_status # updates sms delivery status. returns status or status check response code on error
|
49
|
+
|
50
|
+
Get any sms status:
|
51
|
+
|
52
|
+
code, status = Smstraffic::SMS.status(sms_id) # status - sms delivery status unless error or return error
|
53
|
+
|
54
|
+
Ex.:
|
55
|
+
|
56
|
+
sms = Smstraffic::SMS.new('79031111111','MyFavouriteCompany','Testing mfms gem')
|
57
|
+
sms.send # => 1032
|
58
|
+
sms.id # => 1032
|
59
|
+
|
60
|
+
## Development
|
61
|
+
|
62
|
+
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake false` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
63
|
+
|
64
|
+
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
65
|
+
|
66
|
+
## Contributing
|
67
|
+
|
68
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/smstraffic.
|
69
|
+
|
70
|
+
|
71
|
+
## License
|
72
|
+
|
73
|
+
The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
|
74
|
+
|
data/Rakefile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require "bundler/gem_tasks"
|
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "smstraffic"
|
5
|
+
|
6
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
7
|
+
# with your gem easier. You can also use a different console, if you like.
|
8
|
+
|
9
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
10
|
+
# require "pry"
|
11
|
+
# Pry.start
|
12
|
+
|
13
|
+
require "irb"
|
14
|
+
IRB.start
|
data/bin/setup
ADDED
data/lib/smstraffic.rb
ADDED
@@ -0,0 +1,164 @@
|
|
1
|
+
require 'net/http'
|
2
|
+
require 'openssl'
|
3
|
+
require 'uri'
|
4
|
+
require 'russian'
|
5
|
+
|
6
|
+
module Smstraffic
|
7
|
+
class SMS
|
8
|
+
|
9
|
+
attr_accessor :phone, :subject, :message
|
10
|
+
attr_reader :id, :status
|
11
|
+
|
12
|
+
def initialize(phone, subject, message, translit=nil)
|
13
|
+
@phone = phone.to_s.length == 10 ? "7#{phone}".to_i : phone
|
14
|
+
@subject = subject
|
15
|
+
@message = message
|
16
|
+
@status = 'not-sent'
|
17
|
+
@translit = translit.nil? ? @@translit : translit
|
18
|
+
|
19
|
+
validate!
|
20
|
+
end
|
21
|
+
|
22
|
+
def self.settings=(settings={})
|
23
|
+
@@login = settings[:login]
|
24
|
+
@@password = settings[:password]
|
25
|
+
@@server = settings[:server]
|
26
|
+
@@routeGroupID = settings[:routeGroupID]
|
27
|
+
@@port = 80
|
28
|
+
@@ssl_port = 443
|
29
|
+
@@ssl = !settings[:ssl].nil? ? settings[:ssl] : true # connect using ssl by default
|
30
|
+
@@translit = !settings[:translit].nil? ? settings[:translit] : false # use translit or not
|
31
|
+
validate_settings!
|
32
|
+
end
|
33
|
+
|
34
|
+
def self.ssl=(flag)
|
35
|
+
@@ssl = flag
|
36
|
+
end
|
37
|
+
|
38
|
+
def self.ssl
|
39
|
+
@@ssl
|
40
|
+
end
|
41
|
+
|
42
|
+
# => SMS send status codes:
|
43
|
+
# 401 - Не указан логин
|
44
|
+
# 402 - Не указан пароль
|
45
|
+
# 403 - Не указаны номера телефонов
|
46
|
+
# 404 - Несовместимые параметры запроса
|
47
|
+
# 405 - Не указан текст сообщения
|
48
|
+
# 406 - wap push сообщение слишком длинное
|
49
|
+
# 407 - Не указан ни один телефон
|
50
|
+
# 408 - Неподдерживаемый тип сообщения: "тип_сообщения"
|
51
|
+
# 409 - Не указан udh
|
52
|
+
# 410 - Автоматическая разбивка бинарных сообщений не поддерживается
|
53
|
+
# 411 - Неверный логин или пароль
|
54
|
+
# 412 - Неверный IP
|
55
|
+
# 413 - Такой группы не существует: "имя_группы"
|
56
|
+
# 414 - В группе нет ни одного телефона
|
57
|
+
# 415 - Недостаточно средств
|
58
|
+
# 416 - Неверный формат даты начала рассылки: "дата_старта_рассылки"
|
59
|
+
# 417 - Дата начала рассылки "дата_старта_рассылки" находится в прошлом
|
60
|
+
# 418 - Идентификаторы не предоставляются для отложенных сообщений
|
61
|
+
# 419 - Вам не разрешено использовать данный маршрут
|
62
|
+
# 420 - Сообщение "текст_сообщения" слишком длинное
|
63
|
+
# 421 - Имя отправителя слишком длинное
|
64
|
+
# 422 - Не указан телефон в строке "номер_строки": "строка"
|
65
|
+
# 423 - Пустое сообщение для телефона "номер_телефона"
|
66
|
+
# 424 - Сообщение "текст_сообщения" для телефона "номер_телефона" слишком длинное
|
67
|
+
# 425 - Номер телефона "номер_телефона" слишком короткий. Ни одно сообщение не было отправлено
|
68
|
+
# 426 - Номер телефона "номер_телефона" слишком длинный. Ни одно сообщение не было отправлено
|
69
|
+
# 427 - "номер_телефона": неверная длина номера телефона. Ни одно сообщение не было отправлено
|
70
|
+
# 428 - "номер_телефона": неверный формат номера телефона. Ни одно сообщение не было отправлено
|
71
|
+
# 429 - "номер_телефона": неподдерживаемый оператор. Ни одно сообщение не было отправлено
|
72
|
+
# 430 - "номер_телефона": неверный номер телефона. Ни одно сообщение не было отправлено
|
73
|
+
# 431 - Телефон +"номер_телефона" не подписан на рассылку. Ни одно сообщение не было отправлено
|
74
|
+
# 432 - Заблокированный номер телефона: "номер_телефона". Ни одно сообщение не было отправлено
|
75
|
+
# 433 - Не указан параметр sms_id
|
76
|
+
# 434 - Такого сообщения нет или оно вам не принадлежит
|
77
|
+
# 435 - Невозможно отменить сообщение "sms_id"
|
78
|
+
# 436 - Отправитель "отправитель" запрещен
|
79
|
+
# 437 - Сообщение превышает 160 символов после транслитерации "текст_сообщения"
|
80
|
+
# 438 - В сообщении найден шаблон, но не задана ни одна группа
|
81
|
+
# 439 - Вы не можете отправлять SMSсообщения через HTTP
|
82
|
+
# 440 - Параметр "phones" не задан или задан некорректно
|
83
|
+
# 441 - Неверный формат файла параметров
|
84
|
+
# 442 - Неверное число параметров
|
85
|
+
# 501 - Время окончания рассылки в прошлом
|
86
|
+
# 502 - Время начала рассылки больше времени окончания рассылки
|
87
|
+
# 1000 - Временные проблемы на сервере
|
88
|
+
|
89
|
+
def send
|
90
|
+
#return stubbed_send if (defined?(Rails) && !Rails.env.production?)
|
91
|
+
self.class.establish_connection.start do |http|
|
92
|
+
request = Net::HTTP::Get.new(send_url)
|
93
|
+
response = http.request(request)
|
94
|
+
body = response.body
|
95
|
+
hash = Hash.from_xml(Nokogiri::XML(body).to_s)['reply']
|
96
|
+
result = hash['result']
|
97
|
+
return "#{result}: code: #{hash['code']}, description: #{hash['description']}" unless result == 'OK'
|
98
|
+
@status = 'sent'
|
99
|
+
@id = hash['message_infos']['message_info']['sms_id']
|
100
|
+
end
|
101
|
+
end
|
102
|
+
|
103
|
+
# => SMS status codes:
|
104
|
+
# СТАТУС ТИП
|
105
|
+
# 'Нет статуса (blank)' - Промежуточный
|
106
|
+
# 'Acceptd' - Промежуточный
|
107
|
+
# 'Delivered' - Окончательный
|
108
|
+
# 'Non Delivered' - - Окончательный
|
109
|
+
# 'Rejected' - Окончательный
|
110
|
+
# 'Expired' - Окончательный
|
111
|
+
# 'Deleted' - Окончательный
|
112
|
+
# 'Unknown status' - Окончательный
|
113
|
+
|
114
|
+
|
115
|
+
def self.status(id)
|
116
|
+
establish_connection.start do |http|
|
117
|
+
request = Net::HTTP::Get.new(status_url id)
|
118
|
+
response = http.request(request)
|
119
|
+
body = response.body
|
120
|
+
hash = Hash.from_xml(Nokogiri::XML(body).to_s)['reply']
|
121
|
+
hash['status'] || hash['error'] #status or error
|
122
|
+
end
|
123
|
+
end
|
124
|
+
|
125
|
+
def update_status
|
126
|
+
return @status if @id.nil?
|
127
|
+
code, status = self.class.status(@id)
|
128
|
+
return code unless code == 'ok'
|
129
|
+
@status = status
|
130
|
+
end
|
131
|
+
|
132
|
+
def validate!
|
133
|
+
raise ArgumentError, "Phone should be assigned to #{self.class}." if @phone.nil?
|
134
|
+
raise ArgumentError, "Phone number should contain only numbers. Minimum length is 11. #{@phone.inspect} is given." unless "#{@phone}" =~ /^[0-9]{11}$/
|
135
|
+
raise ArgumentError, "Subject should be assigned to #{self.class}." if @subject.nil?
|
136
|
+
raise ArgumentError, "Message should be assigned to #{self.class}." if @message.nil?
|
137
|
+
end
|
138
|
+
|
139
|
+
private
|
140
|
+
|
141
|
+
def self.establish_connection
|
142
|
+
port = @@ssl ? @@ssl_port : @@port
|
143
|
+
http = Net::HTTP.new(@@server, port)
|
144
|
+
http.use_ssl = @@ssl
|
145
|
+
http
|
146
|
+
end
|
147
|
+
|
148
|
+
def self.validate_settings!
|
149
|
+
raise ArgumentError, "Login should be defined for #{self}." if @@login.nil?
|
150
|
+
raise ArgumentError, "Password should be defined for #{self}." if @@password.nil?
|
151
|
+
raise ArgumentError, "Server should be defined for #{self}." if @@server.nil?
|
152
|
+
end
|
153
|
+
|
154
|
+
def send_url
|
155
|
+
message, rus = @translit ? [Russian.translit(@message), 0] : [@message, 1]
|
156
|
+
"/smartdelivery"+"-in/multi.php?login=#{@@login}&password=#{@@password}&phones=#{@phone}&message=#{URI.encode(message)}&want_sms_ids=1&routeGroupID=#{@@routeGroupID}&rus=#{rus}"
|
157
|
+
end
|
158
|
+
|
159
|
+
def self.status_url(msg_id)
|
160
|
+
"/smartdelivery"+"-in/multi.php?login=#{@@login}&password=#{@@password}&operation=status&sms_id=#{msg_id}"
|
161
|
+
end
|
162
|
+
|
163
|
+
end
|
164
|
+
end
|
data/smstraffic.gemspec
ADDED
@@ -0,0 +1,26 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'smstraffic/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "smstraffic"
|
8
|
+
spec.version = Smstraffic::VERSION
|
9
|
+
spec.authors = ["Neodelf"]
|
10
|
+
spec.email = ["neodelf@gmail.com"]
|
11
|
+
|
12
|
+
spec.summary = %q{Send sms via SMSTraffic service.}
|
13
|
+
spec.description = %q{Send sms via SMSTraffic service.}
|
14
|
+
spec.homepage = "https://github.com/RevoTechnology/sms-traffic"
|
15
|
+
spec.license = "MIT"
|
16
|
+
|
17
|
+
spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
18
|
+
spec.bindir = "exe"
|
19
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
20
|
+
spec.require_paths = ["lib"]
|
21
|
+
|
22
|
+
spec.add_development_dependency "bundler", "~> 1.10"
|
23
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
24
|
+
spec.add_dependency 'russian'
|
25
|
+
spec.add_dependency 'nokogiri'
|
26
|
+
end
|
metadata
ADDED
@@ -0,0 +1,112 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: smstraffic
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Neodelf
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2015-12-10 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.10'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.10'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '10.0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '10.0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: russian
|
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
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: nokogiri
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ">="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
type: :runtime
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ">="
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
69
|
+
description: Send sms via SMSTraffic service.
|
70
|
+
email:
|
71
|
+
- neodelf@gmail.com
|
72
|
+
executables: []
|
73
|
+
extensions: []
|
74
|
+
extra_rdoc_files: []
|
75
|
+
files:
|
76
|
+
- ".gitignore"
|
77
|
+
- ".travis.yml"
|
78
|
+
- Gemfile
|
79
|
+
- LICENSE.txt
|
80
|
+
- README.md
|
81
|
+
- Rakefile
|
82
|
+
- bin/console
|
83
|
+
- bin/setup
|
84
|
+
- lib/smstraffic.rb
|
85
|
+
- lib/smstraffic/sms.rb
|
86
|
+
- lib/smstraffic/version.rb
|
87
|
+
- smstraffic.gemspec
|
88
|
+
homepage: https://github.com/RevoTechnology/sms-traffic
|
89
|
+
licenses:
|
90
|
+
- MIT
|
91
|
+
metadata: {}
|
92
|
+
post_install_message:
|
93
|
+
rdoc_options: []
|
94
|
+
require_paths:
|
95
|
+
- lib
|
96
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
97
|
+
requirements:
|
98
|
+
- - ">="
|
99
|
+
- !ruby/object:Gem::Version
|
100
|
+
version: '0'
|
101
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
102
|
+
requirements:
|
103
|
+
- - ">="
|
104
|
+
- !ruby/object:Gem::Version
|
105
|
+
version: '0'
|
106
|
+
requirements: []
|
107
|
+
rubyforge_project:
|
108
|
+
rubygems_version: 2.4.3
|
109
|
+
signing_key:
|
110
|
+
specification_version: 4
|
111
|
+
summary: Send sms via SMSTraffic service.
|
112
|
+
test_files: []
|