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 +4 -4
- data/.gitignore +1 -0
- data/README.md +39 -5
- data/lib/sms_gateway_to/client.rb +25 -14
- data/lib/sms_gateway_to/config.rb +7 -7
- data/lib/sms_gateway_to/error_handler.rb +24 -0
- data/lib/sms_gateway_to/exceptions.rb +4 -0
- data/lib/sms_gateway_to/rails.rb +2 -2
- data/lib/sms_gateway_to/version.rb +1 -1
- data/lib/sms_gateway_to.rb +25 -23
- metadata +4 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 07f4d377903576016a482c4e3ef4d8324f9be504
|
4
|
+
data.tar.gz: f2002aaad7c3890f892e7351cb79589289001c9b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e0d8773873d9ab6a690df0861ba237558f08f485957af9b73ad757c7cb2e0344ebe1323baff2d96f92012a4ee8c8c94bcb6c9cce31da2f18e0eea07b7aacf703
|
7
|
+
data.tar.gz: 5fe73131a62775c045822a7fbf2ed824f527888b66258c93a107425e5a25389f64e03170ad8afaed10f01ed5579b63ced93565560529b7898e355d6a0080029d
|
data/.gitignore
CHANGED
data/README.md
CHANGED
@@ -1,8 +1,6 @@
|
|
1
1
|
# SmsGatewayTo
|
2
2
|
|
3
|
-
|
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
|
-
|
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/
|
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
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
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
|
-
|
10
|
-
@product_token = product_token
|
11
|
-
end
|
22
|
+
private
|
12
23
|
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
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
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
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
|
data/lib/sms_gateway_to/rails.rb
CHANGED
data/lib/sms_gateway_to.rb
CHANGED
@@ -1,27 +1,29 @@
|
|
1
|
-
require
|
2
|
-
require
|
3
|
-
require
|
4
|
-
require
|
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
|
-
|
9
|
-
|
10
|
-
|
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
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
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.
|
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-
|
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
|