Class: Bixby::Client
- 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.("../../../../VERSION", __FILE__)).read.strip
Class Attribute Summary collapse
-
.app ⇒ Object
Returns the value of attribute app.
Instance Method Summary collapse
-
#exec(op, params) ⇒ JsonResponse
Execute the given API request on the manager.
-
#exec_api(json_req) ⇒ JsonResponse
Execute the given API request on the manager.
-
#exec_api_download(json_req, download_path) ⇒ JsonResponse
Execute the given API download request.
-
#exec_download(download_path, op, params) ⇒ JsonResponse
Execute the given API download request.
-
#initialize(access_key, secret_key) ⇒ Client
constructor
Create a new Client.
-
#manager_uri ⇒ String
Get the manager URI.
-
#sign_http_request(request) ⇒ Object
Sign the given request.
Constructor Details
#initialize(access_key, secret_key) ⇒ Client
Create a new Client
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 |
Class Attribute Details
.app ⇒ Object
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
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
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.) end end |
#exec_api_download(json_req, download_path) ⇒ JsonResponse
Execute the given API download request
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.) end end |
#exec_download(download_path, op, params) ⇒ JsonResponse
Execute the given API download request
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 |
#manager_uri ⇒ String
Get the manager URI
81 82 83 |
# File 'lib/bixby-client/client.rb', line 81 def manager_uri Bixby.manager_uri end |
#sign_http_request(request) ⇒ Object
Sign the given request
74 75 76 |
# File 'lib/bixby-client/client.rb', line 74 def sign_http_request(request) ApiAuth.sign!(request, @access_key, @secret_key) end |