didww-v3 5.0.0 → 5.2.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.
Files changed (46) hide show
  1. checksums.yaml +4 -4
  2. data/.github/workflows/tests.yml +57 -0
  3. data/README.md +202 -6
  4. data/examples/README.md +86 -0
  5. data/examples/balance.rb +17 -0
  6. data/examples/capacity_pools.rb +35 -0
  7. data/examples/countries.rb +34 -0
  8. data/examples/did_groups.rb +45 -0
  9. data/examples/did_reservations.rb +55 -0
  10. data/examples/did_trunk_assignment.rb +107 -0
  11. data/examples/dids.rb +62 -0
  12. data/examples/exports.rb +44 -0
  13. data/examples/identities_and_proofs.rb +62 -0
  14. data/examples/orders.rb +60 -0
  15. data/examples/orders_all_item_types.rb +153 -0
  16. data/examples/orders_available_dids.rb +63 -0
  17. data/examples/orders_by_sku.rb +53 -0
  18. data/examples/orders_capacity.rb +44 -0
  19. data/examples/orders_nanpa.rb +44 -0
  20. data/examples/orders_reservation_dids.rb +71 -0
  21. data/examples/regions.rb +45 -0
  22. data/examples/shared_capacity_groups.rb +51 -0
  23. data/examples/voice_in_trunk_groups.rb +51 -0
  24. data/examples/voice_in_trunks.rb +43 -0
  25. data/examples/voice_out_trunks.rb +68 -0
  26. data/lib/didww/base_middleware.rb +12 -6
  27. data/lib/didww/callback/request_validator.rb +5 -12
  28. data/lib/didww/client.rb +37 -98
  29. data/lib/didww/jsonapi_middleware.rb +5 -14
  30. data/lib/didww/resource/address.rb +2 -2
  31. data/lib/didww/resource/address_verification.rb +17 -14
  32. data/lib/didww/resource/concerns/has_status_helpers.rb +17 -0
  33. data/lib/didww/resource/did.rb +4 -0
  34. data/lib/didww/resource/did_group.rb +1 -0
  35. data/lib/didww/resource/encrypted_file.rb +2 -2
  36. data/lib/didww/resource/exclusive_relationship.rb +54 -0
  37. data/lib/didww/resource/export.rb +22 -4
  38. data/lib/didww/resource/identity.rb +7 -2
  39. data/lib/didww/resource/order.rb +5 -11
  40. data/lib/didww/resource/permanent_supporting_document.rb +2 -2
  41. data/lib/didww/resource/proof.rb +5 -5
  42. data/lib/didww/resource/region.rb +4 -0
  43. data/lib/didww/resource/requirement.rb +2 -2
  44. data/lib/didww/resource/supporting_document_template.rb +4 -0
  45. data/lib/didww/version.rb +1 -1
  46. metadata +26 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 22a712d25c5bdfa402c73df24b8529f0e001e97256cf7d84cdfbb8d492af4dcd
4
- data.tar.gz: f3fdb4186c6821dd1d9c93744515e0a3eb6d0d1b3da3c1da4d0449dd8d726512
3
+ metadata.gz: df4c6143fca0f8b1f6c6d5c4e43fc89a71a4a9fcc5b63b3b63c3bb9ab03ce102
4
+ data.tar.gz: dd9ad527373290850d9555f1117aa097aa534497668115fdcbb9dd2f2323f783
5
5
  SHA512:
