Class: Yade::Common::Client::BaseClient
- Inherits:
-
Object
- Object
- Yade::Common::Client::BaseClient
- Defined in:
- lib/yade/common/client/base_client.rb
Overview
base client
Instance Method Summary collapse
-
#get(id) ⇒ Object
get by id.
-
#initialize(microservice, resource_name, model_class) ⇒ BaseClient
constructor
initialize prepare options hash with authorization header for httpparty requests.
-
#list ⇒ Object
list all.
Constructor Details
#initialize(microservice, resource_name, model_class) ⇒ BaseClient
initialize prepare options hash with authorization header for httpparty requests
11 12 13 14 15 16 17 18 |
# File 'lib/yade/common/client/base_client.rb', line 11 def initialize(microservice, resource_name, model_class) @microservice = microservice @resource_name = resource_name @model_class = model_class @authentication_client = Yade::Common::Client::AuthenticationClient.new @options = { headers: { Authorization: "Bearer #{@authentication_client.access_token}", 'Content-Type' => 'application/json' } } end |
Instance Method Details
#get(id) ⇒ Object
get by id
30 31 32 33 34 35 36 37 38 |
# File 'lib/yade/common/client/base_client.rb', line 30 def get(id) response = get_request("#{id}") if response.success? create_instance.new(response.parsed_response) else raise "Unable to make get request. Response code was #{response.code}" end end |
#list ⇒ Object
list all
21 22 23 24 25 26 27 |
# File 'lib/yade/common/client/base_client.rb', line 21 def list response = self.class.get(base_path, @options) response.parsed_response.map do |p| create_instance.new(p) end end |