sms_aero 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.codeclimate.yml +7 -0
- data/.gitignore +9 -0
- data/.rspec +2 -0
- data/.rubocop.yml +12 -0
- data/.travis.yml +17 -0
- data/Gemfile +12 -0
- data/LICENSE.txt +21 -0
- data/README.md +126 -0
- data/Rakefile +6 -0
- data/lib/sms_aero.rb +55 -0
- data/lib/sms_aero/models/answer.rb +8 -0
- data/lib/sms_aero/models/sms.rb +15 -0
- data/lib/sms_aero/models/tariff.rb +8 -0
- data/lib/sms_aero/operations/add_blacklist.rb +11 -0
- data/lib/sms_aero/operations/add_group.rb +11 -0
- data/lib/sms_aero/operations/add_phone.rb +17 -0
- data/lib/sms_aero/operations/check_balance.rb +11 -0
- data/lib/sms_aero/operations/check_groups.rb +12 -0
- data/lib/sms_aero/operations/check_senders.rb +15 -0
- data/lib/sms_aero/operations/check_sending.rb +11 -0
- data/lib/sms_aero/operations/check_sign.rb +15 -0
- data/lib/sms_aero/operations/check_status.rb +11 -0
- data/lib/sms_aero/operations/check_tariff.rb +12 -0
- data/lib/sms_aero/operations/delete_group.rb +11 -0
- data/lib/sms_aero/operations/delete_phone.rb +12 -0
- data/lib/sms_aero/operations/send_sms.rb +17 -0
- data/lib/sms_aero/operations/send_to_group.rb +15 -0
- data/lib/sms_aero/types/birthday.rb +20 -0
- data/lib/sms_aero/types/channel.rb +4 -0
- data/lib/sms_aero/types/digital.rb +8 -0
- data/lib/sms_aero/types/filled_string.rb +3 -0
- data/lib/sms_aero/types/future.rb +16 -0
- data/lib/sms_aero/types/phone.rb +12 -0
- data/lib/sms_aero/types/sign_status.rb +9 -0
- data/sms_aero.gemspec +23 -0
- data/spec/sms_aero/operations/add_blacklist_spec.rb +88 -0
- data/spec/sms_aero/operations/add_group_spec.rb +88 -0
- data/spec/sms_aero/operations/add_phone_spec.rb +221 -0
- data/spec/sms_aero/operations/check_balance_spec.rb +85 -0
- data/spec/sms_aero/operations/check_groups_spec.rb +72 -0
- data/spec/sms_aero/operations/check_senders_spec.rb +98 -0
- data/spec/sms_aero/operations/check_sending_spec.rb +88 -0
- data/spec/sms_aero/operations/check_sign_spec.rb +87 -0
- data/spec/sms_aero/operations/check_status_spec.rb +88 -0
- data/spec/sms_aero/operations/check_tariff_spec.rb +72 -0
- data/spec/sms_aero/operations/delete_group_spec.rb +88 -0
- data/spec/sms_aero/operations/delete_phone_spec.rb +118 -0
- data/spec/sms_aero/operations/send_sms_spec.rb +179 -0
- data/spec/sms_aero/operations/send_to_group_spec.rb +171 -0
- data/spec/sms_aero/types/birthday_spec.rb +33 -0
- data/spec/sms_aero/types/channel_spec.rb +19 -0
- data/spec/sms_aero/types/digital_spec.rb +15 -0
- data/spec/sms_aero/types/future_spec.rb +38 -0
- data/spec/sms_aero/types/phone_spec.rb +21 -0
- data/spec/sms_aero/types/sign_status_spec.rb +19 -0
- data/spec/spec_helper.rb +20 -0
- metadata +205 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: fd3453fde3013efda34bdd4eef1de330c07933fc
|
4
|
+
data.tar.gz: 62bb50f526ccfd080df2b399fdefad5aedfbdc15
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 6ac5ea53d23db0b146cc6aea6cac0cf4ebad9f0f72715d8b9b085f3bf0d42c299a7d91530fdfd51483ceb35d97700f0df2d232d3b791a01c092ac0390502b044
|
7
|
+
data.tar.gz: a9a944438acf080749852be2fbcb5dedc3e23c79098269d89b8e21d546bfd3d09c20eb1e93b2d28f1c2e176c782f03927c053bd63a5c6691d902dfd442dab477
|
data/.codeclimate.yml
ADDED
data/.gitignore
ADDED
data/.rspec
ADDED
data/.rubocop.yml
ADDED
data/.travis.yml
ADDED
@@ -0,0 +1,17 @@
|
|
1
|
+
---
|
2
|
+
sudo: false
|
3
|
+
language: ruby
|
4
|
+
cache: bundler
|
5
|
+
script:
|
6
|
+
- bundle exec rspec
|
7
|
+
- bundle exec rubocop
|
8
|
+
rvm:
|
9
|
+
- '2.3.0'
|
10
|
+
- ruby-head
|
11
|
+
- jruby-9.1.0.0
|
12
|
+
- jruby-head
|
13
|
+
before_install: gem install bundler -v 1.12.5
|
14
|
+
matrix:
|
15
|
+
allow_failures:
|
16
|
+
- rvm: ruby-head
|
17
|
+
- rvm: jruby-head
|
data/Gemfile
ADDED
@@ -0,0 +1,12 @@
|
|
1
|
+
source "https://rubygems.org"
|
2
|
+
|
3
|
+
# Specify your gem's dependencies in sms_aero.gemspec
|
4
|
+
gemspec
|
5
|
+
|
6
|
+
group :development, :test do
|
7
|
+
gem "pry", platform: :mri
|
8
|
+
gem "pry-byebug", platform: :mri
|
9
|
+
end
|
10
|
+
|
11
|
+
gem "evil-client", github: "evilmartians/evil-client", branch: "master"
|
12
|
+
gem "dry-initializer", github: "dry-rb/dry-initializer", branch: "master"
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2016 Andrew Kozin (aka nepalez)
|
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,126 @@
|
|
1
|
+
# SmsAero
|
2
|
+
|
3
|
+
[![Gem Version][gem-badger]][gem]
|
4
|
+
[![Build Status][travis-badger]][travis]
|
5
|
+
[![Dependency Status][gemnasium-badger]][gemnasium]
|
6
|
+
[![Code Climate][codeclimate-badger]][codeclimate]
|
7
|
+
|
8
|
+
HTTP(s) client to [SMS Aero service API][sms-aero].
|
9
|
+
|
10
|
+
[sms-aero]: https://smsaero.ru/api/description/
|
11
|
+
[codeclimate-badger]: https://img.shields.io/codeclimate/github/nepalez/sms_aero.svg?style=flat
|
12
|
+
[codeclimate]: https://codeclimate.com/github/nepalez/sms_aero
|
13
|
+
[gem-badger]: https://img.shields.io/gem/v/sms_aero.svg?style=flat
|
14
|
+
[gem]: https://rubygems.org/gems/sms_aero
|
15
|
+
[gemnasium-badger]: https://img.shields.io/gemnasium/nepalez/sms_aero.svg?style=flat
|
16
|
+
[gemnasium]: https://gemnasium.com/nepalez/sms_aero
|
17
|
+
[travis-badger]: https://img.shields.io/travis/nepalez/sms_aero/master.svg?style=flat
|
18
|
+
[travis]: https://travis-ci.org/nepalez/sms_aero
|
19
|
+
|
20
|
+
## Synopsis
|
21
|
+
|
22
|
+
See [operation specs][specs] for more verbose examples.
|
23
|
+
|
24
|
+
[specs]: https://github.com/nepalez/sms_aero/tree/master/spec/sms_aero/operations
|
25
|
+
|
26
|
+
Initialize a client with user and password:
|
27
|
+
|
28
|
+
```ruby
|
29
|
+
client = SmsAero.new user: "joe", password: "foobar"
|
30
|
+
```
|
31
|
+
|
32
|
+
Then send requests:
|
33
|
+
|
34
|
+
```ruby
|
35
|
+
answer = client.send_sms text: "Hello!",
|
36
|
+
to: "+7 (909) 382-84-45",
|
37
|
+
date: "2100/01/12", # Date, Time, DateTime are accepted as well
|
38
|
+
type: 3 # see API docs for details
|
39
|
+
|
40
|
+
answer.result # => "accepted"
|
41
|
+
answer.id # => "38293"
|
42
|
+
```
|
43
|
+
|
44
|
+
```ruby
|
45
|
+
answer = client.check_status id: "38293"
|
46
|
+
answer.result # => "pending"
|
47
|
+
```
|
48
|
+
|
49
|
+
```ruby
|
50
|
+
answer = client.send_to_group text: "Hello!",
|
51
|
+
group: "customers",
|
52
|
+
date: "2100/01/12",
|
53
|
+
type: 1
|
54
|
+
|
55
|
+
answer.result # => "accepted"
|
56
|
+
answer.id # => "894924"
|
57
|
+
```
|
58
|
+
|
59
|
+
```ruby
|
60
|
+
answer = client.check_sending id: "894924"
|
61
|
+
answer.result # => "pending"
|
62
|
+
```
|
63
|
+
|
64
|
+
```ruby
|
65
|
+
answer = client.add_blacklist phone: "+7 (999) 123-45-67"
|
66
|
+
answer.result # => "accepted"
|
67
|
+
```
|
68
|
+
|
69
|
+
```ruby
|
70
|
+
answer = client.add_group group: "baz"
|
71
|
+
answer.result # => "accepted"
|
72
|
+
```
|
73
|
+
|
74
|
+
```ruby
|
75
|
+
answer = client.add_phone phone: "+7 (999) 123-45-67",
|
76
|
+
group: "customers",
|
77
|
+
fname: "John",
|
78
|
+
lname: "Paul",
|
79
|
+
lname: "Doe",
|
80
|
+
bday: "1998/08/12",
|
81
|
+
param: "VIP"
|
82
|
+
|
83
|
+
answer.result # => "accepted"
|
84
|
+
```
|
85
|
+
|
86
|
+
```ruby
|
87
|
+
answer = client.check_balance
|
88
|
+
answer.result # => "accepted"
|
89
|
+
answer.balance # => 1973.2
|
90
|
+
```
|
91
|
+
|
92
|
+
```ruby
|
93
|
+
answer = client.check_groups
|
94
|
+
answer.result # => "accepted"
|
95
|
+
answer.channels # => ["customers", "employee"]
|
96
|
+
```
|
97
|
+
|
98
|
+
```ruby
|
99
|
+
answer = client.check_senders sign: "qux"
|
100
|
+
answer.result # => "accepted"
|
101
|
+
answer.result # => ["peter", "paul"]
|
102
|
+
```
|
103
|
+
|
104
|
+
```ruby
|
105
|
+
answer = client.check_sign sign: "qux"
|
106
|
+
answer.result # => "accepted"
|
107
|
+
answer.data # => ["approved"]
|
108
|
+
```
|
109
|
+
|
110
|
+
```ruby
|
111
|
+
answer = client.check_tariff
|
112
|
+
answer.result # => "accepted"
|
113
|
+
answer.tariff # => { direct: 10.3, digital: 3.89 }
|
114
|
+
```
|
115
|
+
|
116
|
+
```ruby
|
117
|
+
answer = client.delete_group group: "employee"
|
118
|
+
answer.result # => "accepted"
|
119
|
+
```
|
120
|
+
|
121
|
+
```ruby
|
122
|
+
answer = client.delete_phone phone: "+7 (999) 123-4567",
|
123
|
+
group: "customers"
|
124
|
+
|
125
|
+
answer.result # => "accepted"
|
126
|
+
```
|
data/Rakefile
ADDED
data/lib/sms_aero.rb
ADDED
@@ -0,0 +1,55 @@
|
|
1
|
+
require "evil/client"
|
2
|
+
require "dry-types"
|
3
|
+
|
4
|
+
# HTTP(s) client to the "SMS Aero" online service
|
5
|
+
class SmsAero
|
6
|
+
extend Evil::Client::DSL
|
7
|
+
|
8
|
+
# Collection of dry-types with gem-specific additions
|
9
|
+
Types = Module.new { |types| types.include Dry::Types.module }
|
10
|
+
|
11
|
+
# Definitions for types, models, and API operations
|
12
|
+
%w(types models operations).each do |folder|
|
13
|
+
path = File.expand_path("lib/sms_aero/#{folder}/*.rb")
|
14
|
+
Dir[path].each { |file| require(file) }
|
15
|
+
end
|
16
|
+
|
17
|
+
settings do
|
18
|
+
option :user, Types::FilledString
|
19
|
+
option :password, Types::FilledString
|
20
|
+
option :use_ssl, Types::Form::Bool, default: proc { true }
|
21
|
+
option :use_post, Types::Form::Bool, default: proc { true }
|
22
|
+
end
|
23
|
+
|
24
|
+
base_url do |settings|
|
25
|
+
"http#{"s" if settings.use_ssl}://gate.smsaero.ru/"
|
26
|
+
end
|
27
|
+
|
28
|
+
operation do |settings|
|
29
|
+
documentation "https://smsaero.ru/api/description/"
|
30
|
+
|
31
|
+
http_method(settings.use_post ? :post : :get)
|
32
|
+
|
33
|
+
security do |user: nil, password: nil, **|
|
34
|
+
key_auth :user, user || settings.user, using: :query
|
35
|
+
key_auth :password, password || settings.password, using: :query
|
36
|
+
key_auth :answer, "json", using: :query
|
37
|
+
end
|
38
|
+
|
39
|
+
responses format: :json do
|
40
|
+
response :success, 200, model: Answer
|
41
|
+
response :failure, 200, model: Answer
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
private
|
46
|
+
|
47
|
+
def method_missing(name, *args)
|
48
|
+
op = operations[name.to_sym]
|
49
|
+
op ? op.call(*args) : super
|
50
|
+
end
|
51
|
+
|
52
|
+
def respond_to_missing?(name, *)
|
53
|
+
operations.key? name.to_sym
|
54
|
+
end
|
55
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
# Describes an SMS that can be send to either a phone or a group
|
2
|
+
class SmsAero
|
3
|
+
class Sms < Evil::Client::Model
|
4
|
+
attribute :text, Types::FilledString
|
5
|
+
attribute :date, Types::Future, optional: true
|
6
|
+
attribute :digital, Types::Digital, optional: true
|
7
|
+
attribute :type, Types::Channel, default: -> (*) do
|
8
|
+
case digital
|
9
|
+
when Dry::Initializer::UNDEFINED
|
10
|
+
2
|
11
|
+
else Dry::Initializer::UNDEFINED
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
class SmsAero
|
2
|
+
operation :add_phone do
|
3
|
+
documentation "https://smsaero.ru/api/description/#contacts"
|
4
|
+
|
5
|
+
path { "addphone" }
|
6
|
+
|
7
|
+
query do
|
8
|
+
attribute :phone, Types::Phone
|
9
|
+
attribute :group, Types::FilledString, optional: true
|
10
|
+
attribute :lname, Types::FilledString, optional: true
|
11
|
+
attribute :fname, Types::FilledString, optional: true
|
12
|
+
attribute :sname, Types::FilledString, optional: true
|
13
|
+
attribute :param, Types::FilledString, optional: true
|
14
|
+
attribute :bday, Types::Birthday, optional: true
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
@@ -0,0 +1,12 @@
|
|
1
|
+
class SmsAero
|
2
|
+
operation :check_groups do
|
3
|
+
documentation "https://smsaero.ru/api/description/#groups"
|
4
|
+
|
5
|
+
path { "checkgroup" }
|
6
|
+
|
7
|
+
response :success, 200, format: :json do
|
8
|
+
attribute :result, Types::FilledString
|
9
|
+
attribute :reason, Types::Hash, as: :channels
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
class SmsAero
|
2
|
+
operation :check_senders do
|
3
|
+
documentation "https://smsaero.ru/api/description/#signs"
|
4
|
+
|
5
|
+
path { "senders" }
|
6
|
+
|
7
|
+
query do
|
8
|
+
attribute :sign, Types::FilledString
|
9
|
+
end
|
10
|
+
|
11
|
+
response :success, 200, format: :json, model: Answer do
|
12
|
+
attribute :data, Types::Array.member(Types::FilledString)
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
class SmsAero
|
2
|
+
operation :check_sign do
|
3
|
+
documentation "https://smsaero.ru/api/description/#signs"
|
4
|
+
|
5
|
+
path { "sign" }
|
6
|
+
|
7
|
+
query do
|
8
|
+
attribute :sign, Types::FilledString
|
9
|
+
end
|
10
|
+
|
11
|
+
response :success, 200, format: :json do
|
12
|
+
attribute :data, Types::Array.member(Types::SignStatus), as: :statuses
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|