Class: Bixby::Client

Inherits:
Object show all
Includes:
Log
Defined in:
lib/bixby-client/client.rb

Overview

Implements the Bixby client API

Instance Method Summary collapse

Constructor Details

#initialize(access_key, secret_key) ⇒ Client

Create a new Client

Parameters:

  • access_key (String)
  • secret_key (String)


15
16
17
18
# File 'lib/bixby-client/client.rb', line 15

def initialize(access_key, secret_key)
  @access_key = access_key
  @secret_key = secret_key
end

Instance Method Details

#exec(op, params) ⇒ JsonResponse

Execute the given API request on the manager

Parameters:

  • operation (String)

    Name of operation

  • params (Array)

    Array of parameters; must ve valid JSON types

Returns:

  • (JsonResponse)


26
27
28
# File 'lib/bixby-client/client.rb', line 26

def exec(op, params)
  exec_api(JsonRequest.new(op, params))
end

#exec_api(json_req) ⇒ JsonResponse

Execute the given API request on the manager

Parameters:

  • json_req (JsonRequest)

Returns:

  • (JsonResponse)


45
46
47
48
49
50
51
52
# File 'lib/bixby-client/client.rb', line 45

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) ⇒ JsonResponse

Execute the given API download request

Parameters:

  • json_req (JsonRequest)

    Request to download a file

  • download_path (String)

    Absolute filename to download requested file to

Returns:

  • (JsonResponse)


59
60
61
62
63
64
65
66
67
68
# File 'lib/bixby-client/client.rb', line 59

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) ⇒ JsonResponse

Execute the given API download request

Parameters:

  • download_path (String)

    Absolute filename to download requested file to

  • operation (String)

    Name of operation

  • params (Array)

    Array of parameters; must ve valid JSON types

Returns:

  • (JsonResponse)


37
38
39
# File 'lib/bixby-client/client.rb', line 37

def exec_download(download_path, op, params)
  exec_api_download(JsonRequest.new(op, params), download_path)
end