Class: Gapic::Rest::ClientStub
- Inherits:
-
Object
- Object
- Gapic::Rest::ClientStub
- Includes:
- UniverseDomainConcerns
- Defined in:
- lib/gapic/rest/client_stub.rb
Overview
A class for making REST calls through Faraday ClientStub's responsibilities:
- wrap Faraday methods with a bounded explicit interface
- store service endpoint and create full url for the request
- store credentials and add auth information to the request
Constant Summary
Constants included from UniverseDomainConcerns
UniverseDomainConcerns::ENDPOINT_SUBSTITUTION
Instance Attribute Summary
Attributes included from UniverseDomainConcerns
#credentials, #endpoint, #universe_domain
Instance Method Summary collapse
-
#initialize(credentials:, endpoint: nil, endpoint_template: nil, universe_domain: nil, numeric_enums: false, raise_faraday_errors: true) {|Faraday::Connection| ... } ⇒ ClientStub
constructor
Initializes with an endpoint and credentials.
-
#make_delete_request(uri:, params: {}, options: {}) ⇒ Faraday::Response
Makes a DELETE request.
-
#make_get_request(uri:, params: {}, options: {}) ⇒ Faraday::Response
Makes a GET request.
-
#make_patch_request(uri:, body:, params: {}, options: {}) ⇒ Faraday::Response
Makes a PATCH request.
-
#make_post_request(uri:, body: nil, params: {}, options: {}) ⇒ Faraday::Response
Makes a POST request.
-
#make_put_request(uri:, body: nil, params: {}, options: {}) ⇒ Faraday::Response
Makes a PUT request.
Constructor Details
#initialize(credentials:, endpoint: nil, endpoint_template: nil, universe_domain: nil, numeric_enums: false, raise_faraday_errors: true) {|Faraday::Connection| ... } ⇒ ClientStub
Initializes with an endpoint and credentials
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 |
# File 'lib/gapic/rest/client_stub.rb', line 53 def initialize credentials:, endpoint: nil, endpoint_template: nil, universe_domain: nil, numeric_enums: false, raise_faraday_errors: true setup_universe_domain universe_domain: universe_domain, endpoint: endpoint, endpoint_template: endpoint_template, credentials: credentials endpoint_url = self.endpoint endpoint_url = "https://#{endpoint_url}" unless /^https?:/.match? endpoint_url endpoint_url = endpoint_url.sub %r{/$}, "" @numeric_enums = numeric_enums @raise_faraday_errors = raise_faraday_errors @connection = Faraday.new url: endpoint_url do |conn| conn.headers = { "Content-Type" => "application/json" } conn.request :google_authorization, self.credentials unless self.credentials.is_a? ::Symbol conn.request :retry conn.response :raise_error conn.adapter :net_http end yield @connection if block_given? end |
Instance Method Details
#make_delete_request(uri:, params: {}, options: {}) ⇒ Faraday::Response
Makes a DELETE request
103 104 105 |
# File 'lib/gapic/rest/client_stub.rb', line 103 def make_delete_request uri:, params: {}, options: {} make_http_request :delete, uri: uri, body: nil, params: params, options: end |
#make_get_request(uri:, params: {}, options: {}) ⇒ Faraday::Response
Makes a GET request
91 92 93 |
# File 'lib/gapic/rest/client_stub.rb', line 91 def make_get_request uri:, params: {}, options: {} make_http_request :get, uri: uri, body: nil, params: params, options: end |
#make_patch_request(uri:, body:, params: {}, options: {}) ⇒ Faraday::Response
Makes a PATCH request
116 117 118 |
# File 'lib/gapic/rest/client_stub.rb', line 116 def make_patch_request uri:, body:, params: {}, options: {} make_http_request :patch, uri: uri, body: body, params: params, options: end |
#make_post_request(uri:, body: nil, params: {}, options: {}) ⇒ Faraday::Response
Makes a POST request
129 130 131 |
# File 'lib/gapic/rest/client_stub.rb', line 129 def make_post_request uri:, body: nil, params: {}, options: {} make_http_request :post, uri: uri, body: body, params: params, options: end |
#make_put_request(uri:, body: nil, params: {}, options: {}) ⇒ Faraday::Response
Makes a PUT request
142 143 144 |
# File 'lib/gapic/rest/client_stub.rb', line 142 def make_put_request uri:, body: nil, params: {}, options: {} make_http_request :put, uri: uri, body: body, params: params, options: end |