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)


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

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)


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

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)


46
47
48
49
50
51
52
53
# 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) ⇒ 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)


60
61
62
63
64
65
66
67
68
69
# 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) ⇒ 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)


38
39
40
# 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