Class: Habitat::Client
- Inherits:
-
Object
- Object
- Habitat::Client
- Defined in:
- lib/habitat/client.rb,
lib/habitat/client/version.rb
Overview
Habitat Client
This class is an API client to the Habitat Depot. It uses Faraday under the covers to give us a nice HTTP interface.
Constant Summary collapse
- VERSION =
'0.6.0'.freeze
Instance Attribute Summary collapse
-
#connection ⇒ Object
readonly
Returns the value of attribute connection.
-
#depot ⇒ Object
readonly
Returns the value of attribute depot.
Instance Method Summary collapse
-
#fetch_key(_key, _path = '.') ⇒ Object
Downloads the specified key.
-
#fetch_package(pkg, path = '.') ⇒ Object
Downloads the specified package.
-
#initialize(depot = 'https://willem.habitat.sh/v1/depot') ⇒ Client
constructor
Creates the Habitat client connection object.
-
#promote_package(pkg, view) ⇒ Object
Promotes a package to the specified view, for example
core/zlib
tostaging
orproduction
. -
#put_key(_key, _path) ⇒ Object
Uploads the specified key from the given path location.
-
#put_package(file) ⇒ Object
Uploads a package from the specified filepath.
-
#show_package(pkg) ⇒ Object
Show details about the specified package using a package identifier string.
Constructor Details
#initialize(depot = 'https://willem.habitat.sh/v1/depot') ⇒ Client
Creates the Habitat client connection object. The public interface should be used for the common interactions with the API, but more complex operations can be done using the connection
attribute through Faraday.
Attributes
-
depot
- URL to the Habitat Depot, defaults to the publicservice run by the Habitat organization
-
connection
- A Faraday object representing the HTTP connection
Examples
hc = Habitat::Client.new
hc = Habitat::Client.new('https://habitat-depot.example.com')
hc.connection.get('/pkgs')
49 50 51 52 53 54 55 56 |
# File 'lib/habitat/client.rb', line 49 def initialize(depot = 'https://willem.habitat.sh/v1/depot') @depot = depot @connection = Faraday.new(url: @depot) do |f| f.request :multipart f.request :url_encoded f.adapter :net_http end end |
Instance Attribute Details
#connection ⇒ Object (readonly)
Returns the value of attribute connection.
30 31 32 |
# File 'lib/habitat/client.rb', line 30 def connection @connection end |
#depot ⇒ Object (readonly)
Returns the value of attribute depot.
30 31 32 |
# File 'lib/habitat/client.rb', line 30 def depot @depot end |
Instance Method Details
#fetch_key(_key, _path = '.') ⇒ Object
Downloads the specified key. By default, it will download to the current directory as a file named by the X-Filename
HTTP header.
61 62 63 |
# File 'lib/habitat/client.rb', line 61 def fetch_key(_key, _path = '.') raise 'Downloading keys is not yet implemented' end |
#fetch_package(pkg, path = '.') ⇒ Object
Downloads the specified package. It will default to the latest version if not specified, or the latest release of a version if the release is not specified.
The file will be downloaded to the current directory as a file named by the X-Filename
HTTP header.
Arguments
-
pkg
- A package string, likecore/zlib
80 81 82 |
# File 'lib/habitat/client.rb', line 80 def fetch_package(pkg, path = '.') download(fetch_package_path(pkg), path) end |
#promote_package(pkg, view) ⇒ Object
116 117 118 |
# File 'lib/habitat/client.rb', line 116 def promote_package(pkg, view) promote(promote_artifact_path(pkg, view)) end |
#put_key(_key, _path) ⇒ Object
Uploads the specified key from the given path location.
66 67 68 |
# File 'lib/habitat/client.rb', line 66 def put_key(_key, _path) raise 'Uploading keys is not yet implemented' end |
#put_package(file) ⇒ Object
Uploads a package from the specified filepath.
Arguments
-
file
- The file to upload
Examples
105 106 107 |
# File 'lib/habitat/client.rb', line 105 def put_package(file) upload(upload_package_path(file), file) end |
#show_package(pkg) ⇒ Object
94 95 96 |
# File 'lib/habitat/client.rb', line 94 def show_package(pkg) JSON.parse(@connection.get(show_package_path(pkg)).body) end |