monokera-sdk 0.27.0

Sign up to get free protection for your applications and to get access to all the features.
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,25 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Monokera
4
+ module SDK
5
+ module Middleware
6
+ class ServiceMiddleware < Faraday::Middleware
7
+ def initialize(app, options = {})
8
+ super(app)
9
+ @service_name = options.fetch(:service_name, 'unknown-service')
10
+ @origin_service_name = ENV['APP_NAME']
11
+ end
12
+
13
+ def call(env)
14
+ ActiveSupport::Notifications.instrument('monokera-sdk.request.faraday', env) do
15
+ env[:service_name] ||= @service_name
16
+ env[:origin_service_name] ||= @origin_service_name
17
+ @app.call(env)
18
+ end
19
+ end
20
+ end
21
+ end
22
+ end
23
+ end
24
+
25
+ Faraday::Response.register_middleware(custom_service: Monokera::SDK::Middleware::ServiceMiddleware)
@@ -0,0 +1,49 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'virtus'
4
+ require 'active_support/json'
5
+ require 'active_support/core_ext'
6
+
7
+ module Monokera
8
+ module SDK
9
+ class Model
10
+ include Virtus.model
11
+ include Monokera::SDK::ActiveModelSerializer
12
+
13
+ attribute :errors, Set[Error], default: []
14
+
15
+ def add_error(attribute, code, description)
16
+ error = errors.find(-> { Error.new(attribute: attribute) }) { |e| e.attribute == attribute.to_s }
17
+ error.messages << ErrorMessage.new(code: code, description: description)
18
+
19
+ errors.add(error)
20
+ end
21
+
22
+ def valid?
23
+ errors.empty?
24
+ end
25
+
26
+ def as_json(*)
27
+ json = super
28
+ except_attributes!(json, 'errors')
29
+ json.with_indifferent_access
30
+ end
31
+
32
+ def except_attributes!(model, *attributes_to_reject)
33
+ if model.is_a?(Hash)
34
+ model.except!(*attributes_to_reject).each_value do |child|
35
+ except_attributes!(child, *attributes_to_reject)
36
+ end
37
+ end
38
+ end
39
+
40
+ def to_json(_options = nil)
41
+ JSON.generate(as_json)
42
+ end
43
+
44
+ def self.model_name
45
+ self.name.to_s
46
+ end
47
+ end
48
+ end
49
+ end
@@ -0,0 +1,14 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Monokera
4
+ module SDK
5
+ class Model
6
+ class Error
7
+ include Virtus.model
8
+
9
+ attribute :attribute, String
10
+ attribute :messages, Array[ErrorMessage], default: []
11
+ end
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,14 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Monokera
4
+ module SDK
5
+ class Model
6
+ class ErrorMessage
7
+ include Virtus.model
8
+
9
+ attribute :code, String
10
+ attribute :description, String
11
+ end
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,22 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Monokera
4
+ module SDK
5
+ class Plan < Monokera::SDK::ActiveModel
6
+ attribute :billable_id
7
+ attribute :billable_product
8
+ attribute :total_amount
9
+ attribute :initial_date
10
+ attribute :installments_count
11
+ attribute :installments_frequency
12
+ attribute :status
13
+ attribute :installments, Array[BillingService::Models::PlanInstallment]
14
+
15
+ BASE_ENDPOINT = '/v1/plans'
16
+
17
+ def self.client
18
+ @client ||= BillingService::Client.new
19
+ end
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,32 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Monokera
4
+ module SDK
5
+ class Policy < Monokera::SDK::ActiveModel
6
+ attribute :product
7
+ attribute :number
8
+ attribute :quote_id
9
+ attribute :pricing_id
10
+ attribute :status
11
+ attribute :issued_at
12
+ attribute :cancelled_at
13
+ attribute :effective_from
14
+ attribute :effective_until
15
+ attribute :customer_id
16
+ attribute :product_uid
17
+ attribute :product_version
18
+
19
+ attribute :cancellation, CancellationRequest
20
+ attribute :pricing_history, Array[PolicyService::Models::PricingHistory]
21
+ attribute :holder, PolicyService::Models::PolicyHolder
22
+ attribute :documents, Array[PolicyService::Models::Document]
23
+ attribute :settings, Array[PolicyService::Models::Setting]
24
+
25
+ BASE_ENDPOINT = '/v1/policies'
26
+
27
+ def self.client
28
+ @client ||= PolicyService::Client.new
29
+ end
30
+ end
31
+ end
32
+ end
@@ -0,0 +1,9 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Monokera
4
+ module SDK
5
+ module PolicyService
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 PolicyService
6
+ class Configuration < ::Monokera::SDK::Configuration
7
+ def service_name
8
+ 'policy-service'
9
+ end
10
+ end
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,21 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Monokera
4
+ module SDK
5
+ module PolicyService
6
+ module Models
7
+ class Address < Monokera::SDK::Model
8
+ attribute :street, String
9
+ attribute :complement, String
10
+ attribute :neighborhood, String
11
+ attribute :city, String
12
+ attribute :state, String
13
+ attribute :country, String
14
+ attribute :zip_code, String
15
+ attribute :latitude, String
16
+ attribute :longitude, String
17
+ end
18
+ end
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,15 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Monokera
4
+ module SDK
5
+ module PolicyService
6
+ module Models
7
+ class Document < Monokera::SDK::Model
8
+ attribute :integration_id, String
9
+ attribute :document_type, String
10
+ attribute :reference_number, String
11
+ end
12
+ end
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,15 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Monokera
4
+ module SDK
5
+ module PolicyService
6
+ module Models
7
+ class EndorsementOperation < Monokera::SDK::Model
8
+ attribute :code, String
9
+ attribute :pricing_id, String
10
+ attribute :needs_repricing, Boolean
11
+ end
12
+ end
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,22 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Monokera
4
+ module SDK
5
+ module PolicyService
6
+ module Models
7
+ class PolicyHolder < Monokera::SDK::Model
8
+ attribute :name, String
9
+ attribute :first_name, String
10
+ attribute :middle_name, String
11
+ attribute :last_name, String
12
+ attribute :second_last_name, String
13
+ attribute :document_number, String
14
+ attribute :document_type, String
15
+ attribute :phone, String
16
+ attribute :email, String
17
+ attribute :address, PolicyService::Models::Address
18
+ end
19
+ end
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,15 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Monokera
4
+ module SDK
5
+ module PolicyService
6
+ module Models
7
+ class PricingHistory < Monokera::SDK::Model
8
+ attribute :pricing_id, String
9
+ attribute :effective_from, String
10
+ attribute :effective_until, String
11
+ end
12
+ end
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,15 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Monokera
4
+ module SDK
5
+ module PolicyService
6
+ module Models
7
+ class Setting < Monokera::SDK::Model
8
+ attribute :coverage_uid
9
+ attribute :good_uid
10
+ attribute :insured_value
11
+ end
12
+ end
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,20 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Monokera
4
+ module SDK
5
+ class Pricing < Monokera::SDK::ActiveModel
6
+ attribute :id
7
+ attribute :original_id
8
+ attribute :premium
9
+ attribute :insured_value
10
+
11
+ attribute :settings, Array[PricingService::Models::Setting]
12
+
13
+ BASE_ENDPOINT = '/v1/pricings'
14
+
15
+ def self.client
16
+ @client ||= PricingService::Client.new
17
+ end
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,9 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Monokera
4
+ module SDK
5
+ module PricingService
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 PricingService
6
+ class Configuration < ::Monokera::SDK::Configuration
7
+ def service_name
8
+ 'pricing-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 PricingService
6
+ module Models
7
+ class Setting < Monokera::SDK::Model
8
+ attribute :coverage_uid, String
9
+ attribute :good_uid, String
10
+ attribute :premium, String
11
+ end
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 PricingSnapshot < Monokera::SDK::Pricing
6
+ BASE_ENDPOINT = '/v1/pricings/%{pricing_id}/snapshots'
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,21 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Monokera
4
+ module SDK
5
+ class Product < Monokera::SDK::ActiveModel
6
+ attribute :uid, String
7
+ attribute :name, String
8
+ attribute :description, String
9
+ attribute :version
10
+ attribute :quote_validity
11
+ attribute :quote_validity_type
12
+ attribute :settings, Array[ProductDefinition::Models::Setting]
13
+
14
+ BASE_ENDPOINT = '/v1/products'
15
+
16
+ def self.client
17
+ @client ||= ProductDefinition::Client.new
18
+ end
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,9 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Monokera
4
+ module SDK
5
+ module ProductDefinition
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 ProductDefinition
6
+ class Configuration < ::Monokera::SDK::Configuration
7
+ def service_name
8
+ 'product-definition'
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 ProductDefinition
6
+ module Models
7
+ class Condition < Monokera::SDK::Model
8
+ attribute :name, String
9
+ attribute :description, String
10
+ attribute :type, String
11
+ end
12
+ end
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,14 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Monokera
4
+ module SDK
5
+ module ProductDefinition
6
+ module Models
7
+ class Deductible < Monokera::SDK::Model
8
+ attribute :description, String
9
+ attribute :value, Float
10
+ end
11
+ end
12
+ end
13
+ end
14
+ end