Class: RestResource::RestCrud
- Inherits:
-
Object
- Object
- RestResource::RestCrud
- Defined in:
- lib/rest_resource/rest_crud.rb
Instance Attribute Summary collapse
-
#http ⇒ Object
readonly
Returns the value of attribute http.
Instance Method Summary collapse
- #all(params) ⇒ Object
- #create(params) ⇒ Object
- #find(resource_id) ⇒ Object
-
#initialize(url) ⇒ RestCrud
constructor
A new instance of RestCrud.
- #update(params) ⇒ Object
Constructor Details
#initialize(url) ⇒ RestCrud
Returns a new instance of RestCrud.
5 6 7 8 9 10 11 |
# File 'lib/rest_resource/rest_crud.rb', line 5 def initialize(url) @http = Class.new do include HTTParty base_uri "#{url}" end @url = url end |
Instance Attribute Details
#http ⇒ Object (readonly)
Returns the value of attribute http.
3 4 5 |
# File 'lib/rest_resource/rest_crud.rb', line 3 def http @http end |
Instance Method Details
#all(params) ⇒ Object
17 18 19 |
# File 'lib/rest_resource/rest_crud.rb', line 17 def all(params) RestClient.get "#{url}.json", params end |
#create(params) ⇒ Object
21 22 23 |
# File 'lib/rest_resource/rest_crud.rb', line 21 def create(params) RestClient.post "#{url}.json", params end |
#find(resource_id) ⇒ Object
13 14 15 |
# File 'lib/rest_resource/rest_crud.rb', line 13 def find(resource_id) RestClient.get "#{url}/#{resource_id}.json" end |
#update(params) ⇒ Object
25 26 27 |
# File 'lib/rest_resource/rest_crud.rb', line 25 def update(params) RestClient.put "#{url}/#{params.delete(:id)}.json", params end |