smsforall 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +18 -0
- data/.rspec +2 -0
- data/Gemfile +3 -0
- data/LICENSE +22 -0
- data/README.md +41 -0
- data/Rakefile +7 -0
- data/bin/smsforall +91 -0
- data/lib/smsforall/version.rb +4 -0
- data/lib/smsforall.rb +56 -0
- data/smsforall.gemspec +21 -0
- data/spec/api_spec.rb +9 -0
- data/spec/api_spec.rb~ +5 -0
- data/spec/spec_helper.rb +5 -0
- metadata +90 -0
data/.gitignore
ADDED
data/.rspec
ADDED
data/Gemfile
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2012 drakmail
|
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,41 @@
|
|
1
|
+
# Smsforall
|
2
|
+
|
3
|
+
Client for smsforall.ru site API (http://www.smsforall.ru/doc/api/)
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
gem 'smsforall'
|
10
|
+
|
11
|
+
And then execute:
|
12
|
+
|
13
|
+
$ bundle
|
14
|
+
|
15
|
+
Or install it yourself as:
|
16
|
+
|
17
|
+
$ gem install smsforall
|
18
|
+
|
19
|
+
## Usage
|
20
|
+
|
21
|
+
Usage is pretty simple:
|
22
|
+
|
23
|
+
sms = Smsforall::Sms.new("test", "test", :test) # for test
|
24
|
+
# for production:
|
25
|
+
# sms = Smsforall::Sms.new("login", "password")
|
26
|
+
balance = sms.get_balance()
|
27
|
+
message = sms.send_message("sender", "sms text", "79251233232")
|
28
|
+
status = sms.get_status(message)
|
29
|
+
puts "#{balance}, #{message}, #{status}"
|
30
|
+
|
31
|
+
## Command-line client
|
32
|
+
|
33
|
+
smsforall-gem also provides command line utility `smsforall`. You may see usage instructions by executing `smsforall -h`.
|
34
|
+
|
35
|
+
## Contributing
|
36
|
+
|
37
|
+
1. Fork it
|
38
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
39
|
+
3. Commit your changes (`git commit -am 'Added some feature'`)
|
40
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
41
|
+
5. Create new Pull Request
|
data/Rakefile
ADDED
data/bin/smsforall
ADDED
@@ -0,0 +1,91 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require 'smsforall'
|
4
|
+
require 'optparse'
|
5
|
+
|
6
|
+
# Parameters parsing
|
7
|
+
options = {}
|
8
|
+
|
9
|
+
optparse = OptionParser.new do|opts|
|
10
|
+
opts.banner = "Usage: smsforall (-l login -p password|--test) COMMAND [options] ..."
|
11
|
+
|
12
|
+
opts.separator ""
|
13
|
+
opts.separator "Commands"
|
14
|
+
opts.separator " balance : get balance"
|
15
|
+
opts.separator " send SENDER NUMBER TEXT : send SMS with TEXT to NUMBER"
|
16
|
+
opts.separator " status TRANSACTION : get status of transaction"
|
17
|
+
opts.separator ""
|
18
|
+
opts.separator "Options"
|
19
|
+
|
20
|
+
# Define the options, and what they do
|
21
|
+
options[:login] = nil
|
22
|
+
opts.on( '-l', '--login LOGIN', 'Login' ) do|login|
|
23
|
+
options[:login] = login
|
24
|
+
end
|
25
|
+
|
26
|
+
options[:password] = nil
|
27
|
+
opts.on( '-p', '--password PASSWORD', 'Password' ) do|password|
|
28
|
+
options[:password] = password
|
29
|
+
end
|
30
|
+
|
31
|
+
options[:test] = :production
|
32
|
+
opts.on( '-t', '--test', 'Enable test mode' ) do
|
33
|
+
options[:test] = :test
|
34
|
+
end
|
35
|
+
|
36
|
+
opts.on( '-h', '--help', 'Display this screen' ) do
|
37
|
+
puts opts
|
38
|
+
exit
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
optparse.parse!
|
43
|
+
|
44
|
+
if options[:test] == :test
|
45
|
+
puts "[WARNING]: test mode enabled!"
|
46
|
+
options[:login] = "test"
|
47
|
+
options[:password] = "test"
|
48
|
+
end
|
49
|
+
|
50
|
+
if not (options[:login] && options[:password])
|
51
|
+
puts "[ERROR]: you must provide login and password!"
|
52
|
+
exit
|
53
|
+
end
|
54
|
+
|
55
|
+
if not %w[balance send status].include?(ARGV[0])
|
56
|
+
puts "[ERROR]: command not defined!"
|
57
|
+
exit
|
58
|
+
end
|
59
|
+
|
60
|
+
# actions
|
61
|
+
def get_balance(login, password, test)
|
62
|
+
sms = Smsforall::Sms.new(login,password, test)
|
63
|
+
puts "[INFO]: getting balance for #{login}"
|
64
|
+
balance = sms.get_balance()
|
65
|
+
puts "#{balance}"
|
66
|
+
end
|
67
|
+
|
68
|
+
def send_sms(login, password, test, sender, number, text)
|
69
|
+
if not (sender && number && text)
|
70
|
+
puts "[ERROR]: wrong number of parameters!"
|
71
|
+
exit
|
72
|
+
end
|
73
|
+
puts "[INFO]: sending SMS to #{number}"
|
74
|
+
sms = Smsforall::Sms.new(login,password, test)
|
75
|
+
transaction = sms.send_message(sender, text, number)
|
76
|
+
puts "#{transaction}"
|
77
|
+
end
|
78
|
+
|
79
|
+
def get_status(login, password, test, transaction)
|
80
|
+
puts "[INFO]: getting status"
|
81
|
+
sms = Smsforall::Sms.new(login,password, test)
|
82
|
+
status = sms.get_status(transaction)["status"]
|
83
|
+
puts "#{status}"
|
84
|
+
end
|
85
|
+
|
86
|
+
# route command
|
87
|
+
action = case ARGV[0]
|
88
|
+
when "balance" then get_balance(options[:login], options[:password], options[:test])
|
89
|
+
when "send" then send_sms(options[:login], options[:password], options[:test], ARGV[1], ARGV[2], ARGV[3])
|
90
|
+
when "status" then get_status(options[:login], options[:password], options[:test], ARGV[1])
|
91
|
+
end
|
data/lib/smsforall.rb
ADDED
@@ -0,0 +1,56 @@
|
|
1
|
+
require "smsforall/version"
|
2
|
+
require 'net/http'
|
3
|
+
require 'cgi'
|
4
|
+
require 'digest'
|
5
|
+
require 'json'
|
6
|
+
|
7
|
+
# Main module for Smsforall API class
|
8
|
+
module Smsforall
|
9
|
+
# Class for interaction with smsforall.ru API
|
10
|
+
class Sms
|
11
|
+
attr_reader :username, :password, :api
|
12
|
+
|
13
|
+
# Initialize Sms-API class. For testing purporoses set mode to :test
|
14
|
+
def initialize(username, password, mode=:production)
|
15
|
+
@username = username
|
16
|
+
@password = Digest::MD5.hexdigest(password)
|
17
|
+
modes = {:production => "/api/", :test => "/testapi/"}
|
18
|
+
@api = modes[mode]
|
19
|
+
end
|
20
|
+
|
21
|
+
# Return user balance
|
22
|
+
def get_balance()
|
23
|
+
do_request("balance", {})["balance"]
|
24
|
+
end
|
25
|
+
|
26
|
+
# Send message
|
27
|
+
def send_message(sender,text,msisdn)
|
28
|
+
do_request("send", { :msisdn => msisdn, :sender => sender, :text => text })["transactionid"]
|
29
|
+
end
|
30
|
+
|
31
|
+
# Get status of transaction
|
32
|
+
def get_status(transactionid)
|
33
|
+
do_request("status", { :transactionid => transactionid })
|
34
|
+
end
|
35
|
+
|
36
|
+
private
|
37
|
+
# Simple HTTP GET request wrapper
|
38
|
+
def http_get(domain,path,params)
|
39
|
+
return Net::HTTP.get(domain, "#{path}?".concat(params.collect { |k,v| "#{k}=#{CGI::escape(v.to_s)}" }.join('&'))) if not params.nil?
|
40
|
+
return Net::HTTP.get(domain, path)
|
41
|
+
end
|
42
|
+
|
43
|
+
# Convert hash to inner signature format
|
44
|
+
def to_signature(parameters)
|
45
|
+
parameters.map{|k,v| "#{v}"}.join('')
|
46
|
+
end
|
47
|
+
|
48
|
+
# Send request to smsforall
|
49
|
+
def do_request(action,parameters)
|
50
|
+
request_parameters = { :action => action, :login => @username}.merge(parameters)
|
51
|
+
signature = Digest::MD5.hexdigest( to_signature( request_parameters.merge({:password => @password}) ) )
|
52
|
+
request_parameters["signature"] = signature
|
53
|
+
result = JSON.parse(http_get("www.smsforall.ru",@api,request_parameters.merge(parameters) ))
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
data/smsforall.gemspec
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
require File.expand_path('../lib/smsforall/version', __FILE__)
|
3
|
+
|
4
|
+
Gem::Specification.new do |gem|
|
5
|
+
gem.authors = ["drakmail"]
|
6
|
+
gem.email = ["drakmail@delta.pm"]
|
7
|
+
gem.description = %q{Interaction with smsforall.ru API}
|
8
|
+
gem.summary = %q{Sending SMS with smsforall.ru API}
|
9
|
+
gem.homepage = "https://github.com/drakmail/smsforall-gem"
|
10
|
+
|
11
|
+
gem.files = `git ls-files`.split($\)
|
12
|
+
gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
|
13
|
+
gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
|
14
|
+
gem.name = "smsforall"
|
15
|
+
gem.require_paths = ["lib"]
|
16
|
+
gem.version = Smsforall::VERSION
|
17
|
+
|
18
|
+
gem.add_dependency 'json'
|
19
|
+
|
20
|
+
gem.add_development_dependency 'rspec'
|
21
|
+
end
|
data/spec/api_spec.rb
ADDED
@@ -0,0 +1,9 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Smsforall do
|
4
|
+
sms = Smsforall::Sms.new("test","test", :test)
|
5
|
+
balance = sms.get_balance()
|
6
|
+
message = sms.send_message("sender", "sms text", "79251233232")
|
7
|
+
status = sms.get_status(message)
|
8
|
+
puts "#{balance}, #{message}, #{status}"
|
9
|
+
end
|
data/spec/api_spec.rb~
ADDED
data/spec/spec_helper.rb
ADDED
metadata
ADDED
@@ -0,0 +1,90 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: smsforall
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
prerelease:
|
5
|
+
version: 0.0.2
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- drakmail
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
|
13
|
+
date: 2012-08-30 00:00:00 Z
|
14
|
+
dependencies:
|
15
|
+
- !ruby/object:Gem::Dependency
|
16
|
+
name: json
|
17
|
+
prerelease: false
|
18
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
19
|
+
none: false
|
20
|
+
requirements:
|
21
|
+
- - ">="
|
22
|
+
- !ruby/object:Gem::Version
|
23
|
+
version: "0"
|
24
|
+
type: :runtime
|
25
|
+
version_requirements: *id001
|
26
|
+
- !ruby/object:Gem::Dependency
|
27
|
+
name: rspec
|
28
|
+
prerelease: false
|
29
|
+
requirement: &id002 !ruby/object:Gem::Requirement
|
30
|
+
none: false
|
31
|
+
requirements:
|
32
|
+
- - ">="
|
33
|
+
- !ruby/object:Gem::Version
|
34
|
+
version: "0"
|
35
|
+
type: :development
|
36
|
+
version_requirements: *id002
|
37
|
+
description: Interaction with smsforall.ru API
|
38
|
+
email:
|
39
|
+
- drakmail@delta.pm
|
40
|
+
executables:
|
41
|
+
- smsforall
|
42
|
+
extensions: []
|
43
|
+
|
44
|
+
extra_rdoc_files: []
|
45
|
+
|
46
|
+
files:
|
47
|
+
- .gitignore
|
48
|
+
- .rspec
|
49
|
+
- Gemfile
|
50
|
+
- LICENSE
|
51
|
+
- README.md
|
52
|
+
- Rakefile
|
53
|
+
- bin/smsforall
|
54
|
+
- lib/smsforall.rb
|
55
|
+
- lib/smsforall/version.rb
|
56
|
+
- smsforall.gemspec
|
57
|
+
- spec/api_spec.rb
|
58
|
+
- spec/api_spec.rb~
|
59
|
+
- spec/spec_helper.rb
|
60
|
+
homepage: https://github.com/drakmail/smsforall-gem
|
61
|
+
licenses: []
|
62
|
+
|
63
|
+
post_install_message:
|
64
|
+
rdoc_options: []
|
65
|
+
|
66
|
+
require_paths:
|
67
|
+
- lib
|
68
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
69
|
+
none: false
|
70
|
+
requirements:
|
71
|
+
- - ">="
|
72
|
+
- !ruby/object:Gem::Version
|
73
|
+
version: "0"
|
74
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
75
|
+
none: false
|
76
|
+
requirements:
|
77
|
+
- - ">="
|
78
|
+
- !ruby/object:Gem::Version
|
79
|
+
version: "0"
|
80
|
+
requirements: []
|
81
|
+
|
82
|
+
rubyforge_project:
|
83
|
+
rubygems_version: 1.8.24
|
84
|
+
signing_key:
|
85
|
+
specification_version: 3
|
86
|
+
summary: Sending SMS with smsforall.ru API
|
87
|
+
test_files:
|
88
|
+
- spec/api_spec.rb
|
89
|
+
- spec/api_spec.rb~
|
90
|
+
- spec/spec_helper.rb
|