Class: CommunityZero::CookbookEndpoint
- Defined in:
- lib/community_zero/endpoints/cookbook_endpoint.rb
Overview
The endpoint for interacting with a single cookbook.
Constant Summary
Constants inherited from Endpoint
Instance Attribute Summary
Attributes inherited from Endpoint
Instance Method Summary collapse
-
#delete(request) ⇒ Object
DELETE /cookbooks/:name.
-
#get(request) ⇒ Object
GET /cookbooks/:name.
Methods inherited from Endpoint
#call, #initialize, #store, #url_for, #version_url_for
Constructor Details
This class inherits a constructor from CommunityZero::Endpoint
Instance Method Details
#delete(request) ⇒ Object
DELETE /cookbooks/:name
52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 |
# File 'lib/community_zero/endpoints/cookbook_endpoint.rb', line 52 def delete(request) name = request.path.last if cookbook = store.find(name) store.remove(cookbook) respond({}) else respond(404, { 'error_code' => 'NOT_FOUND', 'error_messages' => ['Resource not found'], } ) end end |
#get(request) ⇒ Object
GET /cookbooks/:name
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/community_zero/endpoints/cookbook_endpoint.rb', line 24 def get(request) name = request.path.last cookbook = store.find(name) if cookbook = store.find(name) respond({ 'name' => cookbook.name, 'maintainer' => cookbook.maintainer, 'category' => cookbook.category, 'external_url' => cookbook.external_url, 'description' => cookbook.description, 'average_rating' => cookbook., 'versions' => store.versions(cookbook).map { |i| version_url_for(cookbook, i) }, 'latest_version' => version_url_for(cookbook, store.latest_version(cookbook)), 'created_at' => cookbook.created_at, 'updated_at' => cookbook.upadated_at, }) else respond(404, { 'error_code' => 'NOT_FOUND', 'error_messages' => ['Resource not found'], } ) end end |