smsru 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/.gitignore +14 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +47 -0
- data/Rakefile +2 -0
- data/lib/sms_ru.rb +48 -0
- data/lib/sms_ru/config.rb +23 -0
- data/lib/sms_ru/version.rb +3 -0
- data/sms_ru.gemspec +24 -0
- metadata +95 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: eff9871e0fffdb57639c42e9fb79d7cc07954bea
|
4
|
+
data.tar.gz: 07f78b226b0a6b8a6f1e605afb1873f4611a21ed
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 17d0c69ddc0022faf03bcd15826cb1d71609e024b447342a7a0d08ee0f5774bf7ec916f8982831cf953bc2a07ec0b7300ce0c9602f9d8ad430d335cce476dc14
|
7
|
+
data.tar.gz: 2ec90de00f68533c9ae8172d4d9eda9babe1c0027d505fc2d0f0c9ccac0e9e4c6b05bbb3e3f03362a7f487c997c379eabacd6aec12894ff010b21ad4255bd00d
|
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2015 Alex
|
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,47 @@
|
|
1
|
+
# SmsRu
|
2
|
+
|
3
|
+
This gem is API for sending sms through [sms.ru](http://sms.ru) service. SmsRu allows you to connect to sms.ru api without Net::HTTP syntax sugar. Check [API](http://sms.ru/?panel=api) to list of all available queries.
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
**WARNING** There is obsolete ruby gem `sms_ru`, so name of this gem is '**smsru**'
|
8
|
+
|
9
|
+
Add this line to your application's Gemfile:
|
10
|
+
|
11
|
+
```ruby
|
12
|
+
gem 'smsru'
|
13
|
+
```
|
14
|
+
|
15
|
+
And then execute:
|
16
|
+
|
17
|
+
$ bundle
|
18
|
+
|
19
|
+
Or install it yourself as:
|
20
|
+
|
21
|
+
$ gem install smsru
|
22
|
+
|
23
|
+
## Usage
|
24
|
+
|
25
|
+
Firstly, add `sms_ru.rb` to initializers. Here you can set api_id.
|
26
|
+
|
27
|
+
``` ruby
|
28
|
+
SmsRu.setup do |config|
|
29
|
+
config.api_id = Rails.application.secrets.sms_ru_key
|
30
|
+
### you can setup default settings for every sms.ru API method you want
|
31
|
+
config.methods.sms.send.from = 'fasteria.ru'
|
32
|
+
end
|
33
|
+
```
|
34
|
+
|
35
|
+
``` ruby
|
36
|
+
SmsRu.sms.send(api_id: 'abcdef', to: '79112223344', text: 'Sample message') # => '100\n000-00000'
|
37
|
+
SmsRu.my.balance # => '100\n87.79'
|
38
|
+
# et.c.
|
39
|
+
```
|
40
|
+
|
41
|
+
## Contributing
|
42
|
+
|
43
|
+
1. Fork it ( https://github.com/asiniy/sms_ru/fork )
|
44
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
45
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
46
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
47
|
+
5. Create a new Pull Request
|
data/Rakefile
ADDED
data/lib/sms_ru.rb
ADDED
@@ -0,0 +1,48 @@
|
|
1
|
+
require 'active_support/core_ext/module/attribute_accessors'
|
2
|
+
require 'active_support/core_ext/hash/deep_merge'
|
3
|
+
require 'net/http'
|
4
|
+
|
5
|
+
require 'sms_ru/version'
|
6
|
+
require 'sms_ru/config'
|
7
|
+
|
8
|
+
module SmsRu
|
9
|
+
# Setup configuration
|
10
|
+
mattr_accessor :api_id
|
11
|
+
|
12
|
+
mattr_reader :methods
|
13
|
+
@@methods = SmsRu::Config
|
14
|
+
|
15
|
+
def self.setup
|
16
|
+
yield self
|
17
|
+
end
|
18
|
+
|
19
|
+
# Sms.ru api settings
|
20
|
+
|
21
|
+
# all possible queries is exactly 2 level deep
|
22
|
+
@@stack_method ||= nil
|
23
|
+
|
24
|
+
# we need to undefine method send because of we use it at the api
|
25
|
+
class <<self
|
26
|
+
undef_method :send
|
27
|
+
end
|
28
|
+
|
29
|
+
def self.method_missing(m, options = {})
|
30
|
+
if @@stack_method
|
31
|
+
query_options = methods.configuration.to_h[@@stack_method].to_h[m].to_h
|
32
|
+
query_options.deep_merge!(api_id: api_id)
|
33
|
+
query_options.deep_merge! options
|
34
|
+
|
35
|
+
uri = URI.parse("http://sms.ru/#{@@stack_method.to_s}/#{m.to_s}")
|
36
|
+
@@stack_method = nil
|
37
|
+
|
38
|
+
response = Net::HTTP.post_form(uri, query_options)
|
39
|
+
|
40
|
+
raise 'you have troubles with internet connection or API query is missing' unless response.header == '200'
|
41
|
+
raise "something going wrong: #{query_options}, #{response.body}" unless response.body.match(/^100/)
|
42
|
+
response.body
|
43
|
+
else
|
44
|
+
@@stack_method = m
|
45
|
+
return self
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
module SmsRu
|
2
|
+
module Config
|
3
|
+
mattr_accessor :configuration
|
4
|
+
@@configuration = {}
|
5
|
+
|
6
|
+
# Scope is used for dynamic params assignment
|
7
|
+
@@current_scope = []
|
8
|
+
|
9
|
+
def self.current_scope_to_config(args)
|
10
|
+
@@current_scope.reverse.inject(args) { |a, n| { n => a } }
|
11
|
+
end
|
12
|
+
|
13
|
+
def self.method_missing(m, *args)
|
14
|
+
@@current_scope.push m
|
15
|
+
if m.match(/=/)
|
16
|
+
@@configuration.deep_merge! current_scope_to_config(*args)
|
17
|
+
@@current_scope = []
|
18
|
+
else
|
19
|
+
return self
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
data/sms_ru.gemspec
ADDED
@@ -0,0 +1,24 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'sms_ru/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = 'smsru'
|
8
|
+
spec.version = SmsRu::VERSION
|
9
|
+
spec.authors = ['Alex Antonov']
|
10
|
+
spec.email = ['alex@fasteria.ru']
|
11
|
+
spec.summary = %q{http://sms.ru api integration for ruby}
|
12
|
+
spec.homepage = 'https://github.com/asiniy/sms_ru'
|
13
|
+
spec.license = 'MIT'
|
14
|
+
|
15
|
+
spec.files = `git ls-files`.split($/)
|
16
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
17
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
18
|
+
spec.require_paths = ['lib']
|
19
|
+
|
20
|
+
spec.add_dependency 'activesupport', '>= 4.0.0'
|
21
|
+
|
22
|
+
spec.add_development_dependency 'bundler', '~> 1.7'
|
23
|
+
spec.add_development_dependency 'rake', '~> 10.0'
|
24
|
+
end
|
metadata
ADDED
@@ -0,0 +1,95 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: smsru
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Alex Antonov
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2015-02-11 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: activesupport
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: 4.0.0
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: 4.0.0
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: bundler
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '1.7'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '1.7'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rake
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '10.0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '10.0'
|
55
|
+
description:
|
56
|
+
email:
|
57
|
+
- alex@fasteria.ru
|
58
|
+
executables: []
|
59
|
+
extensions: []
|
60
|
+
extra_rdoc_files: []
|
61
|
+
files:
|
62
|
+
- ".gitignore"
|
63
|
+
- Gemfile
|
64
|
+
- LICENSE.txt
|
65
|
+
- README.md
|
66
|
+
- Rakefile
|
67
|
+
- lib/sms_ru.rb
|
68
|
+
- lib/sms_ru/config.rb
|
69
|
+
- lib/sms_ru/version.rb
|
70
|
+
- sms_ru.gemspec
|
71
|
+
homepage: https://github.com/asiniy/sms_ru
|
72
|
+
licenses:
|
73
|
+
- MIT
|
74
|
+
metadata: {}
|
75
|
+
post_install_message:
|
76
|
+
rdoc_options: []
|
77
|
+
require_paths:
|
78
|
+
- lib
|
79
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
80
|
+
requirements:
|
81
|
+
- - ">="
|
82
|
+
- !ruby/object:Gem::Version
|
83
|
+
version: '0'
|
84
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
85
|
+
requirements:
|
86
|
+
- - ">="
|
87
|
+
- !ruby/object:Gem::Version
|
88
|
+
version: '0'
|
89
|
+
requirements: []
|
90
|
+
rubyforge_project:
|
91
|
+
rubygems_version: 2.4.5
|
92
|
+
signing_key:
|
93
|
+
specification_version: 4
|
94
|
+
summary: http://sms.ru api integration for ruby
|
95
|
+
test_files: []
|