Class: Bcnd::QuayIo::Connection
- Inherits:
-
Object
- Object
- Bcnd::QuayIo::Connection
- Defined in:
- lib/bcnd/quay_io.rb
Constant Summary collapse
- BASE_URL =
'https://quay.io/api/v1'
Instance Attribute Summary collapse
-
#token ⇒ Object
Returns the value of attribute token.
Instance Method Summary collapse
- #delete(path:, body: {}, query_params: {}) ⇒ Object
- #get(path:, body: {}, query_params: {}) ⇒ Object
-
#initialize(token) ⇒ Connection
constructor
A new instance of Connection.
- #post(path:, body: {}, query_params: {}) ⇒ Object
- #put(path:, body: {}, query_params: {}) ⇒ Object
- #request(method: :get, path:, body: {}, query_params: {}) ⇒ Object
Constructor Details
#initialize(token) ⇒ Connection
Returns a new instance of Connection.
10 11 12 |
# File 'lib/bcnd/quay_io.rb', line 10 def initialize(token) @token = token end |
Instance Attribute Details
#token ⇒ Object
Returns the value of attribute token.
8 9 10 |
# File 'lib/bcnd/quay_io.rb', line 8 def token @token end |
Instance Method Details
#delete(path:, body: {}, query_params: {}) ⇒ Object
40 41 42 |
# File 'lib/bcnd/quay_io.rb', line 40 def delete(path:, body: {}, query_params: {}) request(method: :delete, path: path, body: body, query_params: query_params) end |
#get(path:, body: {}, query_params: {}) ⇒ Object
28 29 30 |
# File 'lib/bcnd/quay_io.rb', line 28 def get(path:, body: {}, query_params: {}) request(method: :get, path: path, body: body, query_params: query_params) end |
#post(path:, body: {}, query_params: {}) ⇒ Object
36 37 38 |
# File 'lib/bcnd/quay_io.rb', line 36 def post(path:, body: {}, query_params: {}) request(method: :post, path: path, body: body, query_params: query_params) end |
#put(path:, body: {}, query_params: {}) ⇒ Object
32 33 34 |
# File 'lib/bcnd/quay_io.rb', line 32 def put(path:, body: {}, query_params: {}) request(method: :put, path: path, body: body, query_params: query_params) end |
#request(method: :get, path:, body: {}, query_params: {}) ⇒ Object
14 15 16 17 18 19 20 21 22 23 24 25 26 |
# File 'lib/bcnd/quay_io.rb', line 14 def request(method: :get, path:, body: {}, query_params: {}) response = RestClient::Request.execute( method: method, url: "#{BASE_URL}#{path}", payload: body.empty? ? nil : body.to_json, headers: { "Authorization" => "Bearer #{token}", "Content-Type" => "application/json", params: query_params } ) JSON.load(response.to_s) end |