Class: TestdroidApi::Client
- Inherits:
-
Object
- Object
- TestdroidApi::Client
- Defined in:
- lib/testdroid-api/client.rb,
lib/testdroid-api/client/project.rb,
lib/testdroid-api/client/device_group.rb,
lib/testdroid-api/client/project/test_run.rb,
lib/testdroid-api/client/project/test_run/device_run.rb
Defined Under Namespace
Classes: DeviceGroup, Project
Constant Summary collapse
- USERS_URL =
"http://users.testdroid.com/api/v1/authorize"- CLOUD_URL =
"https://cloud.testdroid.com"
Instance Method Summary collapse
-
#authenticate! ⇒ String
Authenticate client and retrieve apiKey.
-
#create_project(name, description) ⇒ TestdroidApi::Client::Project
Create new project.
-
#device_groups(name = nil) ⇒ Array<TestdroidApi::Client::DeviceGroup>
Get user’s clusters.
- #get_api_request(endpoint, resource_name = endpoint) ⇒ Object private
- #get_file(endpoint, resource_name = endpoint) ⇒ Object private
-
#initialize(username, password) ⇒ Client
constructor
Initialize a Client object with TestDroid credentials.
- #post_api_request(endpoint, params = nil, resource_name = endpoint, extra_headers = {}) ⇒ Object private
-
#projects(name = nil) ⇒ Array<TestdroidApi::Client::Project>
List all projects.
Constructor Details
#initialize(username, password) ⇒ Client
Initialize a Client object with TestDroid credentials
10 11 12 13 14 |
# File 'lib/testdroid-api/client.rb', line 10 def initialize(username, password) @username = username @password = password @api_key = "" end |
Instance Method Details
#authenticate! ⇒ String
Authenticate client and retrieve apiKey
18 19 20 21 22 23 |
# File 'lib/testdroid-api/client.rb', line 18 def authenticate! response = post(USERS_URL, { "email" => @username, "password" => @password}) raise 'Could not authenticate, are you sure you have the right credentials?' if !response['secretApiKey'] @api_key = response['secretApiKey'] end |
#create_project(name, description) ⇒ TestdroidApi::Client::Project
Create new project
38 39 40 41 42 |
# File 'lib/testdroid-api/client.rb', line 38 def create_project(name, description) config = post_api_request('projects', { :name => name, :description => description }) Project.new(self, config) end |
#device_groups(name = nil) ⇒ Array<TestdroidApi::Client::DeviceGroup>
Get user’s clusters
47 48 49 50 51 |
# File 'lib/testdroid-api/client.rb', line 47 def device_groups(name = nil) devices = get_api_request('clusters') name ? find_device_groups_by(name, devices) : create_device_groups_from(devices) end |
#get_api_request(endpoint, resource_name = endpoint) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
60 61 62 63 |
# File 'lib/testdroid-api/client.rb', line 60 def get_api_request(endpoint, resource_name = endpoint) check_api_key get(get_endpoint(endpoint), get_auth_header(resource_name) ) end |
#get_file(endpoint, resource_name = endpoint) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
66 67 68 69 |
# File 'lib/testdroid-api/client.rb', line 66 def get_file(endpoint, resource_name = endpoint) check_api_key RestClient.get(get_endpoint(endpoint), get_auth_header(resource_name)) end |
#post_api_request(endpoint, params = nil, resource_name = endpoint, extra_headers = {}) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
54 55 56 57 |
# File 'lib/testdroid-api/client.rb', line 54 def post_api_request(endpoint, params = nil, resource_name = endpoint, extra_headers = {}) check_api_key post(get_endpoint(endpoint), params, get_auth_header(resource_name).merge(extra_headers)) end |
#projects(name = nil) ⇒ Array<TestdroidApi::Client::Project>
List all projects
28 29 30 31 32 |
# File 'lib/testdroid-api/client.rb', line 28 def projects(name = nil) configs = get_api_request('projects') name ? find_projects_by(name, configs) : create_projects_from(configs) end |