monokera-sdk 0.27.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 (103) hide show
  1. checksums.yaml +7 -0
  2. data/.env.example +35 -0
  3. data/.github/dependabot.yml +44 -0
  4. data/.github/pull_request_template.md +15 -0
  5. data/.github/workflows/ci.yml +67 -0
  6. data/.github/workflows/lint.yml +28 -0
  7. data/.gitignore +18 -0
  8. data/.markdownlint.yaml +6 -0
  9. data/.rspec +1 -0
  10. data/.rubocop.yml +15 -0
  11. data/.yamllint.yml +6 -0
  12. data/.yardopts +6 -0
  13. data/CHANGELOG.md +166 -0
  14. data/CODEOWNERS +8 -0
  15. data/Gemfile +6 -0
  16. data/Guardfile +19 -0
  17. data/README.md +37 -0
  18. data/Rakefile +8 -0
  19. data/bin/bump +20 -0
  20. data/bin/console +12 -0
  21. data/bin/rspec +29 -0
  22. data/bin/setup +8 -0
  23. data/build_tools/changelog.rb +52 -0
  24. data/build_tools/spec/changelog_spec.rb +36 -0
  25. data/build_tools/spec/fixtures/CHANGELOG.md +11 -0
  26. data/docs/product_definition.md +48 -0
  27. data/lib/monokera/sdk.rb +18 -0
  28. data/lib/monokera/sdk/active_client.rb +44 -0
  29. data/lib/monokera/sdk/active_model.rb +150 -0
  30. data/lib/monokera/sdk/active_model_serializer.rb +11 -0
  31. data/lib/monokera/sdk/active_support_notifications.rb +27 -0
  32. data/lib/monokera/sdk/billing_service/client.rb +9 -0
  33. data/lib/monokera/sdk/billing_service/configuration.rb +13 -0
  34. data/lib/monokera/sdk/billing_service/models/installment_item.rb +17 -0
  35. data/lib/monokera/sdk/billing_service/models/plan_installment.rb +17 -0
  36. data/lib/monokera/sdk/cancellation_request.rb +18 -0
  37. data/lib/monokera/sdk/claim.rb +24 -0
  38. data/lib/monokera/sdk/claim_service/client.rb +9 -0
  39. data/lib/monokera/sdk/claim_service/configuration.rb +13 -0
  40. data/lib/monokera/sdk/claim_service/models/attendant.rb +14 -0
  41. data/lib/monokera/sdk/claim_service/models/setting.rb +17 -0
  42. data/lib/monokera/sdk/client_base.rb +113 -0
  43. data/lib/monokera/sdk/client_deprecation.rb +37 -0
  44. data/lib/monokera/sdk/client_service/client.rb +9 -0
  45. data/lib/monokera/sdk/client_service/configuration.rb +13 -0
  46. data/lib/monokera/sdk/config/gem_inflector.rb +17 -0
  47. data/lib/monokera/sdk/configuration.rb +57 -0
  48. data/lib/monokera/sdk/configurator.rb +15 -0
  49. data/lib/monokera/sdk/consolidated_pricing.rb +9 -0
  50. data/lib/monokera/sdk/coverage.rb +18 -0
  51. data/lib/monokera/sdk/credential.rb +18 -0
  52. data/lib/monokera/sdk/customer.rb +26 -0
  53. data/lib/monokera/sdk/customer_prospect.rb +24 -0
  54. data/lib/monokera/sdk/customer_service/client.rb +9 -0
  55. data/lib/monokera/sdk/customer_service/configuration.rb +13 -0
  56. data/lib/monokera/sdk/customer_service/models/address.rb +15 -0
  57. data/lib/monokera/sdk/document.rb +19 -0
  58. data/lib/monokera/sdk/document_service/client.rb +9 -0
  59. data/lib/monokera/sdk/document_service/configuration.rb +13 -0
  60. data/lib/monokera/sdk/endorsed_plan_preview.rb +9 -0
  61. data/lib/monokera/sdk/endorsement.rb +26 -0
  62. data/lib/monokera/sdk/error.rb +61 -0
  63. data/lib/monokera/sdk/good.rb +17 -0
  64. data/lib/monokera/sdk/hash_model.rb +29 -0
  65. data/lib/monokera/sdk/middleware/custom_logger_middleware.rb +89 -0
  66. data/lib/monokera/sdk/middleware/service_middleware.rb +25 -0
  67. data/lib/monokera/sdk/model.rb +49 -0
  68. data/lib/monokera/sdk/model/error.rb +14 -0
  69. data/lib/monokera/sdk/model/error_message.rb +14 -0
  70. data/lib/monokera/sdk/plan.rb +22 -0
  71. data/lib/monokera/sdk/policy.rb +32 -0
  72. data/lib/monokera/sdk/policy_service/client.rb +9 -0
  73. data/lib/monokera/sdk/policy_service/configuration.rb +13 -0
  74. data/lib/monokera/sdk/policy_service/models/address.rb +21 -0
  75. data/lib/monokera/sdk/policy_service/models/document.rb +15 -0
  76. data/lib/monokera/sdk/policy_service/models/endorsement_operation.rb +15 -0
  77. data/lib/monokera/sdk/policy_service/models/policy_holder.rb +22 -0
  78. data/lib/monokera/sdk/policy_service/models/pricing_history.rb +15 -0
  79. data/lib/monokera/sdk/policy_service/models/setting.rb +15 -0
  80. data/lib/monokera/sdk/pricing.rb +20 -0
  81. data/lib/monokera/sdk/pricing_service/client.rb +9 -0
  82. data/lib/monokera/sdk/pricing_service/configuration.rb +13 -0
  83. data/lib/monokera/sdk/pricing_service/models/setting.rb +15 -0
  84. data/lib/monokera/sdk/pricing_snapshot.rb +9 -0
  85. data/lib/monokera/sdk/product.rb +21 -0
  86. data/lib/monokera/sdk/product_definition/client.rb +9 -0
  87. data/lib/monokera/sdk/product_definition/configuration.rb +13 -0
  88. data/lib/monokera/sdk/product_definition/models/condition.rb +15 -0
  89. data/lib/monokera/sdk/product_definition/models/deductible.rb +14 -0
  90. data/lib/monokera/sdk/product_definition/models/limit.rb +16 -0
  91. data/lib/monokera/sdk/product_definition/models/rate.rb +15 -0
  92. data/lib/monokera/sdk/product_definition/models/setting.rb +20 -0
  93. data/lib/monokera/sdk/quote.rb +29 -0
  94. data/lib/monokera/sdk/quote_service/client.rb +9 -0
  95. data/lib/monokera/sdk/quote_service/configuration.rb +13 -0
  96. data/lib/monokera/sdk/quote_service/models/address.rb +21 -0
  97. data/lib/monokera/sdk/quote_service/models/customer_prospect.rb +23 -0
  98. data/lib/monokera/sdk/quote_service/models/setting.rb +15 -0
  99. data/lib/monokera/sdk/resource_not_found.rb +7 -0
  100. data/lib/monokera/sdk/validity.rb +18 -0
  101. data/lib/monokera/sdk/version.rb +7 -0
  102. data/monokera-sdk.gemspec +45 -0
  103. metadata +423 -0
