testdroid-api-client 0.2.2 → 0.5.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/.gitignore +5 -0
- data/.travis.yml +11 -0
- data/Gemfile.lock +65 -37
- data/README.md +30 -41
- data/lib/testdroid-api-client.rb +25 -9
- data/lib/testdroid-api-filter-builder.rb +145 -0
- data/lib/testdroid_api/admin.rb +25 -0
- data/lib/testdroid_api/admin_device_models.rb +10 -0
- data/lib/testdroid_api/admin_device_problems.rb +9 -0
- data/lib/testdroid_api/admin_device_statuses.rb +12 -0
- data/lib/testdroid_api/admin_devices.rb +10 -0
- data/lib/testdroid_api/apikey_client.rb +120 -0
- data/lib/testdroid_api/client.rb +158 -123
- data/lib/testdroid_api/cloud_list_resource.rb +69 -70
- data/lib/testdroid_api/cloud_resource.rb +83 -71
- data/lib/testdroid_api/device_groups.rb +9 -9
- data/lib/testdroid_api/device_session_connections.rb +10 -0
- data/lib/testdroid_api/device_sessions.rb +21 -12
- data/lib/testdroid_api/devices.rb +8 -11
- data/lib/testdroid_api/files.rb +60 -58
- data/lib/testdroid_api/frameworks.rb +11 -0
- data/lib/testdroid_api/label_groups.rb +9 -10
- data/lib/testdroid_api/labels.rb +9 -10
- data/lib/testdroid_api/projects.rb +9 -16
- data/lib/testdroid_api/properties.rb +13 -0
- data/lib/testdroid_api/runs.rb +22 -12
- data/lib/testdroid_api/services.rb +18 -0
- data/lib/testdroid_api/user.rb +11 -6
- data/sample/BitbarSampleApp.apk +0 -0
- data/sample/BitbarSampleAppTest.apk +0 -0
- data/sample/sample.rb +23 -23
- data/spec/client_spec.rb +7 -7
- data/spec/device_groups_spec.rb +30 -17
- data/spec/files_spec.rb +40 -20
- data/spec/fixtures/apk.apk +0 -0
- data/spec/fixtures/cassettes/device_groups_authorize.json +1 -0
- data/spec/fixtures/cassettes/device_groups_create.json +1 -0
- data/spec/fixtures/cassettes/device_groups_delete.json +1 -0
- data/spec/fixtures/cassettes/device_groups_get_all.json +1 -0
- data/spec/fixtures/cassettes/device_groups_get_one.json +1 -0
- data/spec/fixtures/cassettes/files_authorize.json +1 -0
- data/spec/fixtures/cassettes/files_delete.json +1 -0
- data/spec/fixtures/cassettes/files_get_all.json +1 -0
- data/spec/fixtures/cassettes/files_get_one.json +1 -0
- data/spec/fixtures/cassettes/files_upload.json +1 -0
- data/spec/fixtures/cassettes/files_upload_with_wait.json +1 -0
- data/spec/fixtures/cassettes/label_groups_authorize.json +1 -0
- data/spec/fixtures/cassettes/label_groups_create.json +1 -0
- data/spec/fixtures/cassettes/label_groups_delete.json +1 -0
- data/spec/fixtures/cassettes/label_groups_get_all.json +1 -0
- data/spec/fixtures/cassettes/label_groups_get_labels.json +1 -0
- data/spec/fixtures/cassettes/label_groups_get_one.json +1 -0
- data/spec/fixtures/cassettes/projects_authorize.json +1 -0
- data/spec/fixtures/cassettes/projects_create.json +1 -0
- data/spec/fixtures/cassettes/projects_delete.json +1 -0
- data/spec/fixtures/cassettes/projects_get_all.json +1 -0
- data/spec/fixtures/cassettes/projects_get_one.json +1 -0
- data/spec/fixtures/cassettes/runs_abort_run.json +1 -0
- data/spec/fixtures/cassettes/runs_authorize.json +1 -0
- data/spec/fixtures/cassettes/runs_get_project_runs.json +1 -0
- data/spec/fixtures/cassettes/runs_start_run.json +1 -0
- data/spec/fixtures/data.txt +1 -0
- data/spec/fixtures/data2.txt +1 -0
- data/spec/label_groups_spec.rb +35 -42
- data/spec/projects_spec.rb +41 -0
- data/spec/runs_spec.rb +41 -0
- data/spec/spec_helper.rb +3 -4
- data/testdroid-api-client.gemspec +13 -11
- metadata +92 -134
- data/lib/testdroid_api/config.rb +0 -7
- data/lib/testdroid_api/device_runs.rb +0 -20
- data/lib/testdroid_api/file_sets.rb +0 -12
- data/spec/device_runs_spec.rb +0 -25
- data/spec/file_sets_spec.rb +0 -47
- data/spec/fixtures/cassettes/dg_all_device_groups.json +0 -1
- data/spec/fixtures/cassettes/dg_device_group_4165.json +0 -1
- data/spec/fixtures/cassettes/dg_oauth2_auth_device_groups.json +0 -1
- data/spec/fixtures/cassettes/dr_all_run_171221_device_runs.json +0 -1
- data/spec/fixtures/cassettes/dr_device_run_33044722.json +0 -1
- data/spec/fixtures/cassettes/dr_oauth2_auth_device_runs.json +0 -1
- data/spec/fixtures/cassettes/dr_run_33044722_device_runs.json +0 -1
- data/spec/fixtures/cassettes/f_add_file_set.json +0 -1
- data/spec/fixtures/cassettes/f_android_app_file.json +0 -1
- data/spec/fixtures/cassettes/f_file_sets.json +0 -1
- data/spec/fixtures/cassettes/f_oauth2_auth_files.json +0 -1
- data/spec/fixtures/cassettes/f_upload_files.json +0 -1
- data/spec/fixtures/cassettes/fs_add_file_set.json +0 -1
- data/spec/fixtures/cassettes/fs_add_file_to_fileset.json +0 -1
- data/spec/fixtures/cassettes/fs_delete_file_set.json +0 -1
- data/spec/fixtures/cassettes/fs_file_sets.json +0 -1
- data/spec/fixtures/cassettes/fs_get_file_set.json +0 -1
- data/spec/fixtures/cassettes/fs_oauth2_auth_files.json +0 -1
- data/spec/fixtures/cassettes/fs_update_file_set.json +0 -1
- data/spec/fixtures/cassettes/fu_oauth2_auth_files.json +0 -1
- data/spec/fixtures/cassettes/lg_all_label_groups.json +0 -1
- data/spec/fixtures/cassettes/lg_get_resources_by_label.json +0 -1
- data/spec/fixtures/cassettes/lg_label_group_1058800.json +0 -1
- data/spec/fixtures/cassettes/lg_labels_of_group_1058800.json +0 -1
- data/spec/fixtures/cassettes/lg_oauth2_auth_label_groups.json +0 -1
- data/spec/fixtures/cassettes/p_all_projects.json +0 -1
- data/spec/fixtures/cassettes/p_create_project.json +0 -1
- data/spec/fixtures/cassettes/p_get_run_devices.json +0 -1
- data/spec/fixtures/cassettes/p_oauth2_auth.json +0 -1
- data/spec/fixtures/cassettes/p_oauth2_local.json +0 -1
- data/spec/fixtures/cassettes/p_project_id_33029366.json +0 -1
- data/spec/fixtures/cassettes/p_run_project.json +0 -1
- data/spec/fixtures/cassettes/pc_get_current.json +0 -1
- data/spec/fixtures/cassettes/pc_oauth2_auth_config.json +0 -1
- data/spec/fixtures/cassettes/pc_set_current_config.json +0 -1
- data/spec/fixtures/cassettes/pc_validate_config.json +0 -1
- data/spec/fixtures/cassettes/r_all_project_33029366_runs.json +0 -1
- data/spec/fixtures/cassettes/r_delete_test_run.json +0 -1
- data/spec/fixtures/cassettes/r_oauth2_auth_runs.json +0 -1
- data/spec/fixtures/cassettes/r_run_171221.json +0 -1
- data/spec/fixtures/cassettes/r_run_project.json +0 -1
- data/spec/fixtures/cassettes/upload_files.json +0 -1
- data/spec/fixtures/project.json +0 -8
- data/spec/project_config_spec.rb +0 -36
- data/spec/project_spec.rb +0 -56
- data/spec/run_spec.rb +0 -33
@@ -0,0 +1,25 @@
|
|
1
|
+
module TestdroidAPI
|
2
|
+
class Admin < CloudResource
|
3
|
+
def initialize(uri, client, params = {})
|
4
|
+
super uri, client, "admin", params
|
5
|
+
@uri, @client = uri, client
|
6
|
+
end
|
7
|
+
|
8
|
+
def device_statuses
|
9
|
+
AdminDeviceStatuses.new(@uri + "/device/statuses", @client)
|
10
|
+
end
|
11
|
+
|
12
|
+
def device_problems
|
13
|
+
AdminDeviceProblems.new(@uri + "/device-problems", @client)
|
14
|
+
end
|
15
|
+
|
16
|
+
def device_models
|
17
|
+
AdminDeviceModels.new(@uri + "/device-models", @client)
|
18
|
+
end
|
19
|
+
|
20
|
+
def devices
|
21
|
+
AdminDevices.new(@uri + "/devices", @client)
|
22
|
+
end
|
23
|
+
|
24
|
+
end
|
25
|
+
end
|
@@ -0,0 +1,12 @@
|
|
1
|
+
module TestdroidAPI
|
2
|
+
class AdminDeviceStatuses < CloudListResource
|
3
|
+
def initialize(uri, client)
|
4
|
+
super uri, client, "AdminDeviceStatus"
|
5
|
+
end
|
6
|
+
end
|
7
|
+
class AdminDeviceStatus < CloudResource
|
8
|
+
def initialize(uri, client, params = {})
|
9
|
+
super uri, client, "adminDeviceStatus", params
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
@@ -0,0 +1,120 @@
|
|
1
|
+
module TestdroidAPI
|
2
|
+
class ApikeyClient < Client
|
3
|
+
|
4
|
+
attr_reader :config
|
5
|
+
attr_accessor :logger
|
6
|
+
|
7
|
+
API_VERSION = 'api/v2'
|
8
|
+
CLOUD_ENDPOINT = 'https://cloud.bitbar.com'
|
9
|
+
|
10
|
+
def initialize(api_key, cloud_url = CLOUD_ENDPOINT, logger = nil)
|
11
|
+
# Instance variables
|
12
|
+
@api_key = api_key
|
13
|
+
@cloud_url = cloud_url
|
14
|
+
@logger = logger
|
15
|
+
|
16
|
+
if @logger.nil?
|
17
|
+
@logger = Logger.new(STDOUT)
|
18
|
+
@logger.info("Logger is not defined => output to STDOUT")
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
def authorize
|
23
|
+
|
24
|
+
if @cloud_user.nil?
|
25
|
+
@cloud_user = TestdroidAPI::User.new("/#{API_VERSION}/me", self).refresh
|
26
|
+
@cloud_user = TestdroidAPI::User.new("/#{API_VERSION}/users/#{@cloud_user.id}", self).refresh
|
27
|
+
|
28
|
+
end
|
29
|
+
@cloud_user
|
30
|
+
end
|
31
|
+
|
32
|
+
# Basic methods
|
33
|
+
|
34
|
+
def request_factory(method, uri, http_params = {}, headers = {})
|
35
|
+
default_http_params = {
|
36
|
+
:method => method,
|
37
|
+
:url => uri,
|
38
|
+
:user => @api_key,
|
39
|
+
:password => "",
|
40
|
+
:headers => headers
|
41
|
+
}
|
42
|
+
request_http_params = default_http_params.deep_merge!(http_params)
|
43
|
+
|
44
|
+
RestClient::Request.new(request_http_params)
|
45
|
+
end
|
46
|
+
|
47
|
+
def get(uri, params = {}, http_params = {})
|
48
|
+
uri = @cloud_url + uri
|
49
|
+
begin
|
50
|
+
http_params = http_params.deep_merge({:headers => {:params => params}})
|
51
|
+
request = self.request_factory(:get, uri, http_params)
|
52
|
+
resp = request.execute
|
53
|
+
rescue => e
|
54
|
+
@logger.error "Failed to get resource #{uri} #{e}"
|
55
|
+
return nil
|
56
|
+
end
|
57
|
+
JSON.parse(resp.body)
|
58
|
+
end
|
59
|
+
|
60
|
+
def post(uri, params = {}, http_params = {})
|
61
|
+
uri = @cloud_url + uri
|
62
|
+
begin
|
63
|
+
payload = params.fetch(:body, params)
|
64
|
+
headers = params.fetch(:headers, {})
|
65
|
+
http_params = http_params.deep_merge({:payload => payload})
|
66
|
+
request = self.request_factory(:post, uri, http_params, headers)
|
67
|
+
resp = request.execute
|
68
|
+
rescue => e
|
69
|
+
@logger.error "Failed to post resource #{uri} #{e}"
|
70
|
+
return nil
|
71
|
+
end
|
72
|
+
|
73
|
+
if resp.body.nil? || resp.body.length == 0
|
74
|
+
return nil
|
75
|
+
end
|
76
|
+
|
77
|
+
JSON.parse(resp.body)
|
78
|
+
end
|
79
|
+
|
80
|
+
def delete(uri)
|
81
|
+
uri = @cloud_url + uri
|
82
|
+
begin
|
83
|
+
request = self.request_factory(:delete, uri)
|
84
|
+
resp = request.execute
|
85
|
+
rescue => e
|
86
|
+
@logger.error "Failed to delete resource #{uri} #{e}"
|
87
|
+
return nil
|
88
|
+
end
|
89
|
+
|
90
|
+
if resp.code != 204
|
91
|
+
@logger.error "Failed to delete resource #{uri} #{e}"
|
92
|
+
else
|
93
|
+
@logger.info "response: #{resp.code}"
|
94
|
+
end
|
95
|
+
end
|
96
|
+
|
97
|
+
def upload(uri, file_name)
|
98
|
+
self.post(uri, {
|
99
|
+
:multipart => true,
|
100
|
+
:file => ::File.new(file_name, 'rb')
|
101
|
+
})
|
102
|
+
end
|
103
|
+
|
104
|
+
def download(uri, file_name, params = {}, http_params = {})
|
105
|
+
begin
|
106
|
+
::File.open(file_name, "w+b") do |file|
|
107
|
+
full_uri = uri.start_with?(@cloud_url) ? uri : @cloud_url + uri
|
108
|
+
http_params = http_params.deep_merge({:headers => {:params => params}})
|
109
|
+
request = self.request_factory(:get, full_uri, http_params)
|
110
|
+
resp = request.execute
|
111
|
+
file.write(resp.body)
|
112
|
+
end
|
113
|
+
rescue => e
|
114
|
+
@logger.error "Failed to get resource #{uri} #{e}"
|
115
|
+
return nil
|
116
|
+
end
|
117
|
+
end
|
118
|
+
|
119
|
+
end
|
120
|
+
end
|
data/lib/testdroid_api/client.rb
CHANGED
@@ -1,126 +1,161 @@
|
|
1
1
|
module TestdroidAPI
|
2
2
|
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
3
|
+
class Client
|
4
|
+
attr_reader :config
|
5
|
+
attr_accessor :logger
|
6
|
+
attr_reader :token
|
7
|
+
|
8
|
+
API_VERSION = 'api/v2'
|
9
|
+
CLOUD_ENDPOINT = 'https://cloud.bitbar.com'
|
10
|
+
|
11
|
+
def initialize(username, password, cloud_url = CLOUD_ENDPOINT, logger = nil)
|
12
|
+
# Instance variables
|
13
|
+
@username = username
|
14
|
+
@password = password
|
15
|
+
@cloud_url = cloud_url
|
16
|
+
@logger = logger
|
17
|
+
|
18
|
+
if @logger.nil?
|
19
|
+
@logger = Logger.new(STDOUT)
|
20
|
+
@logger.info("Logger is not defined => output to STDOUT")
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
def authorize
|
25
|
+
@client = OAuth2::Client.new(
|
26
|
+
'testdroid-cloud-api', nil, :site => @cloud_url, :token_url => 'oauth/token') do |faraday|
|
27
|
+
faraday.request :multipart
|
28
|
+
faraday.request :url_encoded
|
29
|
+
faraday.response :logger, @logger
|
30
|
+
faraday.adapter Faraday.default_adapter
|
31
|
+
end
|
32
|
+
|
33
|
+
@token = @client.password.get_token(@username, @password)
|
34
|
+
|
35
|
+
if @cloud_user.nil?
|
36
|
+
@cloud_user = TestdroidAPI::User.new("/#{API_VERSION}/me", self).refresh
|
37
|
+
@cloud_user = TestdroidAPI::User.new("/#{API_VERSION}/users/#{@cloud_user.id}", self).refresh
|
38
|
+
|
39
|
+
end
|
40
|
+
@cloud_user
|
41
|
+
end
|
42
|
+
|
43
|
+
def mime_for(path)
|
44
|
+
mime = MIME::Types.type_for path
|
45
|
+
mime.empty? ? 'text/plain' : mime[0].content_type
|
46
|
+
end
|
47
|
+
|
48
|
+
def upload(uri, filename)
|
49
|
+
begin
|
50
|
+
@token = @token.refresh! if @token.expired?
|
51
|
+
connection = @token.client.connection
|
52
|
+
payload = {:file => Faraday::UploadIO.new(filename, mime_for(filename))}
|
53
|
+
response = connection.post(@cloud_url + "#{uri}", payload, @token.headers)
|
54
|
+
rescue => e
|
55
|
+
@logger.error e
|
56
|
+
return nil
|
57
|
+
end
|
58
|
+
JSON.parse(response.body)
|
59
|
+
end
|
60
|
+
|
61
|
+
def post(uri, params = {})
|
62
|
+
|
63
|
+
@token = @token.refresh! if @token.expired?
|
64
|
+
|
65
|
+
begin
|
66
|
+
resp = @token.post("#{@cloud_url}#{uri}", params)
|
67
|
+
rescue => e
|
68
|
+
@logger.error "Failed to post resource #{uri} #{e}"
|
69
|
+
return nil
|
70
|
+
end
|
71
|
+
|
72
|
+
if resp.body.nil? || resp.body.length == 0
|
73
|
+
return nil
|
74
|
+
end
|
75
|
+
|
76
|
+
JSON.parse(resp.body)
|
77
|
+
end
|
78
|
+
|
79
|
+
def get(uri, params = {})
|
80
|
+
|
81
|
+
@token = @token.refresh! if @token.expired?
|
82
|
+
|
83
|
+
begin
|
84
|
+
resp = @token.get(@cloud_url + "#{uri}", :params => params)
|
85
|
+
rescue => e
|
86
|
+
@logger.error "Failed to get resource #{uri} #{e}"
|
87
|
+
return nil
|
88
|
+
end
|
89
|
+
JSON.parse(resp.body)
|
90
|
+
end
|
91
|
+
|
92
|
+
def delete(uri)
|
93
|
+
|
94
|
+
@token = @token.refresh! if @token.expired?
|
95
|
+
|
96
|
+
begin
|
97
|
+
resp = @token.delete(@cloud_url + "#{uri}")
|
98
|
+
rescue => e
|
99
|
+
@logger.error "Failed to delete resource #{uri} #{e}"
|
100
|
+
return nil
|
101
|
+
end
|
102
|
+
|
103
|
+
if resp.status != 204
|
104
|
+
@logger.error "Failed to delete resource #{uri} #{e}"
|
105
|
+
else
|
106
|
+
@logger.info "response: #{resp.status}"
|
107
|
+
end
|
108
|
+
end
|
109
|
+
|
110
|
+
def download(uri, file_name)
|
111
|
+
begin
|
112
|
+
@token = @token.refresh! if @token.expired?
|
113
|
+
::File.open(file_name, "w+b") do |file|
|
114
|
+
full_uri = uri.start_with?(@cloud_url) ? uri : @cloud_url + uri
|
115
|
+
resp = @token.get(full_uri)
|
116
|
+
file.write(resp.body)
|
117
|
+
end
|
118
|
+
rescue => e
|
119
|
+
@logger.error "Failed to get resource #{uri} #{e}"
|
120
|
+
return nil
|
121
|
+
end
|
122
|
+
end
|
123
|
+
|
124
|
+
# Resources
|
125
|
+
|
126
|
+
# public read-only
|
127
|
+
|
128
|
+
def info
|
129
|
+
TestdroidAPI::CloudResource.new("/#{API_VERSION}/info", self, "info")
|
130
|
+
end
|
131
|
+
|
132
|
+
def devices
|
133
|
+
TestdroidAPI::Devices.new("/#{API_VERSION}/devices", self)
|
134
|
+
end
|
135
|
+
|
136
|
+
def label_groups
|
137
|
+
TestdroidAPI::LabelGroups.new("/#{API_VERSION}/label-groups", self)
|
138
|
+
end
|
139
|
+
|
140
|
+
# user read-write
|
141
|
+
|
142
|
+
def me
|
143
|
+
TestdroidAPI::User.new("/#{API_VERSION}/me", self).load
|
144
|
+
end
|
145
|
+
|
146
|
+
def properties
|
147
|
+
TestdroidAPI::Properties.new("/#{API_VERSION}/properties", self)
|
148
|
+
end
|
149
|
+
|
150
|
+
def device_session_connections
|
151
|
+
TestdroidAPI::DeviceSessionConnections.new("/#{API_VERSION}/device-session-connections", self)
|
152
|
+
end
|
153
|
+
|
154
|
+
# admin only
|
155
|
+
|
156
|
+
def admin
|
157
|
+
TestdroidAPI::Admin.new("/#{API_VERSION}/admin", self)
|
158
|
+
end
|
159
|
+
|
160
|
+
end
|
126
161
|
end
|