didww-v3 1.3.1 → 4.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (69) hide show
  1. checksums.yaml +4 -4
  2. data/.github/workflows/tests.yml +5 -1
  3. data/.rubocop.yml +3 -0
  4. data/CHANGELOG.md +51 -2
  5. data/Gemfile +2 -1
  6. data/README.md +10 -1
  7. data/Rakefile +1 -0
  8. data/bin/console +1 -0
  9. data/didww-v3.gemspec +3 -1
  10. data/lib/didww/{middleware.rb → base_middleware.rb} +5 -4
  11. data/lib/didww/callback/const.rb +14 -0
  12. data/lib/didww/callback/request_validator.rb +77 -0
  13. data/lib/didww/client.rb +98 -39
  14. data/lib/didww/complex_objects/base.rb +2 -3
  15. data/lib/didww/complex_objects/capacity_order_item.rb +1 -0
  16. data/lib/didww/complex_objects/configurations/base.rb +143 -2
  17. data/lib/didww/complex_objects/configurations/h323_configuration.rb +1 -0
  18. data/lib/didww/complex_objects/configurations/iax2_configuration.rb +1 -0
  19. data/lib/didww/complex_objects/configurations/pstn_configuration.rb +1 -0
  20. data/lib/didww/complex_objects/configurations/sip_configuration.rb +34 -3
  21. data/lib/didww/complex_objects/configurations.rb +1 -0
  22. data/lib/didww/complex_objects/did_order_item.rb +15 -12
  23. data/lib/didww/complex_objects/export_filters.rb +26 -0
  24. data/lib/didww/encrypt.rb +101 -0
  25. data/lib/didww/jsonapi_middleware.rb +21 -0
  26. data/lib/didww/resource/address.rb +37 -0
  27. data/lib/didww/resource/address_verification.rb +56 -0
  28. data/lib/didww/resource/area.rb +12 -0
  29. data/lib/didww/{resources → resource}/available_did.rb +2 -0
  30. data/lib/didww/{resources → resource}/balance.rb +1 -0
  31. data/lib/didww/{resources → resource}/base.rb +2 -2
  32. data/lib/didww/{resources → resource}/capacity_pool.rb +1 -0
  33. data/lib/didww/resource/city.rb +14 -0
  34. data/lib/didww/{resources → resource}/country.rb +1 -0
  35. data/lib/didww/{resources → resource}/did.rb +5 -3
  36. data/lib/didww/{resources → resource}/did_group.rb +13 -25
  37. data/lib/didww/{resources → resource}/did_group_type.rb +1 -0
  38. data/lib/didww/{resources → resource}/did_reservation.rb +1 -0
  39. data/lib/didww/resource/encrypted_file.rb +58 -0
  40. data/lib/didww/{resources/cdr_export.rb → resource/export.rb} +24 -5
  41. data/lib/didww/resource/identity.rb +78 -0
  42. data/lib/didww/resource/nanpa_prefix.rb +18 -0
  43. data/lib/didww/{resources → resource}/order.rb +20 -12
  44. data/lib/didww/resource/permanent_supporting_document.rb +15 -0
  45. data/lib/didww/{resources → resource}/pop.rb +1 -0
  46. data/lib/didww/resource/proof.rb +19 -0
  47. data/lib/didww/resource/proof_type.rb +14 -0
  48. data/lib/didww/resource/public_key.rb +12 -0
  49. data/lib/didww/{resources → resource}/qty_based_pricing.rb +1 -0
  50. data/lib/didww/{resources → resource}/region.rb +1 -0
  51. data/lib/didww/resource/requirement.rb +61 -0
  52. data/lib/didww/resource/requirement_validation.rb +10 -0
  53. data/lib/didww/{resources → resource}/shared_capacity_group.rb +1 -0
  54. data/lib/didww/{resources → resource}/stock_keeping_unit.rb +1 -0
  55. data/lib/didww/resource/supporting_document_template.rb +14 -0
  56. data/lib/didww/{resources/trunk.rb → resource/voice_in_trunk.rb} +40 -4
  57. data/lib/didww/{resources/trunk_group.rb → resource/voice_in_trunk_group.rb} +3 -2
  58. data/lib/didww/resource/voice_out_trunk.rb +75 -0
  59. data/lib/didww/resource/voice_out_trunk_regenerate_credential.rb +11 -0
  60. data/lib/didww/types/ip_addresses.rb +23 -0
  61. data/lib/didww/types/strings.rb +21 -0
  62. data/lib/didww/types.rb +12 -0
  63. data/lib/didww/version.rb +2 -1
  64. data/lib/didww.rb +6 -1
  65. metadata +63 -28
  66. data/lib/didww/complex_objects/cdr_export_filter.rb +0 -23
  67. data/lib/didww/complex_objects/configurations/const.rb +0 -149
  68. data/lib/didww/resources/city.rb +0 -9
  69. data/lib/didww/resources/trunk/const.rb +0 -46
