sms_gateway_to 0.1.0 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 0cb120782e2fdfd35481deeb0abaf200ac28637e
4
- data.tar.gz: 9deb9fd1b583301d65864bdeac143044a4658cbd
3
+ metadata.gz: 07f4d377903576016a482c4e3ef4d8324f9be504
4
+ data.tar.gz: f2002aaad7c3890f892e7351cb79589289001c9b
5
5
  SHA512:
6
- metadata.gz: c28d67205040f135b76e037b29685c2aeb9e6885e9aba97eb362917e73320de580bacfd6225a38433002cdf99fd4b7d71af0566d93a9d6e4e577966b409e3a83
7
- data.tar.gz: 72cb7780ab54b6e8edb64575492a4c64af3fc6d12a664c8441b11765a368b896057da1faff1c307c05d238648e7e076f1f32bc393faff18c49e1a56216a2d8dd
6
+ metadata.gz: e0d8773873d9ab6a690df0861ba237558f08f485957af9b73ad757c7cb2e0344ebe1323baff2d96f92012a4ee8c8c94bcb6c9cce31da2f18e0eea07b7aacf703
7
+ data.tar.gz: 5fe73131a62775c045822a7fbf2ed824f527888b66258c93a107425e5a25389f64e03170ad8afaed10f01ed5579b63ced93565560529b7898e355d6a0080029d
data/.gitignore CHANGED
@@ -8,3 +8,4 @@
8
8
  /spec/reports/
9
9
  /tmp/
10
10
  .DS_Store
11
+ *.sw*
data/README.md CHANGED
@@ -1,8 +1,6 @@
1
1
  # SmsGatewayTo
2
2
 
