Class: Takeout::Client
- Inherits:
-
Object
- Object
- Takeout::Client
- Defined in:
- lib/takeout/client.rb
Constant Summary collapse
- CALLBACKS =
A constant specifying the kind of event callbacks and if they should or should not raise an error
{failure: true, missing: true}
- JSON_REQUEST_BODY =
[:put, :post]
Instance Attribute Summary collapse
-
#debug ⇒ Boolean
A boolean specifying whether or not to run curl with teh verbose setting.
-
#endpoint_prefix ⇒ Object
Returns the value of attribute endpoint_prefix.
-
#extension ⇒ String
A string with the extension to be appended on each request.
-
#headers ⇒ Hash
A hash specifying the headers to apply to each request.
-
#options ⇒ Hash
A hash specifying the global options to apply to each request.
-
#port ⇒ Object
Returns the value of attribute port.
-
#schemas ⇒ Hash
A hash specifying the custom per-endpoint schema templates.
-
#ssl ⇒ Boolean
A boolean to specify whether or not SSL is turned on.
-
#uri ⇒ String
The uri to send requests to.
Instance Method Summary collapse
-
#disable_ssl ⇒ Object
Flips the @ssl instance variable to false.
-
#enable_ssl ⇒ Object
Flips the @ssl instance variable to true.
-
#initialize(options = {}) ⇒ Client
constructor
The main client initialization method.
-
#port? ⇒ Boolean
Check if a port is specified.
-
#ssl? ⇒ Boolean
Check if SSL is enabled.
Constructor Details
#initialize(options = {}) ⇒ Client
The main client initialization method.
Attributes
-
options- The main atrtibute and extra global options to set for the client
Options
-
:uri- A string defining the URI for the API to call. -
:headers- A hash specifying the headers to apply to each request -
:ssl- A boolean to specify whether or not SSL is turned on -
:schemas- A hash specifying the custom per-endpoint schema templates -
:extension- A string with the extension to be appended on each request
52 53 54 55 56 57 58 |
# File 'lib/takeout/client.rb', line 52 def initialize(={}) if block_given? yield self else () end end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method_sym, *attributes, &block) ⇒ Object (private)
190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 |
# File 'lib/takeout/client.rb', line 190 def method_missing(method_sym, *attributes, &block) request_type = method_sym.to_s.scan(/^(?:get|post|put|delete|patch|update)/).first request_name = method_sym.to_s.scan(/(?<=_{1}).*/).first if (request_type && request_name) self.define_singleton_method(method_sym) do |={}, &block| # Extract values that we store separately from the options hash and then clean it up headers.merge!([:headers]) if [:headers] # Merge in global options .merge!() if # Build the request_url and update the options to remove templated values (if there are any) request_url, = generate_request_url(request_name, request_type, ) # Clean up options hash before performing request [:headers, :extension, :object_id, :endpoint].each { |value| .delete(value)} return perform_curl_request(request_type, request_url, , headers) end self.send(method_sym, *attributes, &block) else super end end |
Instance Attribute Details
#debug ⇒ Boolean
Returns a boolean specifying whether or not to run curl with teh verbose setting.
12 13 14 |
# File 'lib/takeout/client.rb', line 12 def debug @debug end |
#endpoint_prefix ⇒ Object
Returns the value of attribute endpoint_prefix.
34 35 36 |
# File 'lib/takeout/client.rb', line 34 def endpoint_prefix @endpoint_prefix end |
#extension ⇒ String
Returns a string with the extension to be appended on each request.
21 22 23 |
# File 'lib/takeout/client.rb', line 21 def extension @extension end |
#headers ⇒ Hash
Returns a hash specifying the headers to apply to each request.
18 19 20 |
# File 'lib/takeout/client.rb', line 18 def headers @headers end |
#options ⇒ Hash
Returns a hash specifying the global options to apply to each request.
15 16 17 |
# File 'lib/takeout/client.rb', line 15 def end |
#port ⇒ Object
Returns the value of attribute port.
32 33 34 |
# File 'lib/takeout/client.rb', line 32 def port @port end |
#schemas ⇒ Hash
Returns a hash specifying the custom per-endpoint schema templates.
27 28 29 |
# File 'lib/takeout/client.rb', line 27 def schemas @schemas end |
#ssl ⇒ Boolean
Returns a boolean to specify whether or not SSL is turned on.
24 25 26 |
# File 'lib/takeout/client.rb', line 24 def ssl @ssl end |
#uri ⇒ String
Returns the uri to send requests to.
30 31 32 |
# File 'lib/takeout/client.rb', line 30 def uri @uri end |
Instance Method Details
#disable_ssl ⇒ Object
Flips the @ssl instance variable to false
78 79 80 |
# File 'lib/takeout/client.rb', line 78 def disable_ssl @ssl=false end |
#enable_ssl ⇒ Object
Flips the @ssl instance variable to true
73 74 75 |
# File 'lib/takeout/client.rb', line 73 def enable_ssl @ssl=true end |
#port? ⇒ Boolean
Check if a port is specified.
68 69 70 |
# File 'lib/takeout/client.rb', line 68 def port? return !port.nil? end |
#ssl? ⇒ Boolean
Check if SSL is enabled.
62 63 64 |
# File 'lib/takeout/client.rb', line 62 def ssl? return @ssl end |