Class: Phlanket::Wrapper
- Inherits:
-
Object
- Object
- Phlanket::Wrapper
- Defined in:
- lib/phlanket/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
46 47 48 49 50 51 52 |
# File 'lib/phlanket/wrapper.rb', line 46 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)
56 57 58 59 60 61 62 |
# File 'lib/phlanket/wrapper.rb', line 56 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
34 35 36 |
# File 'lib/phlanket/wrapper.rb', line 34 def extension @extension end |
#headers ⇒ Object
Attribute accessor for HTTP Headers that should be applied to all requests
26 27 28 |
# File 'lib/phlanket/wrapper.rb', line 26 def headers @headers end |
#params ⇒ Object
Attribute accessor for params that should be applied to all requests
30 31 32 |
# File 'lib/phlanket/wrapper.rb', line 30 def params @params end |
Instance Method Details
#delete ⇒ Blanket::Response, Array
Performs a delete request on the wrapped URL
40 |
# File 'lib/phlanket/wrapper.rb', line 40 add_action :delete |
#get ⇒ Blanket::Response, Array
Performs a get request on the wrapped URL
36 |
# File 'lib/phlanket/wrapper.rb', line 36 add_action :get |
#patch ⇒ Blanket::Response, Array
Performs a patch request on the wrapped URL
39 |
# File 'lib/phlanket/wrapper.rb', line 39 add_action :patch |
#post ⇒ Blanket::Response, Array
Performs a post request on the wrapped URL
37 |
# File 'lib/phlanket/wrapper.rb', line 37 add_action :post |
#put ⇒ Blanket::Response, Array
Performs a put request on the wrapped URL
38 |
# File 'lib/phlanket/wrapper.rb', line 38 add_action :put |