sms_manager 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +12 -0
- data/CHANGELOG.md +3 -0
- data/LICENSE.md +22 -0
- data/README.md +73 -0
- data/lib/sms_manager/client.rb +32 -0
- data/lib/sms_manager/configurable.rb +30 -0
- data/lib/sms_manager/error/configuration_error.rb +3 -0
- data/lib/sms_manager/error/sending_error.rb +3 -0
- data/lib/sms_manager/version.rb +13 -0
- data/lib/sms_manager.rb +24 -0
- data/sms_manager.gemspec +21 -0
- metadata +57 -0
data/.gitignore
ADDED
data/CHANGELOG.md
ADDED
data/LICENSE.md
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2013 David Hrachovy
|
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,73 @@
|
|
1
|
+
# SmsManager
|
2
|
+
|
3
|
+
A Ruby SDK for smsmanager.cz - SMS provider.
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
gem install sms_manager
|
7
|
+
|
8
|
+
Add this line to your application's Gemfile:
|
9
|
+
|
10
|
+
gem 'sms_manager'
|
11
|
+
|
12
|
+
And then execute:
|
13
|
+
|
14
|
+
bundle
|
15
|
+
|
16
|
+
Or install it yourself as:
|
17
|
+
|
18
|
+
gem install sms_manager
|
19
|
+
|
20
|
+
## Usage
|
21
|
+
|
22
|
+
First you need to setup your credentials. This can be done only once:
|
23
|
+
|
24
|
+
```ruby
|
25
|
+
SmsManager.configure do |config|
|
26
|
+
config.username = YOUR_USERNAME
|
27
|
+
config.hashed_password = HASHED_PASSWORD
|
28
|
+
end
|
29
|
+
```
|
30
|
+
|
31
|
+
Create the password hash with SHA-1 in console and then put the string into the configuration block:
|
32
|
+
|
33
|
+
```ruby
|
34
|
+
require 'digest/sha1'
|
35
|
+
Digest::SHA1.hexdigest 'password'
|
36
|
+
```
|
37
|
+
|
38
|
+
That's all. Now you can send SMS messages.
|
39
|
+
|
40
|
+
```ruby
|
41
|
+
SmsManager.send_message number: '+420123456789', message: 'Hello!'
|
42
|
+
```
|
43
|
+
|
44
|
+
## Background call
|
45
|
+
|
46
|
+
If you do not want to block your app you can use sucker_punch to deleagte the method call to a pool of workers. Note that any raised exception is not propagated to you, it's _fire and forget_.
|
47
|
+
|
48
|
+
```ruby
|
49
|
+
module SmsManager
|
50
|
+
class Client
|
51
|
+
include SuckerPunch::Job
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
SmsManager.configure do |config|
|
56
|
+
config.username = YOUR_USERNAME
|
57
|
+
config.hashed_password = HASHED_PASSWORD
|
58
|
+
end
|
59
|
+
|
60
|
+
SmsManager.async.send_message number: '+420123456789', message: 'Hello!'
|
61
|
+
```
|
62
|
+
|
63
|
+
## TODO
|
64
|
+
|
65
|
+
* add other params to send_message method
|
66
|
+
* recognize error codes (only a single exception is raised)
|
67
|
+
|
68
|
+
## Copyright
|
69
|
+
|
70
|
+
Copyright (c) 2013 David Hrachovy
|
71
|
+
See [LICENSE][] for details.
|
72
|
+
|
73
|
+
[license]: LICENSE.md
|
@@ -0,0 +1,32 @@
|
|
1
|
+
require "sms_manager/error/sending_error"
|
2
|
+
|
3
|
+
module SmsManager
|
4
|
+
|
5
|
+
class Client
|
6
|
+
# options should be { number: String, message: String }
|
7
|
+
def send_message(options = {})
|
8
|
+
validate_send_message_options! options
|
9
|
+
options = {
|
10
|
+
username: SmsManager.instance_variable_get(:@username),
|
11
|
+
password: SmsManager.instance_variable_get(:@hashed_password),
|
12
|
+
number: options[:number],
|
13
|
+
message: options[:message]
|
14
|
+
}
|
15
|
+
body = HTTPClient.get('http://http-api.smsmanager.cz/Send', options).body
|
16
|
+
unless body =~ /^OK/
|
17
|
+
raise SendingError, "Sending text '#{options[:message]}' to phone '#{options[:number]}' failed"
|
18
|
+
end
|
19
|
+
nil
|
20
|
+
end
|
21
|
+
|
22
|
+
private
|
23
|
+
|
24
|
+
def validate_send_message_options!(options)
|
25
|
+
options.each do |option, value|
|
26
|
+
unless value.is_a?(String)
|
27
|
+
raise ArgumentError, "Invalid #{option} specified: #{value} must be a string."
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
@@ -0,0 +1,30 @@
|
|
1
|
+
require "sms_manager/error/configuration_error"
|
2
|
+
|
3
|
+
module SmsManager
|
4
|
+
module Configurable
|
5
|
+
attr_writer :username, :hashed_password
|
6
|
+
|
7
|
+
def configure
|
8
|
+
yield self
|
9
|
+
validate_credential_type!
|
10
|
+
self
|
11
|
+
end
|
12
|
+
|
13
|
+
private
|
14
|
+
|
15
|
+
def credentials
|
16
|
+
{
|
17
|
+
:username => @username,
|
18
|
+
:hashed_password => @hashed_password,
|
19
|
+
}
|
20
|
+
end
|
21
|
+
|
22
|
+
def validate_credential_type!
|
23
|
+
credentials.each do |credential, value|
|
24
|
+
unless value.is_a?(String)
|
25
|
+
raise ConfigurationError, "Invalid #{credential} specified: #{value} must be a string."
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
data/lib/sms_manager.rb
ADDED
@@ -0,0 +1,24 @@
|
|
1
|
+
require 'sms_manager/configurable'
|
2
|
+
require "sms_manager/client"
|
3
|
+
|
4
|
+
module SmsManager
|
5
|
+
class << self
|
6
|
+
include Configurable
|
7
|
+
|
8
|
+
# delegate calls to client
|
9
|
+
def client
|
10
|
+
return @client if instance_variable_defined?(:@client)
|
11
|
+
@client = SmsManager::Client.new
|
12
|
+
end
|
13
|
+
|
14
|
+
def method_missing(method_name, *args, &block)
|
15
|
+
return super unless respond_to_missing?(method_name)
|
16
|
+
client.send(method_name, *args, &block)
|
17
|
+
end
|
18
|
+
|
19
|
+
def respond_to_missing?(method_name, include_private=false)
|
20
|
+
client.respond_to?(method_name, include_private)
|
21
|
+
end
|
22
|
+
|
23
|
+
end
|
24
|
+
end
|
data/sms_manager.gemspec
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'sms_manager/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |gem|
|
7
|
+
gem.name = "sms_manager"
|
8
|
+
gem.version = SmsManager::Version
|
9
|
+
gem.date = '2013-08-07'
|
10
|
+
gem.authors = ["David Hrachovy"]
|
11
|
+
gem.email = ["david.hrachovy@gmail.com"]
|
12
|
+
gem.description = %q{Ruby SDK for smsmanager.cz API}
|
13
|
+
gem.summary = %q{SmsManager is a Ruby library for sending SMS messages by smsmanager.cz provider}
|
14
|
+
gem.homepage = "https://github.com/dayweek/sms_manager"
|
15
|
+
|
16
|
+
gem.files = `git ls-files`.split($/)
|
17
|
+
gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
|
18
|
+
gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
|
19
|
+
gem.require_paths = ["lib"]
|
20
|
+
gem.license = 'MIT'
|
21
|
+
end
|
metadata
ADDED
@@ -0,0 +1,57 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: sms_manager
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- David Hrachovy
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2013-08-07 00:00:00.000000000 Z
|
13
|
+
dependencies: []
|
14
|
+
description: Ruby SDK for smsmanager.cz API
|
15
|
+
email:
|
16
|
+
- david.hrachovy@gmail.com
|
17
|
+
executables: []
|
18
|
+
extensions: []
|
19
|
+
extra_rdoc_files: []
|
20
|
+
files:
|
21
|
+
- .gitignore
|
22
|
+
- CHANGELOG.md
|
23
|
+
- LICENSE.md
|
24
|
+
- README.md
|
25
|
+
- lib/sms_manager.rb
|
26
|
+
- lib/sms_manager/client.rb
|
27
|
+
- lib/sms_manager/configurable.rb
|
28
|
+
- lib/sms_manager/error/configuration_error.rb
|
29
|
+
- lib/sms_manager/error/sending_error.rb
|
30
|
+
- lib/sms_manager/version.rb
|
31
|
+
- sms_manager.gemspec
|
32
|
+
homepage: https://github.com/dayweek/sms_manager
|
33
|
+
licenses:
|
34
|
+
- MIT
|
35
|
+
post_install_message:
|
36
|
+
rdoc_options: []
|
37
|
+
require_paths:
|
38
|
+
- lib
|
39
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
40
|
+
none: false
|
41
|
+
requirements:
|
42
|
+
- - ! '>='
|
43
|
+
- !ruby/object:Gem::Version
|
44
|
+
version: '0'
|
45
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
46
|
+
none: false
|
47
|
+
requirements:
|
48
|
+
- - ! '>='
|
49
|
+
- !ruby/object:Gem::Version
|
50
|
+
version: '0'
|
51
|
+
requirements: []
|
52
|
+
rubyforge_project:
|
53
|
+
rubygems_version: 1.8.24
|
54
|
+
signing_key:
|
55
|
+
specification_version: 3
|
56
|
+
summary: SmsManager is a Ruby library for sending SMS messages by smsmanager.cz provider
|
57
|
+
test_files: []
|