Class: Blanket::Wrapper
- Inherits:
-
Object
- Object
- Blanket::Wrapper
- Defined in:
- lib/blanket/wrapper.rb
Instance Attribute Summary collapse
-
#extension ⇒ Object
Attribute accessor for file extension that should be appended to all requests.
-
#headers ⇒ Object
Attribute accessor for HTTP Headers that should be applied to all requests.
-
#params ⇒ Object
Attribute accessor for params that should be applied to all requests.
Instance Method Summary collapse
-
#delete ⇒ Blanket::Response, Array
Performs a delete request on the wrapped URL.
-
#get ⇒ Blanket::Response, Array
Performs a get request on the wrapped URL.
-
#initialize(base_uri, options = {}) ⇒ Blanket
constructor
Wraps the base URL for an API.
-
#patch ⇒ Blanket::Response, Array
Performs a patch request on the wrapped URL.
-
#post ⇒ Blanket::Response, Array
Performs a post request on the wrapped URL.
-
#put ⇒ Blanket::Response, Array
Performs a put request on the wrapped URL.
Constructor Details
#initialize(base_uri, options = {}) ⇒ Blanket
Wraps the base URL for an API
40 41 42 43 44 45 46 |
# File 'lib/blanket/wrapper.rb', line 40 def initialize(base_uri, ={}) @base_uri = base_uri @uri_parts = [] @headers = [:headers] || {} @params = [:params] || {} @extension = [:extension] end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method, *args, &block) ⇒ Object (private)
50 51 52 53 54 55 56 |
# File 'lib/blanket/wrapper.rb', line 50 def method_missing(method, *args, &block) Wrapper.new uri_from_parts([method, args.first]), { headers: @headers, extension: @extension, params: @params } end |
Instance Attribute Details
#extension ⇒ Object
Attribute accessor for file extension that should be appended to all requests
28 29 30 |
# File 'lib/blanket/wrapper.rb', line 28 def extension @extension end |
#headers ⇒ Object
Attribute accessor for HTTP Headers that should be applied to all requests
20 21 22 |
# File 'lib/blanket/wrapper.rb', line 20 def headers @headers end |
#params ⇒ Object
Attribute accessor for params that should be applied to all requests
24 25 26 |
# File 'lib/blanket/wrapper.rb', line 24 def params @params end |
Instance Method Details
#delete ⇒ Blanket::Response, Array
Performs a delete request on the wrapped URL
34 |
# File 'lib/blanket/wrapper.rb', line 34 add_action :delete |
#get ⇒ Blanket::Response, Array
Performs a get request on the wrapped URL
30 |
# File 'lib/blanket/wrapper.rb', line 30 add_action :get |
#patch ⇒ Blanket::Response, Array
Performs a patch request on the wrapped URL
33 |
# File 'lib/blanket/wrapper.rb', line 33 add_action :patch |
#post ⇒ Blanket::Response, Array
Performs a post request on the wrapped URL
31 |
# File 'lib/blanket/wrapper.rb', line 31 add_action :post |
#put ⇒ Blanket::Response, Array
Performs a put request on the wrapped URL
32 |
# File 'lib/blanket/wrapper.rb', line 32 add_action :put |