monokera-sdk 0.27.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.env.example +35 -0
- data/.github/dependabot.yml +44 -0
- data/.github/pull_request_template.md +15 -0
- data/.github/workflows/ci.yml +67 -0
- data/.github/workflows/lint.yml +28 -0
- data/.gitignore +18 -0
- data/.markdownlint.yaml +6 -0
- data/.rspec +1 -0
- data/.rubocop.yml +15 -0
- data/.yamllint.yml +6 -0
- data/.yardopts +6 -0
- data/CHANGELOG.md +166 -0
- data/CODEOWNERS +8 -0
- data/Gemfile +6 -0
- data/Guardfile +19 -0
- data/README.md +37 -0
- data/Rakefile +8 -0
- data/bin/bump +20 -0
- data/bin/console +12 -0
- data/bin/rspec +29 -0
- data/bin/setup +8 -0
- data/build_tools/changelog.rb +52 -0
- data/build_tools/spec/changelog_spec.rb +36 -0
- data/build_tools/spec/fixtures/CHANGELOG.md +11 -0
- data/docs/product_definition.md +48 -0
- data/lib/monokera/sdk.rb +18 -0
- data/lib/monokera/sdk/active_client.rb +44 -0
- data/lib/monokera/sdk/active_model.rb +150 -0
- data/lib/monokera/sdk/active_model_serializer.rb +11 -0
- data/lib/monokera/sdk/active_support_notifications.rb +27 -0
- data/lib/monokera/sdk/billing_service/client.rb +9 -0
- data/lib/monokera/sdk/billing_service/configuration.rb +13 -0
- data/lib/monokera/sdk/billing_service/models/installment_item.rb +17 -0
- data/lib/monokera/sdk/billing_service/models/plan_installment.rb +17 -0
- data/lib/monokera/sdk/cancellation_request.rb +18 -0
- data/lib/monokera/sdk/claim.rb +24 -0
- data/lib/monokera/sdk/claim_service/client.rb +9 -0
- data/lib/monokera/sdk/claim_service/configuration.rb +13 -0
- data/lib/monokera/sdk/claim_service/models/attendant.rb +14 -0
- data/lib/monokera/sdk/claim_service/models/setting.rb +17 -0
- data/lib/monokera/sdk/client_base.rb +113 -0
- data/lib/monokera/sdk/client_deprecation.rb +37 -0
- data/lib/monokera/sdk/client_service/client.rb +9 -0
- data/lib/monokera/sdk/client_service/configuration.rb +13 -0
- data/lib/monokera/sdk/config/gem_inflector.rb +17 -0
- data/lib/monokera/sdk/configuration.rb +57 -0
- data/lib/monokera/sdk/configurator.rb +15 -0
- data/lib/monokera/sdk/consolidated_pricing.rb +9 -0
- data/lib/monokera/sdk/coverage.rb +18 -0
- data/lib/monokera/sdk/credential.rb +18 -0
- data/lib/monokera/sdk/customer.rb +26 -0
- data/lib/monokera/sdk/customer_prospect.rb +24 -0
- data/lib/monokera/sdk/customer_service/client.rb +9 -0
- data/lib/monokera/sdk/customer_service/configuration.rb +13 -0
- data/lib/monokera/sdk/customer_service/models/address.rb +15 -0
- data/lib/monokera/sdk/document.rb +19 -0
- data/lib/monokera/sdk/document_service/client.rb +9 -0
- data/lib/monokera/sdk/document_service/configuration.rb +13 -0
- data/lib/monokera/sdk/endorsed_plan_preview.rb +9 -0
- data/lib/monokera/sdk/endorsement.rb +26 -0
- data/lib/monokera/sdk/error.rb +61 -0
- data/lib/monokera/sdk/good.rb +17 -0
- data/lib/monokera/sdk/hash_model.rb +29 -0
- data/lib/monokera/sdk/middleware/custom_logger_middleware.rb +89 -0
- data/lib/monokera/sdk/middleware/service_middleware.rb +25 -0
- data/lib/monokera/sdk/model.rb +49 -0
- data/lib/monokera/sdk/model/error.rb +14 -0
- data/lib/monokera/sdk/model/error_message.rb +14 -0
- data/lib/monokera/sdk/plan.rb +22 -0
- data/lib/monokera/sdk/policy.rb +32 -0
- data/lib/monokera/sdk/policy_service/client.rb +9 -0
- data/lib/monokera/sdk/policy_service/configuration.rb +13 -0
- data/lib/monokera/sdk/policy_service/models/address.rb +21 -0
- data/lib/monokera/sdk/policy_service/models/document.rb +15 -0
- data/lib/monokera/sdk/policy_service/models/endorsement_operation.rb +15 -0
- data/lib/monokera/sdk/policy_service/models/policy_holder.rb +22 -0
- data/lib/monokera/sdk/policy_service/models/pricing_history.rb +15 -0
- data/lib/monokera/sdk/policy_service/models/setting.rb +15 -0
- data/lib/monokera/sdk/pricing.rb +20 -0
- data/lib/monokera/sdk/pricing_service/client.rb +9 -0
- data/lib/monokera/sdk/pricing_service/configuration.rb +13 -0
- data/lib/monokera/sdk/pricing_service/models/setting.rb +15 -0
- data/lib/monokera/sdk/pricing_snapshot.rb +9 -0
- data/lib/monokera/sdk/product.rb +21 -0
- data/lib/monokera/sdk/product_definition/client.rb +9 -0
- data/lib/monokera/sdk/product_definition/configuration.rb +13 -0
- data/lib/monokera/sdk/product_definition/models/condition.rb +15 -0
- data/lib/monokera/sdk/product_definition/models/deductible.rb +14 -0
- data/lib/monokera/sdk/product_definition/models/limit.rb +16 -0
- data/lib/monokera/sdk/product_definition/models/rate.rb +15 -0
- data/lib/monokera/sdk/product_definition/models/setting.rb +20 -0
- data/lib/monokera/sdk/quote.rb +29 -0
- data/lib/monokera/sdk/quote_service/client.rb +9 -0
- data/lib/monokera/sdk/quote_service/configuration.rb +13 -0
- data/lib/monokera/sdk/quote_service/models/address.rb +21 -0
- data/lib/monokera/sdk/quote_service/models/customer_prospect.rb +23 -0
- data/lib/monokera/sdk/quote_service/models/setting.rb +15 -0
- data/lib/monokera/sdk/resource_not_found.rb +7 -0
- data/lib/monokera/sdk/validity.rb +18 -0
- data/lib/monokera/sdk/version.rb +7 -0
- data/monokera-sdk.gemspec +45 -0
- metadata +423 -0
@@ -0,0 +1,27 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'active_support'
|
4
|
+
require 'statsd-instrument'
|
5
|
+
|
6
|
+
ActiveSupport::Notifications.subscribe 'monokera-sdk.request.faraday' do |*args|
|
7
|
+
event = ActiveSupport::Notifications::Event.new(*args)
|
8
|
+
|
9
|
+
http_status = case event.payload[:exception_object]
|
10
|
+
when Faraday::TimeoutError then 'timeout'
|
11
|
+
when Faraday::ConnectionFailed then 'connection-failed'
|
12
|
+
when Faraday::ClientError then 'client-error'
|
13
|
+
when Faraday::ResourceNotFound then 'not-found'
|
14
|
+
else event.payload[:status]
|
15
|
+
end
|
16
|
+
|
17
|
+
service_name = event.payload[:service_name].to_s.downcase
|
18
|
+
origin_service_name = event.payload[:origin_service_name].to_s.downcase
|
19
|
+
http_method = event.payload[:method].to_s.upcase
|
20
|
+
request_host = event.payload[:url].host
|
21
|
+
request_path = event.payload[:url].path
|
22
|
+
|
23
|
+
tags = "type=rest,method=#{http_method},status=#{http_status},host=#{request_host},path=#{request_path},origin_service=#{origin_service_name},service=#{service_name}"
|
24
|
+
|
25
|
+
StatsD.increment("external-service.requested,#{tags}")
|
26
|
+
StatsD.measure("external-service.response-time,#{tags}", event.duration) if event.duration
|
27
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Monokera
|
4
|
+
module SDK
|
5
|
+
module BillingService
|
6
|
+
module Models
|
7
|
+
class InstallmentItem < Monokera::SDK::Model
|
8
|
+
attribute :description
|
9
|
+
attribute :item_type
|
10
|
+
attribute :good_uid
|
11
|
+
attribute :coverage_uid
|
12
|
+
attribute :amount
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Monokera
|
4
|
+
module SDK
|
5
|
+
module BillingService
|
6
|
+
module Models
|
7
|
+
class PlanInstallment < Monokera::SDK::Model
|
8
|
+
attribute :amount
|
9
|
+
attribute :number
|
10
|
+
attribute :status
|
11
|
+
attribute :due_at
|
12
|
+
attribute :items, Array[BillingService::Models::InstallmentItem]
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Monokera
|
4
|
+
module SDK
|
5
|
+
class CancellationRequest < Monokera::SDK::ActiveModel
|
6
|
+
attribute :protocol_number
|
7
|
+
attribute :motivation
|
8
|
+
attribute :status
|
9
|
+
attribute :additional_info
|
10
|
+
|
11
|
+
BASE_ENDPOINT = '/v1/policies/%{policy_number}/cancellations'
|
12
|
+
|
13
|
+
def self.client
|
14
|
+
@client ||= PolicyService::Client.new
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Monokera
|
4
|
+
module SDK
|
5
|
+
class Claim < Monokera::SDK::ActiveModel
|
6
|
+
attribute :number, String
|
7
|
+
attribute :policy_number, String
|
8
|
+
attribute :description, String
|
9
|
+
attribute :status, String
|
10
|
+
attribute :occurred_at, DateTime
|
11
|
+
attribute :total_amount, Float
|
12
|
+
attribute :report_at, DateTime
|
13
|
+
|
14
|
+
attribute :attendant, ClaimService::Models::Attendant
|
15
|
+
attribute :settings, Array[ClaimService::Models::Setting]
|
16
|
+
|
17
|
+
BASE_ENDPOINT = '/v1/claims'
|
18
|
+
|
19
|
+
def self.client
|
20
|
+
@client ||= ClaimService::Client.new
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Monokera
|
4
|
+
module SDK
|
5
|
+
module ClaimService
|
6
|
+
module Models
|
7
|
+
class Setting < Monokera::SDK::Model
|
8
|
+
attribute :coverage_uid, String
|
9
|
+
attribute :pretension_amount, Float
|
10
|
+
attribute :branch_uid, String
|
11
|
+
attribute :good_uid, String
|
12
|
+
attribute :amount, Float
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
@@ -0,0 +1,113 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'active_support'
|
4
|
+
require 'active_support/core_ext/hash/keys'
|
5
|
+
require 'active_support/core_ext/numeric'
|
6
|
+
require 'active_support/core_ext/object/blank'
|
7
|
+
require 'faraday'
|
8
|
+
require 'faraday/request_id'
|
9
|
+
require 'faraday_middleware'
|
10
|
+
require 'monokera/sdk/middleware/custom_logger_middleware'
|
11
|
+
|
12
|
+
module Monokera
|
13
|
+
module SDK
|
14
|
+
class ClientBase
|
15
|
+
def configuration
|
16
|
+
@configuration ||= self.class.name.deconstantize.gsub(/::V\d$/, '').constantize::Configuration.instance
|
17
|
+
end
|
18
|
+
|
19
|
+
def connection_headers
|
20
|
+
{}
|
21
|
+
end
|
22
|
+
|
23
|
+
def filter_parameters
|
24
|
+
@filter_parameters ||= default_filter_parameters.dup
|
25
|
+
end
|
26
|
+
|
27
|
+
def connection
|
28
|
+
@connection ||= Faraday.new(configuration.host) do |builder|
|
29
|
+
builder.request :json
|
30
|
+
builder.response :json, content_type: /\bjson$/
|
31
|
+
builder.response :custom_logger, Configuration.instance.logger, service_name: configuration.service_name, filter_parameters: filter_parameters
|
32
|
+
builder.options[:timeout] = configuration.timeout.to_i
|
33
|
+
builder.options[:open_timeout] = configuration.open_timeout.to_i
|
34
|
+
builder.use :instrumentation
|
35
|
+
builder.use Faraday::RequestId
|
36
|
+
builder.use Monokera::SDK::Error::Middleware if raise_error?
|
37
|
+
builder.use Monokera::SDK::Middleware::ServiceMiddleware, service_name: configuration.service_name
|
38
|
+
builder.adapter Faraday.default_adapter
|
39
|
+
builder.headers.merge! connection_headers
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
private
|
44
|
+
|
45
|
+
def raise_error?
|
46
|
+
false
|
47
|
+
end
|
48
|
+
|
49
|
+
def cached_request(cache_key, expires_in)
|
50
|
+
able_to_cache = cache_key && expires_in && defined?(Rails)
|
51
|
+
return yield unless able_to_cache
|
52
|
+
|
53
|
+
cached_result = Rails.cache.read(cache_key)
|
54
|
+
|
55
|
+
cached_result || yield.tap do |result|
|
56
|
+
Rails.cache.write(cache_key, result, expires_in: expires_in) if result.success?
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
60
|
+
def handle_error(errors, status, content_type, service_name)
|
61
|
+
if defined?(Rails)
|
62
|
+
Rails.logger.warn "RESPONSE STATUS: #{status}"
|
63
|
+
Rails.logger.warn "CLIENT NAME: #{service_name}"
|
64
|
+
Rails.logger.warn errors
|
65
|
+
end
|
66
|
+
|
67
|
+
OpenStruct.new(success?: false, status: status, body: { errors: errors }, content_type: content_type, client: configuration.service_name.upcase)
|
68
|
+
end
|
69
|
+
|
70
|
+
def process_response(response)
|
71
|
+
content_type = content_type_for(response)
|
72
|
+
result = process_body(response.body, content_type)
|
73
|
+
|
74
|
+
if response.success?
|
75
|
+
OpenStruct.new(success?: true, status: response.status, headers: response.headers, content_type: content_type, body: result)
|
76
|
+
else
|
77
|
+
handle_error(result, response.status, content_type, configuration.service_name)
|
78
|
+
end
|
79
|
+
end
|
80
|
+
|
81
|
+
def process_body(body, content_type)
|
82
|
+
return {} if body.blank?
|
83
|
+
|
84
|
+
if content_type == :json
|
85
|
+
body.is_a?(Array) ? body.map(&:deep_symbolize_keys) : body.deep_symbolize_keys
|
86
|
+
else
|
87
|
+
body
|
88
|
+
end
|
89
|
+
end
|
90
|
+
|
91
|
+
def content_type_for(response)
|
92
|
+
case response.headers['content-type']
|
93
|
+
when /json/i
|
94
|
+
:json
|
95
|
+
when /xml/i
|
96
|
+
:xml
|
97
|
+
when /html/i
|
98
|
+
:html
|
99
|
+
else
|
100
|
+
:plain_text
|
101
|
+
end
|
102
|
+
end
|
103
|
+
|
104
|
+
def default_filter_parameters
|
105
|
+
if defined?(Rails) && Rails.respond_to?(:application)
|
106
|
+
Rails.application.config.filter_parameters
|
107
|
+
else
|
108
|
+
[]
|
109
|
+
end
|
110
|
+
end
|
111
|
+
end
|
112
|
+
end
|
113
|
+
end
|
@@ -0,0 +1,37 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Monokera
|
4
|
+
module SDK
|
5
|
+
module ClientDeprecation
|
6
|
+
def self.included(klass)
|
7
|
+
raise NoMethodError, "#{klass.name} does not have configuration method" unless klass.instance_methods.include?(:configuration)
|
8
|
+
|
9
|
+
deprecated_initialize!(klass)
|
10
|
+
|
11
|
+
deprecated_methods = klass.public_instance_methods - Class.instance_methods - [:configuration]
|
12
|
+
|
13
|
+
deprecated_methods.each do |method_name|
|
14
|
+
deprecated_method!(method_name, klass)
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
def self.deprecated_initialize!(klass)
|
19
|
+
klass.send(:define_method, :initialize) do |*args|
|
20
|
+
super(*args)
|
21
|
+
|
22
|
+
configuration.logger.warn "[DEPRECATED] `#{klass.name}` is deprecated, please use a versioned client"
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
def self.deprecated_method!(method_name, klass)
|
27
|
+
klass.send :alias_method, "deprecated_#{method_name}", method_name
|
28
|
+
|
29
|
+
klass.send :define_method, method_name do |*arguments, &block|
|
30
|
+
configuration.logger.warn "[DEPRECATED] Using `#{method_name}` from `#{klass.name}`. Please migrate to a versioned client"
|
31
|
+
|
32
|
+
send "deprecated_#{method_name}", *arguments, &block
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Monokera
|
4
|
+
module SDK
|
5
|
+
module Config
|
6
|
+
class GemInflector < Zeitwerk::Inflector
|
7
|
+
CAMELIZED_NAMES = {
|
8
|
+
sdk: 'SDK'
|
9
|
+
}.freeze
|
10
|
+
|
11
|
+
def camelize(basename, abspath)
|
12
|
+
CAMELIZED_NAMES[basename.to_sym] || super
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
@@ -0,0 +1,57 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'singleton'
|
4
|
+
|
5
|
+
module Monokera
|
6
|
+
module SDK
|
7
|
+
class Configuration
|
8
|
+
include Singleton
|
9
|
+
|
10
|
+
attr_writer :host, :token, :timeout, :open_timeout, :cache_duration
|
11
|
+
|
12
|
+
def service_name
|
13
|
+
raise('Service\'s name not defined')
|
14
|
+
end
|
15
|
+
|
16
|
+
def host
|
17
|
+
@host ||= ENV.fetch("#{service_name_configuration_prefix}_API_URL")
|
18
|
+
end
|
19
|
+
|
20
|
+
def token
|
21
|
+
@token ||= ENV.fetch("#{service_name_configuration_prefix}_API_TOKEN")
|
22
|
+
end
|
23
|
+
|
24
|
+
def timeout
|
25
|
+
@timeout ||= ENV.fetch("#{service_name_configuration_prefix}_API_TIMEOUT", 10).to_i
|
26
|
+
end
|
27
|
+
|
28
|
+
def open_timeout
|
29
|
+
@open_timeout ||= ENV.fetch("#{service_name_configuration_prefix}_API_OPEN_TIMEOUT", timeout).to_i
|
30
|
+
end
|
31
|
+
|
32
|
+
def cache_duration
|
33
|
+
@cache_duration ||= ENV.fetch("#{service_name_configuration_prefix}_CACHE_DURATION", 5).to_i.minutes
|
34
|
+
end
|
35
|
+
|
36
|
+
def logger
|
37
|
+
@logger ||= defined?(Rails) ? Rails.logger : Logger.new(STDOUT)
|
38
|
+
end
|
39
|
+
|
40
|
+
def logger=(logger)
|
41
|
+
logger = Logger.new(logger) if logger.is_a?(String)
|
42
|
+
@logger = logger
|
43
|
+
end
|
44
|
+
|
45
|
+
def self.configure(&block)
|
46
|
+
yield(instance) if block.present?
|
47
|
+
instance
|
48
|
+
end
|
49
|
+
|
50
|
+
private
|
51
|
+
|
52
|
+
def service_name_configuration_prefix
|
53
|
+
service_name.underscore.upcase
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|