didww-v3 1.3.1 → 2.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (60) 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 +20 -2
  5. data/Gemfile +1 -0
  6. data/README.md +5 -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/request_validator.rb +68 -0
  12. data/lib/didww/client.rb +61 -13
  13. data/lib/didww/complex_objects/base.rb +1 -0
  14. data/lib/didww/complex_objects/capacity_order_item.rb +1 -0
  15. data/lib/didww/complex_objects/cdr_export_filter.rb +1 -0
  16. data/lib/didww/complex_objects/configurations/base.rb +1 -0
  17. data/lib/didww/complex_objects/configurations/const.rb +1 -0
  18. data/lib/didww/complex_objects/configurations/h323_configuration.rb +1 -0
  19. data/lib/didww/complex_objects/configurations/iax2_configuration.rb +1 -0
  20. data/lib/didww/complex_objects/configurations/pstn_configuration.rb +1 -0
  21. data/lib/didww/complex_objects/configurations/sip_configuration.rb +1 -0
  22. data/lib/didww/complex_objects/configurations.rb +1 -0
  23. data/lib/didww/complex_objects/did_order_item.rb +14 -12
  24. data/lib/didww/encrypt.rb +101 -0
  25. data/lib/didww/jsonapi_middleware.rb +21 -0
  26. data/lib/didww/resources/address.rb +37 -0
  27. data/lib/didww/resources/address_verification.rb +56 -0
  28. data/lib/didww/resources/area.rb +12 -0
  29. data/lib/didww/resources/available_did.rb +1 -0
  30. data/lib/didww/resources/balance.rb +1 -0
  31. data/lib/didww/resources/base.rb +2 -1
  32. data/lib/didww/resources/capacity_pool.rb +1 -0
  33. data/lib/didww/resources/cdr_export.rb +12 -1
  34. data/lib/didww/resources/city.rb +5 -0
  35. data/lib/didww/resources/country.rb +1 -0
  36. data/lib/didww/resources/did.rb +3 -1
  37. data/lib/didww/resources/did_group.rb +1 -4
  38. data/lib/didww/resources/did_group_type.rb +1 -0
  39. data/lib/didww/resources/did_reservation.rb +1 -0
  40. data/lib/didww/resources/encrypted_file.rb +58 -0
  41. data/lib/didww/resources/identity.rb +78 -0
  42. data/lib/didww/resources/order.rb +9 -0
  43. data/lib/didww/resources/permanent_supporting_document.rb +15 -0
  44. data/lib/didww/resources/pop.rb +1 -0
  45. data/lib/didww/resources/proof.rb +19 -0
  46. data/lib/didww/resources/proof_type.rb +14 -0
  47. data/lib/didww/resources/public_key.rb +12 -0
  48. data/lib/didww/resources/qty_based_pricing.rb +1 -0
  49. data/lib/didww/resources/region.rb +1 -0
  50. data/lib/didww/resources/requirement.rb +61 -0
  51. data/lib/didww/resources/requirement_validation.rb +10 -0
  52. data/lib/didww/resources/shared_capacity_group.rb +1 -0
  53. data/lib/didww/resources/stock_keeping_unit.rb +1 -0
  54. data/lib/didww/resources/supporting_document_template.rb +14 -0
  55. data/lib/didww/resources/trunk/const.rb +1 -0
  56. data/lib/didww/resources/trunk.rb +1 -0
  57. data/lib/didww/resources/trunk_group.rb +1 -0
  58. data/lib/didww/version.rb +2 -1
  59. data/lib/didww.rb +5 -1
  60. metadata +33 -4
@@ -1,4 +1,5 @@
1
- require 'didww/middleware'
1
+ # frozen_string_literal: true
2
+ require 'didww/jsonapi_middleware'
2
3
  require 'didww/complex_objects/base'
3
4
 
4
5
  module DIDWW
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  module DIDWW
2
3
  module Resource
3
4
  class CapacityPool < Base
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  require 'forwardable'
2
3
  require 'didww/complex_objects/cdr_export_filter'
3
4
  require 'down/http'
@@ -7,6 +8,8 @@ module DIDWW
7
8
  class CdrExport < Base
8
9
  extend Forwardable
9
10
 
11
+ STATUS_COMPLETED = 'Completed'
12
+
10
13
  property :filters, type: :cdr_export_filter
11
14
  # Type: CDR Export Filters Object
12
15
  # Nullable: No
@@ -27,6 +30,14 @@ module DIDWW
27
30
  # Nullable: true
28
31
  # Description: url of csv file for downloading. available only when status is "Completed"
29
32
 
