sms_manager 0.1.2 → 0.2.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: e4c603afa0deded30e5cb06376e840fc8abbb893
4
+ data.tar.gz: ac12ef1fa59399065cc9ed33bf65f6a5ab284779
5
+ SHA512:
6
+ metadata.gz: 5e2c4942edc14ad882abb5a7373de45e7e984c062683250de7c554ec79d19ce674bc4c6057dc88a1a7938cccd32b18116a76a981b983c8d829ea3c093c78cfa7
7
+ data.tar.gz: 693bce49dc61dd1cb1342be6b8f4620340f4e06ad2d833bd6708a28977737956b78c74c940bfe1d4fb6a3e4943bd6e0f4194199062e1cf1bf675325f053614af
@@ -0,0 +1 @@
1
+ service_name: travis-ci
data/.gitignore CHANGED
@@ -1,9 +1,9 @@
1
1
  *.gem
2
2
  *.rbc
3
+ .rvmrc
3
4
  .bundle
4
5
  .config
5
6
  .yardoc
6
- Gemfile.lock
7
7
  InstalledFiles
8
8
  _yardoc
9
9
  coverage
@@ -0,0 +1,26 @@
1
+ cache: bundler
2
+
3
+ language: ruby
4
+
5
+ rvm:
6
+ - 2.0.0
7
+ - 2.1
8
+ - 2.2
9
+ - jruby-head
10
+ - rbx-2
11
+ - ruby-head
12
+
13
+ sudo: false
14
+
15
+ bundler_args: --without development --retry=3 --jobs=3
16
+
17
+ env:
18
+ global:
19
+ - JRUBY_OPTS="$JRUBY_OPTS --debug"
20
+
21
+ matrix:
22
+ allow_failures:
23
+ - rvm: jruby-head
24
+ - rvm: rbx-2
25
+ - rvm: ruby-head
26
+ fast_finish: true
@@ -1,3 +1,13 @@
1
1
  0.1.0
2
2
  -----
3
3
  * Initial release
4
+
5
+ 0.2.0
6
+ -----
7
+ * backward incompatible change: renamed `send_message` to `send`
8
+ * code refactor
9
+
10
+
11
+ 0.2.1
12
+ -----
13
+ * Add `send_message` back to keep backward compatibility
data/Gemfile CHANGED
@@ -1,4 +1,10 @@
1
1
  source 'https://rubygems.org'
2
2
 
3
- # Specify your gem's dependencies in foodie.gemspec
3
+ gem "rake"
4
+ gem "rspec"
5
+ gem "webmock"
6
+ gem "coveralls"
7
+ gem "simplecov"
8
+
9
+ # Specify your gem's dependencies in gemspec
4
10
  gemspec
@@ -0,0 +1,80 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ sms_manager (0.2.1)
5
+ httpclient (~> 2.7.0)
6
+
7
+ GEM
8
+ remote: https://rubygems.org/
9
+ specs:
10
+ addressable (2.4.0)
11
+ coveralls (0.8.10)
12
+ json (~> 1.8)
13
+ rest-client (>= 1.6.8, < 2)
14
+ simplecov (~> 0.11.0)
15
+ term-ansicolor (~> 1.3)
16
+ thor (~> 0.19.1)
17
+ tins (~> 1.6.0)
18
+ crack (0.4.3)
19
+ safe_yaml (~> 1.0.0)
20
+ diff-lcs (1.2.5)
21
+ docile (1.1.5)
22
+ domain_name (0.5.25)
23
+ unf (>= 0.0.5, < 1.0.0)
24
+ hashdiff (0.2.3)
25
+ http-cookie (1.0.2)
26
+ domain_name (~> 0.5)
27
+ httpclient (2.7.1)
28
+ json (1.8.3)
29
+ mime-types (2.99)
30
+ netrc (0.11.0)
31
+ rake (10.5.0)
32
+ rest-client (1.8.0)
33
+ http-cookie (>= 1.0.2, < 2.0)
34
+ mime-types (>= 1.16, < 3.0)
35
+ netrc (~> 0.7)
36
+ rspec (3.4.0)
37
+ rspec-core (~> 3.4.0)
38
+ rspec-expectations (~> 3.4.0)
39
+ rspec-mocks (~> 3.4.0)
40
+ rspec-core (3.4.1)
41
+ rspec-support (~> 3.4.0)
42
+ rspec-expectations (3.4.0)
43
+ diff-lcs (>= 1.2.0, < 2.0)
44
+ rspec-support (~> 3.4.0)
45
+ rspec-mocks (3.4.1)
46
+ diff-lcs (>= 1.2.0, < 2.0)
47
+ rspec-support (~> 3.4.0)
48
+ rspec-support (3.4.1)
49
+ safe_yaml (1.0.4)
50
+ simplecov (0.11.1)
51
+ docile (~> 1.1.0)
52
+ json (~> 1.8)
53
+ simplecov-html (~> 0.10.0)
54
+ simplecov-html (0.10.0)
55
+ term-ansicolor (1.3.2)
56
+ tins (~> 1.0)
57
+ thor (0.19.1)
58
+ tins (1.6.0)
59
+ unf (0.1.4)
60
+ unf_ext
61
+ unf_ext (0.0.7.1)
62
+ webmock (1.22.6)
63
+ addressable (>= 2.3.6)
64
+ crack (>= 0.3.2)
65
+ hashdiff
66
+
67
+ PLATFORMS
68
+ ruby
69
+
70
+ DEPENDENCIES
71
+ bundler
72
+ coveralls
73
+ rake
74
+ rspec
75
+ simplecov
76
+ sms_manager!
77
+ webmock
78
+
79
+ BUNDLED WITH
80
+ 1.11.2
data/README.md CHANGED
@@ -1,25 +1,24 @@
1
1
  # SmsManager
