didww-v3 5.0.0 → 5.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 22a712d25c5bdfa402c73df24b8529f0e001e97256cf7d84cdfbb8d492af4dcd
4
- data.tar.gz: f3fdb4186c6821dd1d9c93744515e0a3eb6d0d1b3da3c1da4d0449dd8d726512
3
+ metadata.gz: 39b910fbb0b5dc4425cf053fd6cacef936c7c46510f8586d33784cccad18a95e
4
+ data.tar.gz: 1dae18d3341a93e2a2b4c74d81e224e0402a8c7020bda0053fb685be5186abb2
5
5
  SHA512:
6
- metadata.gz: de07093d853e4576ea5e18552786f3bb88d3013456a75f2efdaae56a3dbbb2560384d11bd22d1cd42f3cd739c0baf531e190dc70e700fba23bd46e3309861d16
7
- data.tar.gz: 2a434cb0c3a17840b8b7490b45078f66bb835f5656241fb98a6f629f6c7ee7305cfe6015366c7b9fbfb47233c02dbfe3292e0408deaf8f80e116b089524f5c0c
6
+ metadata.gz: eba0ac2332cf5f0f4c1f65155c0714d9ce35f0a96227024d2b3a21ab650c44587c789035cfb3dd995d797a08573e821eb1301e00732f91cdb3732175c163177c
7
+ data.tar.gz: a1ebd2311fa0b1f190d068a210ccfe583b74e3b6ec83c7ad368f2f2eb69d2bdf7d40b8ad5ddb98ab2828b2061ce20a77a67db2406b9c30e5ed4f417d20454259
@@ -5,6 +5,11 @@ on:
5
5
  branches:
6
6
  - master
7
7
 
8
+ permissions:
9
+ contents: read
10
+ pages: write
11
+ id-token: write
12
+
8
13
  jobs:
9
14
  test:
10
15
  runs-on: ubuntu-latest
@@ -23,3 +28,55 @@ jobs:
23
28
  bundler-cache: true
24
29
  - name: Run tests
25
30
  run: bundle exec rake
31
+
32
+ - name: Generate badge.json
33
+ if: matrix.ruby == '3.4' && matrix.rails == '~> 8.1'
34
+ run: |
35
+ LAST_RUN="coverage/.last_run.json"
36
+ if [ ! -f "$LAST_RUN" ]; then
37
+ mkdir -p badge
38
+ echo '{"schemaVersion":1,"label":"coverage","message":"unknown","color":"lightgrey"}' > badge/badge.json
39
+ exit 0
40
+ fi
41
+ PERCENT=$(ruby -rjson -e "puts JSON.parse(File.read('$LAST_RUN')).dig('result','line').round(1)")
42
+ PERCENT_NUM=$(ruby -rjson -e "puts JSON.parse(File.read('$LAST_RUN')).dig('result','line')")
43
+ if ruby -e "exit(($PERCENT_NUM >= 90) ? 0 : 1)"; then COLOR="brightgreen"
44
+ elif ruby -e "exit(($PERCENT_NUM >= 75) ? 0 : 1)"; then COLOR="green"
45
+ elif ruby -e "exit(($PERCENT_NUM >= 60) ? 0 : 1)"; then COLOR="yellow"
46
+ else COLOR="red"; fi
47
+ mkdir -p badge
48
+ echo "{\"schemaVersion\":1,\"label\":\"coverage\",\"message\":\"${PERCENT}%\",\"color\":\"${COLOR}\"}" > badge/badge.json
49
+
50
+ - name: Upload badge artifact
51
+ if: matrix.ruby == '3.4' && matrix.rails == '~> 8.1'
52
+ uses: actions/upload-artifact@v4
53
+ with:
54
+ name: coverage-badge
55
+ path: badge
56
+
57
+ deploy-coverage:
58
+ needs: test
59
+ if: github.ref == 'refs/heads/master' && github.event_name == 'push'
60
+ runs-on: ubuntu-latest
61
+ environment:
62
+ name: github-pages
63
+ url: ${{ steps.deployment.outputs.page_url }}
64
+
65
+ steps:
66
+ - name: Download coverage badge
67
+ uses: actions/download-artifact@v4
68
+ with:
69
+ name: coverage-badge
70
+ path: coverage
71
+
72
+ - name: Setup Pages
73
+ uses: actions/configure-pages@v5
74
+
75
+ - name: Upload Pages artifact
76
+ uses: actions/upload-pages-artifact@v3
77
+ with:
78
+ path: coverage
79
+
80
+ - name: Deploy to GitHub Pages
81
+ id: deployment
82
+ uses: actions/deploy-pages@v4
data/README.md CHANGED
@@ -1,7 +1,9 @@
1
1
  Ruby client for DIDWW API v3.
