Class: Scirocco::Client

Inherits:
Object
  • Object
show all
Defined in:
lib/scirocco/client.rb

Constant Summary collapse

API_POLL_SEC =

test result polled every poll seconds

15

Instance Attribute Summary collapse

Instance Method Summary collapse

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, options={})
  @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(options.symbolize_keys).values
end

Instance Attribute Details

#api_keyObject

Returns the value of attribute api_key.



6
7
8
# File 'lib/scirocco/client.rb', line 6

def api_key
  @api_key
end

#hostObject

Returns the value of attribute host.



6
7
8
# File 'lib/scirocco/client.rb', line 6

def host
  @host
end

#last_requestObject

Returns the value of attribute last_request.



6
7
8
# File 'lib/scirocco/client.rb', line 6

def last_request
  @last_request
end

#open_timeoutObject

Returns the value of attribute open_timeout.



6
7
8
# File 'lib/scirocco/client.rb', line 6

def open_timeout
  @open_timeout
end

#portObject

Returns the value of attribute port.



6
7
8
# File 'lib/scirocco/client.rb', line 6

def port
  @port
end

#request_timeoutObject

Returns the value of attribute request_timeout.



6
7
8
# File 'lib/scirocco/client.rb', line 6

def request_timeout
  @request_timeout
end

#schemeObject

Returns the value of attribute scheme.



6
7
8
# File 'lib/scirocco/client.rb', line 6

def scheme
  @scheme
end

#versionObject

Returns the value of attribute version.



6
7
8
# File 'lib/scirocco/client.rb', line 6

def version
  @version
end

Instance Method Details

#apps(project_id) ⇒ Object

App API



84
85
86
87
# File 'lib/scirocco/client.rb', line 84

def apps(project_id)
  url = build_url("apps")
  get(url, {:project_id => project_id})
end

#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

#projectsObject



22
23
24
25
# File 'lib/scirocco/client.rb', line 22

def projects
  url = build_url("projects")
  get(url)
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)
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})
end

#upload_app(project_id, app_path) ⇒ Object



89
90
91
92
93
94
95
96
97
98
# File 'lib/scirocco/client.rb', line 89

def upload_app(project_id, app_path)
  url = build_url("apps", "upload")
  data = {
    :multipart => true,
    :api_key    => @api_key,
    :project_id => project_id,
    :file   => File.new(app_path)
  }
  post(url, data)
end