@@ -0,0 +1,15 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Monokera
4
+ module SDK
5
+ class Configurator < Configuration
6
+ attr_reader :service_name
7
+
8
+ public_class_method :new
9
+ def initialize(service_name)
10
+ super()
11
+ @service_name = service_name
12
+ end
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,9 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Monokera
4
+ module SDK
5
+ class ConsolidatedPricing < Monokera::SDK::Pricing
6
+ BASE_ENDPOINT = '/v1/consolidated_pricing'
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,18 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Monokera
4
+ module SDK
5
+ class Coverage < Monokera::SDK::ActiveModel
6
+ attribute :uid
7
+ attribute :name
8
+ attribute :description
9
+ attribute :branch_uid
10
+
11
+ BASE_ENDPOINT = '/v1/coverages'
12
+
13
+ def self.client
14
+ @client ||= ProductDefinition::Client.new
15
+ end
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,18 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Monokera
4
+ module SDK
5
+ class Credential < Monokera::SDK::ActiveModel
6
+ attribute :user, String
7
+ attribute :secret, String
8
+ attribute :service, String
9
+ attribute :type, String
10
+
11
+ BASE_ENDPOINT = '/v1/clients/%{client_name}/credentials/%{service}'
12
+
13
+ def self.client
14
+ @client ||= ClientService::Client.new
15
+ end
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,26 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Monokera
4
+ module SDK
5
+ class Customer < Monokera::SDK::ActiveModel
6
+ attribute :document_type, String
7
+ attribute :document_number, String
8
+ attribute :first_name, String
9
+ attribute :middle_name, String
10
+ attribute :last_name, String
11
+ attribute :second_last_name, String
12
+ attribute :business_name, String
13
+ attribute :email, String
14
+ attribute :telephone, String
15
+ attribute :phone, String
16
+
17
+ attribute :address, CustomerService::Models::Address
18
+
19
+ BASE_ENDPOINT = '/v1/customers'
20
+
21
+ def self.client
22
+ @client ||= CustomerService::Client.new
23
+ end
24
+ end
25
+ end
26
+ end
@@ -0,0 +1,24 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Monokera
4
+ module SDK
5
+ class CustomerProspect < Monokera::SDK::ActiveModel
6
+ attribute :id, String
7
+ attribute :document_number, String
8
+ attribute :email, String
9
+ attribute :name, String
10
+ attribute :first_name, String
11
+ attribute :middle_name, String
12
+ attribute :last_name, String
13
+ attribute :second_last_name, String
14
+ attribute :document_type, String
15
+ attribute :phone, String
16
+
17
+ BASE_ENDPOINT = '/v1/customer_prospects'
18
+
19
+ def self.client
20
+ @client ||= QuoteService::Client.new
21
+ end
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,9 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Monokera
4
+ module SDK
5
+ module CustomerService
6
+ class Client < Monokera::SDK::ActiveClient; end
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,13 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Monokera
4
+ module SDK
5
+ module CustomerService
6
+ class Configuration < ::Monokera::SDK::Configuration
7
+ def service_name
8
+ 'customer-service'
9
+ end
10
+ end
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,15 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Monokera
4
+ module SDK
5
+ module CustomerService
6
+ module Models
7
+ class Address < Monokera::SDK::Model
8
+ attribute :street, String
9
+ attribute :city, String
10
+ attribute :state, String
11
+ end
12
+ end
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,19 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Monokera
4
+ module SDK
5
+ class Document < Monokera::SDK::ActiveModel
6
+ attribute :reference_policy
7
+ attribute :reference_number
8
+ attribute :type
9
+ attribute :public_url
10
+ attribute :repo_file_key
11
+
12
+ BASE_ENDPOINT = '/v1/documents'
13
+
14
+ def self.client
15
+ @client ||= DocumentService::Client.new
16
+ end
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,9 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Monokera
4
+ module SDK
5
+ module DocumentService
6
+ class Client < Monokera::SDK::ActiveClient; end
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,13 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Monokera
4
+ module SDK
5
+ module DocumentService
6
+ class Configuration < ::Monokera::SDK::Configuration
7
+ def service_name
8
+ 'document-service'
9
+ end
10
+ end
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,9 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Monokera
4
+ module SDK
5
+ class EndorsedPlanPreview < Plan
6
+ BASE_ENDPOINT = '/v1/plans/%{billable_id}/endorsed_preview'
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,26 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Monokera
4
+ module SDK
5
+ class Endorsement < Monokera::SDK::ActiveModel
6
+ attribute :product
7
+ attribute :status
8
+ attribute :number
9
+ attribute :protocol_number
10
+ attribute :effective_from
11
+ attribute :pricing_id
12
+ attribute :issued_at
13
+ attribute :created_at
14
+
15
+ attribute :former_policy, Policy
16
+ attribute :updated_policy, Policy
17
+ attribute :endorsement_operations, Array[PolicyService::Models::EndorsementOperation]
18
+
19
+ BASE_ENDPOINT = '/v1/policies/%{policy_number}/endorsements'
20
+
21
+ def self.client
22
+ @client ||= PolicyService::Client.new
23
+ end
24
+ end
25
+ end
26
+ end
@@ -0,0 +1,61 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Monokera
4
+ module SDK
5
+ class Error < StandardError
6
+ ClientError = Class.new(self)
7
+
8
+ BadRequest = Class.new(ClientError)
9
+
10
+ NotFound = Class.new(ClientError)
11
+
12
+ Conflict = Class.new(ClientError)
13
+
14
+ Gone = Class.new(ClientError)
15
+
16
+ UnprocessableEntity = Class.new(ClientError)
17
+
18
+ ServerError = Class.new(self)
19
+
20
+ InternalServerError = Class.new(ServerError)
21
+
22
+ ServiceUnavailableError = Class.new(ServerError)
23
+
24
+ HTTP_ERRORS = {
25
+ 400 => BadRequest,
26
+ 401 => ClientError,
27
+ 404 => NotFound,
28
+ 409 => Conflict,
29
+ 410 => Gone,
30
+ 422 => UnprocessableEntity,
31
+ 500 => InternalServerError,
32
+ 503 => ServiceUnavailableError
33
+ }.freeze
34
+
35
+ ERROR_STATUSES = [400, 600].freeze
36
+
37
+ class Middleware < Faraday::Response::Middleware
38
+ def on_complete(env)
39
+ status = env[:status]
40
+
41
+ Error.raise_if_http_error!(status, env)
42
+ end
43
+ end
44
+
45
+ def self.raise_if_http_error!(status, env)
46
+ if status.between?(*ERROR_STATUSES)
47
+ error_klass = HTTP_ERRORS.fetch(status, Error)
48
+
49
+ raise error_klass, env
50
+ end
51
+ end
52
+
53
+ attr_reader :env
54
+
55
+ def initialize(env)
56
+ super(env)
57
+ @env = env
58
+ end
59
+ end
60
+ end
61
+ end
@@ -0,0 +1,17 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Monokera
4
+ module SDK
5
+ class Good < Monokera::SDK::ActiveModel
6
+ attribute :uid
7
+ attribute :name
8
+ attribute :description
9
+
10
+ BASE_ENDPOINT = '/v1/goods'
11
+
12
+ def self.client
13
+ @client ||= ProductDefinition::Client.new
14
+ end
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,29 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'json'
4
+
5
+ module Monokera
6
+ module SDK
7
+ class HashModel < OpenStruct
8
+ include Monokera::SDK::ActiveModelSerializer
9
+
10
+ def self.build(attrs)
11
+ raise 'Invalid keys `attributes`' if attrs.key?(:attributes) || attrs.key?('attributes')
12
+
13
+ JSON.parse(attrs.to_json, object_class: Monokera::SDK::HashModel)
14
+ end
15
+
16
+ def attributes
17
+ self
18
+ end
19
+
20
+ def as_json(options = nil)
21
+ @table.as_json(options).deep_symbolize_keys
22
+ end
23
+
24
+ def self.model_name
25
+ self.name.to_s
26
+ end
27
+ end
28
+ end
29
+ end
@@ -0,0 +1,89 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Monokera
4
+ module SDK
5
+ module Middleware
6
+ class CustomLoggerMiddleware < Faraday::Response::Middleware
7
+ def initialize(app, logger, options)
8
+ super(app)
9
+ @logger = logger
10
+ @service_name = options[:service_name]
11
+ @filter_parameters = options[:filter_parameters]
12
+ end
13
+
14
+ def call(env)
15
+ @request_env = env.dup
16
+ super
17
+ end
18
+
19
+ def on_complete(response_env)
20
+ @logger.info format_log(@request_env, response_env).to_json
21
+ end
22
+
23
+ private
24
+
25
+ def to_curl(request)
26
+ quote = lambda { |value| value.gsub("'", "\\'") }
27
+
28
+ command = ['curl', '-v']
29
+ command << "-X #{request.method.to_s.upcase}"
30
+
31
+ if request.request_headers.present?
32
+ headers = request.request_headers
33
+
34
+ headers.each do |key, value|
35
+ command << "-H '#{key}: #{quote.call(value)}'" if value.present?
36
+ end
37
+ end
38
+
39
+ if request.body.present?
40
+ if request.body.respond_to?(:to_str)
41
+ body = format_body(request.body)
42
+ command << "-d '#{quote.call(body.to_json)}'"
43
+ else
44
+ command << "-d 'body is not string-like, cant render it'"
45
+ end
46
+ end
47
+
48
+ command << request.url
49
+ command.join(' ')
50
+ end
51
+
52
+ def format_log(request, response)
53
+ output = {
54
+ service_name: @service_name,
55
+ request: {
56
+ method: request.method,
57
+ url: request.url.to_s,
58
+ body: format_body(request.body),
59
+ headers: request.request_headers
60
+ },
61
+ response: {
62
+ status: response.status,
63
+ body: response.body.to_s.dup.force_encoding('utf-8'),
64
+ headers: response.response_headers
65
+ }
66
+ }
67
+
68
+ if @logger.level <= Logger::DEBUG
69
+ output[:request][:curl] = to_curl(request)
70
+ end
71
+
72
+ output
73
+ end
74
+
75
+ def format_body(body)
76
+ parameter_filter.filter(JSON.parse(body))
77
+ rescue StandardError
78
+ body
79
+ end
80
+
81
+ def parameter_filter
82
+ @parameter_filter ||= ActiveSupport::ParameterFilter.new(@filter_parameters)
83
+ end
84
+ end
85
+ end
86
+ end
87
+ end
88
+
89
+ Faraday::Response.register_middleware(custom_logger: Monokera::SDK::Middleware::CustomLoggerMiddleware)