6
- metadata.gz: de07093d853e4576ea5e18552786f3bb88d3013456a75f2efdaae56a3dbbb2560384d11bd22d1cd42f3cd739c0baf531e190dc70e700fba23bd46e3309861d16
7
- data.tar.gz: 2a434cb0c3a17840b8b7490b45078f66bb835f5656241fb98a6f629f6c7ee7305cfe6015366c7b9fbfb47233c02dbfe3292e0408deaf8f80e116b089524f5c0c
6
+ metadata.gz: 32dc4dc452c8ef98f1855ec47aee83cd7959f9abc3c3ade68489610d71600a8bcf1e232cb4a4e3a76ffae9a5b68adb19d133b8788d6d4ba7711dff36141c96b4
7
+ data.tar.gz: e759ef5119ea80accac264b297e4730f9391e774adc47d7dca853b0c9d79f6c1d2af4a61562e849af04c4a4ba476213a18696a9e88c7f8ee92b811c68059a09e
@@ -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,27 +42,217 @@ 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
- client = DIDWW::Client.configure do |config|
45
- config.api_key = '34ffe988432b980f4ba19432539b704f'
54
+ DIDWW::Client.configure do |config|
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 = DIDWW::Client.balance
61
+ puts "Balance: #{balance.total_balance}"
62
+
63
+ # List DID groups with stock keeping units
64
+ did_groups = DIDWW::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 details on obtaining your API key please visit https://doc.didww.com/api3/configuration.html
73
+
74
+ ## Examples
75
+
76
+ - Rails integration sample: https://github.com/didww/didww-v3-rails-sample
77
+
78
+ ## Configuration
79
+
80
+ ```ruby
81
+ require 'didww'
82
+
83
+ # Sandbox
84
+ DIDWW::Client.configure do |config|
85
+ config.api_key = 'YOUR_API_KEY'
86
+ config.api_mode = :sandbox
87
+ end
88
+
89
+ # Production
90
+ DIDWW::Client.configure do |config|
91
+ config.api_key = 'YOUR_API_KEY'
92
+ config.api_mode = :production
93
+ end
94
+ ```
95
+
96
+ ### Environments
97
+
98
+ | Environment | Base URL |
99
+ |-------------|----------|
100
+ | `:production` | `https://api.didww.com/v3/` |
101
+ | `:sandbox` | `https://sandbox-api.didww.com/v3/` |
102
+
103
+ ### API Version
104
+
105
+ The SDK sends `X-DIDWW-API-Version: 2022-05-10` by default. You can override it per block:
106
+
107
+ ```ruby
108
+ DIDWW::Client.with_api_version('2022-05-10') do
109
+ DIDWW::Client.countries.all
110
+ end
111
+ ```
112
+
113
+ ## Resources
114
+
115
+ ### Read-Only Resources
116
+
117
+ ```ruby
118
+ # Countries
119
+ countries = DIDWW::Client.countries.all
120
+ country = DIDWW::Client.countries.find('uuid')
121
+
122
+ # Regions, Cities, Areas, POPs
123
+ regions = DIDWW::Client.regions.all
124
+ cities = DIDWW::Client.cities.all
125
+ areas = DIDWW::Client.areas.all
126
+ pops = DIDWW::Client.pops.all
127
+
128
+ # DID Group Types
129
+ types = DIDWW::Client.did_group_types.all
130
+
131
+ # DID Groups (with stock keeping units)
132
+ did_groups = DIDWW::Client.did_groups.all(include: 'stock_keeping_units')
133
+
134
+ # Available DIDs (with DID group and stock keeping units)
135
+ available_dids = DIDWW::Client.available_dids.all(include: 'did_group.stock_keeping_units')
136
+
137
+ # Public Keys
138
+ public_keys = DIDWW::Client.public_keys.all
139
+
140
+ # Requirements
141
+ requirements = DIDWW::Client.requirements.all
142
+
143
+ # Balance (singleton)
144
+ balance = DIDWW::Client.balance
145
+ ```
146
+
147
+ ### DIDs
148
+
149
+ ```ruby
150
+ # List DIDs
151
+ dids = DIDWW::Client.dids.all
152
+
153
+ # Update DID
154
+ did = DIDWW::Client.dids.find('uuid')
155
+ did.description = 'Updated'
156
+ did.capacity_limit = 20
157
+ did.save
50
158
  ```
51
159
 
52
- For details on obtaining your API key please visit https://doc.didww.com/api#introduction-api-keys
160
+ ### Voice In Trunks
53
161
 