33
+ property :callback_url, type: :string
34
+ # Type: String
35
+ # Description: valid URI for callbacks
36
+
37
+ property :callback_method, type: :string
38
+ # Type: String
39
+ # Description: GET or POST
40
+
30
41
  def_delegators :filters, :year, :month, :did_number, :year=, :month=, :did_number=
31
42
 
32
43
  def initialize(params = {})
@@ -39,7 +50,7 @@ module DIDWW
39
50
  end
40
51
 
41
52
  def complete?
42
- status == 'Completed'
53
+ status == STATUS_COMPLETED
43
54
  end
44
55
  alias_method :completed?, :complete?
45
56
  end
@@ -1,6 +1,11 @@
1
+ # frozen_string_literal: true
1
2
  module DIDWW
2
3
  module Resource
3
4
  class City < Base
5
+ has_one :country, class_name: 'Country'
6
+ has_one :region, class_name: 'Region'
7
+ has_one :area, class_name: 'Area'
8
+
4
9
  property :name, type: :string
5
10
  # Type: String
6
11
  # Description: City name
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  module DIDWW
2
3
  module Resource
3
4
  class Country < Base
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  module DIDWW
2
3
  module Resource
3
4
  class Did < Base
@@ -5,6 +6,7 @@ module DIDWW
5
6
  has_one :trunk_group
6
7
  has_one :capacity_pool
7
8
  has_one :shared_capacity_group
9
+ has_one :address_verification
8
10
 
9
11
  property :blocked, type: :boolean
10
12
  # Type: Boolean
@@ -18,7 +20,7 @@ module DIDWW
18
20
  # Type: Boolean
19
21
  # Description: Identifier for terminated DIDs that will be removed from service at the end of the billing cycle.
20
22
 
21
- property :pending_removal, type: :boolean
23
+ property :billing_cycles_count, type: :integer
22
24
  # Type: Boolean
23
25
  # Description: Identifier for DIDs that are pending removal from your account.
24
26
 
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  module DIDWW
2
3
  module Resource
3
4
  class DidGroup < Base
@@ -60,10 +61,6 @@ module DIDWW
60
61
  # is_available
61
62
  # Type: Boolean
62
63
  # Description: Defines if numbers in this DID Group are currently in stock.
63
- #
64
- # restrictions
65
- # Type: String
66
- # Description: Describes possible restrictions for the DID Group, such as "End User Registration is Required".
67
64
 
68
65
  end
69
66
  end
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  module DIDWW
2
3
  module Resource
3
4
  class DidGroupType < Base
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  module DIDWW
2
3
  module Resource
3
4
  class DidReservation < Base
@@ -0,0 +1,58 @@
1
+ # frozen_string_literal: true
2
+ module DIDWW
3
+ module Resource
4
+ class EncryptedFile < Base
5
+ class UploadError < StandardError
6
+ end
7
+
8
+ property :description, type: :string
9
+ # Type: String
10
+ # Description:
11
+
12
+ property :expire_at, type: :date
13
+ # Type: Date
14
+ # Description:
15
+
16
+ # @return [Faraday::Connection]
17
+ def self.upload_connection
18
+ Faraday.new(url: site) do |connection|
19
+ connection.request :multipart
20
+ connection.request :url_encoded
21
+ connection.adapter Faraday.default_adapter
22
+ connection.use DIDWW::BaseMiddleware
23
+ end
24
+ end
25
+
26
+ # @param files [Rack::Multipart::UploadedFile,(#tempfile,#content_type,#original_filename)]
27
+ # @return [Array<String>]
28
+ # @raise [DIDWW::Resource::EncryptedFile::UploadError]
29
+ def self.upload_files(files, fingerprint)
30
+ items = files.map do |file|
31
+ {
32
+ file: Faraday::UploadIO.new(file.tempfile, file.content_type),
33
+ description: file.original_filename
34
+ }
35
+ end
36
+ payload = { encryption_fingerprint: fingerprint, items: items }
37
+ upload(payload)
38
+ end
39
+
40
+ # @param payload [Hash]
41
+ # encryption_fingerprint [String] DIDWW::Encrypt#encryption_fingerprint
42
+ # items [Array]
43
+ # file [Faraday::UploadIO] upload io
44
+ # description [String,nil] optional description
45
+ # @return [Array<String>]
46
+ # @raise [DIDWW::Resource::EncryptedFile::UploadError]
47
+ def self.upload(payload)
48
+ connection = upload_connection
49
+ response = connection.post('/v3/encrypted_files', encrypted_files: payload)
50
+ if response.status == 201
51
+ JSON.parse(response.body, symbolize_names: true)[:ids]
52
+ else
53
+ raise UploadError, "Code: #{response.status} #{response.body}"
54
+ end
55
+ end
56
+ end
57
+ end
58
+ end
@@ -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
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  require 'didww/complex_objects/did_order_item'
2
3
  require 'didww/complex_objects/capacity_order_item'
