bluehouselab-sms 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +9 -0
- data/.rspec +2 -0
- data/.travis.yml +4 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +21 -0
- data/README.md +53 -0
- data/Rakefile +6 -0
- data/bin/console +14 -0
- data/bin/setup +7 -0
- data/bluehouselab-sms.gemspec +36 -0
- data/lib/bluehouselab/sms.rb +116 -0
- data/lib/bluehouselab/sms/version.rb +3 -0
- metadata +156 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: a9276bc38cd43b57f03d757fdba8b356ecb0a5ac
|
4
|
+
data.tar.gz: 8a1f8ac32f4fcf7d35770160ace53c9c25e104fb
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 5233cbe38ad03bfe009fc06d653a02dab72a20912a904f4e7fe37c0c2c135663040f46b4471d12e4f7581bb75f5fb19c119660ef92f9f4a8a8a5bc9ab3c25852
|
7
|
+
data.tar.gz: a7f18dfd1e9c580021b6966ce7f2dbc5ba37797904afe936267a282057fe6452a38d492210738c60ffe0459e9e89116c3509046edd163467a8f579f618c4da91
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2015 Cosmic Color
|
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,53 @@
|
|
1
|
+
# Bluehouselab::Sms
|
2
|
+
|
3
|
+
This is a simple client for sending SMS messages to mobile devices via the Bluehouselab API. http://www.bluehouselab.com/
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
```ruby
|
10
|
+
gem 'bluehouselab-sms'
|
11
|
+
```
|
12
|
+
|
13
|
+
And then execute:
|
14
|
+
|
15
|
+
$ bundle
|
16
|
+
|
17
|
+
Or install it yourself as:
|
18
|
+
|
19
|
+
$ gem install bluehouselab-sms
|
20
|
+
|
21
|
+
## Usage
|
22
|
+
|
23
|
+
```ruby
|
24
|
+
sms = Bluehouselab::Sms.new :api_key => "123", :app_id => "123", :sender => "010111111111"
|
25
|
+
|
26
|
+
#send an sms message
|
27
|
+
sms.send_message :type => :sms, :receivers => ["0102222222","01033333333"], :content => "Hello World"
|
28
|
+
# => { :message_ids => [["0102222222","100001"],["01033333333","100002"]], :success => true, :error => nil, :status_code => 200 }
|
29
|
+
|
30
|
+
#send an lms message
|
31
|
+
sms.send_message :type => :lms, :receivers => ["0102222222","01033333333"], :content => "Hello World", :subject => "Hello" }
|
32
|
+
# => { :message_ids => [["0102222222","100001"],["01033333333","100002"]], :success => true, :error => nil, :status_code => 200 }
|
33
|
+
|
34
|
+
#find if the message was delivered successfully
|
35
|
+
sms.result "100001"
|
36
|
+
# => {:error=>nil, :success=>true, :status_code=>200, :sent_time=>2015-08-28 06:49:05 UTC}
|
37
|
+
```
|
38
|
+
|
39
|
+
## Development
|
40
|
+
|
41
|
+
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake rspec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
42
|
+
|
43
|
+
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
44
|
+
|
45
|
+
## Contributing
|
46
|
+
|
47
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/CosmicColor/bluehouselab-sms.
|
48
|
+
|
49
|
+
|
50
|
+
## License
|
51
|
+
|
52
|
+
The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
|
53
|
+
|
data/Rakefile
ADDED
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "bluehouselab/sms"
|
5
|
+
|
6
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
7
|
+
# with your gem easier. You can also use a different console, if you like.
|
8
|
+
|
9
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
10
|
+
# require "pry"
|
11
|
+
# Pry.start
|
12
|
+
|
13
|
+
require "irb"
|
14
|
+
IRB.start
|
data/bin/setup
ADDED
@@ -0,0 +1,36 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'bluehouselab/sms/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "bluehouselab-sms"
|
8
|
+
spec.version = Bluehouselab::VERSION
|
9
|
+
spec.authors = ["kenleytomlin","neospecial"]
|
10
|
+
spec.email = ["kenleytomlin@gmail.com"]
|
11
|
+
|
12
|
+
spec.summary = %q{A simple gem that sends sms messages via the Bluehouselab api}
|
13
|
+
spec.homepage = "https://github.com/CosmicColor/bluehouselab-sms/"
|
14
|
+
spec.license = "MIT"
|
15
|
+
|
16
|
+
# Prevent pushing this gem to RubyGems.org by setting 'allowed_push_host', or
|
17
|
+
# delete this section to allow pushing this gem to any host.
|
18
|
+
if spec.respond_to?(:metadata)
|
19
|
+
spec.metadata['allowed_push_host'] = "https://rubygems.org"
|
20
|
+
else
|
21
|
+
raise "RubyGems 2.0 or newer is required to protect against public gem pushes."
|
22
|
+
end
|
23
|
+
|
24
|
+
spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
25
|
+
spec.bindir = "exe"
|
26
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
27
|
+
spec.require_paths = ["lib"]
|
28
|
+
|
29
|
+
spec.add_dependency "httparty", "~> 0.13.5"
|
30
|
+
spec.add_development_dependency "bundler", "~> 1.10"
|
31
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
32
|
+
spec.add_development_dependency "rspec", "~> 3.3"
|
33
|
+
spec.add_development_dependency "webmock", "~> 1.21.0"
|
34
|
+
spec.add_development_dependency "fuubar", "~> 2.0.0"
|
35
|
+
spec.add_development_dependency "timecop", "~> 0.8.0"
|
36
|
+
end
|
@@ -0,0 +1,116 @@
|
|
1
|
+
require "bluehouselab/sms/version"
|
2
|
+
require "httparty"
|
3
|
+
require "json"
|
4
|
+
|
5
|
+
module Bluehouselab
|
6
|
+
class Sms
|
7
|
+
|
8
|
+
ROUTES = {
|
9
|
+
:lms => "sendlms",
|
10
|
+
:sms => "sendsms",
|
11
|
+
:result => "result"
|
12
|
+
}
|
13
|
+
|
14
|
+
HEADERS = { "Content-Type" => "application/json;charset=utf-8" }
|
15
|
+
|
16
|
+
HTTP_ERRORS = {
|
17
|
+
400 => "Bad request, check the values sent to the server",
|
18
|
+
401 => "Unauthorized, check api key and app_id",
|
19
|
+
402 => "Insufficient credit, please check your account balance",
|
20
|
+
403 => "Forbidden, connect via HTTPS",
|
21
|
+
404 => "Not found, delivery id or resource",
|
22
|
+
406 => "Not acceptable, check the JSON payload isn't malformed",
|
23
|
+
410 => "API deprecated",
|
24
|
+
412 => "Precondition Failed, check the values sent to the server",
|
25
|
+
500 => "Internal server error",
|
26
|
+
503 => "Service unavailable"
|
27
|
+
}
|
28
|
+
|
29
|
+
SEND_RESULT_ERRORS = {
|
30
|
+
-1 => "Cannot confirm at this time, please retry",
|
31
|
+
10000 => "Message failed",
|
32
|
+
10001 => "Device cannot receive messages",
|
33
|
+
10002 => "NPDB error",
|
34
|
+
10003 => "Service temporarily unavailable",
|
35
|
+
10004 => "Receiving device error",
|
36
|
+
10005 => "System error",
|
37
|
+
10006 => "Message request time limit has expired"
|
38
|
+
}
|
39
|
+
|
40
|
+
def initialize(options)
|
41
|
+
raise ArgumentError.new "api_key cannot be nil" unless options[:api_key]
|
42
|
+
raise ArgumentError.new "app_id cannot be nil" unless options[:app_id]
|
43
|
+
raise ArgumentError.new "sender cannot be nil" unless options[:sender]
|
44
|
+
@api_key = options[:api_key]
|
45
|
+
@app_id = options[:app_id]
|
46
|
+
@sender = options[:sender]
|
47
|
+
@base_url = "https://#{@app_id}:#{@api_key}@api.bluehouselab.com/smscenter/v1.0/"
|
48
|
+
end
|
49
|
+
|
50
|
+
def send_message(options)
|
51
|
+
raise ArgumentError.new "send_message options requires a type either :sms or :lms" unless options[:type]
|
52
|
+
raise ArgumentError.new "send_message options requires an array of receiver phone numbers" unless options[:receivers] && options[:receivers].is_a?(Array)
|
53
|
+
raise ArgumentError.new "send_message options requires content" unless options[:content]
|
54
|
+
|
55
|
+
type = options[:type].nil? ? :sms : options[:type]
|
56
|
+
|
57
|
+
raise ArgumentError.new "send_message options[:type] must be one of :sms or :lms" unless type == :sms || type == :lms
|
58
|
+
raise "content too long for type :sms" unless (options[:content].bytesize <= 80 && type == :sms) || ( type == :lms)
|
59
|
+
|
60
|
+
res = send type, options[:receivers], options[:content], options[:subject]
|
61
|
+
parse_send_response res.code, res.parsed_response
|
62
|
+
end
|
63
|
+
|
64
|
+
def result(request_id)
|
65
|
+
res = HTTParty.get "#{@base_url}#{ROUTES[:result]}/#{request_id}", { :headers => HEADERS }
|
66
|
+
parse_result_response res.code, res.parsed_response
|
67
|
+
end
|
68
|
+
|
69
|
+
private
|
70
|
+
|
71
|
+
def parse_error_and_code(code)
|
72
|
+
if code >= 400
|
73
|
+
error = HTTP_ERRORS[code]
|
74
|
+
success = false
|
75
|
+
else
|
76
|
+
error = nil
|
77
|
+
success = true
|
78
|
+
end
|
79
|
+
{ :error => error, :success => success, :status_code => code }
|
80
|
+
end
|
81
|
+
|
82
|
+
def parse_result_response(code,parsed_body)
|
83
|
+
error_and_code = parse_error_and_code(code)
|
84
|
+
if error_and_code[:success]
|
85
|
+
if parsed_body['status'] == 0
|
86
|
+
error_and_code.merge! :sent_time => Time.parse(parsed_body['sent_time'])
|
87
|
+
else
|
88
|
+
error = SEND_RESULT_ERRORS[parsed_body['status']]
|
89
|
+
error_and_code.merge!({ :error => error })
|
90
|
+
end
|
91
|
+
else
|
92
|
+
error_and_code
|
93
|
+
end
|
94
|
+
end
|
95
|
+
|
96
|
+
def parse_send_response(code,parsed_body)
|
97
|
+
error_and_code = parse_error_and_code(code)
|
98
|
+
{ :message_ids => code >= 400 ? [] : parsed_body["sent"] }.merge! error_and_code
|
99
|
+
end
|
100
|
+
|
101
|
+
def send(type,receivers,content,subject)
|
102
|
+
body = {
|
103
|
+
:sender => @sender,
|
104
|
+
:receivers => receivers,
|
105
|
+
:content => content
|
106
|
+
}
|
107
|
+
|
108
|
+
if subject && type == :lms
|
109
|
+
body.merge! :subject => subject
|
110
|
+
end
|
111
|
+
|
112
|
+
HTTParty.post "#{@base_url}#{ROUTES[type]}", :body => body.to_json, :headers => HEADERS
|
113
|
+
end
|
114
|
+
|
115
|
+
end
|
116
|
+
end
|
metadata
ADDED
@@ -0,0 +1,156 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: bluehouselab-sms
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- kenleytomlin
|
8
|
+
- neospecial
|
9
|
+
autorequire:
|
10
|
+
bindir: exe
|
11
|
+
cert_chain: []
|
12
|
+
date: 2015-08-28 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: httparty
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
requirements:
|
18
|
+
- - "~>"
|
19
|
+
- !ruby/object:Gem::Version
|
20
|
+
version: 0.13.5
|
21
|
+
type: :runtime
|
22
|
+
prerelease: false
|
23
|
+
version_requirements: !ruby/object:Gem::Requirement
|
24
|
+
requirements:
|
25
|
+
- - "~>"
|
26
|
+
- !ruby/object:Gem::Version
|
27
|
+
version: 0.13.5
|
28
|
+
- !ruby/object:Gem::Dependency
|
29
|
+
name: bundler
|
30
|
+
requirement: !ruby/object:Gem::Requirement
|
31
|
+
requirements:
|
32
|
+
- - "~>"
|
33
|
+
- !ruby/object:Gem::Version
|
34
|
+
version: '1.10'
|
35
|
+
type: :development
|
36
|
+
prerelease: false
|
37
|
+
version_requirements: !ruby/object:Gem::Requirement
|
38
|
+
requirements:
|
39
|
+
- - "~>"
|
40
|
+
- !ruby/object:Gem::Version
|
41
|
+
version: '1.10'
|
42
|
+
- !ruby/object:Gem::Dependency
|
43
|
+
name: rake
|
44
|
+
requirement: !ruby/object:Gem::Requirement
|
45
|
+
requirements:
|
46
|
+
- - "~>"
|
47
|
+
- !ruby/object:Gem::Version
|
48
|
+
version: '10.0'
|
49
|
+
type: :development
|
50
|
+
prerelease: false
|
51
|
+
version_requirements: !ruby/object:Gem::Requirement
|
52
|
+
requirements:
|
53
|
+
- - "~>"
|
54
|
+
- !ruby/object:Gem::Version
|
55
|
+
version: '10.0'
|
56
|
+
- !ruby/object:Gem::Dependency
|
57
|
+
name: rspec
|
58
|
+
requirement: !ruby/object:Gem::Requirement
|
59
|
+
requirements:
|
60
|
+
- - "~>"
|
61
|
+
- !ruby/object:Gem::Version
|
62
|
+
version: '3.3'
|
63
|
+
type: :development
|
64
|
+
prerelease: false
|
65
|
+
version_requirements: !ruby/object:Gem::Requirement
|
66
|
+
requirements:
|
67
|
+
- - "~>"
|
68
|
+
- !ruby/object:Gem::Version
|
69
|
+
version: '3.3'
|
70
|
+
- !ruby/object:Gem::Dependency
|
71
|
+
name: webmock
|
72
|
+
requirement: !ruby/object:Gem::Requirement
|
73
|
+
requirements:
|
74
|
+
- - "~>"
|
75
|
+
- !ruby/object:Gem::Version
|
76
|
+
version: 1.21.0
|
77
|
+
type: :development
|
78
|
+
prerelease: false
|
79
|
+
version_requirements: !ruby/object:Gem::Requirement
|
80
|
+
requirements:
|
81
|
+
- - "~>"
|
82
|
+
- !ruby/object:Gem::Version
|
83
|
+
version: 1.21.0
|
84
|
+
- !ruby/object:Gem::Dependency
|
85
|
+
name: fuubar
|
86
|
+
requirement: !ruby/object:Gem::Requirement
|
87
|
+
requirements:
|
88
|
+
- - "~>"
|
89
|
+
- !ruby/object:Gem::Version
|
90
|
+
version: 2.0.0
|
91
|
+
type: :development
|
92
|
+
prerelease: false
|
93
|
+
version_requirements: !ruby/object:Gem::Requirement
|
94
|
+
requirements:
|
95
|
+
- - "~>"
|
96
|
+
- !ruby/object:Gem::Version
|
97
|
+
version: 2.0.0
|
98
|
+
- !ruby/object:Gem::Dependency
|
99
|
+
name: timecop
|
100
|
+
requirement: !ruby/object:Gem::Requirement
|
101
|
+
requirements:
|
102
|
+
- - "~>"
|
103
|
+
- !ruby/object:Gem::Version
|
104
|
+
version: 0.8.0
|
105
|
+
type: :development
|
106
|
+
prerelease: false
|
107
|
+
version_requirements: !ruby/object:Gem::Requirement
|
108
|
+
requirements:
|
109
|
+
- - "~>"
|
110
|
+
- !ruby/object:Gem::Version
|
111
|
+
version: 0.8.0
|
112
|
+
description:
|
113
|
+
email:
|
114
|
+
- kenleytomlin@gmail.com
|
115
|
+
executables: []
|
116
|
+
extensions: []
|
117
|
+
extra_rdoc_files: []
|
118
|
+
files:
|
119
|
+
- ".gitignore"
|
120
|
+
- ".rspec"
|
121
|
+
- ".travis.yml"
|
122
|
+
- Gemfile
|
123
|
+
- LICENSE.txt
|
124
|
+
- README.md
|
125
|
+
- Rakefile
|
126
|
+
- bin/console
|
127
|
+
- bin/setup
|
128
|
+
- bluehouselab-sms.gemspec
|
129
|
+
- lib/bluehouselab/sms.rb
|
130
|
+
- lib/bluehouselab/sms/version.rb
|
131
|
+
homepage: https://github.com/CosmicColor/bluehouselab-sms/
|
132
|
+
licenses:
|
133
|
+
- MIT
|
134
|
+
metadata:
|
135
|
+
allowed_push_host: https://rubygems.org
|
136
|
+
post_install_message:
|
137
|
+
rdoc_options: []
|
138
|
+
require_paths:
|
139
|
+
- lib
|
140
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
141
|
+
requirements:
|
142
|
+
- - ">="
|
143
|
+
- !ruby/object:Gem::Version
|
144
|
+
version: '0'
|
145
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
146
|
+
requirements:
|
147
|
+
- - ">="
|
148
|
+
- !ruby/object:Gem::Version
|
149
|
+
version: '0'
|
150
|
+
requirements: []
|
151
|
+
rubyforge_project:
|
152
|
+
rubygems_version: 2.4.5
|
153
|
+
signing_key:
|
154
|
+
specification_version: 4
|
155
|
+
summary: A simple gem that sends sms messages via the Bluehouselab api
|
156
|
+
test_files: []
|