54
- See integration example at https://github.com/didww/didww-v3-rails-sample
162
+ ```ruby
163
+ trunk = DIDWW::Client.voice_in_trunks.new(
164
+ name: 'My SIP Trunk',
165
+ configuration: {
166
+ type: 'sip_configurations',
167
+ username: '{DID}',
168
+ host: 'sip.example.com',
169
+ port: 5060
170
+ }
171
+ )
172
+
173
+ trunk.save
174
+ ```
175
+
176
+ ### Orders
177
+
178
+ ```ruby
179
+ order = DIDWW::Client.orders.new(
180
+ items: [
181
+ {
182
+ type: 'did_order_items',
183
+ sku_id: 'sku-uuid',
184
+ qty: 2
185
+ }
186
+ ]
187
+ )
188
+
189
+ order.save
190
+ ```
191
+
192
+ ## Date and Datetime Fields
193
+
194
+ The SDK distinguishes between date-only and datetime fields:
195
+
196
+ - **Datetime fields** — deserialized as `Time`:
197
+ - All `created_at` fields — present on most resources (`EncryptedFile` has no `created_at`)
198
+ - Expiry fields: `Did#expires_at`, `DidReservation#expire_at`, `Proof#expires_at`, `EncryptedFile#expire_at`
199
+ - **Date-only fields** — deserialized as `Date`:
200
+ - `Identity#birth_date`
201
+ - **Date-only fields kept as strings** (`CapacityPool#renew_date`) remain as `String`.
202
+
203
+ ```ruby
204
+ did = DIDWW::Client.dids.find("uuid").first
205
+ puts did.created_at # => 2024-01-15 10:00:00 UTC (Time)
206
+ puts did.expires_at # => nil or 2025-01-15 10:00:00 UTC (Time)
207
+
208
+ identity = DIDWW::Client.identities.find("uuid").first
209
+ puts identity.birth_date # => 1990-05-20 (Date)
210
+ ```
55
211
 
56
212
  ## Resource Relationships
57
213
 
58
214
  See [docs/resource_relationships.md](docs/resource_relationships.md) for a Mermaid ER diagram showing all `has_one`, `has_many`, and `belongs_to` relationships between resources.
59
215
 
216
+ ## Webhook Signature Validation
217
+
218
+ Validate incoming webhook callbacks from DIDWW using HMAC-SHA1 signature verification.
219
+
220
+ ```ruby
221
+ require 'didww/callback/request_validator'
222
+
223
+ validator = DIDWW::Callback::RequestValidator.new("YOUR_API_KEY")
224
+
225
+ # In your webhook handler:
226
+ valid = validator.validate(
227
+ request_url, # full original URL
228
+ payload_params, # Hash of payload key-value pairs
229
+ signature # value of X-DIDWW-Signature header
230
+ )
231
+ ```
232
+
233
+ The signature header name is available as the constant `DIDWW::Callback::RequestValidator::HEADER`.
234
+
235
+ ### Rails Example
236
+
237
+ ```ruby
238
+ class WebhooksController < ApplicationController
239
+ skip_before_action :verify_authenticity_token
240
+
241
+ def create
242
+ validator = DIDWW::Callback::RequestValidator.new("YOUR_API_KEY")
243
+ signature = request.headers[DIDWW::Callback::RequestValidator::HEADER]
244
+ params_hash = request.POST
245
+
246
+ if validator.validate(request.original_url, params_hash, signature)
247
+ # Process the webhook
248
+ head :ok
249
+ else
250
+ head :forbidden
251
+ end
252
+ end
253
+ end
254
+ ```
255
+
60
256
  ## Development
61
257
 
62
258
  After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
