class Bixby::Client

Implements the Bixby client API

Constants

VERSION

Attributes

app[RW]

Public Class Methods

new(access_key, secret_key) click to toggle source

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

exec(op, params) click to toggle source

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
exec_api(json_req) click to toggle source

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
exec_api_download(json_req, download_path) click to toggle source

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
exec_download(download_path, op, params) click to toggle source

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
manager_uri() click to toggle source

Get the manager URI

@return [String]

# File lib/bixby-client/client.rb, line 81
def manager_uri
  Bixby.manager_uri
end
sign_http_request(request) click to toggle source

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

api_uri() click to toggle source
# File lib/bixby-client/client.rb, line 100
def api_uri
  URI.join(Bixby.manager_uri, "/api").to_s
end
crypto_enabled?() click to toggle source
# File lib/bixby-client/client.rb, line 104
def crypto_enabled?
  b = ENV["BIXBY_NOCRYPTO"]
  !(b and %w{1 true yes}.include? b)
end
sign_request(json_req) click to toggle source

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