Class: Prest::Client
- Inherits:
- BasicObject
- Defined in:
- lib/prest/client.rb
Overview
Main wrapper class for Prest. To use the gem, call: Prest::Client.new(‘base_uri.com’, { headers: { ‘Authorization’ => ‘Bearer token’ }})
Constant Summary collapse
- SUPPORTED_HTTP_VERBS =
%i[get post put patch delete get! post! put! patch! delete!].freeze
Instance Method Summary collapse
-
#initialize(base_uri, options = {}) ⇒ Client
constructor
A new instance of Client.
- #method_missing(method, *args, **kwargs) ⇒ Object
- #respond_to_missing?(_, _) ⇒ Boolean
Constructor Details
#initialize(base_uri, options = {}) ⇒ Client
Returns a new instance of Client.
9 10 11 12 13 14 |
# File 'lib/prest/client.rb', line 9 def initialize(base_uri, = {}) @base_uri = base_uri @options = @fragments = [] @query_params = {} end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method, *args, **kwargs) ⇒ Object
16 17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/prest/client.rb', line 16 def method_missing(method, *args, **kwargs) if SUPPORTED_HTTP_VERBS.include?(method) if method.to_s.end_with?('!') execute_query!(method[0..-2], **kwargs) else execute_query(method, **kwargs) end else chain_fragment(method.to_s, *args, **kwargs) self end end |
Instance Method Details
#respond_to_missing?(_, _) ⇒ Boolean
29 30 31 |
# File 'lib/prest/client.rb', line 29 def respond_to_missing?(_, _) true end |