Module: Her::Model::HTTP
- Defined in:
- lib/her/model/http.rb
Overview
This module interacts with Her::API to fetch HTTP data
Instance Method Summary collapse
-
#collection_path(path = nil) ⇒ Object
Defines a custom collection path for the resource.
-
#delete_collection(path, attrs = {}) ⇒ Object
Make a DELETE request and return a collection of resources.
-
#delete_raw(path, attrs = {}, &block) ⇒ Object
Make a DELETE request and return the parsed JSON response (not mapped to objects).
-
#delete_resource(path, attrs = {}) ⇒ Object
Make a DELETE request and return a collection of resources.
-
#get_collection(path, attrs = {}) ⇒ Object
Make a GET request and return a collection of resources.
-
#get_raw(path, attrs = {}, &block) ⇒ Object
Make a GET request and return the parsed JSON response (not mapped to objects).
-
#get_resource(path, attrs = {}) ⇒ Object
Make a GET request and return a collection of resources.
-
#item_path(path = nil) ⇒ Object
Defines a custom item path for the resource.
-
#patch_collection(path, attrs = {}) ⇒ Object
Make a PATCH request and return a collection of resources.
-
#patch_raw(path, attrs = {}, &block) ⇒ Object
Make a PATCH request and return the parsed JSON response (not mapped to objects).
-
#patch_resource(path, attrs = {}) ⇒ Object
Make a PATCH request and return a collection of resources.
-
#post_collection(path, attrs = {}) ⇒ Object
Make a POST request and return a collection of resources.
-
#post_raw(path, attrs = {}, &block) ⇒ Object
Make a POST request and return the parsed JSON response (not mapped to objects).
-
#post_resource(path, attrs = {}) ⇒ Object
Make a POST request and return a collection of resources.
-
#put_collection(path, attrs = {}) ⇒ Object
Make a PUT request and return a collection of resources.
-
#put_raw(path, attrs = {}, &block) ⇒ Object
Make a PUT request and return the parsed JSON response (not mapped to objects).
-
#put_resource(path, attrs = {}) ⇒ Object
Make a PUT request and return a collection of resources.
-
#request(attrs = {}) {|@her_api.request(attrs)| ... } ⇒ Object
Main request wrapper around Her::API.
-
#uses_api(api) ⇒ Object
Link a model with a Her::API object.
Instance Method Details
#collection_path(path = nil) ⇒ Object
Defines a custom collection path for the resource
17 18 19 20 |
# File 'lib/her/model/http.rb', line 17 def collection_path(path=nil) # {{{ return @her_collection_path unless path @her_collection_path = path end |
#delete_collection(path, attrs = {}) ⇒ Object
Make a DELETE request and return a collection of resources
122 123 124 125 126 |
# File 'lib/her/model/http.rb', line 122 def delete_collection(path, attrs={}) # {{{ delete_raw(path, attrs) do |parsed_data| new_collection(parsed_data) end end |
#delete_raw(path, attrs = {}, &block) ⇒ Object
Make a DELETE request and return the parsed JSON response (not mapped to objects)
117 118 119 |
# File 'lib/her/model/http.rb', line 117 def delete_raw(path, attrs={}, &block) # {{{ request(attrs.merge(:_method => :delete, :_path => path), &block) end |
#delete_resource(path, attrs = {}) ⇒ Object
Make a DELETE request and return a collection of resources
129 130 131 132 133 |
# File 'lib/her/model/http.rb', line 129 def delete_resource(path, attrs={}) # {{{ delete_raw(path, attrs) do |parsed_data| new(parsed_data[:data]) end end |
#get_collection(path, attrs = {}) ⇒ Object
Make a GET request and return a collection of resources
46 47 48 49 50 |
# File 'lib/her/model/http.rb', line 46 def get_collection(path, attrs={}) # {{{ get_raw(path, attrs) do |parsed_data| new_collection(parsed_data) end end |
#get_raw(path, attrs = {}, &block) ⇒ Object
Make a GET request and return the parsed JSON response (not mapped to objects)
41 42 43 |
# File 'lib/her/model/http.rb', line 41 def get_raw(path, attrs={}, &block) # {{{ request(attrs.merge(:_method => :get, :_path => path), &block) end |
#get_resource(path, attrs = {}) ⇒ Object
Make a GET request and return a collection of resources
53 54 55 56 57 |
# File 'lib/her/model/http.rb', line 53 def get_resource(path, attrs={}) # {{{ get_raw(path, attrs) do |parsed_data| new(parsed_data[:data]) end end |
#item_path(path = nil) ⇒ Object
Defines a custom item path for the resource
29 30 31 32 |
# File 'lib/her/model/http.rb', line 29 def item_path(path=nil) # {{{ return @her_item_path unless path @her_item_path = path end |
#patch_collection(path, attrs = {}) ⇒ Object
Make a PATCH request and return a collection of resources
103 104 105 106 107 |
# File 'lib/her/model/http.rb', line 103 def patch_collection(path, attrs={}) # {{{ patch_raw(path, attrs) do |parsed_data| new_collection(parsed_data) end end |
#patch_raw(path, attrs = {}, &block) ⇒ Object
Make a PATCH request and return the parsed JSON response (not mapped to objects)
98 99 100 |
# File 'lib/her/model/http.rb', line 98 def patch_raw(path, attrs={}, &block) # {{{ request(attrs.merge(:_method => :patch, :_path => path), &block) end |
#patch_resource(path, attrs = {}) ⇒ Object
Make a PATCH request and return a collection of resources
110 111 112 113 114 |
# File 'lib/her/model/http.rb', line 110 def patch_resource(path, attrs={}) # {{{ patch_raw(path, attrs) do |parsed_data| new(parsed_data[:data]) end end |
#post_collection(path, attrs = {}) ⇒ Object
Make a POST request and return a collection of resources
65 66 67 68 69 |
# File 'lib/her/model/http.rb', line 65 def post_collection(path, attrs={}) # {{{ post_raw(path, attrs) do |parsed_data| new_collection(parsed_data) end end |
#post_raw(path, attrs = {}, &block) ⇒ Object
Make a POST request and return the parsed JSON response (not mapped to objects)
60 61 62 |
# File 'lib/her/model/http.rb', line 60 def post_raw(path, attrs={}, &block) # {{{ request(attrs.merge(:_method => :post, :_path => path), &block) end |
#post_resource(path, attrs = {}) ⇒ Object
Make a POST request and return a collection of resources
72 73 74 75 76 |
# File 'lib/her/model/http.rb', line 72 def post_resource(path, attrs={}) # {{{ post_raw(path, attrs) do |parsed_data| new(parsed_data[:data]) end end |
#put_collection(path, attrs = {}) ⇒ Object
Make a PUT request and return a collection of resources
84 85 86 87 88 |
# File 'lib/her/model/http.rb', line 84 def put_collection(path, attrs={}) # {{{ put_raw(path, attrs) do |parsed_data| new_collection(parsed_data) end end |
#put_raw(path, attrs = {}, &block) ⇒ Object
Make a PUT request and return the parsed JSON response (not mapped to objects)
79 80 81 |
# File 'lib/her/model/http.rb', line 79 def put_raw(path, attrs={}, &block) # {{{ request(attrs.merge(:_method => :put, :_path => path), &block) end |
#put_resource(path, attrs = {}) ⇒ Object
Make a PUT request and return a collection of resources
91 92 93 94 95 |
# File 'lib/her/model/http.rb', line 91 def put_resource(path, attrs={}) # {{{ put_raw(path, attrs) do |parsed_data| new(parsed_data[:data]) end end |
#request(attrs = {}) {|@her_api.request(attrs)| ... } ⇒ Object
Main request wrapper around Her::API. Used to make custom request to the API.
36 37 38 |
# File 'lib/her/model/http.rb', line 36 def request(attrs={}, &block) # {{{ yield @her_api.request(attrs) end |
#uses_api(api) ⇒ Object
Link a model with a Her::API object
6 7 8 |
# File 'lib/her/model/http.rb', line 6 def uses_api(api) # {{{ @her_api = api end |