sms_global_sender 0.0.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 +18 -0
- data/LICENSE +20 -0
- data/README.md +46 -0
- data/lib/sms_sender.rb +34 -0
- data/sms_global_sender.gemspec +20 -0
- data/spec/sms_sender_spec.rb +12 -0
- data/spec/spec_helper.rb +1 -0
- metadata +108 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 0bed878785d69c6378b891f639e52c1f736b0bd4
|
4
|
+
data.tar.gz: 37fdf352e352745a56041c03dfb8a19994cdf907
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 62b22526fb66f5dc62d0e71a44efdeb2bda20f742d762ad1f3be27bdc0ef97be7b3bf1d6794f5c8a12e1919842a775a010a9485ceda800723f1d36c631cef226
|
7
|
+
data.tar.gz: 6c38fbc1df725e82986d5f947ddc0ce18d4497a418f18571c1236338af48eac3b96f6bbf20c193144fd2c648af3c0b9c77727906bf8cb3b9f6872ff4a1a1eb21
|
data/.gitignore
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2013 Haiyang (harry) Gao
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy of
|
6
|
+
this software and associated documentation files (the "Software"), to deal in
|
7
|
+
the Software without restriction, including without limitation the rights to
|
8
|
+
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
|
9
|
+
the Software, and to permit persons to whom the Software is furnished to do so,
|
10
|
+
subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
13
|
+
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, FITNESS
|
17
|
+
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
|
18
|
+
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
|
19
|
+
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
20
|
+
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,46 @@
|
|
1
|
+
sms_sender
|
2
|
+
==========
|
3
|
+
|
4
|
+
|
5
|
+
A ruby gem to send SMS through smsglobal.com.au
|
6
|
+
|
7
|
+
|
8
|
+
## Installation
|
9
|
+
|
10
|
+
Add this line to your application's Gemfile:
|
11
|
+
|
12
|
+
gem 'sms_sender'
|
13
|
+
|
14
|
+
Or install it yourself as:
|
15
|
+
|
16
|
+
$ gem install sms_sender
|
17
|
+
|
18
|
+
## Usage
|
19
|
+
|
20
|
+
```
|
21
|
+
sms_sender = Sms_Sender.new('your_client_id', 'your_client_secret')
|
22
|
+
sms_sender.send('title','message','mobile_number')
|
23
|
+
```
|
24
|
+
The return value from send method is the HTTP code from smsglobal.com.au. Below is the code list from smsglobal
|
25
|
+
|
26
|
+
Response Codes
|
27
|
+
The following response codes apply to all requests. Check each request type in the list below for more response codes specific to that request.
|
28
|
+
|
29
|
+
Status Code | Meaning | Scenario
|
30
|
+
--- | --- | ---
|
31
|
+
200 |OK | The request was processed successfully
|
32
|
+
400 |Bad Request |Your request contained invalid or missing data
|
33
|
+
401 |Unauthorized | Authentication failed or the Authenticate header was not provided
|
34
|
+
404 |Not Found |The URI does not match any of the recognised resources, or, if you are asking for a specific resource with an ID, that resource does not exist
|
35
|
+
405 |Method Not Allowed| The HTTP request method you are trying to use is not allowed. Make an OPTIONS request to see the allowed methods
|
36
|
+
406 |Not Acceptable| The Accept content type you are asking for is not supported by the REST API
|
37
|
+
415 |Unsupported Media Type| The Content-Type header is not supported by the REST API
|
38
|
+
|
39
|
+
|
40
|
+
## Contributing
|
41
|
+
|
42
|
+
1. Fork it
|
43
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
44
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
45
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
46
|
+
5. Create new Pull Request
|
data/lib/sms_sender.rb
ADDED
@@ -0,0 +1,34 @@
|
|
1
|
+
require 'digest/hmac'
|
2
|
+
require 'base64'
|
3
|
+
require 'httparty'
|
4
|
+
|
5
|
+
class SmsSender
|
6
|
+
@@host = 'api.smsglobal.com'
|
7
|
+
@@port = '443'
|
8
|
+
@@request_url = '/v1/sms/'
|
9
|
+
def initialize(client_id, client_secret)
|
10
|
+
@client_id = client_id
|
11
|
+
@secret = client_secret
|
12
|
+
end
|
13
|
+
|
14
|
+
def send(title, msg, mobile)
|
15
|
+
@nonce = (0...8).map { (65 + rand(26)).chr }.join
|
16
|
+
@ts = Time.now.to_i
|
17
|
+
mac = calculate_mac
|
18
|
+
header = {'Authorization' => "MAC id=\"#{@client_id}\", ts=\"#{@ts}\", nonce=\"#{@nonce}\", mac=\"#{mac}\"",
|
19
|
+
'Content-Type' => 'application/json',
|
20
|
+
'Accept' => 'application/json'}
|
21
|
+
|
22
|
+
body = {"origin"=>title, "destination"=>mobile, "message"=>msg }
|
23
|
+
|
24
|
+
response = HTTParty.post("https://#{@@host}#{@@request_url}", headers: header, body: body.to_json)
|
25
|
+
response.code
|
26
|
+
end
|
27
|
+
|
28
|
+
private
|
29
|
+
def calculate_mac
|
30
|
+
body = "#{@ts}\n#{@nonce}\nPOST\n#{@@request_url}\n#{@@host}\n#{@@port}\n\n"
|
31
|
+
digest = Digest::HMAC.digest(body, @secret, Digest::SHA256)
|
32
|
+
Base64.strict_encode64 digest
|
33
|
+
end
|
34
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
Gem::Specification.new do |s|
|
2
|
+
s.name = 'sms_global_sender'
|
3
|
+
s.version = '0.0.1'
|
4
|
+
s.date = '2014-02-05'
|
5
|
+
s.summary = "Send sms through SMS gateway"
|
6
|
+
s.description = "specific to smsglobal.com.au"
|
7
|
+
s.authors = ["Harry Gao"]
|
8
|
+
s.email = 'foxgaocn@gmail.com'
|
9
|
+
s.files = [".gitignore", "LICENSE", "sms_global_sender.gemspec", "README.md","lib/sms_sender.rb"]
|
10
|
+
s.homepage =
|
11
|
+
'http://rubygems.org/gems/sms_global_sender'
|
12
|
+
s.license = 'MIT'
|
13
|
+
s.test_files = ["spec/sms_sender_spec.rb", "spec/spec_helper.rb"]
|
14
|
+
|
15
|
+
s.add_dependency "httparty"
|
16
|
+
|
17
|
+
s.add_development_dependency "bundler", "~> 1.3"
|
18
|
+
s.add_development_dependency "rake"
|
19
|
+
s.add_development_dependency "rspec"
|
20
|
+
end
|
@@ -0,0 +1,12 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe SmsSender do
|
4
|
+
let(:sms_sender) { SmsSender.new('c94595c30ba1e84be01cad2d8fc1b302', 'd65933a24bc56fdda8358ca2bc90a978') }
|
5
|
+
|
6
|
+
describe '#send' do
|
7
|
+
subject { sms_sender.send('myob', 'this is a test', "0451111111")}
|
8
|
+
it 'should send' do
|
9
|
+
expect(subject).to eql 201
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require 'sms_sender.rb'
|
metadata
ADDED
@@ -0,0 +1,108 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: sms_global_sender
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Harry Gao
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2014-02-05 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: httparty
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - '>='
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - '>='
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '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.3'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ~>
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '1.3'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rake
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - '>='
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :development
|
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: rspec
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - '>='
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - '>='
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
69
|
+
description: specific to smsglobal.com.au
|
70
|
+
email: foxgaocn@gmail.com
|
71
|
+
executables: []
|
72
|
+
extensions: []
|
73
|
+
extra_rdoc_files: []
|
74
|
+
files:
|
75
|
+
- .gitignore
|
76
|
+
- LICENSE
|
77
|
+
- sms_global_sender.gemspec
|
78
|
+
- README.md
|
79
|
+
- lib/sms_sender.rb
|
80
|
+
- spec/sms_sender_spec.rb
|
81
|
+
- spec/spec_helper.rb
|
82
|
+
homepage: http://rubygems.org/gems/sms_global_sender
|
83
|
+
licenses:
|
84
|
+
- MIT
|
85
|
+
metadata: {}
|
86
|
+
post_install_message:
|
87
|
+
rdoc_options: []
|
88
|
+
require_paths:
|
89
|
+
- lib
|
90
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
91
|
+
requirements:
|
92
|
+
- - '>='
|
93
|
+
- !ruby/object:Gem::Version
|
94
|
+
version: '0'
|
95
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
96
|
+
requirements:
|
97
|
+
- - '>='
|
98
|
+
- !ruby/object:Gem::Version
|
99
|
+
version: '0'
|
100
|
+
requirements: []
|
101
|
+
rubyforge_project:
|
102
|
+
rubygems_version: 2.1.11
|
103
|
+
signing_key:
|
104
|
+
specification_version: 4
|
105
|
+
summary: Send sms through SMS gateway
|
106
|
+
test_files:
|
107
|
+
- spec/sms_sender_spec.rb
|
108
|
+
- spec/spec_helper.rb
|