Class: CommunityZero::Endpoint
- Inherits:
-
Object
- Object
- CommunityZero::Endpoint
- Defined in:
- lib/community_zero/endpoint.rb
Overview
The base class for any endpoint.
Direct Known Subclasses
CookbookEndpoint, CookbookVersionsVersionEndpoint, CookbooksEndpoint, NotFoundEndpoint, SearchEndpoint
Constant Summary collapse
- METHODS =
[:get, :put, :post, :delete].freeze
Instance Attribute Summary collapse
-
#server ⇒ Object
readonly
Returns the value of attribute server.
Instance Method Summary collapse
-
#call(request) ⇒ Object
Call the request.
-
#initialize(server) ⇒ Endpoint
constructor
Create a new endpoint.
-
#store ⇒ CommunityZero::Store
The data store for these endpoints.
-
#url_for(cookbook) ⇒ String
Generate the URL for the given cookbook.
-
#version_url_for(cookbook, version) ⇒ String
Generate the version URL for the given cookbook and version.
Constructor Details
#initialize(server) ⇒ Endpoint
Create a new endpoint.
37 38 39 |
# File 'lib/community_zero/endpoint.rb', line 37 def initialize(server) @server = server end |
Instance Attribute Details
#server ⇒ Object (readonly)
Returns the value of attribute server.
31 32 33 |
# File 'lib/community_zero/endpoint.rb', line 31 def server @server end |
Instance Method Details
#call(request) ⇒ Object
Call the request.
76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 |
# File 'lib/community_zero/endpoint.rb', line 76 def call(request) m = request.method.downcase.to_sym # Only respond to listed methods unless respond_to?(m) allowed = METHODS.select { |m| respond_to?(m) }.map(&:upcase).join(', ') return [ 405, { 'Content-Type' => 'text/plain', 'Allow' => allowed }, "Method not allowed: '#{request.env['REQUEST_METHOD']}'" ] end begin send(m, request) rescue RestError => e error(e.response_code, e.error) end end |
#store ⇒ CommunityZero::Store
The data store for these endpoints
44 45 46 |
# File 'lib/community_zero/endpoint.rb', line 44 def store server.store end |
#url_for(cookbook) ⇒ String
Generate the URL for the given cookbook.
55 56 57 |
# File 'lib/community_zero/endpoint.rb', line 55 def url_for(cookbook) "#{server.url}/cookbooks/#{cookbook.name}" end |
#version_url_for(cookbook, version) ⇒ String
Generate the version URL for the given cookbook and version.
68 69 70 |
# File 'lib/community_zero/endpoint.rb', line 68 def version_url_for(cookbook, version) "#{server.url}/cookbooks/#{cookbook.name}/versions/#{version.gsub('.', '_')}" end |