Class: Spice::Connection

Inherits:
Object
  • Object
show all
Includes:
Authentication, Clients, Cookbooks, DataBags, Environments, Nodes, Roles, Search, Request, Toy::Store
Defined in:
lib/spice/connection.rb,
lib/spice/connection/nodes.rb,
lib/spice/connection/roles.rb,
lib/spice/connection/search.rb,
lib/spice/connection/clients.rb,
lib/spice/connection/cookbooks.rb,
lib/spice/connection/data_bags.rb,
lib/spice/connection/environments.rb,
lib/spice/connection/authentication.rb

Defined Under Namespace

Modules: Authentication, Clients, Cookbooks, DataBags, Environments, Nodes, Roles, Search

Instance Attribute Summary (collapse)

Instance Method Summary (collapse)

Methods included from Request

#request

Methods included from Authentication

#sign_requests?, #signature_headers

Methods included from Search

#search

Methods included from Roles

#role, #roles

Methods included from Nodes

#node, #nodes

Methods included from Environments

#environment, #environments

Methods included from DataBags

#data_bag, #data_bag_item, #data_bags

Methods included from Cookbooks

#cookbook, #cookbook_version, #cookbooks

Methods included from Clients

#client, #clients

Instance Attribute Details

- (String) client_name

The client_name attribute

Returns:

  • (String)

    the client_name attribute



36
# File 'lib/spice/connection.rb', line 36

attribute :client_name, String

- (String) endpoint

The endpoint attribute

Returns:

  • (String)

    the endpoint attribute



42
# File 'lib/spice/connection.rb', line 42

attribute :endpoint, String

- (String) key

The key attribute

Returns:

  • (String)

    the key attribute



38
# File 'lib/spice/connection.rb', line 38

attribute :key, String

- (String) key_file

The key_file attribute

Returns:

  • (String)

    the key_file attribute



37
# File 'lib/spice/connection.rb', line 37

attribute :key_file, String

- (String) server_url

The server_url attribute

Returns:

  • (String)

    the server_url attribute



39
# File 'lib/spice/connection.rb', line 39

attribute :server_url, String

- (Boolean) sign_on_redirect

The sign_on_redirect attribute

Returns:

  • (Boolean)

    the sign_on_redirect attribute



40
# File 'lib/spice/connection.rb', line 40

attribute :sign_on_redirect, Boolean, :default => true

- (Boolean) sign_request

The sign_request attribute

Returns:

  • (Boolean)

    the sign_request attribute



41
# File 'lib/spice/connection.rb', line 41

attribute :sign_request, Boolean, :default => true

Instance Method Details

- (Object) connection



46
47
48
# File 'lib/spice/connection.rb', line 46

def connection
  self
end

- (Faraday::Response) delete(path)

Perform an HTTP DELETE request

Examples:

Delete the client "foo"

Spice.connection.delete("/clients/foo")

Parameters:

  • path (String)

    The relative path

Returns:

  • (Faraday::Response)


110
111
112
113
114
115
116
117
118
# File 'lib/spice/connection.rb', line 110

def delete(path)
  response = request(:headers => build_headers(
    :DELETE, 
    "#{parsed_url.path}#{path}")
  ).delete(
    "#{server_url}#{path}"
  )
  return response
end

- (Faraday::Response) get(path)

Perform an HTTP GET request

Examples:

Get a list of all nodes

Spice.connection.get("/nodes")

Parameters:

  • path (String)

    The relative path

Returns:

  • (Faraday::Response)


59
60
61
62
63
64
65
66
67
# File 'lib/spice/connection.rb', line 59

def get(path)
  response = request(:headers => build_headers(
    :GET, 
    "#{parsed_url.path}#{path}")
  ).get(
    "#{server_url}#{path}"
  )
  return response
end

- (Object) parsed_url



50
51
52
# File 'lib/spice/connection.rb', line 50

def parsed_url
  URI.parse(server_url)
end

- (Faraday::Response) post(path, payload)

Perform an HTTP POST request

Examples:

Create a new client named "foo"

Spice.connection.post("/clients", :name => "foo")

Parameters:

  • path (String)

    The relative path

  • payload (Hash)

    The payload to send with the POST request

Returns:

  • (Faraday::Response)


75
76
77
78
79
80
81
82
83
84
85
# File 'lib/spice/connection.rb', line 75

def post(path, payload)
  response = request(:headers => build_headers(
    :POST, 
    "#{parsed_url.path}#{path}", 
    Yajl.dump(payload))
  ).post(
    "#{server_url}#{path}", 
    Yajl.dump(payload)
  )
  return response
end

- (Faraday::Response) put(path, payload)

Perform an HTTP PUT request

Examples:

Make an existing client "foo" an admin

Spice.connection.put("/clients/foo", :admin => true)

Parameters:

  • path (String)

    The relative path

  • payload (Hash)

    The payload to send with the PUT request

Returns:

  • (Faraday::Response)


93
94
95
96
97
98
99
100
101
102
103
# File 'lib/spice/connection.rb', line 93

def put(path, payload)
  response = request(:headers => build_headers(
    :PUT, 
    "#{parsed_url.path}#{path}", 
    Yajl.dump(payload))
  ).put(
    "#{server_url}#{path}", 
    Yajl.dump(payload)
  )
  return response
end