smslane 0.0.3
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +17 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +67 -0
- data/Rakefile +10 -0
- data/lib/smslane.rb +6 -0
- data/lib/smslane/client.rb +72 -0
- data/lib/smslane/version.rb +3 -0
- data/smslane.gemspec +27 -0
- data/temp.rb +70 -0
- metadata +113 -0
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2013 Steve Robinson
|
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,67 @@
|
|
1
|
+
# Smslane
|
2
|
+
|
3
|
+
A simple wrapper gem for the smslane.com HTTP API for sending Bulk SMS in India.
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
gem 'smslane'
|
10
|
+
|
11
|
+
And then execute:
|
12
|
+
|
13
|
+
$ bundle
|
14
|
+
|
15
|
+
Or install it yourself as:
|
16
|
+
|
17
|
+
$ gem install smslane
|
18
|
+
|
19
|
+
## Usage
|
20
|
+
|
21
|
+
Create an instance of `Smslane::Client` and pass your smslane.com `username` and `password` as arguments like below:
|
22
|
+
|
23
|
+
client = Smslane::Client.new('username','password')
|
24
|
+
|
25
|
+
Now using this client you can check your credit balance, send SMS and check delivery reports.
|
26
|
+
|
27
|
+
### Checking Credit Balance
|
28
|
+
|
29
|
+
To check your balance credits simple call the `check_balance` method on the client:
|
30
|
+
|
31
|
+
client.check_balance
|
32
|
+
# => {:result => 'Success', :response => '2000'}
|
33
|
+
# or
|
34
|
+
# => {:result => 'Failure', :response => 'Invalid Login'}
|
35
|
+
# or
|
36
|
+
# => {:result => 'Failure', :response => 'Unauthorized Access'}
|
37
|
+
# etc
|
38
|
+
|
39
|
+
### Sending SMS
|
40
|
+
|
41
|
+
SMS is sent using the client through the `send_sms` method. This method requires three arguments:
|
42
|
+
* An array of recipient numbers
|
43
|
+
* The message to be sent
|
44
|
+
* A boolean indicating whether or not to send the SMS as a flash message
|
45
|
+
|
46
|
+
Numbers must be of the format `919841254836`.Prefixing with `91` is crucial. But there are mechanisms in the gem that will take care of some malformed numbers.
|
47
|
+
Recipient numbers are split into groups of 90 numbers and are sent seprately to comply with smslane.com's limits. Malformed numbers will cause the entire group in which they are to fail. So it is crucial that numbers are of the specified format.
|
48
|
+
|
49
|
+
The response of this call is an array of hashes. Each hash contains the recipient number and the `message_id` returned by smslane.com. This `message_id` is used to check delivery reports.
|
50
|
+
|
51
|
+
client.send_sms ['919234567888','919999999999'], 'Testing :)', false
|
52
|
+
#=> [{:number => '919234567888', :message_id => '677a468d46f342e66e69ddbe5a963d7d'},
|
53
|
+
{:number => '919999999999', :message_id => '4c52312229df5fbc82cd07ea29ca4d91'}]
|
54
|
+
|
55
|
+
If a number is not present in this response list it indicates that the number is invalid.
|
56
|
+
|
57
|
+
### Delivery Report
|
58
|
+
|
59
|
+
To Do.
|
60
|
+
|
61
|
+
## Contributing
|
62
|
+
|
63
|
+
1. Fork it
|
64
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
65
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
66
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
67
|
+
5. Create new Pull Request
|
data/Rakefile
ADDED
data/lib/smslane.rb
ADDED
@@ -0,0 +1,72 @@
|
|
1
|
+
|
2
|
+
|
3
|
+
module Smslane
|
4
|
+
|
5
|
+
class Client
|
6
|
+
include HTTParty
|
7
|
+
#include WebMock::API
|
8
|
+
|
9
|
+
base_uri 'http://smslane.com'
|
10
|
+
|
11
|
+
#Webmock stubs for testing
|
12
|
+
|
13
|
+
# stub_request(:get, "http://smslane.com/vendorsms/CheckBalance.aspx?password=karimbenzema&user=steverob").to_return(:body => "Success#20000", :status => 200, :headers => { 'Content-Length' => 13 })
|
14
|
+
# stub_request(:get, /http:\/\/smslane\.com\/vendorsms\/pushsms\.aspx?/).to_return(:body => lambda { |request|
|
15
|
+
# nums = CGI::parse(request.uri.query)['msisdn'][0].split(',')
|
16
|
+
# response = ''
|
17
|
+
# nums.each do |num|
|
18
|
+
# if !(/^(\+91|91)[789][0-9]{9}$/.match(num).nil?)
|
19
|
+
# response += 'The Message Id : ' + num + '-' + SecureRandom.hex + '<br />'
|
20
|
+
# else
|
21
|
+
# response = 'Failed#Invalid Mobile Numbers'
|
22
|
+
# break
|
23
|
+
# end
|
24
|
+
# end
|
25
|
+
# response
|
26
|
+
# })
|
27
|
+
|
28
|
+
|
29
|
+
def initialize(username,password)
|
30
|
+
@auth = {user: username, password: password}
|
31
|
+
end
|
32
|
+
|
33
|
+
def check_balance
|
34
|
+
options = {:query => @auth}
|
35
|
+
response = self.class.get '/vendorsms/CheckBalance.aspx?',options
|
36
|
+
responses = response.split('#')
|
37
|
+
{:result=>responses[0],:response=>responses[1]}
|
38
|
+
end
|
39
|
+
|
40
|
+
def send options
|
41
|
+
self.class.get '/vendorsms/pushsms.aspx?',options
|
42
|
+
end
|
43
|
+
|
44
|
+
def send_sms recipients, message, flash
|
45
|
+
flash = flash ? 1 : 0
|
46
|
+
responses = []
|
47
|
+
recipients = recipients.each_slice(90).to_a
|
48
|
+
recipients.each do |recipient_list|
|
49
|
+
recipient_list.each_with_index do |number,i|
|
50
|
+
recipient_list[i] = '91'+number[-10..-1]
|
51
|
+
if /^(\+91|91)[789][0-9]{9}$/.match(recipient_list[i]).nil?
|
52
|
+
recipient_list.delete_at(i)
|
53
|
+
end
|
54
|
+
end
|
55
|
+
options = {:query => @auth.merge({:msisdn=>recipient_list.join(','), :sid=>'WebSMS', :fl => flash, :msg => message})}
|
56
|
+
responses << send(options).parsed_response
|
57
|
+
end
|
58
|
+
|
59
|
+
responses.delete('Failed#Invalid Mobile Numbers')
|
60
|
+
responses = responses.join().split('<br />')
|
61
|
+
result = []
|
62
|
+
responses.each do |response|
|
63
|
+
res = response[-45..-1].split('-')
|
64
|
+
result << {:number => res[0], :message_id=>res[1]}
|
65
|
+
end
|
66
|
+
result
|
67
|
+
end
|
68
|
+
|
69
|
+
end
|
70
|
+
|
71
|
+
|
72
|
+
end
|
data/smslane.gemspec
ADDED
@@ -0,0 +1,27 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'smslane/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "smslane"
|
8
|
+
spec.version = Smslane::VERSION
|
9
|
+
spec.authors = ["Steve Robinson"]
|
10
|
+
spec.email = ["steve.rob@me.com"]
|
11
|
+
spec.description = %q{Wrapper gem for the Smslane.com HTTP API}
|
12
|
+
spec.summary = %q{A simple to use gem that enables developers to integrate Smslane.com's HTTP API with their applications and access the Bulk SMS service. Balance Check, Multiple recipient and delivery report features are all supported.}
|
13
|
+
spec.homepage = "https://github.com/steverob/smslane"
|
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_dependency "httparty"
|
22
|
+
|
23
|
+
spec.add_development_dependency 'webmock'
|
24
|
+
spec.add_development_dependency 'rake'
|
25
|
+
spec.add_development_dependency "bundler", "~> 1.3"
|
26
|
+
spec.add_development_dependency "rake"
|
27
|
+
end
|
data/temp.rb
ADDED
@@ -0,0 +1,70 @@
|
|
1
|
+
require "httparty"
|
2
|
+
require 'webmock'
|
3
|
+
require 'cgi'
|
4
|
+
require 'securerandom'
|
5
|
+
|
6
|
+
#
|
7
|
+
|
8
|
+
class Client
|
9
|
+
include HTTParty
|
10
|
+
include WebMock::API
|
11
|
+
debug_output $stderr
|
12
|
+
base_uri 'http://smslane.com'
|
13
|
+
|
14
|
+
stub_request(:get, "http://smslane.com/vendorsms/CheckBalance.aspx?password=karimbenzema&user=steverob").to_return(:body => "Success#20000", :status => 200, :headers => { 'Content-Length' => 13 })
|
15
|
+
stub_request(:get, /http:\/\/smslane\.com\/vendorsms\/pushsms\.aspx?/).to_return(:body => lambda { |request|
|
16
|
+
nums = CGI::parse(request.uri.query)['msisdn'][0].split(',')
|
17
|
+
response = ''
|
18
|
+
nums.each do |num|
|
19
|
+
if !(/^(\+91|91)[789][0-9]{9}$/.match(num).nil?)
|
20
|
+
response += 'The Message Id : ' + num + '-' + SecureRandom.hex + '<br />'
|
21
|
+
else
|
22
|
+
response = 'Failed#Invalid Mobile Numbers'
|
23
|
+
break
|
24
|
+
end
|
25
|
+
end
|
26
|
+
response
|
27
|
+
})
|
28
|
+
|
29
|
+
|
30
|
+
def initialize(username,password)
|
31
|
+
@auth = {user: username, password: password}
|
32
|
+
end
|
33
|
+
|
34
|
+
def check_balance
|
35
|
+
options = {:query => @auth}
|
36
|
+
response = self.class.get '/vendorsms/CheckBalance.aspx?',options
|
37
|
+
responses = response.split('#')
|
38
|
+
{:result=>responses[0],:response=>responses[1]}
|
39
|
+
end
|
40
|
+
|
41
|
+
def send options
|
42
|
+
self.class.get '/vendorsms/pushsms.aspx?',options
|
43
|
+
end
|
44
|
+
|
45
|
+
def send_sms recipients, message, flash
|
46
|
+
flash = flash ? 1 : 0
|
47
|
+
responses = []
|
48
|
+
recipients = recipients.each_slice(5).to_a
|
49
|
+
recipients.each do |recipient_list|
|
50
|
+
recipient_list.each_with_index do |number,i|
|
51
|
+
recipient_list[i] = '91'+number[-10..-1]
|
52
|
+
if /^(\+91|91)[789][0-9]{9}$/.match(recipient_list[i]).nil?
|
53
|
+
recipient_list.delete_at(i)
|
54
|
+
end
|
55
|
+
end
|
56
|
+
options = {:query => @auth.merge({:msisdn=>recipient_list.join(','), :sid=>'WebSMS', :fl => flash, :msg => message})}
|
57
|
+
responses << send(options).parsed_response
|
58
|
+
end
|
59
|
+
|
60
|
+
responses.delete('Failed#Invalid Mobile Numbers')
|
61
|
+
responses = responses.join().split('<br />')
|
62
|
+
result = []
|
63
|
+
responses.each do |response|
|
64
|
+
res = response[-45..-1].split('-')
|
65
|
+
result << {:number => res[0], :message_id=>res[1]}
|
66
|
+
end
|
67
|
+
result
|
68
|
+
end
|
69
|
+
|
70
|
+
end
|
metadata
ADDED
@@ -0,0 +1,113 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: smslane
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.3
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Steve Robinson
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2013-06-29 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: httparty
|
16
|
+
requirement: &12007440 !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ! '>='
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: '0'
|
22
|
+
type: :runtime
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: *12007440
|
25
|
+
- !ruby/object:Gem::Dependency
|
26
|
+
name: webmock
|
27
|
+
requirement: &12006920 !ruby/object:Gem::Requirement
|
28
|
+
none: false
|
29
|
+
requirements:
|
30
|
+
- - ! '>='
|
31
|
+
- !ruby/object:Gem::Version
|
32
|
+
version: '0'
|
33
|
+
type: :development
|
34
|
+
prerelease: false
|
35
|
+
version_requirements: *12006920
|
36
|
+
- !ruby/object:Gem::Dependency
|
37
|
+
name: rake
|
38
|
+
requirement: &12006400 !ruby/object:Gem::Requirement
|
39
|
+
none: false
|
40
|
+
requirements:
|
41
|
+
- - ! '>='
|
42
|
+
- !ruby/object:Gem::Version
|
43
|
+
version: '0'
|
44
|
+
type: :development
|
45
|
+
prerelease: false
|
46
|
+
version_requirements: *12006400
|
47
|
+
- !ruby/object:Gem::Dependency
|
48
|
+
name: bundler
|
49
|
+
requirement: &12005660 !ruby/object:Gem::Requirement
|
50
|
+
none: false
|
51
|
+
requirements:
|
52
|
+
- - ~>
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '1.3'
|
55
|
+
type: :development
|
56
|
+
prerelease: false
|
57
|
+
version_requirements: *12005660
|
58
|
+
- !ruby/object:Gem::Dependency
|
59
|
+
name: rake
|
60
|
+
requirement: &12004920 !ruby/object:Gem::Requirement
|
61
|
+
none: false
|
62
|
+
requirements:
|
63
|
+
- - ! '>='
|
64
|
+
- !ruby/object:Gem::Version
|
65
|
+
version: '0'
|
66
|
+
type: :development
|
67
|
+
prerelease: false
|
68
|
+
version_requirements: *12004920
|
69
|
+
description: Wrapper gem for the Smslane.com HTTP API
|
70
|
+
email:
|
71
|
+
- steve.rob@me.com
|
72
|
+
executables: []
|
73
|
+
extensions: []
|
74
|
+
extra_rdoc_files: []
|
75
|
+
files:
|
76
|
+
- .gitignore
|
77
|
+
- Gemfile
|
78
|
+
- LICENSE.txt
|
79
|
+
- README.md
|
80
|
+
- Rakefile
|
81
|
+
- lib/smslane.rb
|
82
|
+
- lib/smslane/client.rb
|
83
|
+
- lib/smslane/version.rb
|
84
|
+
- smslane.gemspec
|
85
|
+
- temp.rb
|
86
|
+
homepage: https://github.com/steverob/smslane
|
87
|
+
licenses:
|
88
|
+
- MIT
|
89
|
+
post_install_message:
|
90
|
+
rdoc_options: []
|
91
|
+
require_paths:
|
92
|
+
- lib
|
93
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
94
|
+
none: false
|
95
|
+
requirements:
|
96
|
+
- - ! '>='
|
97
|
+
- !ruby/object:Gem::Version
|
98
|
+
version: '0'
|
99
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
100
|
+
none: false
|
101
|
+
requirements:
|
102
|
+
- - ! '>='
|
103
|
+
- !ruby/object:Gem::Version
|
104
|
+
version: '0'
|
105
|
+
requirements: []
|
106
|
+
rubyforge_project:
|
107
|
+
rubygems_version: 1.8.11
|
108
|
+
signing_key:
|
109
|
+
specification_version: 3
|
110
|
+
summary: A simple to use gem that enables developers to integrate Smslane.com's HTTP
|
111
|
+
API with their applications and access the Bulk SMS service. Balance Check, Multiple
|
112
|
+
recipient and delivery report features are all supported.
|
113
|
+
test_files: []
|