@@ -0,0 +1,78 @@
1
+ # frozen_string_literal: true
2
+ module DIDWW
3
+ module Resource
4
+ class Identity < Base
5
+ IDENTITY_TYPE_PERSONAL = 'Personal'
6
+ IDENTITY_TYPE_BUSINESS = 'Business'
7
+
8
+ has_one :country, class_name: 'Country'
9
+ has_many :proofs, class_name: 'Proof'
10
+ has_many :addresses, class_name: 'Address'
11
+ has_many :permanent_documents, class_name: 'PermanentSupportingDocument'
12
+
13
+ property :first_name, type: :string
14
+ # Type: String
15
+ # Description:
16
+
17
+ property :last_name, type: :string
18
+ # Type: String
19
+ # Description:
20
+
21
+ property :phone_number, type: :string
22
+ # Type: String
23
+ # Description:
24
+
25
+ property :id_number, type: :string
26
+ # Type: String
27
+ # Description:
28
+
29
+ property :birth_date, type: :date
30
+ # Type: Date
31
+ # Description:
32
+
33
+ property :company_name, type: :string
34
+ # Type: String
35
+ # Description:
36
+
37
+ property :company_reg_number, type: :string
38
+ # Type: String
39
+ # Description:
40
+
41
+ property :vat_id, type: :string
42
+ # Type: String
43
+ # Description:
44
+
45
+ property :description, type: :string
46
+ # Type: String
47
+ # Description:
48
+
49
+ property :personal_tax_id, type: :string
50
+ # Type: String
51
+ # Description:
52
+
53
+ property :identity_type, type: :string
54
+ # Type: String
55
+ # Description:
56
+
57
+ property :created_at, type: :date
58
+ # Type: Date
59
+ # Description:
60
+
61
+ property :external_reference_id, type: :string
62
+ # Type: String
63
+ # Description:
64
+
65
+ property :verified, type: :boolean
66
+ # Type: Boolean
67
+ # Description:
68
+
69
+ def personal?
70
+ identity_type == IDENTITY_TYPE_PERSONAL
71
+ end
72
+
73
+ def business?
74
+ identity_type == IDENTITY_TYPE_BUSINESS
75
+ end
76
+ end
77
+ end
78
+ end
@@ -0,0 +1,18 @@
1
+ # frozen_string_literal: true
2
+
3
+ module DIDWW
4
+ module Resource
5
+ class NanpaPrefix < Base
6
+ has_one :country, class_name: Country
7
+ has_one :region, class_name: Region
8
+
9
+ property :npa, type: :string
10
+ # Type: String
11
+ # Description: NPA codes, or area codes consisting of three digits
12
+ property :nxx, type: :string
13
+ # Type: String
14
+ # Description: Refer to three-digit code
15
+ # that forms the second part of a 10-digit North American phone number
16
+ end
17
+ end
18
+ end
@@ -1,22 +1,22 @@
1
+ # frozen_string_literal: true
1
2
  require 'didww/complex_objects/did_order_item'