2
2
 
3
3
  ![Tests](https://github.com/didww/didww-v3-ruby/workflows/Tests/badge.svg)
4
+ ![Coverage](https://img.shields.io/endpoint?url=https://didww.github.io/didww-v3-ruby/badge.json)
4
5
  [![Gem Version](https://badge.fury.io/rb/didww-v3.svg)](https://badge.fury.io/rb/didww-v3)
6
+ ![Ruby](https://img.shields.io/badge/ruby-3.3%2B-blue)
5
7
 
6
8
  About DIDWW API v3
7
9
  -----
@@ -10,8 +12,12 @@ The DIDWW API provides a simple yet powerful interface that allows you to fully
10
12
 
11
13
  The DIDWW API v3 is a fully compliant implementation of the [JSON API specification](http://jsonapi.org/format/).
12
14
 
15
+ This SDK uses [json_api_client](https://github.com/JsonApiClient/json_api_client) for JSON:API serialization and deserialization.
16
+
13
17
  Read more https://doc.didww.com/api
14
18
 
19
+ This SDK sends the `X-DIDWW-API-Version: 2022-05-10` header with every request by default.
20
+
15
21
  Gem Versions **4.X.X** and branch [master](https://github.com/didww/didww-v3-ruby) are intended to use with DIDWW API 3 version [2022-05-10](https://doc.didww.com/api3/2022-05-10/index.html).
16
22
 
17
23
  Gem Versions **3.X.X** and branch [release-3](https://github.com/didww/didww-v3-ruby/tree/release-3) are intended to use with DIDWW API 3 version [2021-12-15](https://doc.didww.com/api3/2021-12-15/index.html).
@@ -36,22 +42,155 @@ Or install it yourself as:
36
42
 
37
43
  $ gem install didww-v3
38
44
 
39
- ## Usage
45
+ ## Requirements
46
+
47
+ - Ruby 3.3+
48
+
49
+ ## Quick Start
40
50
 
41
51
  ```ruby
42
52
  require 'didww'
43
53
 
44
54
  client = DIDWW::Client.configure do |config|
45
- config.api_key = '34ffe988432b980f4ba19432539b704f'
55
+ config.api_key = 'YOUR_API_KEY'
46
56
  config.api_mode = :sandbox
47
57
  end
48
58
 
49
- client.balance
59
+ # Check balance
60
+ balance = client.balance
61
+ puts "Balance: #{balance.total_balance}"
62
+
63
+ # List DID groups with stock keeping units
64
+ did_groups = client.did_groups.all(
65
+ include: 'stock_keeping_units',
66
+ filter: { area_name: 'Acapulco' }
67
+ )
68
+
69
+ puts "DID groups: #{did_groups.count}"
70
+ ```
71
+
72
+ For more examples visit [examples](examples/).
73
+
74
+ For details on obtaining your API key please visit https://doc.didww.com/api3/configuration.html
75
+
76
+ ## Examples
77
+
78
+ - Source code: [examples/](examples/)
79
+ - How to run: [examples/README.md](examples/README.md)
80
+ - Rails integration sample: https://github.com/didww/didww-v3-rails-sample
81
+
82
+ ## Configuration
83
+
84
+ ```ruby
85
+ require 'didww'
86
+
87
+ # Sandbox
88
+ DIDWW::Client.configure do |config|
89
+ config.api_key = 'YOUR_API_KEY'
90
+ config.api_mode = :sandbox
91
+ end
92
+
93
+ # Production
94
+ DIDWW::Client.configure do |config|
95
+ config.api_key = 'YOUR_API_KEY'
96
+ config.api_mode = :production
97
+ end
98
+ ```
99
+
100
+ ### Environments
101
+
102
+ | Environment | Base URL |
103
+ |-------------|----------|
104
+ | `:production` | `https://api.didww.com/v3/` |
105
+ | `:sandbox` | `https://sandbox-api.didww.com/v3/` |
106
+
107
+ ### API Version
108
+
109
+ The SDK sends `X-DIDWW-API-Version: 2022-05-10` by default. You can override it per block:
110
+
111
+ ```ruby
112
+ DIDWW::Client.with_api_version('2022-05-10') do
113
+ DIDWW::Client.countries.all
114
+ end
115
+ ```
116
+
117
+ ## Resources
118
+
119
+ ### Read-Only Resources
120
+
121
+ ```ruby
122
+ # Countries
123
+ countries = DIDWW::Client.countries.all
124
+ country = DIDWW::Client.countries.find('uuid')
125
+
126
+ # Regions, Cities, Areas, POPs
127
+ regions = DIDWW::Client.regions.all
128
+ cities = DIDWW::Client.cities.all
129
+ areas = DIDWW::Client.areas.all
130
+ pops = DIDWW::Client.pops.all
131
+
132
+ # DID Group Types
133
+ types = DIDWW::Client.did_group_types.all
134
+
135
+ # DID Groups (with stock keeping units)
136
+ did_groups = DIDWW::Client.did_groups.all(include: 'stock_keeping_units')
137
+
138
+ # Available DIDs (with DID group and stock keeping units)
139
+ available_dids = DIDWW::Client.available_dids.all(include: 'did_group.stock_keeping_units')
140
+
141
+ # Public Keys
142
+ public_keys = DIDWW::Client.public_keys.all
143
+
144
+ # Requirements
145
+ requirements = DIDWW::Client.requirements.all
146
+
147
+ # Balance (singleton)
148
+ balance = DIDWW::Client.balance
149
+ ```
150
+
151
+ ### DIDs
152
+
153
+ ```ruby
154
+ # List DIDs
155
+ dids = DIDWW::Client.dids.all
156
+
157
+ # Update DID
158
+ did = DIDWW::Client.dids.find('uuid')
159
+ did.description = 'Updated'
160
+ did.capacity_limit = 20
161
+ did.save
50
162
  ```
51
163
 
52
- For details on obtaining your API key please visit https://doc.didww.com/api#introduction-api-keys
164
+ ### Voice In Trunks
53
165
 
54
- See integration example at https://github.com/didww/didww-v3-rails-sample
166
+ ```ruby
167
+ trunk = DIDWW::Client.voice_in_trunks.new(
168
+ name: 'My SIP Trunk',
169
+ configuration: {
170
+ type: 'sip_configurations',
171
+ host: 'sip.example.com',
172
+ port: 5060
173
+ }
174
+ )
175
+
176
+ trunk.save
177
+ ```
178
+
179
+ ### Orders
180
+
181
+ ```ruby
182
+ order = DIDWW::Client.orders.new(
183
+ items: [
184
+ {
185
+ type: 'did_order_items',
186
+ sku_id: 'sku-uuid',
187
+ qty: 2
188
+ }
189
+ ]
190
+ )
191
+
192
+ order.save
193
+ ```
55
194
 
56
195
  ## Resource Relationships
57
196
 
data/lib/didww/client.rb CHANGED
@@ -12,8 +12,10 @@ module DIDWW
12
12
  production: 'https://api.didww.com/v3/'.freeze
13
13
  }.freeze
14
14
  DEFAULT_MODE = :sandbox
15
+ DEFAULT_API_VERSION = '2022-05-10'
15
16
 
16
17
  mattr_accessor :api_key, :api_mode, :http_verbose, :api_version
18
+ self.api_version = DEFAULT_API_VERSION
17
19
 
18
20
  class << self
19
21
  def configure
@@ -147,6 +149,22 @@ module DIDWW
147
149
  Resource::RequirementValidation
148
150
  end
149
151
 
152
+ def areas
153
+ Resource::Area
154
+ end
155
+
156
+ def proof_types
157
+ Resource::ProofType
158
+ end
159
+
160
+ def supporting_document_templates
161
+ Resource::SupportingDocumentTemplate
162
+ end
163
+
164
+ def public_keys
165
+ Resource::PublicKey
166
+ end
167
+
150
168
  def api_mode=(arg)
151
169
  unless BASE_URLS.keys.include?(arg)
152
170
  raise ArgumentError.new("Mode should be in #{BASE_URLS.keys} (given '#{arg}').")
@@ -183,6 +201,7 @@ module DIDWW
183
201
  require 'didww/resource/country'
184
202
  require 'didww/resource/did_group_type'
185
203
  require 'didww/resource/did_group'
204
+ require 'didww/resource/exclusive_relationship'
186
205
  require 'didww/resource/did'
187
206
  require 'didww/resource/order'
188
207
  require 'didww/resource/pop'
@@ -2,6 +2,8 @@
2
2
  module DIDWW
3
3
  module Resource
4
4
  class Did < Base
5
+ include ExclusiveRelationship
6
+
5
7
  has_one :did_group
6
8
  has_one :order
7
9
  has_one :voice_in_trunk
@@ -10,6 +12,8 @@ module DIDWW
10
12
  has_one :shared_capacity_group
11
13
  has_one :address_verification
12
14
 
15
+ exclusive_relationships(voice_in_trunk: :voice_in_trunk_group)
16
+
13
17
  property :blocked, type: :boolean
14
18
  # Type: Boolean
15
19
  # Description: Identifier for a blocked DID. Blocked DIDs are numbers that have expired, have been cancelled or have been suspended by DIDWW.
@@ -0,0 +1,54 @@
1
+ # frozen_string_literal: true
2
+ module DIDWW
3
+ module Resource
4
+ module ExclusiveRelationship
5
+ class Relations < JsonApiClient::Relationships::Relations
6
+ def initialize(record_class, relations, exclusions)
7
+ @exclusions = exclusions
8
+ @_initializing = true
9
+ super(record_class, relations)
10
+ @_initializing = false
11
+ end
12
+
13
+ def set_attribute(name, value)
14
+ super
15
+ return if @_initializing
16
+ exclusive = @exclusions[name.to_s]
17
+ if exclusive && !value.nil?
18
+ super(exclusive, nil)
19
+ end
20
+ end
21
+ end
22
+
23
+ def self.included(base)
24
+ base.extend(ClassMethods)
25
+ end
26
+
27
+ module ClassMethods
28
+ def exclusive_relationships(mapping)
29
+ full_mapping = {}
30
+ mapping.each do |a, b|
31
+ full_mapping[a.to_s] = b.to_s
32
+ full_mapping[b.to_s] = a.to_s
33
+ end
34
+ full_mapping.freeze
35
+
36
+ define_method(:_exclusive_relationship_mapping) { full_mapping }
37
+
38
+ define_method(:relationships) do
39
+ @relationships ||= Relations.new(self.class, {}, full_mapping)
40
+ end
41
+
42
+ define_method(:relationships=) do |rels|
43
+ attrs = case rels
44
+ when JsonApiClient::Relationships::Relations then rels.attributes
45
+ when Hash then rels
46
+ else rels || {}
47
+ end
48
+ @relationships = Relations.new(self.class, attrs, full_mapping)
49
+ end
50
+ end
51
+ end
52
+ end
53
+ end
54
+ end
@@ -1,6 +1,8 @@
1
1
  # frozen_string_literal: true
2
2
  require 'forwardable'
3
3
  require 'down/http'
4
+ require 'zlib'
5
+ require 'stringio'
4
6
  require 'didww/callback/const'
5
7
 
6
8
  module DIDWW
@@ -52,9 +54,21 @@ module DIDWW
52
54
  super params.reverse_merge(filters: {})
53
55
  end
54
56
 
55
- def csv
57
+ def download
56
58
  return unless url.present?
57
- Down::Http.new(headers: { 'Api-Key' => DIDWW::Client.api_key }).open(url)
59
+ Down::Http.new(headers: { 'Api-Key' => DIDWW::Client.api_key, 'X-DIDWW-API-Version' => DIDWW::Client.api_version }).open(url)
60
+ end
61
+
62
+ def csv
63
+ file = download
64
+ return unless file
65
+ gz = Zlib::GzipReader.new(file)
66
+ begin
67
+ StringIO.new(gz.read)
68
+ ensure
69
+ gz.close unless gz.closed?
70
+ file.close if file.respond_to?(:close) && !file.closed?
71
+ end
58
72
  end
59
73
 
60
74
  def complete?
data/lib/didww/version.rb CHANGED
@@ -1,4 +1,4 @@
1
1
  # frozen_string_literal: true
2
2
  module DIDWW
3
- VERSION = '5.0.0'.freeze
3
+ VERSION = '5.1.0'.freeze
4
4
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: didww-v3
3
3
  version: !ruby/object:Gem::Version
4
- version: 5.0.0
4
+ version: 5.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Alex Korobeinikov
@@ -145,6 +145,7 @@ files:
145
145
  - lib/didww/resource/did_group_type.rb
146
146
  - lib/didww/resource/did_reservation.rb
147
147
  - lib/didww/resource/encrypted_file.rb
148
+ - lib/didww/resource/exclusive_relationship.rb
148
149
  - lib/didww/resource/export.rb
149
150
  - lib/didww/resource/identity.rb
150
151
  - lib/didww/resource/nanpa_prefix.rb