Class: Bixby::Client

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

Overview

Implements the Bixby client API

Defined Under Namespace

Classes: App

Constant Summary collapse

VERSION =
File.new(File.expand_path("../../../../VERSION", __FILE__)).read.strip

Class Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(access_key, secret_key) ⇒ Client

Create a new Client

Parameters:

  • access_key (String)
  • secret_key (String)


18
19
20
21
# File 'lib/bixby-client/client.rb', line 18

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

Class Attribute Details

.appObject

Returns the value of attribute app.



11
12
13
# File 'lib/bixby-client/app.rb', line 11

def app
  @app
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)


29
30
31
# File 'lib/bixby-client/client.rb', line 29

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)


48
49
50
51
52
53
54
55
# File 'lib/bixby-client/client.rb', line 48

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)


62
63
64
65
66
67
68
69
70
71
# File 'lib/bixby-client/client.rb', line 62

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)


40
41
42
# File 'lib/bixby-client/client.rb', line 40

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

#manager_uriString

Get the manager URI

Returns:

  • (String)


83
84
85
# File 'lib/bixby-client/client.rb', line 83

def manager_uri
  Bixby.manager_uri
end

#sign_http_request(request) ⇒ Object

Sign the given request

Parameters:

  • request (HTTPI::Request)


76
77
78
# File 'lib/bixby-client/client.rb', line 76

def sign_http_request(request)
  ApiAuth.sign!(request, @access_key, @secret_key)
end