class DockerCloud::API
Constants
- API_VERSION
- BASE_API_PATH
Attributes
client[R]
headers[R]
type[R]
Public Class Methods
new(headers, type, client)
click to toggle source
# File lib/docker_cloud/api/api.rb, line 11 def initialize(headers, type, client) @headers = headers @type = type @client = client end
Public Instance Methods
get_from_uri(uri)
click to toggle source
# File lib/docker_cloud/api/api.rb, line 50 def get_from_uri(uri) uri = BASE_API_PATH + uri.split('/api')[1] response = RestClient.get(uri, headers) response = parse(response) format_object(response, self.class::TYPE) end
http_delete(path)
click to toggle source
# File lib/docker_cloud/api/api.rb, line 39 def http_delete(path) response = RestClient.delete(url(path), headers) parse(response) end
http_get(path, params = {})
click to toggle source
# File lib/docker_cloud/api/api.rb, line 21 def http_get(path, params = {}) query = '?' + params.map { |k, v| "#{k}=#{v}" }.join('&') full_path = path full_path += query unless params.empty? response = RestClient.get(url(full_path), headers) parse(response) end
http_patch(path, content = {})
click to toggle source
# File lib/docker_cloud/api/api.rb, line 34 def http_patch(path, content = {}) response = RestClient.patch(url("#{path}/"), content.to_json, headers) parse(response) end
http_post(path, content = {})
click to toggle source
# File lib/docker_cloud/api/api.rb, line 29 def http_post(path, content = {}) response = RestClient.post(url(path), content.to_json, headers) parse(response) end
parse(response)
click to toggle source
# File lib/docker_cloud/api/api.rb, line 44 def parse(response) hash = JSON.parse(response, symbolize_names: true) hash.delete(:meta) hash[:objects].nil? ? hash : hash[:objects] end
url(path)
click to toggle source
# File lib/docker_cloud/api/api.rb, line 17 def url(path) BASE_API_PATH + '/' + @type + '/' + API_VERSION + path end