class DeployGate::API::V1::Base
Constants
- API_BASE_URL
- BASE_URL
Public Class Methods
new(token = nil)
click to toggle source
@param [String] token @return [DeployGate::API::V1::Base]
# File lib/deploygate/api/v1/base.rb, line 10 def initialize(token = nil) @token = token end
Public Instance Methods
get(path, params)
click to toggle source
@param [String] path @param [Hash] params @return [Hash] Responce parse json
# File lib/deploygate/api/v1/base.rb, line 17 def get(path, params) url = API_BASE_URL + path res = client.get(url, params, headers) JSON.parse(res.body) end
post(path, params, &process_block)
click to toggle source
@param [String] path @param [Hash] params @yield Upload process block @return [Hash] Responce parse json
# File lib/deploygate/api/v1/base.rb, line 28 def post(path, params, &process_block) url = API_BASE_URL + path connection = client.post_async(url, params, headers) while true break if connection.finished? process_block.call unless process_block.nil? end io = connection.pop.content body = '' while str = io.read(40) body += str end JSON.parse(body) end
Private Instance Methods
client()
click to toggle source
# File lib/deploygate/api/v1/base.rb, line 47 def client timeout = 60 * 5 # 5 minutes HTTPClient.new(agent_name: "dg/#{DeployGate::VERSION}").tap do |c| c.receive_timeout = timeout c.send_timeout = timeout end end
headers()
click to toggle source
# File lib/deploygate/api/v1/base.rb, line 55 def headers extheaders = [] unless @token.nil? extheaders.push(['AUTHORIZATION', @token]) end extheaders end