sisal-timwe 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +17 -0
- data/Gemfile +5 -0
- data/LICENSE +22 -0
- data/README.md +29 -0
- data/Rakefile +9 -0
- data/lib/sisal/providers/timwe_provider.rb +71 -0
- data/lib/sisal-timwe/version.rb +5 -0
- data/lib/sisal-timwe.rb +2 -0
- data/sisal-timwe.gemspec +23 -0
- data/spec/sisal/providers/timwe_provider_spec.rb +45 -0
- data/spec/spec_helper.rb +5 -0
- metadata +91 -0
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2012 Vinicius Horewicz
|
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,29 @@
|
|
1
|
+
# Sisal::Timwe
|
2
|
+
|
3
|
+
TODO: Write a gem description
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
gem 'sisal-timwe'
|
10
|
+
|
11
|
+
And then execute:
|
12
|
+
|
13
|
+
$ bundle
|
14
|
+
|
15
|
+
Or install it yourself as:
|
16
|
+
|
17
|
+
$ gem install sisal-timwe
|
18
|
+
|
19
|
+
## Usage
|
20
|
+
|
21
|
+
TODO: Write usage instructions here
|
22
|
+
|
23
|
+
## Contributing
|
24
|
+
|
25
|
+
1. Fork it
|
26
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
27
|
+
3. Commit your changes (`git commit -am 'Added some feature'`)
|
28
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
29
|
+
5. Create new Pull Request
|
data/Rakefile
ADDED
@@ -0,0 +1,71 @@
|
|
1
|
+
require "sisal/provider"
|
2
|
+
require "rest-client"
|
3
|
+
|
4
|
+
module Sisal
|
5
|
+
module Providers
|
6
|
+
def self.timwe(options)
|
7
|
+
TimweProvider.new(options)
|
8
|
+
end
|
9
|
+
|
10
|
+
class TimweProvider < Provider
|
11
|
+
def initialize(options = {})
|
12
|
+
@partner_role_id = options[:partner_role_id]
|
13
|
+
@password = options[:password]
|
14
|
+
@product_id = options[:product_id]
|
15
|
+
@price_point_id = options[:price_point_id]
|
16
|
+
end
|
17
|
+
|
18
|
+
def send(message, options = {})
|
19
|
+
params = {
|
20
|
+
PartnerRoleId: @partner_role_id,
|
21
|
+
Password: @password,
|
22
|
+
ProductId: @product_id,
|
23
|
+
PricePointId: @price_point_id,
|
24
|
+
Destination: message.to,
|
25
|
+
Text: message.text,
|
26
|
+
ExtTxId: options[:exttxid] || Time.now.to_i,
|
27
|
+
OpId: options[:opid] || "1"
|
28
|
+
}
|
29
|
+
|
30
|
+
begin
|
31
|
+
response = RestClient.get(API_URL, params: params)
|
32
|
+
code = response.to_s.dup.to_i
|
33
|
+
|
34
|
+
Sisal::Response.new((code > 0), code, status_code(code))
|
35
|
+
rescue ::SocketError, ::Errno::ETIMEDOUT, ::RestClient::Exception => e
|
36
|
+
Sisal::Response.new(false, nil, e.message)
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
private
|
41
|
+
|
42
|
+
API_URL = "http://mb.timwe.com/sendMT"
|
43
|
+
STATUS_CODES = {
|
44
|
+
0 => "General Error",
|
45
|
+
-1 => "Invalid Destination",
|
46
|
+
-2 => "Invalid Operator",
|
47
|
+
-3 => "Invalid Credentials",
|
48
|
+
-4 => "Invalid Price Point",
|
49
|
+
-6 => "Invalid Partner Product",
|
50
|
+
-10 => "Transaction in process",
|
51
|
+
-12 => "Blacklisted destination",
|
52
|
+
-19 => "Invalid Message Priority",
|
53
|
+
-20 => "Invalid Message Purpose",
|
54
|
+
-81 => "Blocked Billing MT for Unsubscribed Customer",
|
55
|
+
-82 => "Blacklisted destination (Backoffice)",
|
56
|
+
-83 => "Blacklisted destination (User Request)",
|
57
|
+
-84 => "Blacklisted destination (User Chargeable Limit)",
|
58
|
+
-85 => "Blacklisted destination (User MT Limit reach)",
|
59
|
+
-86 => "Blacklisted destination (Operator Request)",
|
60
|
+
-87 => "Blacklisted destination (Fraud)",
|
61
|
+
-88 => "Invalid Partner External Id",
|
62
|
+
-89 => "Invalid Sender Id",
|
63
|
+
-90 => "Invalid Text"
|
64
|
+
}
|
65
|
+
|
66
|
+
def status_code(code)
|
67
|
+
code > 0 ? "Success" : STATUS_CODES[code]
|
68
|
+
end
|
69
|
+
end
|
70
|
+
end
|
71
|
+
end
|
data/lib/sisal-timwe.rb
ADDED
data/sisal-timwe.gemspec
ADDED
@@ -0,0 +1,23 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
require File.expand_path("../lib/sisal-timwe/version", __FILE__)
|
3
|
+
|
4
|
+
Gem::Specification.new do |gem|
|
5
|
+
gem.authors = ["Vinicius Horewicz"]
|
6
|
+
gem.email = ["vinicius@horewi.cz"]
|
7
|
+
gem.description = %q{Timwe provider for Sisal}
|
8
|
+
gem.summary = %q{Timwe provider for Sisal}
|
9
|
+
gem.homepage = "https://github.com/wicz/sisal-timwe"
|
10
|
+
|
11
|
+
gem.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
12
|
+
gem.files = `git ls-files`.split("\n")
|
13
|
+
gem.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
14
|
+
gem.name = "sisal-timwe"
|
15
|
+
gem.require_paths = ["lib"]
|
16
|
+
gem.version = Sisal::Timwe::VERSION
|
17
|
+
|
18
|
+
# gem.add_dependency "sisal", "~> 0.0"
|
19
|
+
gem.add_dependency "rest-client", "~> 1.6"
|
20
|
+
|
21
|
+
gem.add_development_dependency "rspec", "~> 2.8"
|
22
|
+
gem.add_development_dependency "webmock", "~> 1.7"
|
23
|
+
end
|
@@ -0,0 +1,45 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
describe Sisal::Providers::TimweProvider do
|
4
|
+
let(:timwe) { Sisal::Providers::TimweProvider.new }
|
5
|
+
let(:message) { stub(:message, to: "1234", text: "ohai") }
|
6
|
+
|
7
|
+
before(:each) do
|
8
|
+
stub_request(:get, /.*OpId=connfail.*/).to_raise(::SocketError)
|
9
|
+
stub_request(:get, /.*OpId=timeout.*/).to_raise(::Errno::ETIMEDOUT)
|
10
|
+
stub_request(:get, /.*OpId=notfound.*/).to_raise(::RestClient::Exception)
|
11
|
+
stub_request(:get, /.*OpId=error.*/).to_return(body: "0")
|
12
|
+
stub_request(:get, /.*OpId=success.*/).to_return(body: "123")
|
13
|
+
end
|
14
|
+
|
15
|
+
describe "#send" do
|
16
|
+
it "handles connection failure" do
|
17
|
+
response = timwe.send(message, opid: "connfail")
|
18
|
+
response.success?.should be_false
|
19
|
+
end
|
20
|
+
|
21
|
+
it "handles timeout" do
|
22
|
+
response = timwe.send(message, opid: "timeout")
|
23
|
+
response.success?.should be_false
|
24
|
+
end
|
25
|
+
|
26
|
+
it "handles rest-client's exceptions" do
|
27
|
+
response = timwe.send(message, opid: "notfound")
|
28
|
+
response.success?.should be_false
|
29
|
+
end
|
30
|
+
|
31
|
+
it "sets status codes and messages on error" do
|
32
|
+
response = timwe.send(message, opid: "error")
|
33
|
+
response.success?.should be_false
|
34
|
+
response.code.should eq(0)
|
35
|
+
response.message.should eq("General Error")
|
36
|
+
end
|
37
|
+
|
38
|
+
it "succeeds when return code greater than zero" do
|
39
|
+
response = timwe.send(message, opid: "success")
|
40
|
+
response.success?.should be_true
|
41
|
+
response.code.should eq(123)
|
42
|
+
response.message.should eq("Success")
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
data/spec/spec_helper.rb
ADDED
metadata
ADDED
@@ -0,0 +1,91 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: sisal-timwe
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Vinicius Horewicz
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2012-05-10 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: rest-client
|
16
|
+
requirement: &2171652060 !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ~>
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: '1.6'
|
22
|
+
type: :runtime
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: *2171652060
|
25
|
+
- !ruby/object:Gem::Dependency
|
26
|
+
name: rspec
|
27
|
+
requirement: &2171651560 !ruby/object:Gem::Requirement
|
28
|
+
none: false
|
29
|
+
requirements:
|
30
|
+
- - ~>
|
31
|
+
- !ruby/object:Gem::Version
|
32
|
+
version: '2.8'
|
33
|
+
type: :development
|
34
|
+
prerelease: false
|
35
|
+
version_requirements: *2171651560
|
36
|
+
- !ruby/object:Gem::Dependency
|
37
|
+
name: webmock
|
38
|
+
requirement: &2171651100 !ruby/object:Gem::Requirement
|
39
|
+
none: false
|
40
|
+
requirements:
|
41
|
+
- - ~>
|
42
|
+
- !ruby/object:Gem::Version
|
43
|
+
version: '1.7'
|
44
|
+
type: :development
|
45
|
+
prerelease: false
|
46
|
+
version_requirements: *2171651100
|
47
|
+
description: Timwe provider for Sisal
|
48
|
+
email:
|
49
|
+
- vinicius@horewi.cz
|
50
|
+
executables: []
|
51
|
+
extensions: []
|
52
|
+
extra_rdoc_files: []
|
53
|
+
files:
|
54
|
+
- .gitignore
|
55
|
+
- Gemfile
|
56
|
+
- LICENSE
|
57
|
+
- README.md
|
58
|
+
- Rakefile
|
59
|
+
- lib/sisal-timwe.rb
|
60
|
+
- lib/sisal-timwe/version.rb
|
61
|
+
- lib/sisal/providers/timwe_provider.rb
|
62
|
+
- sisal-timwe.gemspec
|
63
|
+
- spec/sisal/providers/timwe_provider_spec.rb
|
64
|
+
- spec/spec_helper.rb
|
65
|
+
homepage: https://github.com/wicz/sisal-timwe
|
66
|
+
licenses: []
|
67
|
+
post_install_message:
|
68
|
+
rdoc_options: []
|
69
|
+
require_paths:
|
70
|
+
- lib
|
71
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
72
|
+
none: false
|
73
|
+
requirements:
|
74
|
+
- - ! '>='
|
75
|
+
- !ruby/object:Gem::Version
|
76
|
+
version: '0'
|
77
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
78
|
+
none: false
|
79
|
+
requirements:
|
80
|
+
- - ! '>='
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0'
|
83
|
+
requirements: []
|
84
|
+
rubyforge_project:
|
85
|
+
rubygems_version: 1.8.11
|
86
|
+
signing_key:
|
87
|
+
specification_version: 3
|
88
|
+
summary: Timwe provider for Sisal
|
89
|
+
test_files:
|
90
|
+
- spec/sisal/providers/timwe_provider_spec.rb
|
91
|
+
- spec/spec_helper.rb
|