3
4
 
@@ -46,6 +47,14 @@ module DIDWW
46
47
  # Type: Boolean
47
48
  # Description: Allowing back ordering
48
49
 
50
+ property :callback_url, type: :string
51
+ # Type: String
52
+ # Description: valid URI for callbacks
53
+
54
+ property :callback_method, type: :string
55
+ # Type: String
56
+ # Description: GET or POST
57
+
49
58
  def initialize(*args)
50
59
  super
51
60
  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,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  module DIDWW
2
3
  module Resource
3
4
  class Trunk < Base
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  require 'didww/complex_objects/configurations'
2
3
  require 'didww/resources/trunk/const'
3
4
 
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  module DIDWW
2
3
  module Resource
3
4
  class TrunkGroup < Base
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 = '2.0.0'.freeze
3
4
  end
data/lib/didww.rb CHANGED
@@ -1,3 +1,7 @@
1
+ # frozen_string_literal: true
1
2
  require 'didww/version'
2
3
  require 'didww/client'
3
- require 'didww/middleware'
4
+ require 'didww/base_middleware'
5
+ require 'didww/jsonapi_middleware'
6
+ require 'didww/callback/request_validator'
7
+ require 'didww/encrypt'
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: 1.3.1
4
+ version: 2.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Alex Korobeinikov
@@ -44,14 +44,14 @@ dependencies:
44
44
  requirements:
45
45
  - - '='
46
46
  - !ruby/object:Gem::Version
47
- version: 1.5.3
47
+ version: 1.18.0
48
48
  type: :runtime
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
52
  - - '='
53
53
  - !ruby/object:Gem::Version
54
- version: 1.5.3
54
+ version: 1.18.0
55
55
  - !ruby/object:Gem::Dependency
56
56
  name: http
57
57
  requirement: !ruby/object:Gem::Requirement
@@ -80,6 +80,20 @@ dependencies:
80
80
  - - ">="
81
81
  - !ruby/object:Gem::Version
82
82
  version: '0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: openssl-oaep
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ type: :runtime
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ">="
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
83
97
  description: Ruby client for DIDWW API v3
84
98
  email:
85
99
  - alex.k@didww.com
@@ -100,6 +114,8 @@ files:
100
114
  - bin/setup
101
115
  - didww-v3.gemspec
102
116
  - lib/didww.rb
117
+ - lib/didww/base_middleware.rb
118
+ - lib/didww/callback/request_validator.rb
103
119
  - lib/didww/client.rb
104
120
  - lib/didww/complex_objects/base.rb
105
121
  - lib/didww/complex_objects/capacity_order_item.rb
@@ -112,7 +128,11 @@ files:
112
128
  - lib/didww/complex_objects/configurations/pstn_configuration.rb
113
129
  - lib/didww/complex_objects/configurations/sip_configuration.rb
114
130
  - lib/didww/complex_objects/did_order_item.rb
115
- - lib/didww/middleware.rb
131
+ - lib/didww/encrypt.rb
132
+ - lib/didww/jsonapi_middleware.rb
133
+ - lib/didww/resources/address.rb
134
+ - lib/didww/resources/address_verification.rb
135
+ - lib/didww/resources/area.rb
116
136
  - lib/didww/resources/available_did.rb
117
137
  - lib/didww/resources/balance.rb
118
138
  - lib/didww/resources/base.rb
@@ -124,12 +144,21 @@ files:
124
144
  - lib/didww/resources/did_group.rb
125
145
  - lib/didww/resources/did_group_type.rb
126
146
  - lib/didww/resources/did_reservation.rb
147
+ - lib/didww/resources/encrypted_file.rb
148
+ - lib/didww/resources/identity.rb
127
149
  - lib/didww/resources/order.rb
150
+ - lib/didww/resources/permanent_supporting_document.rb
128
151
  - lib/didww/resources/pop.rb
152
+ - lib/didww/resources/proof.rb
153
+ - lib/didww/resources/proof_type.rb
154
+ - lib/didww/resources/public_key.rb
129
155
  - lib/didww/resources/qty_based_pricing.rb
130
156
  - lib/didww/resources/region.rb
157
+ - lib/didww/resources/requirement.rb
158
+ - lib/didww/resources/requirement_validation.rb
131
159
  - lib/didww/resources/shared_capacity_group.rb
132
160
  - lib/didww/resources/stock_keeping_unit.rb
161
+ - lib/didww/resources/supporting_document_template.rb
133
162
  - lib/didww/resources/trunk.rb
134
163
  - lib/didww/resources/trunk/const.rb
135
164
  - lib/didww/resources/trunk_group.rb