class CommunityZero::CookbookVersionsVersionEndpoint

The endpoint for interacting with a single cookbook version.

@author Seth Vargo <sethvargo@gmail.com>

Public Instance Methods

get(request) click to toggle source
# File lib/community_zero/endpoints/cookbook_versions_version_endpoint.rb, line 23
def get(request)
  name, version = request.path[1], request.path[-1].gsub('_', '.')

  unless cookbook = store.find(name)
    return respond(404,
      {
        'error_code' => 'NOT_FOUND',
        'error_messages' => ['Resource not found'],
      }
    )
  end

  version = store.latest_version(cookbook) if version == 'latest'
  cookbook = store.find(name, version)
  respond(response_hash_for(cookbook))
end

Private Instance Methods

response_hash_for(cookbook) click to toggle source

The response hash for this cookbook.

@param [CommunityZero::Cookbook] cookbook

the cookbook to generate a hash for
# File lib/community_zero/endpoints/cookbook_versions_version_endpoint.rb, line 45
def response_hash_for(cookbook)
  {
    'cookbook'           => url_for(cookbook),
    'average_rating'     => cookbook.average_rating,
    'version'            => cookbook.version,
    'license'            => cookbook.license,
    'file'               => "http://s3.amazonaws.com/#{cookbook.name}.tgz",
    'tarball_file_size'  => cookbook.name.split('').map(&:ord).inject(&:+) * 25, # don't even
    'created_at'         => cookbook.created_at,
    'updated_at'         => cookbook.upadated_at,
  }
end