Class: Koine::RestClient::Client
- Inherits:
-
Object
- Object
- Koine::RestClient::Client
- Defined in:
- lib/koine/rest_client/client.rb
Instance Method Summary collapse
- #async {|builder| ... } ⇒ Object
- #create_delete_request(path, body = {}, options = {}) ⇒ Object
- #create_get_request(path, query = {}, options = {}) ⇒ Object
- #create_patch_request(path, body = {}, options = {}) ⇒ Object
- #create_post_request(path, body = {}, options = {}) ⇒ Object
- #create_put_request(path, body = {}, options = {}) ⇒ Object
- #delete(path, body = {}, options = {}, &block) ⇒ Object
- #get(path, query = {}, options = {}, &block) ⇒ Object
-
#initialize(adapter: Adapters::HttpPartyAdapter.new, response_parser: ResponseParser.new, base_request: Request.new) ⇒ Client
constructor
A new instance of Client.
- #patch(path, body = {}, options = {}, &block) ⇒ Object
- #perform_request(request) ⇒ Object
- #post(path, body = {}, options = {}, &block) ⇒ Object
- #put(path, body = {}, options = {}, &block) ⇒ Object
Constructor Details
#initialize(adapter: Adapters::HttpPartyAdapter.new, response_parser: ResponseParser.new, base_request: Request.new) ⇒ Client
Returns a new instance of Client.
8 9 10 11 12 13 14 15 16 |
# File 'lib/koine/rest_client/client.rb', line 8 def initialize( adapter: Adapters::HttpPartyAdapter.new, response_parser: ResponseParser.new, base_request: Request.new ) @adapter = adapter @response_parser = response_parser @request = base_request end |
Instance Method Details
#async {|builder| ... } ⇒ Object
68 69 70 71 72 |
# File 'lib/koine/rest_client/client.rb', line 68 def async builder = AsyncBuilder.new(self, @response_parser) yield(builder) builder.parsed_responses end |
#create_delete_request(path, body = {}, options = {}) ⇒ Object
64 65 66 |
# File 'lib/koine/rest_client/client.rb', line 64 def create_delete_request(path, body = {}, = {}) create_request(:delete, path, .merge(body: body)) end |
#create_get_request(path, query = {}, options = {}) ⇒ Object
24 25 26 |
# File 'lib/koine/rest_client/client.rb', line 24 def create_get_request(path, query = {}, = {}) create_request(:get, path, .merge(query_params: query)) end |
#create_patch_request(path, body = {}, options = {}) ⇒ Object
54 55 56 |
# File 'lib/koine/rest_client/client.rb', line 54 def create_patch_request(path, body = {}, = {}) create_request(:patch, path, .merge(body: body)) end |
#create_post_request(path, body = {}, options = {}) ⇒ Object
34 35 36 |
# File 'lib/koine/rest_client/client.rb', line 34 def create_post_request(path, body = {}, = {}) create_request(:post, path, .merge(body: body)) end |
#create_put_request(path, body = {}, options = {}) ⇒ Object
44 45 46 |
# File 'lib/koine/rest_client/client.rb', line 44 def create_put_request(path, body = {}, = {}) create_request(:put, path, .merge(body: body)) end |
#delete(path, body = {}, options = {}, &block) ⇒ Object
58 59 60 61 62 |
# File 'lib/koine/rest_client/client.rb', line 58 def delete(path, body = {}, = {}, &block) request = create_delete_request(path, body, ) response = perform_request(request) parse_response(response, &block) end |
#get(path, query = {}, options = {}, &block) ⇒ Object
18 19 20 21 22 |
# File 'lib/koine/rest_client/client.rb', line 18 def get(path, query = {}, = {}, &block) request = create_get_request(path, query, ) response = perform_request(request) parse_response(response, &block) end |
#patch(path, body = {}, options = {}, &block) ⇒ Object
48 49 50 51 52 |
# File 'lib/koine/rest_client/client.rb', line 48 def patch(path, body = {}, = {}, &block) request = create_patch_request(path, body, ) response = perform_request(request) parse_response(response, &block) end |
#perform_request(request) ⇒ Object
74 75 76 |
# File 'lib/koine/rest_client/client.rb', line 74 def perform_request(request) @adapter.send_request(request) end |
#post(path, body = {}, options = {}, &block) ⇒ Object
28 29 30 31 32 |
# File 'lib/koine/rest_client/client.rb', line 28 def post(path, body = {}, = {}, &block) request = create_post_request(path, body, ) response = perform_request(request) parse_response(response, &block) end |
#put(path, body = {}, options = {}, &block) ⇒ Object
38 39 40 41 42 |
# File 'lib/koine/rest_client/client.rb', line 38 def put(path, body = {}, = {}, &block) request = create_put_request(path, body, ) response = perform_request(request) parse_response(response, &block) end |