didww-v3 1.0.0 → 2.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/.github/workflows/tests.yml +27 -0
- data/.rubocop.yml +22 -19
- data/CHANGELOG.md +53 -0
- data/Gemfile +20 -0
- data/README.md +7 -1
- data/Rakefile +6 -1
- data/bin/console +1 -0
- data/didww-v3.gemspec +3 -18
- data/lib/didww/{middleware.rb → base_middleware.rb} +5 -3
- data/lib/didww/callback/request_validator.rb +68 -0
- data/lib/didww/client.rb +91 -7
- data/lib/didww/complex_objects/base.rb +9 -6
- data/lib/didww/complex_objects/capacity_order_item.rb +17 -0
- data/lib/didww/complex_objects/cdr_export_filter.rb +1 -0
- data/lib/didww/complex_objects/configurations/base.rb +1 -0
- data/lib/didww/complex_objects/configurations/const.rb +1 -0
- data/lib/didww/complex_objects/configurations/h323_configuration.rb +1 -0
- data/lib/didww/complex_objects/configurations/iax2_configuration.rb +1 -0
- data/lib/didww/complex_objects/configurations/pstn_configuration.rb +1 -0
- data/lib/didww/complex_objects/configurations/sip_configuration.rb +11 -0
- data/lib/didww/complex_objects/configurations.rb +1 -0
- data/lib/didww/complex_objects/did_order_item.rb +14 -5
- data/lib/didww/encrypt.rb +101 -0
- data/lib/didww/jsonapi_middleware.rb +21 -0
- data/lib/didww/resources/address.rb +37 -0
- data/lib/didww/resources/address_verification.rb +56 -0
- data/lib/didww/resources/area.rb +12 -0
- data/lib/didww/resources/available_did.rb +13 -0
- data/lib/didww/resources/balance.rb +1 -0
- data/lib/didww/resources/base.rb +2 -1
- data/lib/didww/resources/capacity_pool.rb +47 -0
- data/lib/didww/resources/cdr_export.rb +12 -1
- data/lib/didww/resources/city.rb +5 -0
- data/lib/didww/resources/country.rb +1 -0
- data/lib/didww/resources/did.rb +9 -1
- data/lib/didww/resources/did_group.rb +5 -4
- data/lib/didww/resources/did_group_type.rb +1 -0
- data/lib/didww/resources/did_reservation.rb +17 -0
- data/lib/didww/resources/encrypted_file.rb +58 -0
- data/lib/didww/resources/identity.rb +78 -0
- data/lib/didww/resources/order.rb +10 -0
- data/lib/didww/resources/permanent_supporting_document.rb +15 -0
- data/lib/didww/resources/pop.rb +10 -0
- data/lib/didww/resources/proof.rb +19 -0
- data/lib/didww/resources/proof_type.rb +14 -0
- data/lib/didww/resources/public_key.rb +12 -0
- data/lib/didww/resources/qty_based_pricing.rb +20 -0
- data/lib/didww/resources/region.rb +1 -0
- data/lib/didww/resources/requirement.rb +61 -0
- data/lib/didww/resources/requirement_validation.rb +10 -0
- data/lib/didww/resources/shared_capacity_group.rb +27 -0
- data/lib/didww/resources/stock_keeping_unit.rb +1 -0
- data/lib/didww/resources/supporting_document_template.rb +14 -0
- data/lib/didww/resources/trunk/const.rb +1 -15
- data/lib/didww/resources/trunk.rb +2 -4
- data/lib/didww/resources/trunk_group.rb +1 -0
- data/lib/didww/version.rb +2 -1
- data/lib/didww.rb +5 -1
- metadata +39 -157
- data/.travis.yml +0 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 9d736e9893b21ef96ef76993d6bb3da3e47c1dbb760edcc6ea13d0cf86d5e847
|
4
|
+
data.tar.gz: 9d641935ce36af938ea6641b7488835535ef4a01f6464b5c90f667dafac953c3
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b2cef4993cda70bd45a3a1efd960ab26d9ba603de9a10c246c537ccdbbb3506e923f1628643fabcefcc7be8ca1f9a6a93342b996e6233b9eadadc77818d766fe
|
7
|
+
data.tar.gz: de556881b793c412ea2fb486bacd00f89a3c07ad3902e755f5a4140e2eb0fda10f1b748ea719ce9968e87e476797bed8b28ce3b032f1e107ed457946235f303f
|
@@ -0,0 +1,27 @@
|
|
1
|
+
name: Tests
|
2
|
+
on:
|
3
|
+
pull_request:
|
4
|
+
push:
|
5
|
+
branches:
|
6
|
+
- master
|
7
|
+
|
8
|
+
jobs:
|
9
|
+
test:
|
10
|
+
runs-on: ubuntu-latest
|
11
|
+
strategy:
|
12
|
+
matrix:
|
13
|
+
ruby: [ '2.5', '2.6', '2.7' ]
|
14
|
+
rails: [ '~> 5.0', '~> 6.0' ]
|
15
|
+
name: Tests with Ruby ${{ matrix.ruby }} Activesupport ${{ matrix.rails }}
|
16
|
+
env:
|
17
|
+
RAILS_VERSION: ${{ matrix.rails }}
|
18
|
+
steps:
|
19
|
+
- uses: actions/checkout@v2
|
20
|
+
- uses: actions/setup-ruby@v1
|
21
|
+
with:
|
22
|
+
ruby-version: ${{ matrix.ruby }}
|
23
|
+
- name: Run tests
|
24
|
+
run: |
|
25
|
+
gem install bundler -v 2.2.7
|
26
|
+
bundle install
|
27
|
+
bundle exec rake
|
data/.rubocop.yml
CHANGED
@@ -1,18 +1,18 @@
|
|
1
|
+
require:
|
2
|
+
- rubocop-performance
|
3
|
+
- rubocop-rake
|
4
|
+
- rubocop-rspec
|
5
|
+
|
1
6
|
AllCops:
|
2
|
-
TargetRubyVersion: 2.
|
7
|
+
TargetRubyVersion: 2.5
|
3
8
|
DisplayCopNames: true
|
4
9
|
DisabledByDefault: true
|
5
10
|
|
6
11
|
Exclude:
|
7
12
|
- db/migrate/**/*
|
8
13
|
|
9
|
-
Include:
|
10
|
-
- "**/*.rake"
|
11
|
-
- "**/Gemfile"
|
12
|
-
- "**/Rakefile"
|
13
|
-
|
14
14
|
##################### Layout ##################################
|
15
|
-
Layout/
|
15
|
+
Layout/TrailingEmptyLines:
|
16
16
|
Enabled: true
|
17
17
|
|
18
18
|
Layout/TrailingWhitespace:
|
@@ -52,6 +52,9 @@ Style/StringLiterals:
|
|
52
52
|
Style/StringLiteralsInInterpolation:
|
53
53
|
Enabled: true
|
54
54
|
|
55
|
+
Style/FrozenStringLiteralComment:
|
56
|
+
Enabled: true
|
57
|
+
|
55
58
|
##################### Performance ############################
|
56
59
|
|
57
60
|
# Use `casecmp` rather than `downcase ==`.
|
@@ -68,7 +71,7 @@ Performance/EndWith:
|
|
68
71
|
Enabled: true
|
69
72
|
|
70
73
|
# Use `strip` instead of `lstrip.rstrip`.
|
71
|
-
|
74
|
+
Style/Strip:
|
72
75
|
Enabled: true
|
73
76
|
|
74
77
|
# Use `Range#cover?` instead of `Range#include?`.
|
@@ -91,7 +94,7 @@ Performance/RedundantMerge:
|
|
91
94
|
Enabled: true
|
92
95
|
|
93
96
|
# Use `sort` instead of `sort_by { |x| x }`.
|
94
|
-
|
97
|
+
Style/RedundantSortBy:
|
95
98
|
Enabled: true
|
96
99
|
|
97
100
|
# Use `start_with?` instead of a regex match anchored to the beginning of a
|
@@ -138,7 +141,7 @@ Lint/AssignmentInCondition:
|
|
138
141
|
Enabled: true
|
139
142
|
|
140
143
|
# Align block ends correctly.
|
141
|
-
|
144
|
+
Layout/BlockAlignment:
|
142
145
|
Enabled: true
|
143
146
|
|
144
147
|
# Default values in optional keyword arguments and optional ordinal arguments
|
@@ -147,7 +150,7 @@ Lint/CircularArgumentReference:
|
|
147
150
|
Enabled: true
|
148
151
|
|
149
152
|
# Checks for condition placed in a confusing position relative to the keyword.
|
150
|
-
|
153
|
+
Layout/ConditionPosition:
|
151
154
|
Enabled: true
|
152
155
|
|
153
156
|
# Check for debugger calls.
|
@@ -155,7 +158,7 @@ Lint/Debugger:
|
|
155
158
|
Enabled: true
|
156
159
|
|
157
160
|
# Align ends corresponding to defs correctly.
|
158
|
-
|
161
|
+
Layout/DefEndAlignment:
|
159
162
|
Enabled: true
|
160
163
|
|
161
164
|
# Check for deprecated class method calls.
|
@@ -179,11 +182,11 @@ Lint/EmptyWhen:
|
|
179
182
|
Enabled: true
|
180
183
|
|
181
184
|
# Align ends correctly.
|
182
|
-
|
185
|
+
Layout/EndAlignment:
|
183
186
|
Enabled: true
|
184
187
|
|
185
188
|
# END blocks should not be placed inside method definitions.
|
186
|
-
|
189
|
+
Style/EndBlock:
|
187
190
|
Enabled: true
|
188
191
|
|
189
192
|
# Do not use return in an ensure block.
|
@@ -199,7 +202,7 @@ Lint/FormatParameterMismatch:
|
|
199
202
|
Enabled: true
|
200
203
|
|
201
204
|
# This cop checks for *rescue* blocks with no body.
|
202
|
-
Lint/
|
205
|
+
Lint/SuppressedException:
|
203
206
|
Enabled: true
|
204
207
|
|
205
208
|
# Checks for adjacent string literals on the same line, which could better be
|
@@ -255,7 +258,7 @@ Lint/ShadowingOuterLocalVariable:
|
|
255
258
|
Enabled: false
|
256
259
|
|
257
260
|
# Checks for Object#to_s usage in string interpolation.
|
258
|
-
Lint/
|
261
|
+
Lint/RedundantStringCoercion:
|
259
262
|
Enabled: false
|
260
263
|
|
261
264
|
# Do not use prefix `_` for a variable that is used.
|
@@ -269,11 +272,11 @@ Lint/UnifiedInteger:
|
|
269
272
|
# Checks for rubocop:disable comments that can be removed.
|
270
273
|
# Note: this cop is not disabled when disabling all cops.
|
271
274
|
# It must be explicitly disabled.
|
272
|
-
Lint/
|
275
|
+
Lint/RedundantCopDisableDirective:
|
273
276
|
Enabled: false
|
274
277
|
|
275
278
|
# This cop checks for unneeded usages of splat expansion
|
276
|
-
Lint/
|
279
|
+
Lint/RedundantSplatExpansion:
|
277
280
|
Enabled: false
|
278
281
|
|
279
282
|
# Unreachable code.
|
@@ -297,7 +300,7 @@ Lint/UselessAssignment:
|
|
297
300
|
Enabled: false
|
298
301
|
|
299
302
|
# Checks for comparison of something with itself.
|
300
|
-
Lint/
|
303
|
+
Lint/BinaryOperatorWithIdenticalOperands:
|
301
304
|
Enabled: false
|
302
305
|
|
303
306
|
# Checks for useless `else` in `begin..end` without `rescue`.
|
data/CHANGELOG.md
ADDED
@@ -0,0 +1,53 @@
|
|
1
|
+
# Changelog
|
2
|
+
All notable changes to this project will be documented in this file.
|
3
|
+
|
4
|
+
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
|
5
|
+
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
6
|
+
|
7
|
+
## [2.0.0] - 2021-10-26
|
8
|
+
### Breaking Changes
|
9
|
+
- upgrade `json_api_client` version to `1.18.0` [#9](https://github.com/didww/didww-v3-ruby/pull/9)
|
10
|
+
Handling of 4XX responses was changed - it now raises JsonApiClient::Errors::ClientError with `detail` as error message instead of adding it into base errors.
|
11
|
+
- /v3/dids in request and response attributes pending_removal being removed in favor of billing_cycles_count.
|
12
|
+
- /v3/did_groups restriction message removed in favor of requirements relationship.
|
13
|
+
|
14
|
+
### Changes
|
15
|
+
- replace travis with github actions [#7](https://github.com/didww/didww-v3-ruby/pull/7) [#9](https://github.com/didww/didww-v3-ruby/pull/9)
|
16
|
+
- use rubocop 1.9.X version [#7](https://github.com/didww/didww-v3-ruby/pull/7)
|
17
|
+
- add bundle-audit [#7](https://github.com/didww/didww-v3-ruby/pull/7)
|
18
|
+
- /v3/orders request attribute items of type DID Order Item Attributes can have billing_cycles_count.
|
19
|
+
- /v3/dids added address_verification relationship.
|
20
|
+
- callbacks attributes added to /v3/orders, /v3/cdr_exports.
|
21
|
+
- /v3/proof_types read endpoints being added.
|
22
|
+
- /v3/supporting_document_templates read endpoints being added.
|
23
|
+
- /v3/requirements read endpoints being added.
|
24
|
+
- /v3/identities read, write, and delete endpoints being added.
|
25
|
+
- /v3/addresses read, write, and delete endpoints being added.
|
26
|
+
- /v3/encrypted_files read, write, and delete endpoints being added.
|
27
|
+
- /v3/proofs write, delete endpoint being added.
|
28
|
+
- /v3/permanent_supporting_documents write, delete endpoint being added.
|
29
|
+
- /v3/address_verifications read and write endpoints being added.
|
30
|
+
- /v3/requirement_validations write endpoint being added.
|
31
|
+
|
32
|
+
### Bugfixes
|
33
|
+
- fix order purchase when activesupport 6.X.X is used.
|
34
|
+
|
35
|
+
## [1.3.0] - 2018-09-03
|
36
|
+
### Changes
|
37
|
+
- Add Capacity Pool and Shared Capacity Group resources
|
38
|
+
- Add Capacity Pool and Shared Capacity Group relationships to DID
|
39
|
+
- Add Quantity based pricings and Capacity type Order Item
|
40
|
+
|
41
|
+
## [1.2.0] - 2018-04-25
|
42
|
+
### Changes
|
43
|
+
- add number selection feature
|
44
|
+
|
45
|
+
## [1.1.0] - 2018-03-05
|
46
|
+
### Changes
|
47
|
+
- add Pop resource
|
48
|
+
- Remove old trunk.preferred_server property
|
49
|
+
- Add max_transfers and max_30x_redirects to sip_configurations
|
50
|
+
- Added custom user-agent header
|
51
|
+
|
52
|
+
## [1.0.0] - 2017-12-05
|
53
|
+
- initial release
|
data/Gemfile
CHANGED
@@ -1,6 +1,26 @@
|
|
1
|
+
# frozen_string_literal: true
|
1
2
|
source 'https://rubygems.org'
|
2
3
|
|
3
4
|
git_source(:github) { |repo_name| "https://github.com/#{repo_name}" }
|
4
5
|
|
5
6
|
# Specify your gem's dependencies in didww-v3.gemspec
|
6
7
|
gemspec
|
8
|
+
|
9
|
+
if ENV['RAILS_VERSION']
|
10
|
+
gem 'activesupport', ENV['RAILS_VERSION'], require: false
|
11
|
+
end
|
12
|
+
|
13
|
+
gem 'rake', '~> 12.0'
|
14
|
+
gem 'rspec', '~> 3.0'
|
15
|
+
gem 'pry'
|
16
|
+
gem 'byebug'
|
17
|
+
gem 'awesome_print'
|
18
|
+
gem 'http_logger'
|
19
|
+
gem 'rubocop', '~> 1.9'
|
20
|
+
gem 'rubocop-performance'
|
21
|
+
gem 'rubocop-rake'
|
22
|
+
gem 'rubocop-rspec'
|
23
|
+
gem 'simplecov'
|
24
|
+
gem 'smart_rspec'
|
25
|
+
gem 'webmock'
|
26
|
+
gem 'bundler-audit'
|
data/README.md
CHANGED
@@ -1,14 +1,20 @@
|
|
1
1
|
Ruby client for DIDWW API v3.
|
2
2
|
|
3
|
+
![Tests](https://github.com/didww/didww-v3-ruby/workflows/Tests/badge.svg)
|
4
|
+
|
3
5
|
About DIDWW API v3
|
4
6
|
-----
|
5
7
|
|
6
|
-
The DIDWW API provides a simple yet powerful interface that allows you to fully integrate your own applications with DIDWW services. An extensive set of actions may be performed using this API, such as ordering and configuring phone numbers, setting capacity, creating SIP trunks and retrieving CDRs and other operational data.
|
8
|
+
The DIDWW API provides a simple yet powerful interface that allows you to fully integrate your own applications with DIDWW services. An extensive set of actions may be performed using this API, such as ordering and configuring phone numbers, setting capacity, creating SIP trunks and retrieving CDRs and other operational data.
|
7
9
|
|
8
10
|
The DIDWW API v3 is a fully compliant implementation of the [JSON API specification](http://jsonapi.org/format/).
|
9
11
|
|
10
12
|
Read more https://doc.didww.com/api
|
11
13
|
|
14
|
+
Gem Versions **2.X.X** are intended to use with DIDWW API 3 version [2021-04-19](https://doc.didww.com/api3/2021-04-19/index.html).
|
15
|
+
|
16
|
+
Gem Versions **1.X.X** are intended to use with DIDWW API 3 version [2017-09-18](https://doc.didww.com/api3/2017-09-18/index.html).
|
17
|
+
|
12
18
|
## Installation
|
13
19
|
|
14
20
|
Add this line to your application's Gemfile:
|
data/Rakefile
CHANGED
@@ -1,6 +1,11 @@
|
|
1
|
+
# frozen_string_literal: true
|
1
2
|
require 'bundler/gem_tasks'
|
2
3
|
require 'rspec/core/rake_task'
|
4
|
+
require 'bundler/audit/task'
|
5
|
+
require 'rubocop/rake_task'
|
3
6
|
|
4
7
|
RSpec::Core::RakeTask.new(:spec)
|
8
|
+
Bundler::Audit::Task.new
|
9
|
+
RuboCop::RakeTask.new
|
5
10
|
|
6
|
-
task default: :spec
|
11
|
+
task default: ['bundle:audit', :rubocop, :spec]
|
data/bin/console
CHANGED
data/didww-v3.gemspec
CHANGED
@@ -1,3 +1,4 @@
|
|
1
|
+
# frozen_string_literal: true
|
1
2
|
|
2
3
|
lib = File.expand_path('../lib', __FILE__)
|
3
4
|
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
@@ -21,26 +22,10 @@ Gem::Specification.new do |spec|
|
|
21
22
|
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
22
23
|
spec.require_paths = ['lib']
|
23
24
|
|
24
|
-
spec.add_development_dependency 'bundler', '~> 1.16'
|
25
|
-
spec.add_development_dependency 'rake', '~> 10.0'
|
26
|
-
spec.add_development_dependency 'rspec', '~> 3.0'
|
27
|
-
|
28
|
-
# development
|
29
|
-
spec.add_development_dependency 'pry'
|
30
|
-
spec.add_development_dependency 'byebug'
|
31
|
-
spec.add_development_dependency 'awesome_print'
|
32
|
-
spec.add_development_dependency 'http_logger'
|
33
|
-
spec.add_development_dependency 'rubocop'
|
34
|
-
|
35
|
-
# test
|
36
|
-
spec.add_development_dependency 'simplecov'
|
37
|
-
spec.add_development_dependency 'smart_rspec'
|
38
|
-
spec.add_development_dependency 'webmock'
|
39
|
-
|
40
25
|
spec.add_dependency 'activesupport'
|
41
26
|
spec.add_dependency 'faraday'
|
42
|
-
spec.add_dependency 'json_api_client'
|
27
|
+
spec.add_dependency 'json_api_client', '1.18.0'
|
43
28
|
spec.add_dependency 'http'
|
44
29
|
spec.add_dependency 'down'
|
45
|
-
|
30
|
+
spec.add_dependency 'openssl-oaep'
|
46
31
|
end
|
@@ -1,10 +1,12 @@
|
|
1
|
+
# frozen_string_literal: true
|
1
2
|
module DIDWW
|
2
3
|
# :nodoc:
|
3
|
-
class
|
4
|
+
class BaseMiddleware < Faraday::Middleware
|
4
5
|
def call(request_env)
|
5
6
|
headers = {}
|
6
|
-
headers['
|
7
|
-
headers['
|
7
|
+
headers['Api-Key'] = DIDWW::Client.api_key
|
8
|
+
headers['User-Agent'] = "didww-v3 Ruby gem v#{VERSION}"
|
9
|
+
headers['x-didww-api-version'] = DIDWW::Client.api_version unless DIDWW::Client.api_version.blank?
|
8
10
|
|
9
11
|
request_env[:request_headers].merge!(headers)
|
10
12
|
request_env.url.host = URI(DIDWW::Client.api_base_url).host
|
@@ -0,0 +1,68 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
require 'openssl'
|
3
|
+
|
4
|
+
module DIDWW
|
5
|
+
module Callback
|
6
|
+
# @example
|
7
|
+
# validator = DIDWW::Callback::RequestValidator.new(api_key)
|
8
|
+
# uri = request.original_url
|
9
|
+
# if request.post?
|
10
|
+
# # Collect all parameters passed from DIDWW.
|
11
|
+
# params = env['rack.request.form_hash']
|
12
|
+
# else
|
13
|
+
# params = env['rack.request.query_hash']
|
14
|
+
# end
|
15
|
+
#
|
16
|
+
# signature = env['HTTP_X_DIDWW_SIGNATURE']
|
17
|
+
# validator.validate(uri, params, signature) #=> true if the request is from DIDWW
|
18
|
+
# # or with rails
|
19
|
+
class RequestValidator
|
20
|
+
DIGEST_ALGO = 'SHA1'
|
21
|
+
HEADER = 'X-DIDWW-Signature'
|
22
|
+
|
23
|
+
def initialize(api_key)
|
24
|
+
@api_key = api_key
|
25
|
+
end
|
26
|
+
|
27
|
+
# @param url [String]
|
28
|
+
# @param payload [Hash]
|
29
|
+
# @param signature [String]
|
30
|
+
# @return [Boolean] whether signature valid or not.
|
31
|
+
def validate(url, payload, signature)
|
32
|
+
return false if signature.blank?
|
33
|
+
|
34
|
+
signature == valid_signature(url, payload)
|
35
|
+
end
|
36
|
+
|
37
|
+
private
|
38
|
+
|
39
|
+
# @param url [String]
|
40
|
+
# @param payload [Hash]
|
41
|
+
# @return [String] generated signature in URL safe format.
|
42
|
+
def valid_signature(url, payload)
|
43
|
+
normalized_url = normalize_url(url)
|
44
|
+
data = normalized_url + payload.sort.join
|
45
|
+
OpenSSL::HMAC.hexdigest(DIGEST_ALGO, @api_key, data)
|
46
|
+
end
|
47
|
+
|
48
|
+
# @return [String] normalized URL.
|
49
|
+
def normalize_url(url)
|
50
|
+
parsed_url = URI ensure_protocol_url(url)
|
51
|
+
url = "#{parsed_url.scheme || 'http'}://"
|
52
|
+
url += "#{parsed_url.userinfo}@" if parsed_url.userinfo
|
53
|
+
url += "#{parsed_url.host}:#{parsed_url.port || parsed_url.default_port}#{parsed_url.path}"
|
54
|
+
url += "?#{parsed_url.query}" if parsed_url.query
|
55
|
+
url += "##{parsed_url.fragment}" if parsed_url.fragment
|
56
|
+
url
|
57
|
+
end
|
58
|
+
|
59
|
+
def ensure_protocol_url(url)
|
60
|
+
if url[%r{\A[a-zA-Z]+://}i]
|
61
|
+
url
|
62
|
+
else
|
63
|
+
'http://' + url
|
64
|
+
end
|
65
|
+
end
|
66
|
+
end
|
67
|
+
end
|
68
|
+
end
|
data/lib/didww/client.rb
CHANGED
@@ -1,4 +1,6 @@
|
|
1
|
+
# frozen_string_literal: true
|
1
2
|
require 'active_support/core_ext/module/attribute_accessors'
|
3
|
+
require 'active_support/core_ext/object/blank'
|
2
4
|
require 'json_api_client'
|
3
5
|
|
4
6
|
require 'didww/resources/base'
|
@@ -11,7 +13,7 @@ module DIDWW
|
|
11
13
|
}.freeze
|
12
14
|
DEFAULT_MODE = :sandbox
|
13
15
|
|
14
|
-
mattr_accessor :api_key, :api_mode, :http_verbose
|
16
|
+
mattr_accessor :api_key, :api_mode, :http_verbose, :api_version
|
15
17
|
|
16
18
|
class << self
|
17
19
|
def configure
|
@@ -29,14 +31,38 @@ module DIDWW
|
|
29
31
|
@@api_key
|
30
32
|
end
|
31
33
|
|
34
|
+
def api_version
|
35
|
+
@@api_version
|
36
|
+
end
|
37
|
+
|
38
|
+
def with_api_version(api_version)
|
39
|
+
old_api_version = self.api_version
|
40
|
+
self.api_version = api_version
|
41
|
+
yield
|
42
|
+
ensure
|
43
|
+
self.api_version = old_api_version
|
44
|
+
end
|
45
|
+
|
32
46
|
def api_base_url
|
33
|
-
BASE_URLS[api_mode]
|
47
|
+
ENV['DIDWW_API_URL'].presence || BASE_URLS[api_mode]
|
34
48
|
end
|
35
49
|
|
36
50
|
def balance
|
37
51
|
Resource::Balance.all.first
|
38
52
|
end
|
39
53
|
|
54
|
+
def capacity_pools
|
55
|
+
Resource::CapacityPool
|
56
|
+
end
|
57
|
+
|
58
|
+
def cdr_exports
|
59
|
+
Resource::CdrExport
|
60
|
+
end
|
61
|
+
|
62
|
+
def shared_capacity_groups
|
63
|
+
Resource::SharedCapacityGroup
|
64
|
+
end
|
65
|
+
|
40
66
|
def cities
|
41
67
|
Resource::City
|
42
68
|
end
|
@@ -61,6 +87,10 @@ module DIDWW
|
|
61
87
|
Resource::Order
|
62
88
|
end
|
63
89
|
|
90
|
+
def pops
|
91
|
+
Resource::Pop
|
92
|
+
end
|
93
|
+
|
64
94
|
def regions
|
65
95
|
Resource::Region
|
66
96
|
end
|
@@ -73,8 +103,44 @@ module DIDWW
|
|
73
103
|
Resource::Trunk
|
74
104
|
end
|
75
105
|
|
76
|
-
def
|
77
|
-
Resource::
|
106
|
+
def available_dids
|
107
|
+
Resource::AvailableDid
|
108
|
+
end
|
109
|
+
|
110
|
+
def did_reservations
|
111
|
+
Resource::DidReservation
|
112
|
+
end
|
113
|
+
|
114
|
+
def requirements
|
115
|
+
Resource::Requirement
|
116
|
+
end
|
117
|
+
|
118
|
+
def identities
|
119
|
+
Resource::Identity
|
120
|
+
end
|
121
|
+
|
122
|
+
def proofs
|
123
|
+
Resource::Proof
|
124
|
+
end
|
125
|
+
|
126
|
+
def addresses
|
127
|
+
Resource::Address
|
128
|
+
end
|
129
|
+
|
130
|
+
def permanent_supporting_documents
|
131
|
+
Resource::PermanentSupportingDocument
|
132
|
+
end
|
133
|
+
|
134
|
+
def encrypted_file
|
135
|
+
Resource::EncryptedFile
|
136
|
+
end
|
137
|
+
|
138
|
+
def address_verifications
|
139
|
+
Resource::AddressVerification
|
140
|
+
end
|
141
|
+
|
142
|
+
def requirement_validation
|
143
|
+
Resource::RequirementValidation
|
78
144
|
end
|
79
145
|
|
80
146
|
def api_mode=(arg)
|
@@ -94,7 +160,7 @@ module DIDWW
|
|
94
160
|
DIDWW::Resource::Base.site = api_base_url
|
95
161
|
DIDWW::Resource::Base.connection do |connection|
|
96
162
|
connection.use Faraday::Response::Logger if http_verbose?
|
97
|
-
connection.use DIDWW::
|
163
|
+
connection.use DIDWW::JsonapiMiddleware
|
98
164
|
end
|
99
165
|
JsonApiClient::Paginating::Paginator.page_param = 'number'
|
100
166
|
JsonApiClient::Paginating::Paginator.per_page_param = 'size'
|
@@ -102,17 +168,35 @@ module DIDWW
|
|
102
168
|
|
103
169
|
def require_didww_resources
|
104
170
|
require 'didww/resources/balance'
|
171
|
+
require 'didww/resources/capacity_pool'
|
172
|
+
require 'didww/resources/cdr_export'
|
173
|
+
require 'didww/resources/shared_capacity_group'
|
105
174
|
require 'didww/resources/city'
|
106
175
|
require 'didww/resources/country'
|
107
176
|
require 'didww/resources/did_group_type'
|
108
177
|
require 'didww/resources/did_group'
|
109
178
|
require 'didww/resources/did'
|
110
179
|
require 'didww/resources/order'
|
180
|
+
require 'didww/resources/pop'
|
181
|
+
require 'didww/resources/qty_based_pricing'
|
111
182
|
require 'didww/resources/region'
|
183
|
+
require 'didww/resources/stock_keeping_unit'
|
112
184
|
require 'didww/resources/trunk_group'
|
113
185
|
require 'didww/resources/trunk'
|
114
|
-
require 'didww/resources/
|
115
|
-
require 'didww/resources/
|
186
|
+
require 'didww/resources/available_did'
|
187
|
+
require 'didww/resources/did_reservation'
|
188
|
+
require 'didww/resources/requirement'
|
189
|
+
require 'didww/resources/proof_type'
|
190
|
+
require 'didww/resources/supporting_document_template'
|
191
|
+
require 'didww/resources/identity'
|
192
|
+
require 'didww/resources/proof'
|
193
|
+
require 'didww/resources/address'
|
194
|
+
require 'didww/resources/permanent_supporting_document'
|
195
|
+
require 'didww/resources/encrypted_file'
|
196
|
+
require 'didww/resources/address_verification'
|
197
|
+
require 'didww/resources/requirement_validation'
|
198
|
+
require 'didww/resources/public_key'
|
199
|
+
require 'didww/resources/area'
|
116
200
|
end
|
117
201
|
|
118
202
|
end
|
@@ -1,3 +1,4 @@
|
|
1
|
+
# frozen_string_literal: true
|
1
2
|
require 'json_api_client/schema'
|
2
3
|
|
3
4
|
module DIDWW
|
@@ -12,10 +13,8 @@ module DIDWW
|
|
12
13
|
|
13
14
|
def property(name, options = {})
|
14
15
|
property = schema.add(name, options)
|
15
|
-
define_method(name) {
|
16
|
-
define_method("#{name}=".to_sym)
|
17
|
-
attributes[name] = property.cast(val)
|
18
|
-
end
|
16
|
+
define_method(name.to_sym) { self[name] }
|
17
|
+
define_method("#{name}=".to_sym) { |val| self[name] = val }
|
19
18
|
end
|
20
19
|
|
21
20
|
def schema
|
@@ -46,7 +45,10 @@ module DIDWW
|
|
46
45
|
|
47
46
|
# Returns a ComplexObject class if given JSON API type matches any
|
48
47
|
def class_for_type(type)
|
49
|
-
|
48
|
+
# activesupport 6 has breaking change - parent* methods renamed to module_parent*.
|
49
|
+
# see https://github.com/rails/rails/pull/34051
|
50
|
+
name = respond_to?(:module_parent_name) ? module_parent_name : parent_name
|
51
|
+
"#{name}::#{type.classify}".safe_constantize
|
50
52
|
end
|
51
53
|
end
|
52
54
|
|
@@ -70,7 +72,8 @@ module DIDWW
|
|
70
72
|
end
|
71
73
|
|
72
74
|
def []=(key, value)
|
73
|
-
|
75
|
+
property = self.class.schema.find(key)
|
76
|
+
attributes[key] = property ? property.cast(value) : value
|
74
77
|
end
|
75
78
|
|
76
79
|
# When we represent this resource for serialization (create/update), we do so
|
@@ -0,0 +1,17 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
module DIDWW
|
3
|
+
module ComplexObject
|
4
|
+
class CapacityOrderItem < Base
|
5
|
+
# passed at order creation
|
6
|
+
property :qty, type: :int
|
7
|
+
property :capacity_pool_id, type: :string
|
8
|
+
|
9
|
+
# returned
|
10
|
+
property :nrc, type: :decimal
|
11
|
+
property :mrc, type: :decimal
|
12
|
+
property :propated_mrc, type: :boolean
|
13
|
+
property :billed_from, type: :string
|
14
|
+
property :billed_to, type: :string
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|