didww-client 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 8856f75481da588975f5012ddad226b67cd2315ed8789c091d43082c987076f0
4
+ data.tar.gz: 94dc4b0f6c392f8abc3bf6bf2db9e32f8943ab286d4b22d7c169dae5e7f82282
5
+ SHA512:
6
+ metadata.gz: a14c32e51d333ac7105f9203c9cc933648a4fa8f663bc6450013e936445c9582b767542333eef8d00af206f9843b8b9aeb9b6d5dd2c34eef1f1a67339d67c201
7
+ data.tar.gz: cbeef34e7011139f67d6c8173f438bf2d62a97338dc441ce19aed3e58071f472e5db948ccd2013349f2bfba0dd9f2d167bdac7f14c9ad011de8a81d83e56ccf1
@@ -0,0 +1,10 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
10
+ /vendor/
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --format documentation
2
+ --color
@@ -0,0 +1,28 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'DIDWW/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "DIDWW"
8
+ spec.version = DIDWW::VERSION
9
+ spec.authors = ["Julien Chabanon"]
10
+ spec.email = ["julien.chabanon@modulis.ca"]
11
+ spec.summary = %q{A simple API wrapper for DIDWW SOAP API}
12
+ spec.description = %q{This API wrapper is meant to provide a rails friendly configurable api wrapper to access DIDWW's SOAP based API using Savon gem.}
13
+ spec.homepage = "http://github.com/modulis/DIDWW-API-WRAPPER"
14
+ spec.license = "MIT"
15
+
16
+ spec.name = "didww-client"
17
+ spec.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
18
+ spec.files = `git ls-files`.split("\n")
19
+ spec.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
20
+ spec.require_paths = ["lib"]
21
+ spec.version = DIDWW::VERSION
22
+
23
+ spec.add_development_dependency "bundler", "~> 1.12"
24
+ spec.add_development_dependency "rake", "~> 10.0"
25
+ spec.add_development_dependency "rspec", "~> 3.0"
26
+
27
+ spec.add_dependency "savon", "~> 2.11.1"
28
+ end
data/Gemfile ADDED
@@ -0,0 +1,8 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in DIDWW.gemspec
4
+ gemspec
5
+
6
+ gem 'savon'
7
+ gem 'pry-byebug'
8
+ gem 'pry'
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2016 Luke Jones
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
@@ -0,0 +1,81 @@
1
+ # DIDWW
2
+
3
+ A simple Rails friendly API wrapper for DIDWW's SOAP based API
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ ```ruby
10
+ gem 'DIDWW', git: 'https://github.com/modulis/DIDWW-API-WRAPPER.git'
11
+ ```
12
+
13
+ And then execute:
14
+
15
+ $ bundle
16
+
17
+ Or install it yourself as:
18
+
19
+ $ gem install DIDWW
20
+
21
+ ## Usage
22
+ ### Configuration
23
+ First you must configure DIDWW or you won't be able to make requests.
24
+ ```ruby
25
+ DIDWW.configure do |config|
26
+ config.api_username = 'user@user.ca' # Your api username given to you by didww
27
+ config.api_key = 'example_key_u90sd8f7sd9' # Your secret api key given to you by didww
28
+ config.sandbox = false # Optional. True by default, you must set it to live manually.
29
+ end
30
+ ```
31
+
32
+ For secret information like your `api_key` it's recommended that you use something like environment variables. For example:
33
+ ```ruby
34
+ DIDWW.configure do |config|
35
+ config.api_key = ENV['DIDWW_API_KEY']
36
+ end
37
+ ```
38
+
39
+ ### Building the client
40
+ You can create a client which will inheret DIDWW configuration automatically using
41
+ ```ruby
42
+ client = DIDWW::Client.new
43
+ ```
44
+
45
+ If you would like to change the configuration for a specific client you'll have to do so manually:
46
+ ```ruby
47
+ client.configuration.sandbox = false # sets this client to live mode
48
+ ```
49
+
50
+ ### Making calls
51
+ A list of methods can be seen in `METHOD_TRANSLATIONS` in the client class in the source code. Making a call is as easy as:
52
+ ```ruby
53
+ client = DIDWW::Client.new
54
+ client.check_pstn_number(pstn_number: 1111111)
55
+ ```
56
+
57
+ ### Convenience methods
58
+ DIDWW has a few convenience methods to use in your code:
59
+ ```ruby
60
+ DIDWW.configure do |config|
61
+ config.sandbox = true
62
+ end
63
+ DIDWW.sandbox? #=> true
64
+ DIDWW.live? #=> false
65
+ DIDWW.mode #=> :sandbox (alternatively :live)
66
+ ```
67
+
68
+ ## Development
69
+
70
+ You have access to a developer console to use the gem interactively by running `bin/console` from the project directory.
71
+ Please write specs for any additions, and use shared examples when possible.
72
+
73
+ ## Contributing
74
+
75
+ Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/DIDWW.
76
+
77
+
78
+ ## License
79
+
80
+ The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
81
+
@@ -0,0 +1,6 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
@@ -0,0 +1,10 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "DIDWW"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ require "pry"
10
+ Pry.start
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,33 @@
1
+ require "DIDWW/version"
2
+ require "DIDWW/configuration"
3
+ require 'DIDWW/client'
4
+
5
+ module DIDWW
6
+ class << self
7
+ attr_reader :configuration
8
+ end
9
+
10
+ def self.configuration
11
+ @configuration ||= Configuration.new
12
+ end
13
+
14
+ def self.configure
15
+ yield configuration
16
+ end
17
+
18
+ def self.reset
19
+ @configuration = Configuration.new
20
+ end
21
+
22
+ def self.mode
23
+ configuration.sandbox ? :sandbox : :live
24
+ end
25
+
26
+ def self.sandbox?
27
+ configuration.sandbox
28
+ end
29
+
30
+ def self.live?
31
+ !configuration.sandbox
32
+ end
33
+ end
@@ -0,0 +1,79 @@
1
+ require 'savon'
2
+
3
+ module DIDWW
4
+ class Client
5
+ attr_reader :configuration, :methods
6
+
7
+ # key is method used by this api wrapper,
8
+ # value is method used by DIDWW's SOAP api
9
+ METHOD_TRANSLATIONS = {
10
+ get_invoices: :didww_callhistory_invoices,
11
+ check_pstn_number: :didww_checkpstnnumber,
12
+ restore_did: :didww_didrestore,
13
+ get_cdr_log: :didww_getcdrlog,
14
+ get_coverage: :didww_getcoverage,
15
+ get_api_details: :didww_getdidwwapidetails,
16
+ get_cities: :didww_getdidwwcities,
17
+ get_countries: :didww_getdidwwcountries,
18
+ get_pstn_rates: :didww_getdidwwpstnrates,
19
+ get_regions: :didww_getdidwwregions,
20
+ get_prepaid_balance: :didww_getprepaidbalance,
21
+ get_prepaid_balances: :didww_getprepaidbalancelist,
22
+ get_service_details: :didww_getservicedetails,
23
+ get_service_list: :didww_getservicelist,
24
+ get_sms_log: :didww_getsmslog,
25
+ auto_renew_status: :didww_order_autorenew_status,
26
+ auto_renew: :didww_orderautorenew,
27
+ cancel_order: :didww_ordercancel,
28
+ create_order: :didww_ordercreate,
29
+ get_pstn_traffic_data: :didww_pstn_traffic,
30
+ update_mapping: :didww_updatemapping,
31
+ update_prepaid_balance: :didww_updateprepaidbalance,
32
+ update_pstn_rates: :didww_updatepstnrates
33
+ }.freeze
34
+
35
+ UNIQUE_HASH_METHODS = [
36
+ :create_order,
37
+ :auto_renew,
38
+ :update_prepaid_balance,
39
+ :restore_did
40
+ ].freeze
41
+
42
+ def initialize
43
+ @configuration = DIDWW.configuration
44
+ @savon = savon_client
45
+ @methods = METHOD_TRANSLATIONS.keys
46
+ end
47
+
48
+ def method_missing(method_name, *args, &block)
49
+ if methods.include? method_name
50
+ params = (args.first || {}).merge(auth_string: auth_string)
51
+ params.merge!(uniq_hash: (Time.now.to_i.to_s + auth_string)) if UNIQUE_HASH_METHODS.include?(method_name)
52
+ @savon.call METHOD_TRANSLATIONS[method_name], message: params
53
+ else
54
+ raise NoMethodError, "#{method_name} is not a valid api endpoint!"
55
+ end
56
+ end
57
+
58
+ private
59
+
60
+ def savon_client
61
+ wsdl = configuration.sandbox ? sandbox_url : live_url
62
+ Savon::Client.new wsdl: wsdl
63
+ end
64
+
65
+ def auth_string
66
+ string = configuration.api_username + configuration.api_key
67
+ string += 'sandbox' if configuration.sandbox
68
+ Digest::SHA1.hexdigest(string)
69
+ end
70
+
71
+ def sandbox_url
72
+ 'https://sandbox-api.didww.com/api2/index.php?wsdl'
73
+ end
74
+
75
+ def live_url
76
+ 'https://api.didww.com/api2/?wsdl'
77
+ end
78
+ end
79
+ end
@@ -0,0 +1,11 @@
1
+ module DIDWW
2
+ class Configuration
3
+ attr_accessor :api_username, :api_key, :sandbox
4
+
5
+ def initialize(params = {})
6
+ @api_username = params[:api_username]
7
+ @api_key = params[:api_key]
8
+ @sandbox = params[:sandbox] || true
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,3 @@
1
+ module DIDWW
2
+ VERSION = "0.1.1"
3
+ end
@@ -0,0 +1,32 @@
1
+ require 'spec_helper'
2
+ require 'DIDWW/client'
3
+
4
+ describe DIDWW::Client do
5
+ let(:client) { described_class.new }
6
+
7
+ before(:each) do
8
+ allow(Savon::Client).to receive(:new).and_return(dummy_client)
9
+ allow(dummy_client).to receive(:call)
10
+ end
11
+
12
+ let(:dummy_client) { instance_double Savon::Client }
13
+
14
+ describe '#method_missing' do
15
+ context "when the method is not a valid api endpoint" do
16
+ subject { client.foo }
17
+
18
+ it "raises an exception" do
19
+ expect { subject }.to raise_error(NoMethodError)
20
+ end
21
+ end
22
+
23
+ context "when the method is a valid api endpoint" do
24
+ subject { client.auto_renew_status(customer_id: 0, did: 1111111111) }
25
+
26
+ it "calls the api" do
27
+ expect(dummy_client).to receive(:call)
28
+ subject
29
+ end
30
+ end
31
+ end
32
+ end
@@ -0,0 +1,109 @@
1
+ require 'spec_helper'
2
+
3
+ describe DIDWW do
4
+ it 'has a version number' do
5
+ expect(DIDWW::VERSION).not_to be nil
6
+ end
7
+
8
+ describe '.configure' do
9
+ subject do
10
+ described_class.configure do |config|
11
+ config.api_username = 'test@test.ca'
12
+ config.api_key = 'test_key'
13
+ config.sandbox = false
14
+ end
15
+ end
16
+
17
+ it "changes the configuration" do
18
+ subject
19
+ expect(described_class.configuration.api_username).to eq 'test@test.ca'
20
+ expect(described_class.configuration.api_key).to eq 'test_key'
21
+ expect(described_class.configuration.sandbox).to be false
22
+ end
23
+ end
24
+
25
+ describe '.reset' do
26
+ subject { described_class.reset }
27
+
28
+ before(:each) do
29
+ described_class.configuration.api_key = 'test_key'
30
+ end
31
+
32
+ it "resets the configuration" do
33
+ subject
34
+ expect(described_class.configuration.api_key).not_to eq 'test_key'
35
+ end
36
+ end
37
+
38
+ describe '.mode' do
39
+ subject { described_class.mode }
40
+
41
+ context "when sandbox is set to true" do
42
+ before(:each) do
43
+ described_class.configuration.sandbox = true
44
+ end
45
+
46
+ it "returns :sandbox" do
47
+ expect(subject).to eq :sandbox
48
+ end
49
+ end
50
+
51
+ context "when sandbox is set to false" do
52
+ before(:each) do
53
+ described_class.configuration.sandbox = false
54
+ end
55
+
56
+ it "returns :live" do
57
+ expect(subject).to eq :live
58
+ end
59
+ end
60
+ end
61
+
62
+ describe '.sandbox?' do
63
+ subject { described_class.sandbox? }
64
+
65
+ context "when in sandbox mode" do
66
+ before(:each) do
67
+ described_class.configuration.sandbox = true
68
+ end
69
+
70
+ it "returns true" do
71
+ expect(subject).to be true
72
+ end
73
+ end
74
+
75
+ context "when not in sandbox mode" do
76
+ before(:each) do
77
+ described_class.configuration.sandbox = false
78
+ end
79
+
80
+ it "returns false" do
81
+ expect(subject).to be false
82
+ end
83
+ end
84
+ end
85
+
86
+ describe '.live?' do
87
+ subject { described_class.live? }
88
+
89
+ context "when in sandbox mode" do
90
+ before(:each) do
91
+ described_class.configuration.sandbox = true
92
+ end
93
+
94
+ it "returns false" do
95
+ expect(subject).to be false
96
+ end
97
+ end
98
+
99
+ context "when not in sandbox mode" do
100
+ before(:each) do
101
+ described_class.configuration.sandbox = false
102
+ end
103
+
104
+ it "returns true" do
105
+ expect(subject).to be true
106
+ end
107
+ end
108
+ end
109
+ end
@@ -0,0 +1,9 @@
1
+ $LOAD_PATH.unshift File.expand_path('../../lib', __FILE__)
2
+ require 'DIDWW'
3
+ require 'bundler/setup'
4
+ require 'pry'
5
+
6
+ DIDWW.configure do |config|
7
+ config.api_username = 'test@test.ca'
8
+ config.api_key = 'test_key'
9
+ end
metadata ADDED
@@ -0,0 +1,118 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: didww-client
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.1
5
+ platform: ruby
6
+ authors:
7
+ - Julien Chabanon
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2019-06-10 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.12'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.12'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '10.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '10.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rspec
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '3.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '3.0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: savon
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: 2.11.1
62
+ type: :runtime
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: 2.11.1
69
+ description: This API wrapper is meant to provide a rails friendly configurable api
70
+ wrapper to access DIDWW's SOAP based API using Savon gem.
71
+ email:
72
+ - julien.chabanon@modulis.ca
73
+ executables:
74
+ - console
75
+ - setup
76
+ extensions: []
77
+ extra_rdoc_files: []
78
+ files:
79
+ - ".gitignore"
80
+ - ".rspec"
81
+ - DIDWW.gemspec
82
+ - Gemfile
83
+ - LICENSE.txt
84
+ - README.md
85
+ - Rakefile
86
+ - bin/console
87
+ - bin/setup
88
+ - lib/DIDWW.rb
89
+ - lib/DIDWW/client.rb
90
+ - lib/DIDWW/configuration.rb
91
+ - lib/DIDWW/version.rb
92
+ - spec/DIDWW/Client_spec.rb
93
+ - spec/DIDWW_spec.rb
94
+ - spec/spec_helper.rb
95
+ homepage: http://github.com/modulis/DIDWW-API-WRAPPER
96
+ licenses:
97
+ - MIT
98
+ metadata: {}
99
+ post_install_message:
100
+ rdoc_options: []
101
+ require_paths:
102
+ - lib
103
+ required_ruby_version: !ruby/object:Gem::Requirement
104
+ requirements:
105
+ - - ">="
106
+ - !ruby/object:Gem::Version
107
+ version: '0'
108
+ required_rubygems_version: !ruby/object:Gem::Requirement
109
+ requirements:
110
+ - - ">="
111
+ - !ruby/object:Gem::Version
112
+ version: '0'
113
+ requirements: []
114
+ rubygems_version: 3.0.3
115
+ signing_key:
116
+ specification_version: 4
117
+ summary: A simple API wrapper for DIDWW SOAP API
118
+ test_files: []