Class: Plaza::RestfulAdapter
- Inherits:
-
Object
- Object
- Plaza::RestfulAdapter
show all
- Includes:
- BaseAdapter
- Defined in:
- lib/plaza/adapters/restful_adapter.rb
Instance Attribute Summary collapse
Instance Method Summary
collapse
#handle_error, #handle_response, #response_to_hash
Constructor Details
Returns a new instance of RestfulAdapter.
5
6
7
8
9
10
|
# File 'lib/plaza/adapters/restful_adapter.rb', line 5
def initialize(resource)
@singular_name = resource.singular_name
@plural_name = resource.plural_name
@request = Plaza::Request.new(resource.plaza_config)
@logger = Plaza.configuration(resource.plaza_config).logger
end
|
Instance Attribute Details
#logger ⇒ Object
Returns the value of attribute logger.
3
4
5
|
# File 'lib/plaza/adapters/restful_adapter.rb', line 3
def logger
@logger
end
|
#request ⇒ Object
Returns the value of attribute request.
3
4
5
|
# File 'lib/plaza/adapters/restful_adapter.rb', line 3
def request
@request
end
|
Instance Method Details
#create(data) ⇒ Object
26
27
28
29
|
# File 'lib/plaza/adapters/restful_adapter.rb', line 26
def create(data)
hash = handle_response(request.post(base_url, data))
hash.fetch(@singular_name){hash}
end
|
#delete(id) ⇒ Object
31
32
33
34
|
# File 'lib/plaza/adapters/restful_adapter.rb', line 31
def delete(id)
hash = handle_response(request.delete(resource_url(id)))
hash.fetch(@singular_name){hash}
end
|
#has_many(id, relation) ⇒ Object
36
37
38
39
|
# File 'lib/plaza/adapters/restful_adapter.rb', line 36
def has_many(id, relation)
hash = handle_response(request.get(has_many_url(id,relation)))
hash.fetch(@singular_name){hash}
end
|
#index(query_params = nil) ⇒ Object
12
13
14
|
# File 'lib/plaza/adapters/restful_adapter.rb', line 12
def index(query_params = nil)
handle_response(request.get(base_url(query_params)))
end
|
#show(id) ⇒ Object
16
17
18
19
|
# File 'lib/plaza/adapters/restful_adapter.rb', line 16
def show(id)
hash = handle_response(request.get(resource_url(id)))
hash.fetch(@singular_name){hash}
end
|
#update(id, data) ⇒ Object
21
22
23
24
|
# File 'lib/plaza/adapters/restful_adapter.rb', line 21
def update(id, data)
hash = handle_response(request.put(resource_url(id), data))
hash.fetch(@singular_name){hash}
end
|