Class: Gapic::Rest::ClientStub
- Inherits:
-
Object
- Object
- Gapic::Rest::ClientStub
- 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
Instance Method Summary collapse
-
#initialize(endpoint:, credentials:) {|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(endpoint:, credentials:) {|Faraday::Connection| ... } ⇒ ClientStub
Initializes with an endpoint and credentials
38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 |
# File 'lib/gapic/rest/client_stub.rb', line 38 def initialize endpoint:, credentials: @endpoint = endpoint @endpoint = "https://#{endpoint}" unless /^https?:/.match? endpoint @endpoint = @endpoint.sub %r{/$}, "" @credentials = credentials @connection = Faraday.new url: @endpoint do |conn| conn.headers = { "Content-Type" => "application/json" } conn.request :google_authorization, @credentials unless @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
76 77 78 |
# File 'lib/gapic/rest/client_stub.rb', line 76 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
64 65 66 |
# File 'lib/gapic/rest/client_stub.rb', line 64 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
89 90 91 |
# File 'lib/gapic/rest/client_stub.rb', line 89 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
102 103 104 |
# File 'lib/gapic/rest/client_stub.rb', line 102 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
115 116 117 |
# File 'lib/gapic/rest/client_stub.rb', line 115 def make_put_request uri:, body: nil, params: {}, options: {} make_http_request :put, uri: uri, body: body, params: params, options: end |