Class: Stove::Supermarket

Inherits:
Object
  • Object
show all
Includes:
Mixin::Instanceable, Mixin::Optionable
Defined in:
lib/stove/supermarket.rb

Constant Summary collapse

DEFAULT_ENDPOINT =

The default endpoint where the Supermarket lives.

Returns:

  • (String)
'https://supermarket.chef.io/api/v1'

Instance Method Summary collapse

Methods included from Mixin::Optionable

extended, included

Methods included from Mixin::Instanceable

extended, included

Instance Method Details

#cookbook(name, version = nil) ⇒ Hash

Get and cache a community cookbook’s JSON response from the given name and version.

Examples:

Find a cookbook by name

Supermarket.cookbook('apache2') #=> {...}

Find a cookbook by name and version

Supermarket.cookbook('apache2', '1.0.0') #=> {...}

Find a non-existent cookbook

Supermarket.cookbook('not-real') #=> Community::BadResponse

Parameters:

  • name (String)

    the name of the cookbook on the Supermarket

  • version (String) (defaults to: nil)

    (optional) the version of the cookbook to find

Returns:

  • (Hash)

    the hash of the cookbook

Raises:

  • (Supermarket::BadResponse)

    if the given cookbook (or cookbook version) does not exist on the Supermarket



39
40
41
42
43
44
45
# File 'lib/stove/supermarket.rb', line 39

def cookbook(name, version = nil)
  if version.nil?
    connection.get("cookbooks/#{name}")
  else
    connection.get("cookbooks/#{name}/versions/#{Util.version_for_url(version)}")
  end
end

#upload(cookbook, extended_metadata = false) ⇒ Object

Upload a cookbook to the community site.

Parameters:

  • cookbook (Cookbook)

    the cookbook to upload



53
54
55
56
57
58
59
60
61
62
63
# File 'lib/stove/supermarket.rb', line 53

def upload(cookbook,  = false)
  connection.post('cookbooks', {
    'tarball'  => cookbook.tarball(),

    # This is for legacy, backwards-compatability reasons. The new
    # Supermarket site does not require a category, but many of the testing
    # tools still assume a cookbook category is present. We just hardcode
    # "Other" here.
    'cookbook' => JSON.fast_generate(category: 'Other'),
  })
end