2
3
  require 'didww/complex_objects/capacity_order_item'
4
+ require 'didww/callback/const'
3
5
 
4
6
  module DIDWW
5
7
  module Resource
6
8
  class Order < Base
7
- module CONST
8
- # Possible values for order.status
9
- STATUS_PENDING = 'Pending' .freeze
10
- STATUS_COMPLETED = 'Completed' .freeze
11
- STATUS_CANCELLED = 'Canceled' .freeze
12
- STATUSES = [
13
- STATUS_PENDING,
14
- STATUS_COMPLETED,
15
- STATUS_CANCELLED
16
- ].freeze
17
- end
9
+ include DIDWW::Callback::CONST
18
10
 
19
- include CONST
11
+ # Possible values for order.status
12
+ STATUS_PENDING = 'Pending'
13
+ STATUS_COMPLETED = 'Completed'
14
+ STATUS_CANCELLED = 'Canceled'
15
+ STATUSES = [
16
+ STATUS_PENDING,
17
+ STATUS_COMPLETED,
18
+ STATUS_CANCELLED
19
+ ].freeze
20
20
 
21
21
  property :reference, type: :string
22
22
  # Type: String
@@ -46,6 +46,14 @@ module DIDWW
46
46
  # Type: Boolean
47
47
  # Description: Allowing back ordering
48
48
 
49
+ property :callback_url, type: :string
50
+ # Type: String
51
+ # Description: valid URI for callbacks
52
+
53
+ property :callback_method, type: :string
54
+ # Type: String
55
+ # Description: GET or POST
56
+
49
57
  def initialize(*args)
50
58
  super
51
59
  self.items ||= []
@@ -0,0 +1,15 @@
1
+ # frozen_string_literal: true
2
+ module DIDWW
3
+ module Resource
4
+ class PermanentSupportingDocument < Base
5
+
6
+ has_many :files, class_name: 'EncryptedFile'
7
+ has_one :template, class_name: 'SupportingDocumentTemplate'
8
+ has_one :identity, class_name: 'Identity'
9
+
10
+ property :created_at, type: :date
11
+ # Type: Date
12
+ # Description:
13
+ end
14
+ end
15
+ end
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  module DIDWW
2
3
  module Resource
3
4
  class Pop < Base
@@ -0,0 +1,19 @@
1
+ # frozen_string_literal: true
2
+ module DIDWW
3
+ module Resource
4
+ class Proof < Base
5
+
6
+ has_many :files, class_name: 'EncryptedFile'
7
+ has_one :proof_type, class_name: 'ProofType'
8
+ has_one :entity, class_name: 'Entity', polymorphic: true
9
+
10
+ property :created_at, type: :date
11
+ # Type: Date
12
+ # Description:
13
+
14
+ property :is_expired, type: :boolean
15
+ # Type: Boolean
16
+ # Description:
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,14 @@
1
+ # frozen_string_literal: true
2
+ module DIDWW
3
+ module Resource
4
+ class ProofType < Base
5
+ property :name, type: :string
6
+ # Type: String
7
+ # Description:
8
+
9
+ property :entity_type, type: :string
10
+ # Type: String
11
+ # Description:
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,12 @@
1
+ # frozen_string_literal: true
2
+ module DIDWW
3
+ module Resource
4
+ class PublicKey < Base
5
+
6
+ property :key, type: :string
7
+ # Type: String
8
+ # Description: Public key for encryption.
9
+
10
+ end
11
+ end
12
+ end
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  module DIDWW
2
3
  module Resource
3
4
  class QtyBasedPricing < Base
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  module DIDWW
2
3
  module Resource
3
4
  class Region < Base
