Class: MedicalCopays::Request
- Inherits:
-
Object
- Object
- MedicalCopays::Request
- Extended by:
- Forwardable
- Includes:
- Common::Client::Concerns::Monitoring
- Defined in:
- app/services/medical_copays/request.rb
Overview
An object responsible for making HTTP calls to the VBS service
Constant Summary collapse
- STATSD_KEY_PREFIX =
'api.medical_copays.request'
Instance Attribute Summary collapse
Class Method Summary collapse
-
.build ⇒ MedicalCopays::Request
Builds a MedicalCopays::Request instance.
Instance Method Summary collapse
-
#connection ⇒ Faraday::Connection
Create a connection object that manages the attributes and the middleware stack for making our HTTP requests to VBS.
-
#get(path) ⇒ Faraday::Response
Make a HTTP GET call to the VBS service in order to obtain copays or PDFs by id.
-
#headers ⇒ Hash
HTTP request headers for the VBS API.
-
#initialize ⇒ Request
constructor
A new instance of Request.
-
#mock_enabled? ⇒ Boolean
Betamocks enabled status from settings.
-
#post(path, params) ⇒ Faraday::Response
Make a HTTP POST call to the VBS service in order to obtain user copays.
Methods included from Common::Client::Concerns::Monitoring
Constructor Details
#initialize ⇒ Request
Returns a new instance of Request.
34 35 36 |
# File 'app/services/medical_copays/request.rb', line 34 def initialize @settings = endpoint_settings end |
Instance Attribute Details
#host ⇒ Object
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 |
# File 'app/services/medical_copays/request.rb', line 15 class Request extend Forwardable include Common::Client::Concerns::Monitoring STATSD_KEY_PREFIX = 'api.medical_copays.request' attr_reader :settings def_delegators :settings, :base_path, :host, :service_name, :url ## # Builds a MedicalCopays::Request instance # # @return [MedicalCopays::Request] an instance of this class # def self.build new end def initialize @settings = endpoint_settings end ## # Make a HTTP POST call to the VBS service in order to obtain user copays # # @param path [String] # @param params [Hash] # # @return [Faraday::Response] # def post(path, params) with_monitoring do connection.post(path) do |req| req.body = Oj.dump(params) end end end ## # Make a HTTP GET call to the VBS service in order to obtain copays or PDFs by id # # @param path [String] # # @return [Faraday::Response] # def get(path) with_monitoring do connection.get(path) end end ## # Create a connection object that manages the attributes # and the middleware stack for making our HTTP requests to VBS # # @return [Faraday::Connection] # def connection Faraday.new(url:, headers:) do |conn| conn.request :json conn.use :breakers conn.use Faraday::Response::RaiseError conn.response :raise_error, error_prefix: service_name conn.response :json conn.response :betamocks if mock_enabled? conn.adapter Faraday.default_adapter end end ## # HTTP request headers for the VBS API # # @return [Hash] # def headers { 'Host' => host, 'Content-Type' => 'application/json', api_key => settings.api_key } end ## # Betamocks enabled status from settings # # @return [Boolean] # def mock_enabled? settings.mock || false end private def api_key Flipper.enabled?(:medical_copays_api_key_change) ? 'apiKey' : 'x-api-key' end def endpoint_settings Flipper.enabled?(:medical_copays_api_key_change) ? Settings.mcp.vbs_v2 : Settings.mcp.vbs end end |
#service_name ⇒ Object
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 |
# File 'app/services/medical_copays/request.rb', line 15 class Request extend Forwardable include Common::Client::Concerns::Monitoring STATSD_KEY_PREFIX = 'api.medical_copays.request' attr_reader :settings def_delegators :settings, :base_path, :host, :service_name, :url ## # Builds a MedicalCopays::Request instance # # @return [MedicalCopays::Request] an instance of this class # def self.build new end def initialize @settings = endpoint_settings end ## # Make a HTTP POST call to the VBS service in order to obtain user copays # # @param path [String] # @param params [Hash] # # @return [Faraday::Response] # def post(path, params) with_monitoring do connection.post(path) do |req| req.body = Oj.dump(params) end end end ## # Make a HTTP GET call to the VBS service in order to obtain copays or PDFs by id # # @param path [String] # # @return [Faraday::Response] # def get(path) with_monitoring do connection.get(path) end end ## # Create a connection object that manages the attributes # and the middleware stack for making our HTTP requests to VBS # # @return [Faraday::Connection] # def connection Faraday.new(url:, headers:) do |conn| conn.request :json conn.use :breakers conn.use Faraday::Response::RaiseError conn.response :raise_error, error_prefix: service_name conn.response :json conn.response :betamocks if mock_enabled? conn.adapter Faraday.default_adapter end end ## # HTTP request headers for the VBS API # # @return [Hash] # def headers { 'Host' => host, 'Content-Type' => 'application/json', api_key => settings.api_key } end ## # Betamocks enabled status from settings # # @return [Boolean] # def mock_enabled? settings.mock || false end private def api_key Flipper.enabled?(:medical_copays_api_key_change) ? 'apiKey' : 'x-api-key' end def endpoint_settings Flipper.enabled?(:medical_copays_api_key_change) ? Settings.mcp.vbs_v2 : Settings.mcp.vbs end end |
#settings ⇒ Config::Options
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 |
# File 'app/services/medical_copays/request.rb', line 15 class Request extend Forwardable include Common::Client::Concerns::Monitoring STATSD_KEY_PREFIX = 'api.medical_copays.request' attr_reader :settings def_delegators :settings, :base_path, :host, :service_name, :url ## # Builds a MedicalCopays::Request instance # # @return [MedicalCopays::Request] an instance of this class # def self.build new end def initialize @settings = endpoint_settings end ## # Make a HTTP POST call to the VBS service in order to obtain user copays # # @param path [String] # @param params [Hash] # # @return [Faraday::Response] # def post(path, params) with_monitoring do connection.post(path) do |req| req.body = Oj.dump(params) end end end ## # Make a HTTP GET call to the VBS service in order to obtain copays or PDFs by id # # @param path [String] # # @return [Faraday::Response] # def get(path) with_monitoring do connection.get(path) end end ## # Create a connection object that manages the attributes # and the middleware stack for making our HTTP requests to VBS # # @return [Faraday::Connection] # def connection Faraday.new(url:, headers:) do |conn| conn.request :json conn.use :breakers conn.use Faraday::Response::RaiseError conn.response :raise_error, error_prefix: service_name conn.response :json conn.response :betamocks if mock_enabled? conn.adapter Faraday.default_adapter end end ## # HTTP request headers for the VBS API # # @return [Hash] # def headers { 'Host' => host, 'Content-Type' => 'application/json', api_key => settings.api_key } end ## # Betamocks enabled status from settings # # @return [Boolean] # def mock_enabled? settings.mock || false end private def api_key Flipper.enabled?(:medical_copays_api_key_change) ? 'apiKey' : 'x-api-key' end def endpoint_settings Flipper.enabled?(:medical_copays_api_key_change) ? Settings.mcp.vbs_v2 : Settings.mcp.vbs end end |
#url ⇒ Object
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 |
# File 'app/services/medical_copays/request.rb', line 15 class Request extend Forwardable include Common::Client::Concerns::Monitoring STATSD_KEY_PREFIX = 'api.medical_copays.request' attr_reader :settings def_delegators :settings, :base_path, :host, :service_name, :url ## # Builds a MedicalCopays::Request instance # # @return [MedicalCopays::Request] an instance of this class # def self.build new end def initialize @settings = endpoint_settings end ## # Make a HTTP POST call to the VBS service in order to obtain user copays # # @param path [String] # @param params [Hash] # # @return [Faraday::Response] # def post(path, params) with_monitoring do connection.post(path) do |req| req.body = Oj.dump(params) end end end ## # Make a HTTP GET call to the VBS service in order to obtain copays or PDFs by id # # @param path [String] # # @return [Faraday::Response] # def get(path) with_monitoring do connection.get(path) end end ## # Create a connection object that manages the attributes # and the middleware stack for making our HTTP requests to VBS # # @return [Faraday::Connection] # def connection Faraday.new(url:, headers:) do |conn| conn.request :json conn.use :breakers conn.use Faraday::Response::RaiseError conn.response :raise_error, error_prefix: service_name conn.response :json conn.response :betamocks if mock_enabled? conn.adapter Faraday.default_adapter end end ## # HTTP request headers for the VBS API # # @return [Hash] # def headers { 'Host' => host, 'Content-Type' => 'application/json', api_key => settings.api_key } end ## # Betamocks enabled status from settings # # @return [Boolean] # def mock_enabled? settings.mock || false end private def api_key Flipper.enabled?(:medical_copays_api_key_change) ? 'apiKey' : 'x-api-key' end def endpoint_settings Flipper.enabled?(:medical_copays_api_key_change) ? Settings.mcp.vbs_v2 : Settings.mcp.vbs end end |
Class Method Details
.build ⇒ MedicalCopays::Request
Builds a MedicalCopays::Request instance
30 31 32 |
# File 'app/services/medical_copays/request.rb', line 30 def self.build new end |
Instance Method Details
#connection ⇒ Faraday::Connection
Create a connection object that manages the attributes and the middleware stack for making our HTTP requests to VBS
73 74 75 76 77 78 79 80 81 82 83 |
# File 'app/services/medical_copays/request.rb', line 73 def connection Faraday.new(url:, headers:) do |conn| conn.request :json conn.use :breakers conn.use Faraday::Response::RaiseError conn.response :raise_error, error_prefix: service_name conn.response :json conn.response :betamocks if mock_enabled? conn.adapter Faraday.default_adapter end end |
#get(path) ⇒ Faraday::Response
Make a HTTP GET call to the VBS service in order to obtain copays or PDFs by id
61 62 63 64 65 |
# File 'app/services/medical_copays/request.rb', line 61 def get(path) with_monitoring do connection.get(path) end end |
#headers ⇒ Hash
HTTP request headers for the VBS API
90 91 92 93 94 95 96 |
# File 'app/services/medical_copays/request.rb', line 90 def headers { 'Host' => host, 'Content-Type' => 'application/json', api_key => settings.api_key } end |
#mock_enabled? ⇒ Boolean
Betamocks enabled status from settings
103 104 105 |
# File 'app/services/medical_copays/request.rb', line 103 def mock_enabled? settings.mock || false end |
#post(path, params) ⇒ Faraday::Response
Make a HTTP POST call to the VBS service in order to obtain user copays
46 47 48 49 50 51 52 |
# File 'app/services/medical_copays/request.rb', line 46 def post(path, params) with_monitoring do connection.post(path) do |req| req.body = Oj.dump(params) end end end |