didww-v3 6.2.1 → 7.0.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 +4 -4
- data/.github/workflows/tests.yml +8 -6
- data/.rubocop.yml +0 -110
- data/CHANGELOG.md +61 -0
- data/FILTERS.md +36 -12
- data/Gemfile +0 -2
- data/README.md +427 -56
- data/didww-v3.gemspec +11 -8
- data/docs/resource_relationships.md +35 -15
- data/examples/README.md +54 -61
- data/examples/capacity_pools.rb +28 -10
- data/examples/countries.rb +1 -1
- data/examples/did_groups.rb +1 -1
- data/examples/did_reservations.rb +35 -37
- data/examples/did_sms_routing.rb +91 -0
- data/examples/did_trunk_assignment.rb +106 -80
- data/examples/emergency_calling_services.rb +3 -3
- data/examples/emergency_requirements.rb +3 -3
- data/examples/emergency_scenario.rb +11 -11
- data/examples/emergency_verifications.rb +7 -5
- data/examples/exports.rb +1 -1
- data/examples/exports_sms.rb +72 -0
- data/examples/identity_address_proofs.rb +118 -0
- data/examples/includes.rb +65 -0
- data/examples/orders.rb +8 -6
- data/examples/orders_all_item_types.rb +63 -125
- data/examples/orders_emergency.rb +3 -3
- data/examples/{orders_by_sku.rb → orders_sku.rb} +12 -10
- data/examples/prices_download.rb +45 -0
- data/examples/prices_lookup.rb +43 -0
- data/examples/regions.rb +1 -1
- data/examples/sample.pdf +14 -0
- data/examples/sender_id_verifications.rb +63 -0
- data/examples/shared_capacity_groups.rb +44 -35
- data/examples/sms_trunk_groups.rb +71 -0
- data/examples/sms_trunks.rb +84 -0
- data/examples/test_readme.rb +1216 -0
- data/examples/trunks.rb +115 -0
- data/examples/upload_file.rb +44 -0
- data/examples/voice_in_trunk_groups.rb +57 -33
- data/examples/voice_in_trunk_sip_registration.rb +4 -1
- data/examples/voice_out_trunks.rb +11 -1
- data/examples/webhook.rb +51 -0
- data/lib/didww/auth/bearer_middleware.rb +74 -0
- data/lib/didww/auth/memory_store.rb +40 -0
- data/lib/didww/auth/token.rb +45 -0
- data/lib/didww/auth/token_provider.rb +215 -0
- data/lib/didww/base_middleware.rb +7 -8
- data/lib/didww/callback/request_validator.rb +2 -1
- data/lib/didww/client.rb +122 -13
- data/lib/didww/complex_objects/authentication_methods/generic.rb +6 -0
- data/lib/didww/complex_objects/configurations/base.rb +0 -18
- data/lib/didww/complex_objects/configurations/pstn_configuration.rb +0 -4
- data/lib/didww/complex_objects/configurations/sip_configuration.rb +86 -38
- data/lib/didww/complex_objects/emergency_order_item.rb +1 -1
- data/lib/didww/complex_objects/export_filters.rb +72 -6
- data/lib/didww/complex_objects/generic_order_item.rb +15 -0
- data/lib/didww/complex_objects/sms_trunk_configuration.rb +33 -0
- data/lib/didww/complex_objects/sms_trunk_configurations/base.rb +26 -0
- data/lib/didww/complex_objects/sms_trunk_configurations/generic.rb +32 -0
- data/lib/didww/complex_objects/sms_trunk_configurations/http_in.rb +75 -0
- data/lib/didww/complex_objects/sms_trunk_configurations/http_out.rb +35 -0
- data/lib/didww/complex_objects/sms_trunk_configurations/smpp_esme.rb +37 -0
- data/lib/didww/complex_objects/sms_trunk_configurations/smpp_smsc.rb +56 -0
- data/lib/didww/complex_objects/sms_trunk_configurations/sms_to_email.rb +27 -0
- data/lib/didww/errors.rb +103 -0
- data/lib/didww/http.rb +34 -0
- data/lib/didww/prices/lookup_result.rb +37 -0
- data/lib/didww/prices/price.rb +56 -0
- data/lib/didww/prices/price_file.rb +51 -0
- data/lib/didww/prices/service.rb +248 -0
- data/lib/didww/prices/sms_in_price.rb +43 -0
- data/lib/didww/prices/sms_out_price.rb +52 -0
- data/lib/didww/prices/voice_in_price.rb +48 -0
- data/lib/didww/prices/voice_out_price.rb +88 -0
- data/lib/didww/prices.rb +82 -0
- data/lib/didww/resource/address_requirement.rb +13 -3
- data/lib/didww/resource/base.rb +5 -2
- data/lib/didww/resource/concerns/number_types.rb +24 -0
- data/lib/didww/resource/did.rb +42 -3
- data/lib/didww/resource/did_group.rb +12 -1
- data/lib/didww/resource/emergency_calling_service.rb +10 -5
- data/lib/didww/resource/emergency_requirement.rb +27 -14
- data/lib/didww/resource/encrypted_file.rb +19 -6
- data/lib/didww/resource/export.rb +59 -12
- data/lib/didww/resource/identity.rb +9 -4
- data/lib/didww/resource/order.rb +1 -0
- data/lib/didww/resource/proof_type.rb +1 -1
- data/lib/didww/resource/sender_id_verification.rb +114 -0
- data/lib/didww/resource/sms_trunk.rb +76 -0
- data/lib/didww/resource/sms_trunk_group.rb +31 -0
- data/lib/didww/resource/sms_trunk_regenerate_credential.rb +16 -0
- data/lib/didww/resource/voice_in_trunk.rb +24 -1
- data/lib/didww/resource/voice_out_trunk.rb +72 -0
- data/lib/didww/types/ip_addresses.rb +1 -1
- data/lib/didww/types/strings.rb +1 -1
- data/lib/didww/types.rb +3 -1
- data/lib/didww/version.rb +1 -1
- data/lib/didww.rb +7 -0
- metadata +62 -24
- data/examples/identities_and_proofs.rb +0 -67
- data/examples/voice_in_trunks.rb +0 -108
- data/lib/didww/resource/did_group_type.rb +0 -10
- data/lib/didww/resource/exclusive_relationship.rb +0 -54
- data/lib/didww/resource/pop.rb +0 -10
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module DIDWW
|
|
4
|
+
module Resource
|
|
5
|
+
# Possible values for number_type
|
|
6
|
+
module NumberTypes
|
|
7
|
+
NUMBER_TYPE_LOCAL = 'local'
|
|
8
|
+
NUMBER_TYPE_NATIONAL = 'national'
|
|
9
|
+
NUMBER_TYPE_MOBILE = 'mobile'
|
|
10
|
+
NUMBER_TYPE_TOLL_FREE = 'toll_free'
|
|
11
|
+
NUMBER_TYPE_SHARED_COST = 'shared_cost'
|
|
12
|
+
NUMBER_TYPE_GLOBAL = 'global'
|
|
13
|
+
|
|
14
|
+
NUMBER_TYPES = [
|
|
15
|
+
NUMBER_TYPE_LOCAL,
|
|
16
|
+
NUMBER_TYPE_NATIONAL,
|
|
17
|
+
NUMBER_TYPE_MOBILE,
|
|
18
|
+
NUMBER_TYPE_TOLL_FREE,
|
|
19
|
+
NUMBER_TYPE_SHARED_COST,
|
|
20
|
+
NUMBER_TYPE_GLOBAL
|
|
21
|
+
].freeze
|
|
22
|
+
end
|
|
23
|
+
end
|
|
24
|
+
end
|
data/lib/didww/resource/did.rb
CHANGED
|
@@ -2,12 +2,53 @@
|
|
|
2
2
|
module DIDWW
|
|
3
3
|
module Resource
|
|
4
4
|
class Did < Base
|
|
5
|
-
|
|
5
|
+
# voice_in_trunk and voice_in_trunk_group are mutually exclusive, and so are
|
|
6
|
+
# sms_trunk and sms_trunk_group: assigning one clears the other, matching the
|
|
7
|
+
# server's own constraint.
|
|
8
|
+
class Relations < JsonApiClient::Relationships::Relations
|
|
9
|
+
EXCLUSIONS = {
|
|
10
|
+
'voice_in_trunk' => 'voice_in_trunk_group',
|
|
11
|
+
'voice_in_trunk_group' => 'voice_in_trunk',
|
|
12
|
+
'sms_trunk' => 'sms_trunk_group',
|
|
13
|
+
'sms_trunk_group' => 'sms_trunk'
|
|
14
|
+
}.freeze
|
|
15
|
+
|
|
16
|
+
# Bulk assignment (construction, or the server response applied after save)
|
|
17
|
+
# mirrors the server state as-is; only a single assignment clears its pair.
|
|
18
|
+
def attributes=(attrs = {})
|
|
19
|
+
@_bulk_assigning = true
|
|
20
|
+
super
|
|
21
|
+
ensure
|
|
22
|
+
@_bulk_assigning = false
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
def set_attribute(name, value)
|
|
26
|
+
super
|
|
27
|
+
return if @_bulk_assigning
|
|
28
|
+
exclusive = EXCLUSIONS[name.to_s]
|
|
29
|
+
super(exclusive, nil) if exclusive && !value.nil?
|
|
30
|
+
end
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
def relationships
|
|
34
|
+
@relationships ||= Relations.new(self.class, {})
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
def relationships=(rels)
|
|
38
|
+
attrs = case rels
|
|
39
|
+
when JsonApiClient::Relationships::Relations then rels.attributes
|
|
40
|
+
when Hash then rels
|
|
41
|
+
else rels || {}
|
|
42
|
+
end
|
|
43
|
+
@relationships = Relations.new(self.class, attrs)
|
|
44
|
+
end
|
|
6
45
|
|
|
7
46
|
has_one :did_group
|
|
8
47
|
has_one :order
|
|
9
48
|
has_one :voice_in_trunk
|
|
10
49
|
has_one :voice_in_trunk_group
|
|
50
|
+
has_one :sms_trunk, class_name: 'SmsTrunk'
|
|
51
|
+
has_one :sms_trunk_group, class_name: 'SmsTrunkGroup'
|
|
11
52
|
has_one :capacity_pool
|
|
12
53
|
has_one :shared_capacity_group
|
|
13
54
|
has_one :address_verification
|
|
@@ -15,8 +56,6 @@ module DIDWW
|
|
|
15
56
|
has_one :emergency_verification, class_name: 'EmergencyVerification'
|
|
16
57
|
has_one :identity, class_name: 'Identity'
|
|
17
58
|
|
|
18
|
-
exclusive_relationships(voice_in_trunk: :voice_in_trunk_group)
|
|
19
|
-
|
|
20
59
|
property :blocked, type: :boolean
|
|
21
60
|
# Type: Boolean
|
|
22
61
|
# Description: Identifier for a blocked DID. Blocked DIDs are numbers that have expired, have been canceled or have been suspended by DIDWW.
|
|
@@ -1,7 +1,11 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
|
+
require 'didww/resource/concerns/number_types'
|
|
3
|
+
|
|
2
4
|
module DIDWW
|
|
3
5
|
module Resource
|
|
4
6
|
class DidGroup < Base
|
|
7
|
+
include NumberTypes
|
|
8
|
+
|
|
5
9
|
# Possible values for did_group.features array
|
|
6
10
|
FEATURE_VOICE_IN = 'voice_in'
|
|
7
11
|
FEATURE_VOICE_OUT = 'voice_out'
|
|
@@ -14,7 +18,6 @@ module DIDWW
|
|
|
14
18
|
|
|
15
19
|
has_one :country, class_name: 'Country'
|
|
16
20
|
has_one :city, class_name: 'City'
|
|
17
|
-
has_one :did_group_type, class_name: 'DidGroupType'
|
|
18
21
|
has_one :region, class_name: 'Region'
|
|
19
22
|
has_many :stock_keeping_units, class_name: 'StockKeepingUnit'
|
|
20
23
|
has_one :address_requirement, class_name: 'AddressRequirement'
|
|
@@ -44,6 +47,14 @@ module DIDWW
|
|
|
44
47
|
# Description: Service restriction message associated with this DID Group, if any.
|
|
45
48
|
# Null when no restrictions apply. (API 2026-04-16)
|
|
46
49
|
|
|
50
|
+
property :number_type, type: :string
|
|
51
|
+
# Type: String
|
|
52
|
+
# Description: Number type the group offers, one of NUMBER_TYPES.
|
|
53
|
+
|
|
54
|
+
property :is_demo, type: :boolean
|
|
55
|
+
# Type: Boolean
|
|
56
|
+
# Description: True when the group is flagged as a demo group.
|
|
57
|
+
|
|
47
58
|
# TODO
|
|
48
59
|
# Meta attributes
|
|
49
60
|
#
|
|
@@ -1,18 +1,20 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
3
|
require 'didww/resource/concerns/has_status_helpers'
|
|
4
|
+
require 'didww/resource/concerns/number_types'
|
|
4
5
|
|
|
5
6
|
module DIDWW
|
|
6
7
|
module Resource
|
|
7
8
|
# Customer-owned subscription to emergency calling on one or more DIDs.
|
|
8
9
|
# Supported operations: index, show, destroy. Introduced in API 2026-04-16.
|
|
9
10
|
#
|
|
10
|
-
# Server-side filters: name, reference, country.id,
|
|
11
|
+
# Server-side filters: name, reference, country.id, number_type,
|
|
11
12
|
# address.id, identity.id, status.
|
|
12
13
|
#
|
|
13
14
|
# meta carries: setup_price, monthly_price.
|
|
14
15
|
class EmergencyCallingService < Base
|
|
15
16
|
include HasStatusHelpers
|
|
17
|
+
include NumberTypes
|
|
16
18
|
|
|
17
19
|
STATUS_ACTIVE = 'active'
|
|
18
20
|
STATUS_CANCELED = 'canceled'
|
|
@@ -31,7 +33,6 @@ module DIDWW
|
|
|
31
33
|
].freeze
|
|
32
34
|
|
|
33
35
|
has_one :country, class_name: 'Country'
|
|
34
|
-
has_one :did_group_type, class_name: 'DidGroupType'
|
|
35
36
|
has_one :order, class_name: 'Order'
|
|
36
37
|
has_one :address, class_name: 'Address'
|
|
37
38
|
has_one :emergency_requirement, class_name: 'EmergencyRequirement'
|
|
@@ -62,9 +63,13 @@ module DIDWW
|
|
|
62
63
|
property :created_at, type: :time
|
|
63
64
|
# Type: Time
|
|
64
65
|
|
|
65
|
-
property :renew_date, type: :
|
|
66
|
-
# Type:
|
|
67
|
-
# Description: Next renewal date. nil when canceled.
|
|
66
|
+
property :renew_date, type: :string
|
|
67
|
+
# Type: String
|
|
68
|
+
# Description: Next renewal date, "YYYY-MM-DD". nil when canceled.
|
|
69
|
+
|
|
70
|
+
property :number_type, type: :string
|
|
71
|
+
# Type: String
|
|
72
|
+
# Description: Number type the subscription covers, one of NUMBER_TYPES.
|
|
68
73
|
|
|
69
74
|
status_helper :active, STATUS_ACTIVE
|
|
70
75
|
status_helper :canceled, STATUS_CANCELED
|
|
@@ -1,17 +1,21 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
|
+
require 'didww/resource/concerns/number_types'
|
|
4
|
+
|
|
3
5
|
module DIDWW
|
|
4
6
|
module Resource
|
|
5
7
|
# Requirements that must be satisfied before ordering an emergency
|
|
6
|
-
# calling service for a given country/
|
|
8
|
+
# calling service for a given country/number_type. Introduced in API 2026-04-16.
|
|
7
9
|
#
|
|
8
10
|
# Each record also reports a price preview in `meta` (setup_price,
|
|
9
|
-
# monthly_price) when the customer has a matching
|
|
11
|
+
# monthly_price), both decimal strings, when the customer has a matching
|
|
12
|
+
# emergency plan.
|
|
10
13
|
#
|
|
11
|
-
# Server-side filters: country.id,
|
|
14
|
+
# Server-side filters: country.id, number_type
|
|
12
15
|
class EmergencyRequirement < Base
|
|
16
|
+
include NumberTypes
|
|
17
|
+
|
|
13
18
|
has_one :country, class_name: 'Country'
|
|
14
|
-
has_one :did_group_type, class_name: 'DidGroupType'
|
|
15
19
|
|
|
16
20
|
property :identity_type, type: :string
|
|
17
21
|
# Type: String
|
|
@@ -20,36 +24,45 @@ module DIDWW
|
|
|
20
24
|
|
|
21
25
|
property :address_area_level, type: :string
|
|
22
26
|
# Type: String
|
|
23
|
-
# Description: How precise the service address must be
|
|
27
|
+
# Description: How precise the service address must be: country, area or city.
|
|
24
28
|
|
|
25
29
|
property :personal_area_level, type: :string
|
|
26
|
-
# Type: String
|
|
27
|
-
# Description: How precise a personal identity address must be.
|
|
30
|
+
# Type: String, nullable
|
|
31
|
+
# Description: How precise a personal identity address must be: world_wide or country.
|
|
32
|
+
# Nil when the country does not accept a personal identity for emergency calling.
|
|
28
33
|
|
|
29
34
|
property :business_area_level, type: :string
|
|
30
|
-
# Type: String
|
|
31
|
-
# Description: How precise a business identity address must be.
|
|
35
|
+
# Type: String, nullable
|
|
36
|
+
# Description: How precise a business identity address must be: world_wide or country.
|
|
37
|
+
# Nil when the country does not accept a business identity for emergency calling.
|
|
32
38
|
|
|
33
39
|
property :address_mandatory_fields, type: :array
|
|
34
40
|
# Type: String[]
|
|
35
|
-
# Description: Fields the service address must contain.
|
|
41
|
+
# Description: Fields the service address must contain (area). Empty when none are.
|
|
36
42
|
|
|
37
43
|
property :personal_mandatory_fields, type: :array
|
|
38
44
|
# Type: String[]
|
|
39
|
-
# Description: Fields a personal identity must contain
|
|
45
|
+
# Description: Fields a personal identity must contain, among birth_date, country,
|
|
46
|
+
# id_number, personal_tax_id and contact_email. Empty when none are.
|
|
40
47
|
|
|
41
48
|
property :business_mandatory_fields, type: :array
|
|
42
49
|
# Type: String[]
|
|
43
|
-
# Description: Fields a business identity must contain
|
|
50
|
+
# Description: Fields a business identity must contain, among id_number,
|
|
51
|
+
# tax_id (Identity#vat_id), country, company_reg_number, personal_tax_id, contact_email
|
|
52
|
+
# and birth_date. Empty when none are.
|
|
44
53
|
|
|
45
54
|
property :estimate_setup_time, type: :string
|
|
46
55
|
# Type: String
|
|
47
56
|
# Description: Estimated time before emergency calling is enabled (e.g. "7-14 days").
|
|
48
57
|
|
|
49
58
|
property :requirement_restriction_message, type: :string
|
|
50
|
-
# Type: String
|
|
59
|
+
# Type: String, nullable
|
|
51
60
|
# Description: Human-readable message describing any restrictions that
|
|
52
|
-
# apply to ordering the service.
|
|
61
|
+
# apply to ordering the service. Nil when the country places none.
|
|
62
|
+
|
|
63
|
+
property :number_type, type: :string
|
|
64
|
+
# Type: String
|
|
65
|
+
# Description: Number type the rules apply to, one of NUMBER_TYPES.
|
|
53
66
|
end
|
|
54
67
|
end
|
|
55
68
|
end
|
|
@@ -1,10 +1,20 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
require 'faraday/multipart'
|
|
3
|
+
require 'didww/errors'
|
|
3
4
|
|
|
4
5
|
module DIDWW
|
|
5
6
|
module Resource
|
|
6
7
|
class EncryptedFile < Base
|
|
7
|
-
class UploadError <
|
|
8
|
+
class UploadError < DIDWW::Error
|
|
9
|
+
attr_reader :status, :retry_after
|
|
10
|
+
|
|
11
|
+
# @param status [Integer,nil] HTTP status of the response
|
|
12
|
+
# @param retry_after [Integer,nil] Retry-After seconds of a 429
|
|
13
|
+
def initialize(message = nil, status: nil, retry_after: nil)
|
|
14
|
+
@status = status
|
|
15
|
+
@retry_after = retry_after
|
|
16
|
+
super(message)
|
|
17
|
+
end
|
|
8
18
|
end
|
|
9
19
|
|
|
10
20
|
property :description, type: :string
|
|
@@ -17,11 +27,9 @@ module DIDWW
|
|
|
17
27
|
|
|
18
28
|
# @return [Faraday::Connection]
|
|
19
29
|
def self.upload_connection
|
|
20
|
-
|
|
30
|
+
DIDWW::Http.connection(DIDWW::Client.api_base_url, audience: DIDWW::Client::API_AUDIENCE) do |connection|
|
|
21
31
|
connection.request :multipart
|
|
22
32
|
connection.request :url_encoded
|
|
23
|
-
connection.adapter Faraday.default_adapter
|
|
24
|
-
connection.use DIDWW::BaseMiddleware
|
|
25
33
|
end
|
|
26
34
|
end
|
|
27
35
|
|
|
@@ -47,11 +55,16 @@ module DIDWW
|
|
|
47
55
|
# @raise [DIDWW::Resource::EncryptedFile::UploadError]
|
|
48
56
|
def self.upload(payload)
|
|
49
57
|
connection = upload_connection
|
|
50
|
-
response = connection.post('
|
|
58
|
+
response = connection.post('encrypted_files', encrypted_files: payload)
|
|
51
59
|
if response.status == 201
|
|
52
60
|
JSON.parse(response.body, symbolize_names: true).dig(:data, :id)
|
|
53
61
|
else
|
|
54
|
-
|
|
62
|
+
retry_after = RetryAfter.seconds(response.headers['Retry-After']) if response.status == 429
|
|
63
|
+
raise UploadError.new(
|
|
64
|
+
"Code: #{response.status} #{response.body}",
|
|
65
|
+
status: response.status,
|
|
66
|
+
retry_after: retry_after
|
|
67
|
+
)
|
|
55
68
|
end
|
|
56
69
|
end
|
|
57
70
|
end
|
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
require 'forwardable'
|
|
3
3
|
require 'didww/resource/concerns/has_status_helpers'
|
|
4
|
-
require '
|
|
4
|
+
require 'tempfile'
|
|
5
5
|
require 'zlib'
|
|
6
6
|
require 'stringio'
|
|
7
|
+
require 'uri'
|
|
7
8
|
require 'didww/callback/const'
|
|
8
9
|
|
|
9
10
|
module DIDWW
|
|
@@ -25,15 +26,19 @@ module DIDWW
|
|
|
25
26
|
|
|
26
27
|
EXPORT_TYPE_CDR_IN = 'cdr_in'
|
|
27
28
|
EXPORT_TYPE_CDR_OUT = 'cdr_out'
|
|
29
|
+
EXPORT_TYPE_SMS_IN = 'sms_in'
|
|
30
|
+
EXPORT_TYPE_SMS_OUT = 'sms_out'
|
|
28
31
|
EXPORT_TYPES = [
|
|
29
32
|
EXPORT_TYPE_CDR_IN,
|
|
30
|
-
EXPORT_TYPE_CDR_OUT
|
|
33
|
+
EXPORT_TYPE_CDR_OUT,
|
|
34
|
+
EXPORT_TYPE_SMS_IN,
|
|
35
|
+
EXPORT_TYPE_SMS_OUT
|
|
31
36
|
].freeze
|
|
32
37
|
|
|
33
38
|
property :filters, type: :export_filters
|
|
34
|
-
# Type:
|
|
39
|
+
# Type: Export Filters Object
|
|
35
40
|
# Nullable: No
|
|
36
|
-
# Description: Filters
|
|
41
|
+
# Description: Filters; the accepted keys depend on export_type (see ComplexObject::ExportFilters)
|
|
37
42
|
|
|
38
43
|
property :status, type: :string
|
|
39
44
|
# Type: String
|
|
@@ -59,6 +64,8 @@ module DIDWW
|
|
|
59
64
|
# Description: GET or POST
|
|
60
65
|
|
|
61
66
|
property :export_type, type: :string
|
|
67
|
+
# Type: String
|
|
68
|
+
# Description: One of EXPORT_TYPES
|
|
62
69
|
|
|
63
70
|
property :external_reference_id, type: :string
|
|
64
71
|
# Type: String
|
|
@@ -68,24 +75,34 @@ module DIDWW
|
|
|
68
75
|
super params.reverse_merge(filters: {})
|
|
69
76
|
end
|
|
70
77
|
|
|
78
|
+
# @return [Tempfile,nil] the gzipped CSV, rewound and opened in binary mode
|
|
79
|
+
# @raise [ArgumentError] url is not on the scheme, host and port of the API base URL or of the canonical API URL of the mode
|
|
80
|
+
# @raise [JsonApiClient::Errors::ApiError]
|
|
71
81
|
def download
|
|
72
82
|
return unless url.present?
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
83
|
+
verify_url_on_api_host!
|
|
84
|
+
file = Tempfile.new(['export', '.csv.gz'], binmode: true)
|
|
85
|
+
response = download_connection.get do |request|
|
|
86
|
+
request.options.on_data = proc { |chunk, _received, env| file.write(chunk) if env.status == 200 }
|
|
87
|
+
end
|
|
88
|
+
raise JsonApiClient::Errors::UnexpectedStatus.new(response.status, url) unless response.status == 200
|
|
89
|
+
|
|
90
|
+
file.rewind
|
|
91
|
+
file
|
|
92
|
+
rescue StandardError
|
|
93
|
+
file&.close!
|
|
94
|
+
raise
|
|
78
95
|
end
|
|
79
96
|
|
|
80
97
|
def csv
|
|
81
98
|
file = download
|
|
82
99
|
return unless file
|
|
83
|
-
gz = Zlib::GzipReader.new(file)
|
|
84
100
|
begin
|
|
101
|
+
gz = Zlib::GzipReader.new(file)
|
|
85
102
|
StringIO.new(gz.read)
|
|
86
103
|
ensure
|
|
87
|
-
gz.close
|
|
88
|
-
file.close
|
|
104
|
+
gz.close if gz && !gz.closed?
|
|
105
|
+
file.close!
|
|
89
106
|
end
|
|
90
107
|
end
|
|
91
108
|
|
|
@@ -93,6 +110,36 @@ module DIDWW
|
|
|
93
110
|
status_helper :processing, STATUS_PROCESSING
|
|
94
111
|
status_helper :complete, STATUS_COMPLETED
|
|
95
112
|
alias_method :completed?, :complete?
|
|
113
|
+
|
|
114
|
+
private
|
|
115
|
+
|
|
116
|
+
# The download sends the API bearer token, so it goes only to the API host:
|
|
117
|
+
# that of the API base URL, or the canonical one of the mode, which the API builds export urls from.
|
|
118
|
+
def verify_url_on_api_host!
|
|
119
|
+
allowed = [DIDWW::Client.api_base_url, DIDWW::Client::BASE_URLS[DIDWW::Client.api_mode]].map { |base| URI.parse(base) }
|
|
120
|
+
target = begin
|
|
121
|
+
URI.parse(url)
|
|
122
|
+
rescue URI::InvalidURIError
|
|
123
|
+
nil
|
|
124
|
+
end
|
|
125
|
+
return if target && allowed.any? { |api| same_origin?(target, api) }
|
|
126
|
+
|
|
127
|
+
hosts = allowed.map { |api| "#{api.scheme}://#{api.host}#{":#{api.port}" unless api.port == api.default_port}" }.uniq
|
|
128
|
+
raise ArgumentError.new("Export url must be on the API host #{hosts.join(' or ')}.")
|
|
129
|
+
end
|
|
130
|
+
|
|
131
|
+
def same_origin?(target, api)
|
|
132
|
+
target.is_a?(URI::HTTP) && target.host.present? &&
|
|
133
|
+
target.scheme.casecmp?(api.scheme) &&
|
|
134
|
+
target.host.chomp('.').casecmp?(api.host.chomp('.')) &&
|
|
135
|
+
target.port == api.port
|
|
136
|
+
end
|
|
137
|
+
|
|
138
|
+
def download_connection
|
|
139
|
+
DIDWW::Http.connection(url, audience: DIDWW::Client::API_AUDIENCE) do |connection|
|
|
140
|
+
connection.use JsonApiClient::Middleware::Status, { custom_handlers: DIDWW::TooManyRequests::STATUS_HANDLERS }
|
|
141
|
+
end
|
|
142
|
+
end
|
|
96
143
|
end
|
|
97
144
|
end
|
|
98
145
|
end
|
|
@@ -28,9 +28,9 @@ module DIDWW
|
|
|
28
28
|
# Type: String
|
|
29
29
|
# Description:
|
|
30
30
|
|
|
31
|
-
property :birth_date, type: :
|
|
32
|
-
# Type:
|
|
33
|
-
# Description:
|
|
31
|
+
property :birth_date, type: :string
|
|
32
|
+
# Type: String
|
|
33
|
+
# Description: Date of birth, "YYYY-MM-DD"
|
|
34
34
|
|
|
35
35
|
property :company_name, type: :string
|
|
36
36
|
# Type: String
|
|
@@ -42,7 +42,8 @@ module DIDWW
|
|
|
42
42
|
|
|
43
43
|
property :vat_id, type: :string
|
|
44
44
|
# Type: String
|
|
45
|
-
# Description:
|
|
45
|
+
# Description: VAT identification number, listed as tax_id in the mandatory fields of
|
|
46
|
+
# AddressRequirement and EmergencyRequirement.
|
|
46
47
|
|
|
47
48
|
property :description, type: :string
|
|
48
49
|
# Type: String
|
|
@@ -72,6 +73,10 @@ module DIDWW
|
|
|
72
73
|
# Type: String
|
|
73
74
|
# Description:
|
|
74
75
|
|
|
76
|
+
property :company_website, type: :string
|
|
77
|
+
# Type: String
|
|
78
|
+
# Description: Company website. Rejected on a personal identity.
|
|
79
|
+
|
|
75
80
|
def personal?
|
|
76
81
|
identity_type == IDENTITY_TYPE_PERSONAL
|
|
77
82
|
end
|
data/lib/didww/resource/order.rb
CHANGED
|
@@ -3,6 +3,7 @@ require 'didww/complex_objects/did_order_item'
|
|
|
3
3
|
require 'didww/resource/concerns/has_status_helpers'
|
|
4
4
|
require 'didww/complex_objects/capacity_order_item'
|
|
5
5
|
require 'didww/complex_objects/emergency_order_item'
|
|
6
|
+
require 'didww/complex_objects/generic_order_item'
|
|
6
7
|
require 'didww/callback/const'
|
|
7
8
|
|
|
8
9
|
module DIDWW
|
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require 'didww/resource/concerns/has_status_helpers'
|
|
4
|
+
|
|
5
|
+
module DIDWW
|
|
6
|
+
module Resource
|
|
7
|
+
# Verification of a sender identity used for outbound messages.
|
|
8
|
+
# Supported operations: index, show, update. Only name and sms_trunk can be changed,
|
|
9
|
+
# and a closed verification cannot be updated.
|
|
10
|
+
#
|
|
11
|
+
# Server-side filters: status, sender_type, sms_trunk.id, name, reference.
|
|
12
|
+
#
|
|
13
|
+
# meta carries: setup_price, monthly_price.
|
|
14
|
+
class SenderIdVerification < Base
|
|
15
|
+
include HasStatusHelpers
|
|
16
|
+
|
|
17
|
+
STATUS_ACTIVE = 'active'
|
|
18
|
+
STATUS_CHANGES_REQUIRED = 'changes_required'
|
|
19
|
+
STATUS_CLOSED = 'closed'
|
|
20
|
+
STATUS_CLOSING_IN_PROCESS = 'closing_in_process'
|
|
21
|
+
STATUS_IN_PROCESS = 'in_process'
|
|
22
|
+
STATUS_NEW = 'new'
|
|
23
|
+
|
|
24
|
+
STATUSES = [
|
|
25
|
+
STATUS_ACTIVE,
|
|
26
|
+
STATUS_CHANGES_REQUIRED,
|
|
27
|
+
STATUS_CLOSED,
|
|
28
|
+
STATUS_CLOSING_IN_PROCESS,
|
|
29
|
+
STATUS_IN_PROCESS,
|
|
30
|
+
STATUS_NEW
|
|
31
|
+
].freeze
|
|
32
|
+
|
|
33
|
+
SENDER_TYPE_ALPHANUMERIC = 'alphanumeric'
|
|
34
|
+
SENDER_TYPE_CARRIER = 'carrier'
|
|
35
|
+
SENDER_TYPE_LONG_CODE = 'long_code'
|
|
36
|
+
SENDER_TYPE_SHORT_CODE = 'short_code'
|
|
37
|
+
SENDER_TYPE_TOLL_FREE = 'toll_free'
|
|
38
|
+
|
|
39
|
+
SENDER_TYPES = [
|
|
40
|
+
SENDER_TYPE_ALPHANUMERIC,
|
|
41
|
+
SENDER_TYPE_CARRIER,
|
|
42
|
+
SENDER_TYPE_LONG_CODE,
|
|
43
|
+
SENDER_TYPE_SHORT_CODE,
|
|
44
|
+
SENDER_TYPE_TOLL_FREE
|
|
45
|
+
].freeze
|
|
46
|
+
|
|
47
|
+
has_one :sms_trunk, class_name: 'SmsTrunk'
|
|
48
|
+
has_many :countries, class_name: 'Country'
|
|
49
|
+
has_many :dids, class_name: 'Did'
|
|
50
|
+
has_one :order, class_name: 'Order'
|
|
51
|
+
has_one :identity, class_name: 'Identity'
|
|
52
|
+
has_one :address, class_name: 'Address'
|
|
53
|
+
|
|
54
|
+
property :name, type: :string
|
|
55
|
+
# Type: String
|
|
56
|
+
# Description: Name of the verification
|
|
57
|
+
|
|
58
|
+
property :status, type: :string
|
|
59
|
+
# Type: String
|
|
60
|
+
# Description: One of STATUSES. Read-only.
|
|
61
|
+
|
|
62
|
+
property :sender_type, type: :string
|
|
63
|
+
# Type: String
|
|
64
|
+
# Description: One of SENDER_TYPES. Read-only.
|
|
65
|
+
|
|
66
|
+
property :sender_ids, type: :array
|
|
67
|
+
# Type: Array<String>
|
|
68
|
+
# Description: Sender IDs the verification covers; for long_code and toll_free, the numbers
|
|
69
|
+
# of the DIDs. Read-only.
|
|
70
|
+
|
|
71
|
+
property :reference, type: :string
|
|
72
|
+
# Type: String
|
|
73
|
+
# Description: Human-readable reference. Read-only.
|
|
74
|
+
|
|
75
|
+
property :reject_reasons, type: :array
|
|
76
|
+
# Type: Array<String>
|
|
77
|
+
# Nullable: Yes
|
|
78
|
+
# Description: Reasons the last submission was rejected; nil unless changes_required, and when
|
|
79
|
+
# there are none. Read-only.
|
|
80
|
+
|
|
81
|
+
property :reject_comment, type: :string
|
|
82
|
+
# Type: String
|
|
83
|
+
# Nullable: Yes
|
|
84
|
+
# Description: Reviewer comment on the rejection; nil unless changes_required. Read-only.
|
|
85
|
+
|
|
86
|
+
property :renew_date, type: :string
|
|
87
|
+
# Type: String
|
|
88
|
+
# Nullable: Yes
|
|
89
|
+
# Description: Next renewal date, "YYYY-MM-DD"; nil once closed. Read-only.
|
|
90
|
+
|
|
91
|
+
property :created_at, type: :time
|
|
92
|
+
# Type: Time
|
|
93
|
+
# Description: Read-only.
|
|
94
|
+
|
|
95
|
+
property :activated_at, type: :time
|
|
96
|
+
# Type: Time
|
|
97
|
+
# Nullable: Yes
|
|
98
|
+
# Description: Read-only.
|
|
99
|
+
|
|
100
|
+
property :closed_at, type: :time
|
|
101
|
+
# Type: Time
|
|
102
|
+
# Nullable: Yes
|
|
103
|
+
# Description: Read-only.
|
|
104
|
+
|
|
105
|
+
status_helper :active, STATUS_ACTIVE
|
|
106
|
+
status_helper :changes_required, STATUS_CHANGES_REQUIRED
|
|
107
|
+
status_helper :closed, STATUS_CLOSED
|
|
108
|
+
status_helper :closing_in_process, STATUS_CLOSING_IN_PROCESS
|
|
109
|
+
status_helper :in_process, STATUS_IN_PROCESS
|
|
110
|
+
# "new" collides with Class.new, so expose the predicate as new_status?
|
|
111
|
+
status_helper :new_status, STATUS_NEW
|
|
112
|
+
end
|
|
113
|
+
end
|
|
114
|
+
end
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
require 'didww/complex_objects/sms_trunk_configuration'
|
|
3
|
+
|
|
4
|
+
module DIDWW
|
|
5
|
+
module Resource
|
|
6
|
+
# meta carries: host, the URL to submit outbound messages to (http_out trunks only).
|
|
7
|
+
class SmsTrunk < Base
|
|
8
|
+
has_many :outgoing_dids, class_name: 'Did'
|
|
9
|
+
has_many :incoming_dids, class_name: 'Did'
|
|
10
|
+
has_one :sms_trunk_group, class_name: 'SmsTrunkGroup'
|
|
11
|
+
has_many :sender_id_verifications, class_name: 'SenderIdVerification'
|
|
12
|
+
|
|
13
|
+
property :name, type: :string
|
|
14
|
+
# Type: String
|
|
15
|
+
# Description: Friendly name of the trunk. Required when the trunk is created.
|
|
16
|
+
|
|
17
|
+
property :external_reference_id, type: :string
|
|
18
|
+
# Type: String
|
|
19
|
+
# Nullable: Yes
|
|
20
|
+
# Description: Customer-supplied reference. Max 100 characters.
|
|
21
|
+
|
|
22
|
+
property :blocked, type: :boolean
|
|
23
|
+
# Type: Boolean
|
|
24
|
+
# Description: Set to true to stop the trunk from handling messages
|
|
25
|
+
|
|
26
|
+
property :priority, type: :integer
|
|
27
|
+
# Type: Integer
|
|
28
|
+
# Nullable: Yes
|
|
29
|
+
# Description: Routing priority within an SMS trunk group, 0-32767; the higher value is tried first.
|
|
30
|
+
# Defaults to 100, and must stay null on http_out trunks, which cannot join a group.
|
|
31
|
+
|
|
32
|
+
property :allow_any_did_as_source, type: :boolean
|
|
33
|
+
# Type: Boolean
|
|
34
|
+
# Description: Allow any DID the customer owns as the message source. Turning it on empties
|
|
35
|
+
# outgoing_dids. Refused on the trunk types that only receive messages.
|
|
36
|
+
|
|
37
|
+
property :allow_in, type: :boolean
|
|
38
|
+
# Type: Boolean
|
|
39
|
+
# Description: True when the trunk handles inbound messages. Read-only.
|
|
40
|
+
|
|
41
|
+
property :allow_out, type: :boolean
|
|
42
|
+
# Type: Boolean
|
|
43
|
+
# Description: True when the trunk can send messages. Read-only.
|
|
44
|
+
|
|
45
|
+
property :created_at, type: :time
|
|
46
|
+
# Type: DateTime
|
|
47
|
+
# Description: Trunk created at DateTime. Read-only.
|
|
48
|
+
|
|
49
|
+
property :updated_at, type: :time
|
|
50
|
+
# Type: DateTime
|
|
51
|
+
# Description: Trunk updated at DateTime. Read-only.
|
|
52
|
+
|
|
53
|
+
property :configuration, type: :sms_trunk_configuration
|
|
54
|
+
# Type: one of ComplexObject::SmsTrunkConfiguration::TYPES
|
|
55
|
+
# sms_to_email, http_in, http_out, smpp_esme, smpp_smsc
|
|
56
|
+
# Description: Delivery configuration. Required when the trunk is created. On update the
|
|
57
|
+
# type must match the stored one; attributes left out keep their values.
|
|
58
|
+
|
|
59
|
+
def initialize(*args)
|
|
60
|
+
super
|
|
61
|
+
attribute_will_change!(:configuration) if configuration
|
|
62
|
+
end
|
|
63
|
+
|
|
64
|
+
# The server sends meta on http_out trunks only.
|
|
65
|
+
def host
|
|
66
|
+
attributes[:meta]&.[](:host)
|
|
67
|
+
end
|
|
68
|
+
|
|
69
|
+
def regenerate_credentials
|
|
70
|
+
resource = DIDWW::Resource::SmsTrunkRegenerateCredential.new
|
|
71
|
+
resource.relationships[:sms_trunk] = self
|
|
72
|
+
resource.save
|
|
73
|
+
end
|
|
74
|
+
end
|
|
75
|
+
end
|
|
76
|
+
end
|