3
- Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/sms_gateway_to`. To experiment with that code, run `bin/console` for an interactive prompt.
4
-
5
- TODO: Delete this and the text above, and describe your gem
3
+ SMSGatewayTo gem is a ruby wrapper for the smsgateway.to service.
6
4
 
7
5
  ## Installation
8
6
 
@@ -22,7 +20,43 @@ Or install it yourself as:
22
20
 
23
21
  ## Usage
24
22
 
25
- TODO: Write usage instructions here
23
+ To use the gem as a standalone library
24
+
25
+ ```ruby
26
+ # Product token aka API key from smsgateway.to
27
+
28
+ client = SmsGatewayTo::Client.new("producttoken")
29
+
30
+ # To send an sms
31
+ # from - The from address in the sms
32
+ # to - The number you want to send the sms to
33
+ # message - The text message you want to send
34
+
35
+ client.send_message(from, to, message)
36
+ ```
37
+
38
+ If you are using it with rails
39
+
40
+
41
+ 1. Create a smsgateway.yaml file in the config folder of the rails app
42
+
43
+ ```ruby
44
+ Sample smsgateway.yaml file
45
+
46
+ development:
47
+ token: dev-token
48
+ production:
49
+ token: production-token
50
+ test:
51
+ token: test-token
52
+ ```
53
+
54
+ 2. The Gem will automatically chose the right token based on the environment.
55
+
56
+ ```ruby
57
+ client = SmsGatewayto.client # returns default client based on the environment
58
+ client.send_message(from, to, message)
59
+ ```
26
60
 
27
61
  ## Development
28
62
 
@@ -32,7 +66,7 @@ To install this gem onto your local machine, run `bundle exec rake install`. To
32
66
 
33
67
  ## Contributing
34
68
 
35
- Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/sms_gateway_to. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
69
+ Bug reports and pull requests are welcome on GitHub at https://github.com/h0lyalg0rithm/sms_gateway_to. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
36
70
 
37
71
 
38
72
  ## License
@@ -1,17 +1,28 @@
1
- require 'httparty'
2
-
3
1
  module SmsGatewayTo
4
- class Client
5
- include HTTParty
6
- base_uri 'https://sgw01.cm.nl'
7
- attr_reader :product_token
2
+ class Client
3
+ include HTTParty
4
+ base_uri 'https://sgw01.cm.nl'
5
+ attr_reader :product_token
6
+
7
+ def initialize(product_token)
8
+ @product_token = product_token
9
+ end
10
+
11
+ def send_message(from, to, message)
12
+ self.class.get("/gateway.ashx", { query: {producttoken: @product_token, from: from, to: to, body: message}})
13
+ end
14
+
15
+ def send_message!(from, to, message)
16
+ response = send_message(from, to, message)
17
+ unless response.nil? || response.empty?
18
+ handle_error(response)
19
+ end
20
+ end
8
21
 
9
- def initialize(product_token)
10
- @product_token = product_token
11
- end
22
+ private
12
23
 
13
- def send_message(from, to, message)
14
- self.class.get("/gateway.ashx", { query: {producttoken: @product_token, from: from, to: to, body: message}})
15
- end
16
- end
17
- end
24
+ def handle_error(response)
25
+ SmsGatewayTo::ErrorHandler.new(response).response
26
+ end
27
+ end
28
+ end
@@ -1,8 +1,8 @@
1
1
  module SmsGatewayTo
2
- class Config
3
- attr_reader :token
4
- def initialize(cred)
5
- @token = cred['token']
6
- end
7
- end
8
- end
2
+ class Config
3
+ attr_reader :token
4
+ def initialize(cred)
5
+ @token = cred['token']
6
+ end
7
+ end
8
+ end
@@ -0,0 +1,24 @@
1
+ module SmsGatewayTo
2
+ class ErrorHandler
3
+ attr_accessor :error
4
+
5
+ def initialize(error)
6
+ @error = error
7
+ end
8
+
9
+ def response
10
+ case @error
11
+ when /Error: ERROR Parameter 'body' is required/
12
+ raise SmsGatewayTo::ParameterError.new('Body is required')
13
+ when /Error: ERROR Parameter \'(\w+)\'/
14
+ raise SmsGatewayTo::ParameterError.new("#{$1} is invalid")
15
+ when /Error: ERROR No sender name provided/
16
+ raise SmsGatewayTo::ParameterError.new("Sender name is required")
17
+ when /Error: ERROR (.+)/
18
+ raise SmsGatewayTo::StandardError.new("#{$1}")
19
+ else raise SmsGatewayTo::StandardError
20
+ end
21
+ end
22
+
23
+ end
24
+ end
@@ -0,0 +1,4 @@
1
+ module SmsGatewayTo
2
+ class StandardError < StandardError; end
3
+ class ParameterError < StandardError; end
4
+ end
@@ -12,7 +12,7 @@ module SmsGatewayTo
12
12
 
13
13
  module Rails
14
14
 
15
- def self.setup
15
+ def self.setup
16
16
  load_yaml_config
17
17
  nil
18
18
  end
@@ -44,4 +44,4 @@ module SmsGatewayTo
44
44
  end
45
45
  end
46
46
 
47
- end
47
+ end
@@ -1,3 +1,3 @@
1
1
  module SmsGatewayTo
2
- VERSION = "0.1.0"
2
+ VERSION = '0.2.0'
3
3
  end
@@ -1,27 +1,29 @@
1
- require "sms_gateway_to/version"
2
- require "sms_gateway_to/rails"
3
- require "sms_gateway_to/client"
4
- require "sms_gateway_to/config"
1
+ require 'httparty'
2
+ require 'sms_gateway_to/version'
3
+ require 'sms_gateway_to/rails'
4
+ require 'sms_gateway_to/client'
5
+ require 'sms_gateway_to/config'
6
+ require 'sms_gateway_to/error_handler'
7
+ require 'sms_gateway_to/exceptions'
5
8
 
6
9
  module SmsGatewayTo
10
+ class << self
11
+ attr_accessor :config
12
+ @@config = nil
13
+ def configure(credentials)
14
+ @@config = SmsGatewayTo::Config.new(credentials)
15
+ @@client = build_client
16
+ end
17
+ def config
18
+ @@config
19
+ end
7
20
 
8
- class << self
9
- attr_accessor :config
10
- @@config = nil
11
- def configure(credentials)
12
- @@config = SmsGatewayTo::Config.new(credentials)
13
- @@client = build_client
14
- end
15
- def config
16
- @@config
17
- end
21
+ def client
22
+ @@client
23
+ end
18
24
 
19
- def client
20
- @@client
21
- end
22
-
23
- def build_client
24
- SmsGatewayTo::Client.new(@@config.token)
25
- end
26
- end
27
- end
25
+ def build_client
26
+ SmsGatewayTo::Client.new(@@config.token)
27
+ end
28
+ end
29
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sms_gateway_to
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Suraj Shirvankar
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2016-05-30 00:00:00.000000000 Z
11
+ date: 2016-07-02 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: nokogiri
@@ -100,6 +100,8 @@ files:
100
100
  - lib/sms_gateway_to.rb
101
101
  - lib/sms_gateway_to/client.rb
102
102
  - lib/sms_gateway_to/config.rb
103
+ - lib/sms_gateway_to/error_handler.rb
104
+ - lib/sms_gateway_to/exceptions.rb
103
105
  - lib/sms_gateway_to/rails.rb
104
106
  - lib/sms_gateway_to/version.rb
105
107
  - sms_gateway_to.gemspec