@@ -0,0 +1,61 @@
1
+ # frozen_string_literal: true
2
+ module DIDWW
3
+ module Resource
4
+ class Requirement < Base
5
+
6
+ has_one :country, class_name: 'Country'
7
+ has_one :did_group_type, class_name: 'DidGroupType', relation_name: :group_type
8
+ has_one :personal_permanent_document, class_name: 'SupportingDocumentTemplate'
9
+ has_one :business_permanent_document, class_name: 'SupportingDocumentTemplate'
10
+ has_one :personal_onetime_document, class_name: 'SupportingDocumentTemplate'
11
+ has_one :business_onetime_document, class_name: 'SupportingDocumentTemplate'
12
+ has_many :personal_proof_types, class_name: 'ProofType'
13
+ has_many :business_proof_types, class_name: 'ProofType'
14
+ has_many :address_proof_types, class_name: 'ProofType'
15
+
16
+ property :identity_type, type: :integer
17
+ # Type: Integer
18
+ # Description:
19
+
20
+ property :personal_area_level, type: :string
21
+ # Type: String
22
+ # Description:
23
+
24
+ property :business_area_level, type: :string
25
+ # Type: String
26
+ # Description:
27
+
28
+ property :address_area_level, type: :string
29
+ # Type: String
30
+ # Description:
31
+
32
+ property :personal_proof_qty, type: :integer
33
+ # Type: Integer
34
+ # Description:
35
+
36
+ property :business_proof_qty, type: :integer
37
+ # Type: Integer
38
+ # Description:
39
+
40
+ property :address_proof_qty, type: :integer
41
+ # Type: Integer
42
+ # Description:
43
+
44
+ property :personal_mandatory_fields, type: :array
45
+ # Type: String[]
46
+ # Description:
47
+
48
+ property :business_mandatory_fields, type: :array
49
+ # Type: String[]
50
+ # Description:
51
+
52
+ property :service_description_required, type: :boolean
53
+ # Type: Boolean
54
+ # Description:
55
+
56
+ property :restriction_message, type: :string
57
+ # Type: String
58
+ # Description:
59
+ end
60
+ end
61
+ end
@@ -0,0 +1,10 @@
1
+ # frozen_string_literal: true
2
+ module DIDWW
3
+ module Resource
4
+ class RequirementValidation < Base
5
+ has_one :requirement, class_name: 'Requirement'
6
+ has_one :address, class_name: 'Address'
7
+ has_one :identity, class_name: 'Identity'
8
+ end
9
+ end
10
+ end
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  module DIDWW
2
3
  module Resource
3
4
  class SharedCapacityGroup < Base
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  module DIDWW
2
3
  module Resource
3
4
  class StockKeepingUnit < Base
@@ -0,0 +1,14 @@
1
+ # frozen_string_literal: true
2
+ module DIDWW
3
+ module Resource
4
+ class SupportingDocumentTemplate < Base
5
+ property :name, type: :string
6
+ # Type: String
7
+ # Description:
8
+
9
+ property :url, type: :string
10
+ # Type: String
11
+ # Description:
12
+ end
13
+ end
14
+ end
@@ -1,13 +1,42 @@
1
+ # frozen_string_literal: true
1
2
  require 'didww/complex_objects/configurations'
2
- require 'didww/resources/trunk/const'
3
3
 
4
4
  module DIDWW
5
5
  module Resource
