class Bixby::Client
Implements the Bixby
client API
Constants
- VERSION
Attributes
Public Class Methods
Create a new Client
@param [String] access_key @param [String] secret_key
# File lib/bixby-client/client.rb, line 16 def initialize(access_key, secret_key) @access_key = access_key @secret_key = secret_key end
Public Instance Methods
Execute the given API request on the manager
@param [String] operation Name of operation @param [Array] params Array of parameters; must ve valid JSON types
@return [JsonResponse]
# File lib/bixby-client/client.rb, line 27 def exec(op, params) exec_api(JsonRequest.new(op, params)) end
Execute the given API request on the manager
@param [JsonRequest] json_req @return [JsonResponse]
# File lib/bixby-client/client.rb, line 46 def exec_api(json_req) begin req = sign_request(json_req) return HttpChannel.new(api_uri).execute(req) rescue Curl::Err::CurlError => ex return JsonResponse.new("fail", ex.message) end end
Execute the given API download request
@param [JsonRequest] json_req Request to download a file @param [String] download_path Absolute filename to download requested file to @return [JsonResponse]
# File lib/bixby-client/client.rb, line 60 def exec_api_download(json_req, download_path) begin req = sign_request(json_req) File.open(download_path, "w") do |io| return HttpChannel.new(api_uri).execute_download(req) { |d| io << d; d.length } end rescue Curl::Err::CurlError => ex return JsonResponse.new("fail", ex.message) end end
Execute the given API download request
@param [String] download_path Absolute filename to download requested file to @param [String] operation Name of operation @param [Array] params Array of parameters; must ve valid JSON types
@return [JsonResponse]
# File lib/bixby-client/client.rb, line 38 def exec_download(download_path, op, params) exec_api_download(JsonRequest.new(op, params), download_path) end
Get the manager URI
@return [String]
# File lib/bixby-client/client.rb, line 81 def manager_uri Bixby.manager_uri end
Sign the given request
@param [HTTPI::Request] request
# File lib/bixby-client/client.rb, line 74 def sign_http_request(request) ApiAuth.sign!(request, @access_key, @secret_key) end
Private Instance Methods
# File lib/bixby-client/client.rb, line 100 def api_uri URI.join(Bixby.manager_uri, "/api").to_s end
# File lib/bixby-client/client.rb, line 104 def crypto_enabled? b = ENV["BIXBY_NOCRYPTO"] !(b and %w{1 true yes}.include? b) end
Create a signed request if crypto is enabled
@param [JsonRequest] json_req
@return [JsonRequest]
# File lib/bixby-client/client.rb, line 93 def sign_request(json_req) if crypto_enabled? and not @secret_key.nil? then return Bixby::SignedJsonRequest.new(json_req, @access_key, @secret_key) end return json_req end