@@ -0,0 +1,86 @@
1
+ # Examples
2
+
3
+ All examples read the API key from the `DIDWW_API_KEY` environment variable.
4
+
5
+ ## Prerequisites
6
+
7
+ - Ruby 3.3+
8
+ - Bundler
9
+ - DIDWW API key for sandbox account
10
+
11
+ ## Environment variables
12
+
13
+ - `DIDWW_API_KEY` (required): your DIDWW API key
14
+
15
+ ## Install
16
+
17
+ ```bash
18
+ cd examples && bundle install
19
+ ```
20
+
21
+ ## Run an example
22
+
23
+ ```bash
24
+ DIDWW_API_KEY=your_api_key ruby examples/orders_nanpa.rb
25
+ ```
26
+
27
+ ## Available examples
28
+
29
+ ### Core Resources
30
+ | Script | Description |
31
+ |---|---|
32
+ | [`balance.rb`](balance.rb) | Fetches and prints current account balance and credit. |
33
+ | [`countries.rb`](countries.rb) | Lists countries, demonstrates filtering, and fetches one country by ID. |
34
+ | [`regions.rb`](regions.rb) | Lists regions with filters/includes and fetches a specific region. |
35
+ | [`did_groups.rb`](did_groups.rb) | Fetches DID groups with included SKUs and shows group details. |
36
+ | [`dids.rb`](dids.rb) | Updates DID routing/capacity by assigning trunk and capacity pool. |
37
+ | [`exports.rb`](exports.rb) | Lists CDR exports and their details. |
38
+
39
+ ### Voice In (Inbound)
40
+ | Script | Description |
41
+ |---|---|
42
+ | [`voice_in_trunks.rb`](voice_in_trunks.rb) | Lists voice in trunks and their configurations. |
43
+ | [`voice_in_trunk_groups.rb`](voice_in_trunk_groups.rb) | CRUD for trunk groups with trunk relationships. |
44
+
45
+ ### Voice Out (Outbound)
46
+ | Script | Description |
47
+ |---|---|
48
+ | [`voice_out_trunks.rb`](voice_out_trunks.rb) | CRUD for voice out trunks (requires account config). |
49
+
50
+ ### Capacity Management
51
+ | Script | Description |
52
+ |---|---|
53
+ | [`capacity_pools.rb`](capacity_pools.rb) | Lists capacity pools with included shared capacity groups. |
54
+ | [`shared_capacity_groups.rb`](shared_capacity_groups.rb) | Creates a shared capacity group in a capacity pool. |
55
+
56
+ ### Orders - Basic
57
+ | Script | Description |
58
+ |---|---|
59
+ | [`orders.rb`](orders.rb) | Lists orders and creates/cancels a DID order using live SKU lookup. |
60
+ | [`orders_nanpa.rb`](orders_nanpa.rb) | Orders a DID number by NPA/NXX prefix. |
61
+ | [`orders_by_sku.rb`](orders_by_sku.rb) | Creates a DID order by SKU resolved from DID groups. |
62
+ | [`orders_capacity.rb`](orders_capacity.rb) | Purchases capacity by creating a capacity order item. |
63
+
64
+ ### Orders - Advanced
65
+ | Script | Description |
66
+ |---|---|
67
+ | [`orders_available_dids.rb`](orders_available_dids.rb) | Orders an available DID using included DID group SKU. |
68
+ | [`orders_reservation_dids.rb`](orders_reservation_dids.rb) | Reserves a DID and then places an order from that reservation. |
69
+ | [`orders_all_item_types.rb`](orders_all_item_types.rb) | Creates a DID order with all item types: by SKU, available DID, and reservation. |
70
+
71
+ ### DID Management
72
+ | Script | Description |
73
+ |---|---|
74
+ | [`did_reservations.rb`](did_reservations.rb) | Lists DID reservations and available DIDs. |
75
+ | [`did_trunk_assignment.rb`](did_trunk_assignment.rb) | Demonstrates exclusive trunk/trunk group assignment on DIDs. |
76
+
77
+ ### Compliance & Verification
78
+ | Script | Description |
79
+ |---|---|
80
+ | [`identities_and_proofs.rb`](identities_and_proofs.rb) | Creates identities, addresses, and demonstrates proof workflow. |
81
+
82
+ ## Troubleshooting
83
+
84
+ If `DIDWW_API_KEY` is missing, examples fail fast with:
85
+
86
+ `Please set DIDWW_API_KEY`
@@ -0,0 +1,17 @@
1
+ # frozen_string_literal: true
2
+ # Fetches and prints current account balance and credit.
3
+ #
4
+ # Usage: DIDWW_API_KEY=your_api_key ruby examples/balance.rb
5
+
6
+ require 'bundler/setup'
7
+ require 'didww'
8
+
9
+ DIDWW::Client.configure do |client|
10
+ client.api_key = ENV.fetch('DIDWW_API_KEY') { abort 'Please set DIDWW_API_KEY' }
11
+ client.api_mode = :sandbox
12
+ end
13
+
14
+ balance = DIDWW::Client.balance
15
+ puts "Total Balance: #{balance.total_balance}"
16
+ puts "Balance: #{balance.balance}"
17
+ puts "Credit: #{balance.credit}"
@@ -0,0 +1,35 @@
1
+ # frozen_string_literal: true
2
+ # Lists capacity pools with included shared capacity groups.
3
+ #
4
+ # Usage: DIDWW_API_KEY=your_api_key ruby examples/capacity_pools.rb
5
+
6
+ require 'bundler/setup'
7
+ require 'didww'
8
+
9
+ DIDWW::Client.configure do |client|
10
+ client.api_key = ENV.fetch('DIDWW_API_KEY') { abort 'Please set DIDWW_API_KEY' }
11
+ client.api_mode = :sandbox
12
+ end
13
+
14
+ # List capacity pools with included shared capacity groups
15
+ puts '=== Capacity Pools ==='
16
+ capacity_pools = DIDWW::Client.capacity_pools
17
+ .includes(:shared_capacity_groups)
18
+ .all
19
+
20
+ puts "Found #{capacity_pools.size} capacity pools"
21
+
22
+ capacity_pools.each do |pool|
23
+ puts "\nCapacity Pool: #{pool.name}"
24
+ puts " Total channels: #{pool.total_channels_count}"
25
+ puts " Assigned channels: #{pool.assigned_channels_count}"
26
+ puts " Monthly price: #{pool.monthly_price}"
27
+ puts " Metered rate: #{pool.metered_rate}"
28
+
29
+ if pool.shared_capacity_groups && !pool.shared_capacity_groups.empty?
30
+ puts ' Shared Capacity Groups:'
31
+ pool.shared_capacity_groups.each do |group|
32
+ puts " - #{group.name} (#{group.shared_channels_count} channels)"
33
+ end
34
+ end
35
+ end
@@ -0,0 +1,34 @@
1
+ # frozen_string_literal: true
2
+ # Lists countries, demonstrates filtering, and fetches one country by ID.
3
+ #
4
+ # Usage: DIDWW_API_KEY=your_api_key ruby examples/countries.rb
5
+
6
+ require 'bundler/setup'
7
+ require 'didww'
8
+
9
+ DIDWW::Client.configure do |client|
10
+ client.api_key = ENV.fetch('DIDWW_API_KEY') { abort 'Please set DIDWW_API_KEY' }
11
+ client.api_mode = :sandbox
12
+ end
13
+
14
+ # List all countries
15
+ puts '=== All Countries ==='
16
+ countries = DIDWW::Client.countries.all
17
+ countries.first(5).each do |country|
18
+ puts "#{country.name} (+#{country.prefix}) [#{country.iso}]"
19
+ end
20
+
21
+ # Filter countries by name
22
+ puts "\n=== Filtered Countries (United States) ==="
23
+ filtered = DIDWW::Client.countries.where(name: 'United States').all
24
+ puts "Found: #{filtered.size} countries"
25
+ filtered.each do |country|
26
+ puts "#{country.name} (+#{country.prefix})"
27
+ end
28
+
29
+ # Find a specific country
30
+ if !filtered.empty?
31
+ puts "\n=== Specific Country ==="
32
+ country = DIDWW::Client.countries.find(filtered.first.id).first
33
+ puts "Found: #{country.name}"
34
+ end
@@ -0,0 +1,45 @@
1
+ # frozen_string_literal: true
2
+ # Fetches DID groups with included SKUs and shows group details.
3
+ #
4
+ # Usage: DIDWW_API_KEY=your_api_key ruby examples/did_groups.rb
5
+
6
+ require 'bundler/setup'
7
+ require 'didww'
8
+
9
+ DIDWW::Client.configure do |client|
10
+ client.api_key = ENV.fetch('DIDWW_API_KEY') { abort 'Please set DIDWW_API_KEY' }
11
+ client.api_mode = :sandbox
12
+ end
13
+
14
+ # Fetch DID groups with included stock_keeping_units
15
+ puts '=== DID Groups with SKUs ==='
16
+ did_groups = DIDWW::Client.did_groups
17
+ .includes(:stock_keeping_units)
18
+ .all
19
+
20
+ puts "Found #{did_groups.size} DID groups"
21
+
22
+ did_groups.first(3).each do |did_group|
23
+ puts "\nDID Group: #{did_group.id}"
24
+ puts " Area: #{did_group.area_name}"
25
+ puts " Prefix: #{did_group.prefix}"
26
+ puts " Metered: #{did_group.is_metered}"
27
+ puts " Features: #{did_group.features_human}"
28
+
29
+ if did_group.stock_keeping_units && !did_group.stock_keeping_units.empty?
30
+ puts ' SKUs:'
31
+ did_group.stock_keeping_units.each do |sku|
32
+ puts " - #{sku.id} (monthly: #{sku.monthly_price})"
33
+ end
34
+ end
35
+ end
36
+
37
+ # Find a specific DID group
38
+ if !did_groups.empty?
39
+ puts "\n=== Specific DID Group ==="
40
+ did_group = DIDWW::Client.did_groups
41
+ .includes(:stock_keeping_units)
42
+ .find(did_groups.first.id)
43
+ .first
44
+ puts "Found: #{did_group.area_name} (prefix: #{did_group.prefix})"
45
+ end
@@ -0,0 +1,55 @@
1
+ # frozen_string_literal: true
2
+ # Lists DID reservations and available DIDs.
3
+ #
4
+ # Usage: DIDWW_API_KEY=your_api_key ruby examples/did_reservations.rb
5
+
6
+ require 'bundler/setup'
7
+ require 'didww'
8
+
9
+ DIDWW::Client.configure do |client|
10
+ client.api_key = ENV.fetch('DIDWW_API_KEY') { abort 'Please set DIDWW_API_KEY' }
11
+ client.api_mode = :sandbox
12
+ end
13
+
14
+ # List DID reservations
15
+ puts '=== Existing DID Reservations ==='
16
+ reservations = DIDWW::Client.did_reservations
17
+ .includes(:available_did)
18
+ .all
19
+
20
+ puts "Found #{reservations.size} DID reservations"
21
+ reservations.first(10).each do |reservation|
22
+ did_number = reservation.available_did ? reservation.available_did.number : 'unknown'
23
+ puts "#{reservation.id}"
24
+ puts " DID: #{did_number}"
25
+ puts " Expires: #{reservation.expire_at}"
26
+ puts " Created: #{reservation.created_at}"
27
+ puts ''
28
+ end
29
+
30
+ # List available DIDs
31
+ puts "\n=== Available DIDs ==="
32
+ available_dids = DIDWW::Client.available_dids
33
+ .includes(:did_group)
34
+ .all
35
+
36
+ puts "Found #{available_dids.size} available DIDs"
37
+ available_dids.first(10).each do |available_did|
38
+ puts "#{available_did.number}"
39
+ if available_did.did_group
40
+ puts " Group: #{available_did.did_group.area_name}"
41
+ puts " Prefix: #{available_did.did_group.prefix}"
42
+ end
43
+ puts ''
44
+ end
45
+
46
+ # Find a specific reservation if available
47
+ if !reservations.empty?
48
+ puts "\n=== Specific Reservation Details ==="
49
+ specific_reservation = DIDWW::Client.did_reservations
50
+ .find(reservations.first.id)
51
+ .first
52
+ puts "Reservation: #{specific_reservation.id}"
53
+ puts " Expires at: #{specific_reservation.expire_at}"
54
+ puts " Created at: #{specific_reservation.created_at}"
55
+ end