6
- class Trunk < Base
7
- include CONST
6
+ class VoiceInTrunk < Base
7
+ # Allowed values for trunk.cli_format
8
+ CLI_FORMAT_RAW = 'raw'
9
+ CLI_FORMAT_E164 = 'e164'
10
+ CLI_FORMAT_LOCAL = 'local'
11
+
12
+ CLI_FORMATS = {
13
+ CLI_FORMAT_RAW => 'Raw',
14
+ CLI_FORMAT_E164 => 'E.164',
15
+ CLI_FORMAT_LOCAL => 'Local'
16
+ }.freeze
17
+
18
+ # Configuration types
19
+ CONF_TYPE_SIP = 'sip_configurations'
20
+ CONF_TYPE_H323 = 'h323_configurations'
21
+ CONF_TYPE_IAX2 = 'iax2_configurations'
22
+ CONF_TYPE_PSTN = 'pstn_configurations'
23
+
24
+ CONF_TYPES = {
25
+ CONF_TYPE_SIP => 'SIP',
26
+ CONF_TYPE_H323 => 'H323',
27
+ CONF_TYPE_IAX2 => 'IAX2',
28
+ CONF_TYPE_PSTN => 'PSTN'
29
+ }.freeze
30
+
31
+ CONF_TYPE_CLASSES = {
32
+ CONF_TYPE_SIP => DIDWW::ComplexObject::SipConfiguration,
33
+ CONF_TYPE_H323 => DIDWW::ComplexObject::H323Configuration,
34
+ CONF_TYPE_IAX2 => DIDWW::ComplexObject::Iax2Configuration,
35
+ CONF_TYPE_PSTN => DIDWW::ComplexObject::PstnConfiguration
36
+ }.freeze
8
37
 
9
38
  has_one :pop
10
- has_one :trunk_group
39
+ has_one :voice_in_trunk_group
11
40
 
12
41
  property :priority, type: :integer
13
42
  # Type: Integer
@@ -62,6 +91,13 @@ module DIDWW
62
91
  attribute_will_change!(:configuration) if configuration
63
92
  end
64
93
 
94
+ def cli_format_human
95
+ CLI_FORMATS[cli_format]
96
+ end
97
+
98
+ def configuration_type_human
99
+ CONF_TYPES[configuration.type] if configuration
100
+ end
65
101
  end
66
102
  end
67
103
  end
@@ -1,7 +1,8 @@
1
+ # frozen_string_literal: true
1
2
  module DIDWW
2
3
  module Resource
3
- class TrunkGroup < Base
4
- has_many :trunks
4
+ class VoiceInTrunkGroup < Base
5
+ has_many :voice_in_trunks
5
6
 
6
7
  property :name, type: :string
7
8
  # Type: String
