cellcom 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/.gitignore +14 -0
- data/.rspec +2 -0
- data/.travis.yml +17 -0
- data/Gemfile +12 -0
- data/LICENSE.txt +22 -0
- data/README.md +61 -0
- data/Rakefile +11 -0
- data/cellcom.gemspec +22 -0
- data/lib/cellcom.rb +50 -0
- data/lib/cellcom/client.rb +36 -0
- data/lib/cellcom/request.rb +28 -0
- data/lib/cellcom/response.rb +36 -0
- data/lib/cellcom/sms.rb +69 -0
- data/lib/cellcom/version.rb +3 -0
- data/spec/lib/cellcom/client_spec.rb +65 -0
- data/spec/lib/cellcom/request_spec.rb +26 -0
- data/spec/lib/cellcom/response_spec.rb +25 -0
- data/spec/lib/cellcom/sms_spec.rb +55 -0
- data/spec/lib/cellcom_spec.rb +39 -0
- data/spec/spec_helper.rb +13 -0
- metadata +84 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: ec8f641893a1d5e7056904a055b2ef339b7d82fe
|
4
|
+
data.tar.gz: ebd13684c4f1b3206a0fc62ae7e43641904b1348
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: b3ced4b2e2eb4e96d9c5e3b52a35fc3247032228597c3f84be55a49a1eeb7ef6b4f51568cc25c8e22edb97df86bb52a5f36fdc0b7566115c48dcb877d7a023e9
|
7
|
+
data.tar.gz: 0ba304e1e2ec43989fe750f71dba80bb5b17324e36514a517a9707a3eb7a06e2ccb9d87a0c3c50c7d76ae49d4d9b1cba81b6cd2ef5ff8d705d8a7f952c954ea7
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/.travis.yml
ADDED
data/Gemfile
ADDED
@@ -0,0 +1,12 @@
|
|
1
|
+
source 'https://rubygems.org'
|
2
|
+
|
3
|
+
gemspec
|
4
|
+
|
5
|
+
gem 'rake', '~> 10.0'
|
6
|
+
gem 'rspec', '~> 3.2.0'
|
7
|
+
gem 'coveralls', require: false
|
8
|
+
#gem 'attestor', git: 'https://github.com/gregory/attestor.git', branch: 'cellcom_dev'
|
9
|
+
|
10
|
+
group :extra do
|
11
|
+
gem 'pry'
|
12
|
+
end
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2015 gregory
|
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,61 @@
|
|
1
|
+
# Cellcom
|
2
|
+
|
3
|
+
[](https://travis-ci.org/gregory/cellcom)
|
4
|
+
[](https://codeclimate.com/github/gregory/cellcom)
|
5
|
+
[](https://coveralls.io/r/gregory/cellcom?branch=master)
|
6
|
+
|
7
|
+
Cellcom is a ruby wrapper around the [Cellcom](https://www.cellcom.eu/en/) [HTTP API Spec](http://www.cellcom.be/documenten/Technical%20Specification%20HTTP%20gateway%20v8.pdf).
|
8
|
+
|
9
|
+
## Installation
|
10
|
+
|
11
|
+
Add this line to your application's Gemfile:
|
12
|
+
|
13
|
+
```ruby
|
14
|
+
gem 'cellcom'
|
15
|
+
```
|
16
|
+
|
17
|
+
And then execute:
|
18
|
+
|
19
|
+
$ bundle
|
20
|
+
|
21
|
+
Or install it yourself as:
|
22
|
+
|
23
|
+
$ gem install cellcom
|
24
|
+
|
25
|
+
## Usage
|
26
|
+
|
27
|
+
```rb
|
28
|
+
Cellcom::Configure do |config|
|
29
|
+
config.clid = 12345
|
30
|
+
config.gwid = 123
|
31
|
+
config.pwd = "256ea978c8f8752eaf87e7a"
|
32
|
+
end
|
33
|
+
|
34
|
+
Cellcom::Sms.new(m: 'my message', to: '32496233133', sid: '3228886991').deliver
|
35
|
+
```
|
36
|
+
|
37
|
+
If for some reason you want to send from multiple accounts:
|
38
|
+
|
39
|
+
```rb
|
40
|
+
credentials_hash = {
|
41
|
+
clid: 12345,
|
42
|
+
gwid: 123,
|
43
|
+
pwd : "256ea978c8f8752eaf87e7a"
|
44
|
+
}
|
45
|
+
Cellcom::Client.new(credentials_hash).deliver(m: 'my message', to: '32496233133', sid: '3228886991')
|
46
|
+
|
47
|
+
# or
|
48
|
+
|
49
|
+
sms = Cellcom::Sms.new(m: 'my message', to: '32496233133', sid: '3228886991')
|
50
|
+
client = Cellcom::Client.new(clid: 12345, gwid: 123, pwd : "256ea978c8f8752eaf87e7a")
|
51
|
+
sms.deliver(client)
|
52
|
+
|
53
|
+
```
|
54
|
+
|
55
|
+
## Contributing
|
56
|
+
|
57
|
+
1. Fork it ( https://github.com/gregory/cellcom/fork )
|
58
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
59
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
60
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
61
|
+
5. Create a new Pull Request
|
data/Rakefile
ADDED
data/cellcom.gemspec
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'cellcom/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "cellcom"
|
8
|
+
spec.version = Cellcom::VERSION
|
9
|
+
spec.authors = ["gregory"]
|
10
|
+
spec.email = ["greg2502@gmail.com"]
|
11
|
+
spec.summary = %q{Ruby Wrapper around the Cellcom api}
|
12
|
+
spec.description = %q{More info here: https://www.cellcom.eu/en/}
|
13
|
+
spec.homepage = "https://github.com/gregory/cellcom"
|
14
|
+
spec.license = "MIT"
|
15
|
+
|
16
|
+
spec.files = `git ls-files -z`.split("\x0")
|
17
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
18
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
|
+
spec.require_paths = ["lib"]
|
20
|
+
|
21
|
+
spec.add_dependency "attestor", "~> 2.2.1"
|
22
|
+
end
|
data/lib/cellcom.rb
ADDED
@@ -0,0 +1,50 @@
|
|
1
|
+
require 'ostruct'
|
2
|
+
require 'attestor'
|
3
|
+
require 'cellcom/version'
|
4
|
+
require 'cellcom/client'
|
5
|
+
|
6
|
+
module Cellcom
|
7
|
+
class Configuration < OpenStruct
|
8
|
+
include Attestor::Validations
|
9
|
+
|
10
|
+
CredentialsPolicy = Attestor::Policy.new(:credentials) do
|
11
|
+
REQUIRED_CREDENTIALS = [:pw, :clid, :gwid ]
|
12
|
+
|
13
|
+
def validate!
|
14
|
+
defined_keys = REQUIRED_CREDENTIALS & credentials.keys
|
15
|
+
unless REQUIRED_CREDENTIALS == defined_keys
|
16
|
+
invalid "#{(REQUIRED_CREDENTIALS-defined_keys).join(', ')} needs to be defined"
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
validates {CredentialsPolicy.new(self.to_h) }
|
22
|
+
|
23
|
+
def initialize(h={})
|
24
|
+
super default_attributes.merge(h)
|
25
|
+
end
|
26
|
+
|
27
|
+
private
|
28
|
+
|
29
|
+
def default_attributes
|
30
|
+
{
|
31
|
+
sid: '3228000000'
|
32
|
+
}
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
module_function
|
37
|
+
|
38
|
+
def client(params=config.to_h)
|
39
|
+
Client.new(params)
|
40
|
+
end
|
41
|
+
|
42
|
+
def config
|
43
|
+
@config ||= Configuration.new
|
44
|
+
end
|
45
|
+
|
46
|
+
def configure
|
47
|
+
config.tap { |configuration| yield(configuration) }
|
48
|
+
config.validate!
|
49
|
+
end
|
50
|
+
end
|
@@ -0,0 +1,36 @@
|
|
1
|
+
require 'cellcom/request'
|
2
|
+
require 'cellcom/response'
|
3
|
+
require 'cellcom/sms'
|
4
|
+
|
5
|
+
module Cellcom
|
6
|
+
class Client
|
7
|
+
Error = Class.new(StandardError)
|
8
|
+
|
9
|
+
attr_reader :credentials
|
10
|
+
|
11
|
+
def initialize(params=Cellcom.config.to_h)
|
12
|
+
Configuration::CredentialsPolicy.new(params).validate!
|
13
|
+
@credentials = params
|
14
|
+
rescue Attestor::InvalidError
|
15
|
+
fail(Error)
|
16
|
+
end
|
17
|
+
|
18
|
+
def deliver(params)
|
19
|
+
Sms::MessagePolicy.new(params).validate!
|
20
|
+
Response.new request(params).get
|
21
|
+
rescue Attestor::InvalidError
|
22
|
+
fail Error
|
23
|
+
end
|
24
|
+
|
25
|
+
private
|
26
|
+
|
27
|
+
def request(params)
|
28
|
+
payload = upcase_keys_of_hash @credentials.merge(params)
|
29
|
+
Request.new payload
|
30
|
+
end
|
31
|
+
|
32
|
+
def upcase_keys_of_hash(params)
|
33
|
+
Hash[params.map { |k,v| [k.upcase, v] }]
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
require 'net/http'
|
2
|
+
require 'uri'
|
3
|
+
|
4
|
+
module Cellcom
|
5
|
+
class Request
|
6
|
+
API_URL = 'http://www.cellcom.be/data/bulkHTTP.php'
|
7
|
+
|
8
|
+
def initialize(params={})
|
9
|
+
@params = params
|
10
|
+
end
|
11
|
+
|
12
|
+
def get(opts={})
|
13
|
+
connection(opts).start { |conn| conn.request(Net::HTTP::Get.new(uri)) }
|
14
|
+
end
|
15
|
+
|
16
|
+
def connection(opts={})
|
17
|
+
Net::HTTP.new(uri.host, uri.port).tap do |http|
|
18
|
+
http.open_timeout = http.read_timeout = opts[:timeout] if opts.key? :timeout
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
def uri
|
23
|
+
URI(API_URL).tap do |uri|
|
24
|
+
uri.query = URI.encode_www_form(@params)
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
@@ -0,0 +1,36 @@
|
|
1
|
+
require 'forwardable'
|
2
|
+
module Cellcom
|
3
|
+
class Response
|
4
|
+
extend Forwardable
|
5
|
+
|
6
|
+
ERRORS = {
|
7
|
+
'ERROR 10' => ['WrongCredentials', 'Wrong client id or password'],
|
8
|
+
'ERROR 20' => ['WrongGateway', 'Wrong gateway number (GWID)'],
|
9
|
+
'ERROR 30' => ['NotEnoughCredit', 'Not enough credit left'],
|
10
|
+
'ERROR 40' => ['WrongDestination', 'Recipient number is wrong, or destination not covered'],
|
11
|
+
'ERROR 50' => ['SenderIdNotSupported', 'Sender ID not supported'],
|
12
|
+
'ERROR 60' => ['InvalidMessage', 'Message is too long or invalid'],
|
13
|
+
'ERROR 70' => ['Timeout', 'Timeout, please retry later'],
|
14
|
+
'ERROR 80' => ['InternalError', 'Internal error, please contact Cellcom']
|
15
|
+
}.freeze
|
16
|
+
|
17
|
+
ERRORS.each do |key,(class_name, _)|
|
18
|
+
const_set(class_name, Class.new(StandardError))
|
19
|
+
end
|
20
|
+
|
21
|
+
attr_reader :raw_response
|
22
|
+
def_delegators :@raw_response, :code, :body
|
23
|
+
|
24
|
+
alias_method :status, :code
|
25
|
+
|
26
|
+
def initialize(raw_response)
|
27
|
+
@raw_response = raw_response
|
28
|
+
raise_error(raw_response.body) if ERRORS.keys.include?(raw_response.body)
|
29
|
+
end
|
30
|
+
|
31
|
+
def raise_error(error_key)
|
32
|
+
error_val = ERRORS.fetch(error_key)
|
33
|
+
fail Response.const_get(error_val[0]), error_val[1]
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
data/lib/cellcom/sms.rb
ADDED
@@ -0,0 +1,69 @@
|
|
1
|
+
require 'forwardable'
|
2
|
+
require 'attestor'
|
3
|
+
|
4
|
+
module Cellcom
|
5
|
+
class Sms < OpenStruct
|
6
|
+
extend Forwardable
|
7
|
+
include Attestor::Validations
|
8
|
+
|
9
|
+
MessagePolicy = Attestor::Policy.new(:attributes) do
|
10
|
+
REQUIRED_ATTRIBUTES = [:to, :m]
|
11
|
+
|
12
|
+
def validate!
|
13
|
+
validate_require_attributes
|
14
|
+
validate_ttl if attributes[:ttl]
|
15
|
+
validate_mid if attributes[:mid]
|
16
|
+
validate_msg_hexa_encoded if attributes[:cod] == 2
|
17
|
+
end
|
18
|
+
|
19
|
+
private
|
20
|
+
|
21
|
+
def validate_ttl
|
22
|
+
unless 60 <= attributes[:ttl] && attributes[:ttl] <= 10080
|
23
|
+
invalid "invalid ttl: Must be: 60 <= ttl <= 10080(default)"
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
def validate_mid
|
28
|
+
unless 1 < attributes[:mid] && attributes[:mid] < 4294967295
|
29
|
+
invalid "invalid mid: Must be: 1 < mid < 4294967295"
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
def validate_require_attributes
|
34
|
+
undefined_keys = REQUIRED_ATTRIBUTES - attributes.keys
|
35
|
+
unless undefined_keys.empty?
|
36
|
+
invalid "invalid message: #{undefined_keys.join(', ')} needs to be defined"
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
def validate_msg_hexa_encoded
|
41
|
+
unless attributes[:m][/\H/]
|
42
|
+
invalid "message needs to be hexadecimal when cod == 2"
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
def initialize(params={})
|
48
|
+
super(default_values.merge(params))
|
49
|
+
end
|
50
|
+
|
51
|
+
validates { MessagePolicy.new(self.to_h) }
|
52
|
+
|
53
|
+
def deliver(client=Cellcom.client)
|
54
|
+
client.deliver(self.to_h)
|
55
|
+
end
|
56
|
+
|
57
|
+
def to_hex
|
58
|
+
message.unpack('H*')[0]
|
59
|
+
end
|
60
|
+
|
61
|
+
private
|
62
|
+
|
63
|
+
def default_values
|
64
|
+
{
|
65
|
+
ttl: 10080
|
66
|
+
}
|
67
|
+
end
|
68
|
+
end
|
69
|
+
end
|
@@ -0,0 +1,65 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Cellcom::Client do
|
4
|
+
let(:credentials) do
|
5
|
+
{
|
6
|
+
clid: 'client id',
|
7
|
+
gwid: 'gateway id',
|
8
|
+
pw: 'password'
|
9
|
+
}
|
10
|
+
end
|
11
|
+
|
12
|
+
let(:client) { described_class.new(credentials) }
|
13
|
+
|
14
|
+
context 'when credential missing' do
|
15
|
+
let(:credentials) do
|
16
|
+
{
|
17
|
+
clid: 'client id',
|
18
|
+
gwid: 'gateway id',
|
19
|
+
}
|
20
|
+
end
|
21
|
+
|
22
|
+
it 'fails' do
|
23
|
+
expect { client }.to raise_error(Cellcom::Client::Error)
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
describe '#deliver(payload)' do
|
28
|
+
let(:message) { 'foo bar' }
|
29
|
+
let(:payload) do
|
30
|
+
{
|
31
|
+
m: message,
|
32
|
+
to: '32496233133',
|
33
|
+
sid: '3228886991'
|
34
|
+
}
|
35
|
+
end
|
36
|
+
|
37
|
+
let(:code) { 200 }
|
38
|
+
let(:response_body) { 'OK 11111111111111111111111' }
|
39
|
+
let(:response) { OpenStruct.new(code: code, body: response_body) }
|
40
|
+
|
41
|
+
before do
|
42
|
+
client.stub_chain(:request, :get).and_return(response)
|
43
|
+
end
|
44
|
+
|
45
|
+
subject { client.deliver(payload) }
|
46
|
+
|
47
|
+
it 'sends the message' do
|
48
|
+
expect(subject.status).to eq code
|
49
|
+
expect(subject.body).to eq response_body
|
50
|
+
end
|
51
|
+
|
52
|
+
context 'when invalid sms' do
|
53
|
+
let(:payload) do
|
54
|
+
{
|
55
|
+
to: '32496233133',
|
56
|
+
sid: '3228886991'
|
57
|
+
}
|
58
|
+
end
|
59
|
+
|
60
|
+
it 'fails exception' do
|
61
|
+
expect { subject }.to raise_error(Cellcom::Client::Error)
|
62
|
+
end
|
63
|
+
end
|
64
|
+
end
|
65
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Cellcom::Request do
|
4
|
+
describe '#get(opts={})' do
|
5
|
+
let(:params) do
|
6
|
+
{
|
7
|
+
M: 'foo',
|
8
|
+
SID: 'bar'
|
9
|
+
}
|
10
|
+
end
|
11
|
+
let(:connection) { double(:connection) }
|
12
|
+
let(:http) { double(:http) }
|
13
|
+
let(:request) { described_class.new(params) }
|
14
|
+
|
15
|
+
before do
|
16
|
+
expect(request).to receive(:connection).and_return(http)
|
17
|
+
expect(http).to receive(:start).and_yield(connection)
|
18
|
+
end
|
19
|
+
|
20
|
+
after { request.get }
|
21
|
+
|
22
|
+
it 'makes the request' do
|
23
|
+
expect(connection).to receive(:request).with(an_instance_of(Net::HTTP::Get))
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Cellcom::Response do
|
4
|
+
describe '.new(response)' do
|
5
|
+
let(:code) { 200 }
|
6
|
+
let(:response_body) { 'OK 11111111111111111111111' }
|
7
|
+
let(:raw_response) { OpenStruct.new(code: code, body: response_body) }
|
8
|
+
let(:response) { described_class.new(raw_response) }
|
9
|
+
|
10
|
+
it 'sets the response' do
|
11
|
+
expect(response.code).to eq code
|
12
|
+
expect(response.body).to eq response_body
|
13
|
+
end
|
14
|
+
|
15
|
+
described_class::ERRORS.each do |resp_body, (exception, message)|
|
16
|
+
context "#{message}" do
|
17
|
+
let(:response_body) { resp_body }
|
18
|
+
|
19
|
+
it "fails a #{exception} exception" do
|
20
|
+
expect { response }.to raise_error(Cellcom::Response.const_get(exception))
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
@@ -0,0 +1,55 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Cellcom::Sms do
|
4
|
+
let(:message) { 'foo bar' }
|
5
|
+
let(:ttl) { 70 }
|
6
|
+
let(:mid) { 70 }
|
7
|
+
let(:payload) do
|
8
|
+
{
|
9
|
+
m: message,
|
10
|
+
to: '32496233133',
|
11
|
+
sid: '3228886991',
|
12
|
+
ttl: ttl,
|
13
|
+
mid: mid
|
14
|
+
}
|
15
|
+
end
|
16
|
+
|
17
|
+
describe '.new(params)' do
|
18
|
+
subject { described_class.new(payload) }
|
19
|
+
|
20
|
+
it 'sets the params' do
|
21
|
+
payload.each { |k,v| expect(subject.send(k)).to eq v }
|
22
|
+
end
|
23
|
+
|
24
|
+
it 'is valid' do
|
25
|
+
expect(subject.validate).to be_valid
|
26
|
+
end
|
27
|
+
|
28
|
+
context 'when invalid ttl' do
|
29
|
+
let(:ttl) { 50 }
|
30
|
+
|
31
|
+
it 'fails at validation' do
|
32
|
+
expect { subject.validate! }.to raise_error(Attestor::InvalidError)
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
context 'when invalid mid' do
|
37
|
+
let(:mid) { 4294967296 }
|
38
|
+
|
39
|
+
it 'fails at validation' do
|
40
|
+
expect { subject.validate! }.to raise_error(Attestor::InvalidError)
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
describe '.deliver(client=Cellcom.client)' do
|
46
|
+
let(:client) { double(:client) }
|
47
|
+
let(:sms) { described_class.new(payload) }
|
48
|
+
|
49
|
+
after { sms.deliver(client) }
|
50
|
+
|
51
|
+
it 'sends calls deliver on the client' do
|
52
|
+
expect(client).to receive(:deliver).with(sms.to_h)
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
@@ -0,0 +1,39 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Cellcom do
|
4
|
+
describe '.configure' do
|
5
|
+
let(:credentials) do
|
6
|
+
{
|
7
|
+
clid: 'client id',
|
8
|
+
gwid: 'gateway id',
|
9
|
+
pw: 'password'
|
10
|
+
}
|
11
|
+
end
|
12
|
+
|
13
|
+
subject do
|
14
|
+
described_class.configure { |c| credentials.each { |k,v| c.send(:"#{k}=", v) } }
|
15
|
+
end
|
16
|
+
|
17
|
+
it 'has the config variables' do
|
18
|
+
subject
|
19
|
+
credentials.each { |k,v| expect(described_class.config.send(k)).to eq v }
|
20
|
+
end
|
21
|
+
|
22
|
+
context 'when credentials missing' do
|
23
|
+
let(:credentials) do
|
24
|
+
{
|
25
|
+
clid: 'client id',
|
26
|
+
gwid: 'gateway id',
|
27
|
+
}
|
28
|
+
end
|
29
|
+
|
30
|
+
before do
|
31
|
+
described_class.instance_variable_set("@config", nil)
|
32
|
+
end
|
33
|
+
|
34
|
+
it 'fails if credentials missing' do
|
35
|
+
expect { subject }.to raise_error(Attestor::InvalidError)
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
data/spec/spec_helper.rb
ADDED
metadata
ADDED
@@ -0,0 +1,84 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: cellcom
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- gregory
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2015-05-31 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: attestor
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: 2.2.1
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: 2.2.1
|
27
|
+
description: 'More info here: https://www.cellcom.eu/en/'
|
28
|
+
email:
|
29
|
+
- greg2502@gmail.com
|
30
|
+
executables: []
|
31
|
+
extensions: []
|
32
|
+
extra_rdoc_files: []
|
33
|
+
files:
|
34
|
+
- ".gitignore"
|
35
|
+
- ".rspec"
|
36
|
+
- ".travis.yml"
|
37
|
+
- Gemfile
|
38
|
+
- LICENSE.txt
|
39
|
+
- README.md
|
40
|
+
- Rakefile
|
41
|
+
- cellcom.gemspec
|
42
|
+
- lib/cellcom.rb
|
43
|
+
- lib/cellcom/client.rb
|
44
|
+
- lib/cellcom/request.rb
|
45
|
+
- lib/cellcom/response.rb
|
46
|
+
- lib/cellcom/sms.rb
|
47
|
+
- lib/cellcom/version.rb
|
48
|
+
- spec/lib/cellcom/client_spec.rb
|
49
|
+
- spec/lib/cellcom/request_spec.rb
|
50
|
+
- spec/lib/cellcom/response_spec.rb
|
51
|
+
- spec/lib/cellcom/sms_spec.rb
|
52
|
+
- spec/lib/cellcom_spec.rb
|
53
|
+
- spec/spec_helper.rb
|
54
|
+
homepage: https://github.com/gregory/cellcom
|
55
|
+
licenses:
|
56
|
+
- MIT
|
57
|
+
metadata: {}
|
58
|
+
post_install_message:
|
59
|
+
rdoc_options: []
|
60
|
+
require_paths:
|
61
|
+
- lib
|
62
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
63
|
+
requirements:
|
64
|
+
- - ">="
|
65
|
+
- !ruby/object:Gem::Version
|
66
|
+
version: '0'
|
67
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
68
|
+
requirements:
|
69
|
+
- - ">="
|
70
|
+
- !ruby/object:Gem::Version
|
71
|
+
version: '0'
|
72
|
+
requirements: []
|
73
|
+
rubyforge_project:
|
74
|
+
rubygems_version: 2.4.5
|
75
|
+
signing_key:
|
76
|
+
specification_version: 4
|
77
|
+
summary: Ruby Wrapper around the Cellcom api
|
78
|
+
test_files:
|
79
|
+
- spec/lib/cellcom/client_spec.rb
|
80
|
+
- spec/lib/cellcom/request_spec.rb
|
81
|
+
- spec/lib/cellcom/response_spec.rb
|
82
|
+
- spec/lib/cellcom/sms_spec.rb
|
83
|
+
- spec/lib/cellcom_spec.rb
|
84
|
+
- spec/spec_helper.rb
|