2
2
 
3
- A Ruby SDK for [smsmanager.cz](http://smsmanager.cz/) - SMS provider.
3
+ [![Gem Version](https://badge.fury.io/rb/sms_manager.png)](http://badge.fury.io/rb/sms_manager)
4
+ [![Build Status](https://travis-ci.org/dayweek/sms_manager.png?branch=master)](https://travis-ci.org/dayweek/sms_manager)
5
+ [![Dependency Status](https://gemnasium.com/dayweek/sms_manager.png)](https://gemnasium.com/dayweek/sms_manager)
6
+ [![Code Climate](https://codeclimate.com/github/dayweek/sms_manager.png)](https://codeclimate.com/github/dayweek/sms_manager)
7
+ [![Coverage Status](https://coveralls.io/repos/dayweek/sms_manager/badge.svg?branch=master&service=github)](https://coveralls.io/github/dayweek/sms_manager?branch=master)
4
8
 
5
- ## Installation
6
- gem install sms_manager
7
-
8
- Add this line to your application's Gemfile:
9
+ A Ruby SDK for [smsmanager.cz](http://smsmanager.cz/) - Czech SMS provider.
9
10
 
10
- gem 'sms_manager'
11
-
12
- And then execute:
11
+ ## Installation
13
12
 
14
- bundle
13
+ `gem install sms_manager`
15
14
 
16
- Or install it yourself as:
15
+ Or add to Gemfile:
17
16
 
18
- gem install sms_manager
17
+ `gem 'sms_manager'`
19
18
 
20
19
  ## Usage
21
20
 
22
- First you need to setup your credentials. This can be done only once:
21
+ First you need to setup your credentials:
23
22
 
24
23
  ```ruby
25
24
  SmsManager.configure do |config|
@@ -38,32 +37,25 @@ Digest::SHA1.hexdigest 'password'
38
37
  That's all. Now you can send SMS messages.
39
38
 
40
39
  ```ruby
41
- SmsManager.send_message number: '+420123456789', message: 'Hello!'
40
+ SmsManager.send number: '+420123456789', message: 'Hello!'
42
41
  ```
43
42
 
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_.
43
+ You can pass all the parameters available at [SmsManager API](http://smsmanager.cz/api/http/). These additional parameters will be appended to the request:
47
44
 
48
45
  ```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!'
46
+ SmsManager.send number: '+420123456789', message: 'Hello!', gateway: 'lowcost', time: '2013-01-01T23:59:59'
61
47
  ```
62
48
 
63
- ## TODO
49
+ If the service fails an exception is raised. The exception contains error code as well as error message.
64
50
 
65
- * add other params to send_message method
66
- * recognize error codes (only a single exception is raised)
51
+ ```ruby
52
+ begin
53
+ SmsManager.send number: '+420123456789', message: 'Hello!'
54
+ rescue SmsManager::SendingError => e
55
+ puts e.code # => 104
56
+ puts e.message # => Neplatný parametr gateway
57
+ end
58
+ ```
67
59
 
68
60
  ## Copyright
69
61
 
data/Rakefile CHANGED
@@ -1 +1,5 @@
1
1
  require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+ RSpec::Core::RakeTask.new
4
+ desc "Runs rspec tests"
5
+ task default: :spec
@@ -1,24 +1,28 @@
1
- require 'sms_manager/configurable'
2
- require "sms_manager/client"
1
+ require 'sms_manager/error/sending_error'
2
+ require 'httpclient'
3
3
 
4
4
  module SmsManager
5
5
  class << self
6
- include Configurable
6
+ attr_writer :username, :hashed_password
7
7
 
8
- # delegate calls to client
9
- def client
10
- return @client if instance_variable_defined?(:@client)
11
- @client = SmsManager::Client.new
8
+ def configure
9
+ yield self
12
10
  end
13
11
 
14
- def method_missing(method_name, *args, &block)
15
- return super unless respond_to_missing?(method_name)
16
- client.send(method_name, *args, &block)
12
+ # options should be { number: String, message: String }
13
+ def send(options = {})
14
+ options = {
15
+ username: SmsManager.instance_variable_get(:@username),
16
+ password: SmsManager.instance_variable_get(:@hashed_password),
17
+ number: options[:number],
18
+ message: options[:message]
19
+ }
20
+ body = HTTPClient.get('http://http-api.smsmanager.cz/Send', options).body
21
+ raise SendingError.new(options, body) unless body =~ /^OK/
17
22
  end
18
23
 
19
- def respond_to_missing?(method_name, include_private=false)
20
- client.respond_to?(method_name, include_private)
24
+ def send_message(options = {})
25
+ send options
21
26
  end
22
-
23
27
  end
24
28
  end
@@ -1,3 +1,34 @@
1
1
  module SmsManager
2
- class SendingError < ::Exception; end
2
+ class SendingError < StandardError
3
+ attr_reader :options, :code
4
+
5
+ def initialize(options, body)
6
+ @code = body.split('|').last.to_i
7
+ @options = options
8
+ end
9
+
10
+ def message
11
+ if code >= 900 && code <= 999
12
+ CODE_9XX
13
+ elsif CODES[code]
14
+ CODES[code]
15
+ else
16
+ 'Neznámý chybový kód'
17
+ end
18
+ end
19
+
20
+ private
21
+
22
+ CODES = {
23
+ 101 => 'Neexistující data požadavku (chybí XMLDATA parametr u XML API)',
24
+ 102 => 'Metoda neexistuje',
25
+ 103 => 'Neplatné uživatelské jméno nebo heslo',
26
+ 104 => 'Neplatný parametr gateway',
27
+ 105 => 'Nedostatek kreditu pro prepaid',
28
+ 201 => 'Žádná platná telefonní čísla v požadavku',
29
+ 202 => 'Text zprávy neexistuje nebo je příliš dlouhý',
30
+ 203 => 'Neplatný parametr sender (odesílatele nejprve nastavte ve webovém rozhraní)'
31
+ }
32
+ CODE_9XX = 'Systémová chyba (informujte se na support@smsmanager.cz)'
33
+ end
3
34
  end
@@ -1,8 +1,8 @@
1
1
  module SmsManager
2
2
  class Version
3
3
  MAJOR = 0
4
- MINOR = 1
5
- PATCH = 2
4
+ MINOR = 2
5
+ PATCH = 1
6
6
 
7
7
  class << self
8
8
  def to_s
@@ -6,15 +6,14 @@ require 'sms_manager/version'
6
6
  Gem::Specification.new do |gem|
7
7
  gem.name = "sms_manager"
8
8
  gem.version = SmsManager::Version
9
- gem.date = '2013-08-07'
9
+ gem.date = '2016-01-16'
10
10
  gem.authors = ["David Hrachovy"]
11
11
  gem.email = ["david.hrachovy@gmail.com"]
12
12
  gem.description = %q{Ruby SDK for smsmanager.cz API}
13
13
  gem.summary = %q{SmsManager is a Ruby library for sending SMS messages by smsmanager.cz provider}
14
14
  gem.homepage = "https://github.com/dayweek/sms_manager"
15
- gem.add_dependency "httpclient", "~> 2.3.4.0"
16
- gem.add_development_dependency "bundler", "~> 1.3"
17
- gem.add_development_dependency "rake"
15
+ gem.add_dependency "httpclient", "~> 2.7.0"
16
+ gem.add_development_dependency "bundler"
18
17
  gem.files = `git ls-files`.split($/)
19
18
  gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
20
19
  gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
@@ -0,0 +1,69 @@
1
+ require 'spec_helper.rb'
2
+
3
+ describe SmsManager do
4
+ it 'sets configuration vars' do
5
+ SmsManager.configure do |config|
6
+ config.username = 'U'
7
+ config.hashed_password = 'H'
8
+ end
9
+
10
+ expect(SmsManager.instance_variable_get(:@username)).to eq('U')
11
+ expect(SmsManager.instance_variable_get(:@hashed_password)).to eq('H')
12
+ end
13
+
14
+ describe 'send' do
15
+ before do
16
+ SmsManager.configure do |config|
17
+ config.username = 'david@example.com'
18
+ config.hashed_password = 'b4b976b7217ac3e336d9249ee15a3fc21fc69ce1'
19
+ end
20
+ end
21
+
22
+ it 'uses configuration vars and send params in request' do
23
+ stub_send.to_return body: 'OK'
24
+ SmsManager.send number: '+420123456789', message: 'Hello!'
25
+
26
+ expect(stub_send).to have_been_requested
27
+ end
28
+
29
+ it 'raises error with details if response body is not ok' do
30
+ stub_send.to_return body: 'ERROR|103'
31
+
32
+ expect { SmsManager.send number: '+420123456789', message: 'Hello!' }.to \
33
+ raise_error(SmsManager::SendingError) do |e|
34
+ expect(e.code).to eq(103)
35
+ expect(e.message).to eq('Neplatné uživatelské jméno nebo heslo')
36
+ end
37
+ end
38
+ end
39
+
40
+ describe 'send' do
41
+ before do
42
+ SmsManager.configure do |config|
43
+ config.username = 'david@example.com'
44
+ config.hashed_password = 'b4b976b7217ac3e336d9249ee15a3fc21fc69ce1'
45
+ end
46
+ end
47
+
48
+ it 'uses configuration vars and send params in request' do
49
+ stub_send.to_return body: 'OK'
50
+ SmsManager.send_message number: '+420123456789', message: 'Hello!'
51
+
52
+ expect(stub_send).to have_been_requested
53
+ end
54
+
55
+ it 'raises error with details if response body is not ok' do
56
+ stub_send.to_return body: 'ERROR|103'
57
+
58
+ expect { SmsManager.send_message number: '+420123456789', message: 'Hello!' }.to \
59
+ raise_error(SmsManager::SendingError) do |e|
60
+ expect(e.code).to eq(103)
61
+ expect(e.message).to eq('Neplatné uživatelské jméno nebo heslo')
62
+ end
63
+ end
64
+ end
65
+
66
+ def stub_send
67
+ stub_request(:get, 'http://http-api.smsmanager.cz/Send?message=Hello!&number=%2B420123456789&password=b4b976b7217ac3e336d9249ee15a3fc21fc69ce1&username=david@example.com')
68
+ end
69
+ end
@@ -0,0 +1,9 @@
1
+ require 'webmock/rspec'
2
+ require 'simplecov'
3
+ require 'coveralls'
4
+ require 'sms_manager'
5
+
6
+ SimpleCov.formatters = [SimpleCov::Formatter::HTMLFormatter, Coveralls::SimpleCov::Formatter]
7
+ SimpleCov.start
8
+
9
+ WebMock.disable_net_connect!
metadata CHANGED
@@ -1,62 +1,41 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sms_manager
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.2
5
- prerelease:
4
+ version: 0.2.1
6
5
  platform: ruby
7
6
  authors:
8
7
  - David Hrachovy
9
8
  autorequire:
10
9
  bindir: bin
11
10
  cert_chain: []
12
- date: 2013-08-07 00:00:00.000000000 Z
11
+ date: 2016-01-16 00:00:00.000000000 Z
13
12
  dependencies:
14
13
  - !ruby/object:Gem::Dependency
15
14
  name: httpclient
16
15
  requirement: !ruby/object:Gem::Requirement
17
- none: false
18
16
  requirements:
19
- - - ~>
17
+ - - "~>"
20
18
  - !ruby/object:Gem::Version
21
- version: 2.3.4.0
19
+ version: 2.7.0
22
20
  type: :runtime
23
21
  prerelease: false
24
22
  version_requirements: !ruby/object:Gem::Requirement
25
- none: false
26
23
  requirements:
27
- - - ~>
24
+ - - "~>"
28
25
  - !ruby/object:Gem::Version
29
- version: 2.3.4.0
26
+ version: 2.7.0
30
27
  - !ruby/object:Gem::Dependency
31
28
  name: bundler
32
29
  requirement: !ruby/object:Gem::Requirement
33
- none: false
34
30
  requirements:
35
- - - ~>
36
- - !ruby/object:Gem::Version
37
- version: '1.3'
38
- type: :development
39
- prerelease: false
40
- version_requirements: !ruby/object:Gem::Requirement
41
- none: false
42
- requirements:
43
- - - ~>
44
- - !ruby/object:Gem::Version
45
- version: '1.3'
46
- - !ruby/object:Gem::Dependency
47
- name: rake
48
- requirement: !ruby/object:Gem::Requirement
49
- none: false
50
- requirements:
51
- - - ! '>='
31
+ - - ">="
52
32
  - !ruby/object:Gem::Version
53
33
  version: '0'
54
34
  type: :development
55
35
  prerelease: false
56
36
  version_requirements: !ruby/object:Gem::Requirement
57
- none: false
58
37
  requirements:
59
- - - ! '>='
38
+ - - ">="
60
39
  - !ruby/object:Gem::Version
61
40
  version: '0'
62
41
  description: Ruby SDK for smsmanager.cz API
@@ -66,42 +45,45 @@ executables: []
66
45
  extensions: []
67
46
  extra_rdoc_files: []
68
47
  files:
69
- - .gitignore
48
+ - ".coveralls.yml"
49
+ - ".gitignore"
50
+ - ".travis.yml"
70
51
  - CHANGELOG.md
71
52
  - Gemfile
53
+ - Gemfile.lock
72
54
  - LICENSE.md
73
55
  - README.md
74
56
  - Rakefile
75
57
  - lib/sms_manager.rb
76
- - lib/sms_manager/client.rb
77
- - lib/sms_manager/configurable.rb
78
- - lib/sms_manager/error/configuration_error.rb
79
58
  - lib/sms_manager/error/sending_error.rb
80
59
  - lib/sms_manager/version.rb
81
60
  - sms_manager.gemspec
61
+ - spec/sms_manager_spec.rb
62
+ - spec/spec_helper.rb
82
63
  homepage: https://github.com/dayweek/sms_manager
83
64
  licenses:
84
65
  - MIT
66
+ metadata: {}
85
67
  post_install_message:
86
68
  rdoc_options: []
87
69
  require_paths:
88
70
  - lib
89
71
  required_ruby_version: !ruby/object:Gem::Requirement
90
- none: false
91
72
  requirements:
92
- - - ! '>='
73
+ - - ">="
93
74
  - !ruby/object:Gem::Version
94
75
  version: '0'
95
76
  required_rubygems_version: !ruby/object:Gem::Requirement
96
- none: false
97
77
  requirements:
98
- - - ! '>='
78
+ - - ">="
99
79
  - !ruby/object:Gem::Version
100
80
  version: '0'
101
81
  requirements: []
102
82
  rubyforge_project:
103
- rubygems_version: 1.8.24
83
+ rubygems_version: 2.4.6
104
84
  signing_key:
105
- specification_version: 3
85
+ specification_version: 4
106
86
  summary: SmsManager is a Ruby library for sending SMS messages by smsmanager.cz provider
107
- test_files: []
87
+ test_files:
88
+ - spec/sms_manager_spec.rb
89
+ - spec/spec_helper.rb
@@ -1,33 +0,0 @@
1
- require "sms_manager/error/sending_error"
2
- require "httpclient"
3
-
4
- module SmsManager
5
-
6
- class Client
7
- # options should be { number: String, message: String }
8
- def send_message(options = {})
9
- validate_send_message_options! options
10
- options = {
11
- username: SmsManager.instance_variable_get(:@username),
12
- password: SmsManager.instance_variable_get(:@hashed_password),
13
- number: options[:number],
14
- message: options[:message]
15
- }
16
- body = HTTPClient.get('http://http-api.smsmanager.cz/Send', options).body
17
- unless body =~ /^OK/
18
- raise SendingError, "Sending text '#{options[:message]}' to phone '#{options[:number]}' failed"
19
- end
20
- nil
21
- end
22
-
23
- private
24
-
25
- def validate_send_message_options!(options)
26
- options.each do |option, value|
27
- unless value.is_a?(String)
28
- raise ArgumentError, "Invalid #{option} specified: #{value} must be a string."
29
- end
30
- end
31
- end
32
- end
33
- end
@@ -1,30 +0,0 @@
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
@@ -1,3 +0,0 @@
1
- module SmsManager
2
- class ConfigurationError < ::ArgumentError; end
3
- end