Class: Cabal::Client
- Inherits:
-
Object
- Object
- Cabal::Client
- Defined in:
- lib/cabal/client.rb
Instance Attribute Summary collapse
-
#api_base ⇒ Object
readonly
Returns the value of attribute api_base.
Instance Method Summary collapse
- #get(endpoint, authenticated = nil) ⇒ Object
-
#initialize(options = {}) ⇒ Client
constructor
A new instance of Client.
- #private_key(cluster_name) ⇒ Object
- #public_key(cluster_name) ⇒ Object
Constructor Details
#initialize(options = {}) ⇒ Client
Returns a new instance of Client.
8 9 10 11 12 13 14 15 16 |
# File 'lib/cabal/client.rb', line 8 def initialize( = {}) @api_base = "#{[:api_base]}/v2" @access_key = [:access_key] @secret_key = [:secret_key] @connector = Faraday.new(url: api_base) do |faraday| faraday.request :url_encoded faraday.adapter Faraday.default_adapter end end |
Instance Attribute Details
#api_base ⇒ Object (readonly)
Returns the value of attribute api_base.
6 7 8 |
# File 'lib/cabal/client.rb', line 6 def api_base @api_base end |
Instance Method Details
#get(endpoint, authenticated = nil) ⇒ Object
26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/cabal/client.rb', line 26 def get(endpoint, authenticated = nil) response = connector.get {|req| req.url endpoint req.headers['Content-Type'] = 'application/json' req.headers['Accept'] = 'application/json' req.headers['Authorization'] = } case response.status when 200 Oj.load(response.body) when 404 raise "Cabal::Client::NotFoundError" when 401 raise "Cabal::Client::UnauthorizedError" end end |
#private_key(cluster_name) ⇒ Object
18 19 20 |
# File 'lib/cabal/client.rb', line 18 def private_key(cluster_name) get("private-key/#{URI.encode(cluster_name)}")['private_ssh_key'] end |
#public_key(cluster_name) ⇒ Object
22 23 24 |
# File 'lib/cabal/client.rb', line 22 def public_key(cluster_name) get("key/#{URI.encode(cluster_name)}")['public_ssh_key'] end |