@@ -0,0 +1,75 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'didww/callback/const'
4
+
5
+ module DIDWW
6
+ module Resource
7
+ class VoiceOutTrunk < Base
8
+ include DIDWW::Callback::CONST
9
+
10
+ ON_CLI_MISMATCH_ACTION_REJECT_CALL = 'Reject call'
11
+ ON_CLI_MISMATCH_ACTION_REPLACE_CLI = 'Replace CLI'
12
+ ON_CLI_MISMATCH_ACTION_SEND_ORIGINAL_CLI = 'Send Original CLI'
13
+
14
+ ON_CLI_MISMATCH_ACTIONS = [
15
+ ON_CLI_MISMATCH_ACTION_REJECT_CALL,
16
+ ON_CLI_MISMATCH_ACTION_REPLACE_CLI,
17
+ ON_CLI_MISMATCH_ACTION_SEND_ORIGINAL_CLI
18
+ ].freeze
19
+
20
+ DEFAULT_DST_ACTION_ALLOW_CALLS = 'Allow Calls'
21
+ DEFAULT_DST_ACTION_REJECT_CALLS = 'Reject Calls'
22
+
23
+ DEFAULT_DST_ACTIONS = [
24
+ DEFAULT_DST_ACTION_ALLOW_CALLS,
25
+ DEFAULT_DST_ACTION_REJECT_CALLS
26
+ ].freeze
27
+
28
+ STATUS_ACTIVE = 'Active'
29
+ STATUS_BLOCKED = 'Blocked'
30
+
31
+ STATUSES = [
32
+ STATUS_ACTIVE,
33
+ STATUS_BLOCKED
34
+ ].freeze
35
+
36
+ MEDIA_ENCRYPTION_MODE_DISABLE = 'Disable'
37
+ MEDIA_ENCRYPTION_MODE_SRTP_SDES = 'SRTP SDES'
38
+ MEDIA_ENCRYPTION_MODE_SRTP_DTLS = 'SRTP DTLS'
39
+ MEDIA_ENCRYPTION_MODE_ZRTP = 'ZRTP'
40
+
41
+ MEDIA_ENCRYPTION_MODES = [
42
+ MEDIA_ENCRYPTION_MODE_DISABLE,
43
+ MEDIA_ENCRYPTION_MODE_SRTP_SDES,
44
+ MEDIA_ENCRYPTION_MODE_SRTP_DTLS,
45
+ MEDIA_ENCRYPTION_MODE_ZRTP
46
+ ].freeze
47
+
48
+ property :name, type: :string
49
+ property :allowed_sip_ips, type: :ip_addresses
50
+ property :on_cli_mismatch_action, type: :string
51
+ property :capacity_limit, type: :integer
52
+ property :username, type: :string
53
+ property :password, type: :string
54
+ property :created_at, type: :time
55
+ property :allow_any_did_as_cli, type: :boolean
56
+ property :status, type: :string
57
+ property :threshold_reached, type: :boolean
58
+ property :threshold_amount, type: :decimal
59
+ property :default_dst_action, type: :string
60
+ property :dst_prefixes, type: :strings
61
+ property :media_encryption_mode, type: :string
62
+ property :callback_url, type: :string
63
+ property :force_symmetric_rtp, type: :boolean
64
+ property :allowed_rtp_ips, type: :ip_addresses
65
+
66
+ has_many :dids
67
+
68
+ def regenerate_credentials
69
+ resource = DIDWW::Resource::VoiceOutTrunkRegenerateCredential.new
70
+ resource.relationships[:voice_out_trunk] = self
71
+ resource.save
72
+ end
73
+ end
74
+ end
75
+ end
@@ -0,0 +1,11 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'didww/callback/const'
4
+
5
+ module DIDWW
6
+ module Resource
7
+ class VoiceOutTrunkRegenerateCredential < Base
8
+ has_one :voice_out_trunk
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,23 @@
1
+ # frozen_string_literal: true
2
+
3
+ module DIDWW
4
+ module Types
5
+ module IpAddresses
6
+ module_function
7
+
8
+ def cast(values, default)
9
+ return default unless values.is_a?(Array)
10
+
11
+ values.map do |value|
12
+ cast_item(value)
13
+ end
14
+ rescue IPAddr::Error
15
+ default
16
+ end
17
+
18
+ def cast_item(value)
19
+ value.is_a?(IPAddr) ? value : IPAddr.new(value)
20
+ end
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,21 @@
1
+ # frozen_string_literal: true
2
+
3
+ module DIDWW
4
+ module Types
5
+ module Strings
6
+ module_function
7
+
8
+ def cast(values, default)
9
+ return default unless values.is_a?(Array)
10
+
11
+ values.map do |value|
12
+ cast_item(value)
13
+ end
14
+ end
15
+
16
+ def cast_item(value)
17
+ value.to_s
18
+ end
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,12 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'json_api_client/schema'
4
+ require 'didww/types/ip_addresses'
5
+ require 'didww/types/strings'
6
+ require 'didww/complex_objects/base'
7
+ require 'didww/complex_objects/export_filters'
8
+
9
+ JsonApiClient::Schema.register ip_addresses: DIDWW::Types::IpAddresses,
10
+ strings: DIDWW::Types::Strings,
11
+ complex_object: DIDWW::ComplexObject::Base,
12
+ export_filters: DIDWW::ComplexObject::ExportFilters
data/lib/didww/version.rb CHANGED
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  module DIDWW
2
- VERSION = '1.3.1'.freeze
3
+ VERSION = '4.0.0'.freeze
3
4
  end
data/lib/didww.rb CHANGED
@@ -1,3 +1,8 @@
1
+ # frozen_string_literal: true
1
2
  require 'didww/version'
2
3
  require 'didww/client'
3
- require 'didww/middleware'
4
+ require 'didww/types'
5
+ require 'didww/base_middleware'
6
+ require 'didww/jsonapi_middleware'
7
+ require 'didww/callback/request_validator'
8
+ require 'didww/encrypt'