Class: Scirocco::Client
- Inherits:
-
Object
- Object
- Scirocco::Client
- Defined in:
- lib/scirocco/client.rb
Constant Summary collapse
- API_POLL_SEC =
test result polled every poll seconds
15
Instance Attribute Summary collapse
-
#api_key ⇒ Object
Returns the value of attribute api_key.
-
#host ⇒ Object
Returns the value of attribute host.
-
#last_request ⇒ Object
Returns the value of attribute last_request.
-
#open_timeout ⇒ Object
Returns the value of attribute open_timeout.
-
#port ⇒ Object
Returns the value of attribute port.
-
#request_timeout ⇒ Object
Returns the value of attribute request_timeout.
-
#scheme ⇒ Object
Returns the value of attribute scheme.
-
#version ⇒ Object
Returns the value of attribute version.
Instance Method Summary collapse
- #check_test(test_job_id) ⇒ Object
-
#devices(project_id) ⇒ Object
Device API.
-
#initialize(api_key, options = {}) ⇒ Client
constructor
A new instance of Client.
-
#poll_test_result(test_job_id) ⇒ Object
Checks for when test completes.
- #projects ⇒ Object
- #run_test(test_class_id, device_id) ⇒ Object
-
#tests(project_id) ⇒ Object
Test API.
Constructor Details
#initialize(api_key, options = {}) ⇒ Client
Returns a new instance of Client.
10 11 12 13 14 15 16 17 18 19 20 |
# File 'lib/scirocco/client.rb', line 10 def initialize(api_key, ={}) @api_key = api_key @scheme, @host, @port, @version, @request_timeout, @open_timeout = { scheme: "https", host: HOSTNAME, port: 443, version: API_VERSION, request_timeout: 600, open_timeout: 10 }.merge(.symbolize_keys).values end |
Instance Attribute Details
#api_key ⇒ Object
Returns the value of attribute api_key.
6 7 8 |
# File 'lib/scirocco/client.rb', line 6 def api_key @api_key end |
#host ⇒ Object
Returns the value of attribute host.
6 7 8 |
# File 'lib/scirocco/client.rb', line 6 def host @host end |
#last_request ⇒ Object
Returns the value of attribute last_request.
6 7 8 |
# File 'lib/scirocco/client.rb', line 6 def last_request @last_request end |
#open_timeout ⇒ Object
Returns the value of attribute open_timeout.
6 7 8 |
# File 'lib/scirocco/client.rb', line 6 def open_timeout @open_timeout end |
#port ⇒ Object
Returns the value of attribute port.
6 7 8 |
# File 'lib/scirocco/client.rb', line 6 def port @port end |
#request_timeout ⇒ Object
Returns the value of attribute request_timeout.
6 7 8 |
# File 'lib/scirocco/client.rb', line 6 def request_timeout @request_timeout end |
#scheme ⇒ Object
Returns the value of attribute scheme.
6 7 8 |
# File 'lib/scirocco/client.rb', line 6 def scheme @scheme end |
#version ⇒ Object
Returns the value of attribute version.
6 7 8 |
# File 'lib/scirocco/client.rb', line 6 def version @version end |
Instance Method Details
#check_test(test_job_id) ⇒ Object
74 75 76 77 78 |
# File 'lib/scirocco/client.rb', line 74 def check_test(test_job_id) url = build_url("tests", "check") params = { test_job_id: test_job_id } get(url, params) end |
#devices(project_id) ⇒ Object
Device API
31 32 33 34 |
# File 'lib/scirocco/client.rb', line 31 def devices(project_id) url = build_url("devices") get(url, {:project_id => project_id}) end |
#poll_test_result(test_job_id) ⇒ Object
Checks for when test completes
58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 |
# File 'lib/scirocco/client.rb', line 58 def poll_test_result(test_job_id) status = nil runtime = 0 while !['passed', 'failed'].include?(status) sleep(API_POLL_SEC) test_status = check_test(test_job_id)["test_status"] status = test_status["status"] if ['passed', 'failed'].include?(status) return test_status else puts "polling... status: #{status}" end end end |
#projects ⇒ Object
22 23 24 25 |
# File 'lib/scirocco/client.rb', line 22 def projects url = build_url("projects") get(url)["projects"] end |
#run_test(test_class_id, device_id) ⇒ Object
46 47 48 49 50 51 52 53 54 55 |
# File 'lib/scirocco/client.rb', line 46 def run_test(test_class_id, device_id) url = build_url("tests", "run") data = { :api_key => @api_key, :test_class_id => test_class_id, :device_id => device_id } post(url, data)["test_job"] end |
#tests(project_id) ⇒ Object
Test API
41 42 43 44 |
# File 'lib/scirocco/client.rb', line 41 def tests(project_id) url = build_url("tests") get(url, {:project_id => project_id})["tests"] end |