testdroid-api-client 0.3.0 → 0.4.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/.gitignore +2 -2
- data/.travis.yml +8 -0
- data/Gemfile.lock +39 -37
- data/README.md +26 -41
- data/lib/testdroid-api-client.rb +1 -4
- data/lib/testdroid-api-filter-builder.rb +1 -1
- data/lib/testdroid_api/admin.rb +5 -5
- data/lib/testdroid_api/admin_device_models.rb +1 -1
- data/lib/testdroid_api/admin_device_problems.rb +1 -1
- data/lib/testdroid_api/admin_device_statuses.rb +1 -1
- data/lib/testdroid_api/admin_devices.rb +1 -1
- data/lib/testdroid_api/apikey_client.rb +31 -31
- data/lib/testdroid_api/client.rb +39 -47
- data/lib/testdroid_api/cloud_list_resource.rb +11 -15
- data/lib/testdroid_api/cloud_resource.rb +7 -7
- data/lib/testdroid_api/device_groups.rb +2 -1
- data/lib/testdroid_api/device_session_connections.rb +1 -1
- data/lib/testdroid_api/device_sessions.rb +11 -2
- data/lib/testdroid_api/devices.rb +1 -1
- data/lib/testdroid_api/files.rb +8 -47
- data/lib/testdroid_api/frameworks.rb +11 -0
- data/lib/testdroid_api/label_groups.rb +1 -1
- data/lib/testdroid_api/labels.rb +1 -1
- data/lib/testdroid_api/projects.rb +2 -7
- data/lib/testdroid_api/properties.rb +1 -1
- data/lib/testdroid_api/runs.rb +12 -3
- data/lib/testdroid_api/services.rb +1 -1
- data/lib/testdroid_api/user.rb +7 -2
- data/sample/BitbarSampleApp.apk +0 -0
- data/sample/BitbarSampleAppTest.apk +0 -0
- data/sample/sample.rb +22 -27
- data/spec/client_spec.rb +7 -7
- data/spec/device_groups_spec.rb +30 -17
- data/spec/files_spec.rb +29 -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/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/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 +12 -12
- metadata +53 -162
- data/lib/testdroid_api/config.rb +0 -9
- data/lib/testdroid_api/device_runs.rb +0 -22
- data/lib/testdroid_api/file_sets.rb +0 -11
- data/lib/testdroid_api/parameters.rb +0 -10
- 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/pcp_delete_params.json +0 -1
- data/spec/fixtures/cassettes/pcp_get_current.json +0 -1
- data/spec/fixtures/cassettes/pcp_oauth2_auth_config.json +0 -1
- data/spec/fixtures/cassettes/pcp_set_current_config.json +0 -1
- data/spec/fixtures/cassettes/pcp_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_parameters_spec.rb +0 -44
- data/spec/project_config_spec.rb +0 -36
- data/spec/project_spec.rb +0 -56
- data/spec/run_spec.rb +0 -33
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 59a3631deeb2d0ef505009b5987c7e5af5b0c8d2f7056c1fde16e24bbccae782
|
4
|
+
data.tar.gz: 02b39bb056e015a3ff4bbec687ffaa12ed3f1e9f8b5340754b54c80c2b54cb56
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 5bc54840d45cd25008a0621119bf2f9fb567358ffb3b4a15811c341c526e133a126f09a54299c644672da94250830cff90de141306079d1b4eb092f21dc5a195
|
7
|
+
data.tar.gz: d5a7af777b03581c96b5b24626b912e2d6a89241000d0a5a1a2bef4b46e1efe031796b6f0b01da33243e5f7b54c5329f5cdde2529735386efd5e755528cd1c11
|
data/.gitignore
CHANGED
data/.travis.yml
ADDED
@@ -0,0 +1,8 @@
|
|
1
|
+
deploy:
|
2
|
+
provider: rubygems
|
3
|
+
api_key:
|
4
|
+
secure: ZFKOZzwgB1s4/vD9BDb7lFWCO7xXP3ikG2DBZSdASii5iHM46X9ox2wt8h2XZd9RFKe9pyenJP9RsXmRVGanFgZ0wGu+oveWfA7oIKp6Eb6pNOBPs8MG0ZifAGUc7Ih1JUMuvNuOPRJ+QGc5FwPsu0EoxZn3gQCZNqdMNBRe17o=
|
5
|
+
on:
|
6
|
+
tags: true
|
7
|
+
gem: testdroid-api-client
|
8
|
+
script: bundle exec rspec
|
data/Gemfile.lock
CHANGED
@@ -1,47 +1,49 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
testdroid-api-client (0.
|
5
|
-
deep_merge (~> 1.
|
6
|
-
faraday (~> 0.
|
7
|
-
oauth2 (~>
|
8
|
-
rest-client (~> 2.
|
4
|
+
testdroid-api-client (0.4.0)
|
5
|
+
deep_merge (~> 1.2)
|
6
|
+
faraday (~> 0.17, >= 0.17)
|
7
|
+
oauth2 (~> 1.4)
|
8
|
+
rest-client (~> 2.1)
|
9
9
|
|
10
10
|
GEM
|
11
11
|
remote: https://rubygems.org/
|
12
12
|
specs:
|
13
|
-
addressable (2.
|
14
|
-
public_suffix (
|
15
|
-
bump (0.
|
13
|
+
addressable (2.7.0)
|
14
|
+
public_suffix (>= 2.0.2, < 5.0)
|
15
|
+
bump (0.8.0)
|
16
16
|
crack (0.4.3)
|
17
17
|
safe_yaml (~> 1.0.0)
|
18
|
-
deep_merge (1.
|
18
|
+
deep_merge (1.2.1)
|
19
19
|
diff-lcs (1.2.5)
|
20
|
-
domain_name (0.5.
|
20
|
+
domain_name (0.5.20190701)
|
21
21
|
unf (>= 0.0.5, < 1.0.0)
|
22
|
-
faraday (0.
|
23
|
-
multipart-post (
|
24
|
-
hashdiff (0.
|
22
|
+
faraday (0.17.0)
|
23
|
+
multipart-post (>= 1.2, < 3)
|
24
|
+
hashdiff (1.0.0)
|
25
|
+
http-accept (1.7.0)
|
25
26
|
http-cookie (1.0.3)
|
26
27
|
domain_name (~> 0.5)
|
27
|
-
jwt (
|
28
|
-
mime-types (3.
|
28
|
+
jwt (2.2.1)
|
29
|
+
mime-types (3.3)
|
29
30
|
mime-types-data (~> 3.2015)
|
30
|
-
mime-types-data (3.
|
31
|
-
multi_json (1.
|
32
|
-
multi_xml (0.
|
33
|
-
multipart-post (1.
|
31
|
+
mime-types-data (3.2019.1009)
|
32
|
+
multi_json (1.14.1)
|
33
|
+
multi_xml (0.6.0)
|
34
|
+
multipart-post (2.1.1)
|
34
35
|
netrc (0.11.0)
|
35
|
-
oauth2 (
|
36
|
-
faraday (>= 0.8, < 0
|
37
|
-
jwt (
|
36
|
+
oauth2 (1.4.2)
|
37
|
+
faraday (>= 0.8, < 2.0)
|
38
|
+
jwt (>= 1.0, < 3.0)
|
38
39
|
multi_json (~> 1.3)
|
39
40
|
multi_xml (~> 0.5)
|
40
|
-
rack (
|
41
|
-
public_suffix (
|
42
|
-
rack (
|
41
|
+
rack (>= 1.2, < 3)
|
42
|
+
public_suffix (4.0.1)
|
43
|
+
rack (2.0.7)
|
43
44
|
rake (11.3.0)
|
44
|
-
rest-client (2.
|
45
|
+
rest-client (2.1.0)
|
46
|
+
http-accept (>= 1.7.0, < 2.0)
|
45
47
|
http-cookie (>= 1.0.2, < 2.0)
|
46
48
|
mime-types (>= 1.16, < 4.0)
|
47
49
|
netrc (~> 0.8)
|
@@ -60,29 +62,29 @@ GEM
|
|
60
62
|
diff-lcs (>= 1.2.0, < 2.0)
|
61
63
|
rspec-support (~> 3.5.0)
|
62
64
|
rspec-support (3.5.0)
|
63
|
-
safe_yaml (1.0.
|
65
|
+
safe_yaml (1.0.5)
|
64
66
|
unf (0.1.4)
|
65
67
|
unf_ext
|
66
|
-
unf_ext (0.0.7.
|
67
|
-
vcr (
|
68
|
-
webmock (
|
68
|
+
unf_ext (0.0.7.6)
|
69
|
+
vcr (5.0.0)
|
70
|
+
webmock (3.7.6)
|
69
71
|
addressable (>= 2.3.6)
|
70
72
|
crack (>= 0.3.2)
|
71
|
-
hashdiff
|
72
|
-
yard (0.9.
|
73
|
+
hashdiff (>= 0.4.0, < 2.0.0)
|
74
|
+
yard (0.9.20)
|
73
75
|
|
74
76
|
PLATFORMS
|
75
77
|
ruby
|
76
78
|
|
77
79
|
DEPENDENCIES
|
78
|
-
bump (~> 0.
|
80
|
+
bump (~> 0.8)
|
79
81
|
rake
|
80
82
|
rspec
|
81
83
|
rspec-collection_matchers
|
82
84
|
testdroid-api-client!
|
83
|
-
vcr (~>
|
84
|
-
webmock (~>
|
85
|
-
yard (~> 0.
|
85
|
+
vcr (~> 5.0)
|
86
|
+
webmock (~> 3.7)
|
87
|
+
yard (~> 0.9.20)
|
86
88
|
|
87
89
|
BUNDLED WITH
|
88
|
-
1.
|
90
|
+
1.17.3
|
data/README.md
CHANGED
@@ -1,6 +1,5 @@
|
|
1
1
|
Testdroid API Client for Ruby
|
2
|
-
|
3
|
-
|
2
|
+
=============================
|
4
3
|
|
5
4
|
## Installation
|
6
5
|
|
@@ -12,17 +11,20 @@ gem "testdroid-api-client"
|
|
12
11
|
```bash
|
13
12
|
> bundle install
|
14
13
|
```
|
14
|
+
|
15
15
|
## Sample client usage - Authenticate
|
16
16
|
```ruby
|
17
17
|
require 'testdroid-api-client'
|
18
18
|
|
19
19
|
client = TestdroidAPI::Client.new('admin@localhost', 'admin')
|
20
20
|
```
|
21
|
+
|
21
22
|
## Sample usage - get projects
|
22
23
|
```ruby
|
23
24
|
@user = client.authorize
|
24
25
|
projects = @user.projects.list
|
25
26
|
```
|
27
|
+
|
26
28
|
## Get project by id
|
27
29
|
```ruby
|
28
30
|
project_id = 123
|
@@ -33,61 +35,44 @@ p "Project name #{project123.name}"
|
|
33
35
|
|
34
36
|
## Get project by name
|
35
37
|
```ruby
|
36
|
-
|
38
|
+
project = @user.projects.list({:filter => "s_name_eq_MyProject"})[0]
|
37
39
|
```
|
38
40
|
|
39
|
-
|
40
|
-
## Start project
|
41
|
+
## Get available frameworks
|
41
42
|
```ruby
|
42
|
-
|
43
|
+
frameworks = @user.available_frameworks.list
|
43
44
|
```
|
44
45
|
|
45
|
-
##
|
46
|
-
```ruby
|
47
|
-
p "Project state #{test_run.state}"
|
48
|
-
|
49
|
-
```
|
50
|
-
## Download all logs from test run
|
46
|
+
## Find specific framework
|
51
47
|
```ruby
|
52
|
-
|
48
|
+
framework = @user.available_frameworks.list({:filter => "s_osType_eq_ANDROID;s_name_like_%Instrumentation"})[0]
|
53
49
|
```
|
54
50
|
|
55
|
-
##
|
51
|
+
## Upload files
|
56
52
|
```ruby
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
os_v2_1 = client.label_groups.get(lg_android_versions.id).labels.list.detect {|l| l.display_name.casecmp("2.1") == 0 }
|
61
|
-
|
62
|
-
#get all devices with android os level 2.1
|
63
|
-
devices = client.label_groups.get(lg_android_versions.id).labels.get(os_v2_1.id).devices
|
64
|
-
#get spefici device from devices list
|
65
|
-
lenovo_a820 = devices.list.detect {|d| d.display_name == "Lenovo A820"}
|
66
|
-
|
53
|
+
file_app = @user.files.upload(File.join(File.dirname(__FILE__), "BitbarSampleApp.apk"))
|
54
|
+
file_test = @user.files.upload(File.join(File.dirname(__FILE__), "BitbarSampleAppTest.apk"))
|
67
55
|
```
|
68
56
|
|
69
|
-
|
70
|
-
Device Sessions
|
71
|
-
----
|
57
|
+
## Start test run
|
72
58
|
```ruby
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
#release device session:
|
77
|
-
device_session.release()
|
59
|
+
test_run = @user.runs.create("{\"osType\": \"ANDROID\", \"projectId\": #{project.id}, \"frameworkId\":#{framework_id},
|
60
|
+
\"deviceIds\": #{id_list}, \"files\": [{\"id\": #{file_app.id}, \"action\": \"INSTALL\" },
|
61
|
+
{\"id\": #{file_test.id}, \"action\": \"RUN_TEST\" }]}")
|
78
62
|
|
63
|
+
#See full list of params: https://docs.bitbar.com/testing/api/tests/index.html#details-about-the-configuration-fields
|
79
64
|
```
|
80
65
|
|
81
|
-
|
82
|
-
Project configuration
|
83
|
-
----
|
66
|
+
## Download all files from test run
|
84
67
|
```ruby
|
85
|
-
|
86
|
-
android_project = @user.projects.list.detect {|project| project.name.casecmp("Android Project") == 0 }
|
87
|
-
android_project.config.update({:params => {'instrumentationRunner' => 'abc'}})
|
88
|
-
#See full list of params: http://docs.testdroid.com/_pages/client.html#update-project-config
|
89
|
-
|
68
|
+
test_run.device_sessions.list({:limit => 0}).each { |ds| ds.download_all_files("YOUR_PATH") }
|
90
69
|
```
|
91
70
|
|
71
|
+
## Get all input files
|
72
|
+
```ruby
|
73
|
+
files = @user.files
|
74
|
+
files.list({:limit => 40,:filter => "s_direction_eq_INPUT"}).each {
|
75
|
+
|f| puts "File id: #{f.id} name: #{f.name}" }
|
76
|
+
```
|
92
77
|
|
93
|
-
See https://cloud.
|
78
|
+
See https://cloud.bitbar.com/cloud/swagger-ui.html for more details about API V2
|
data/lib/testdroid-api-client.rb
CHANGED
@@ -12,19 +12,16 @@ require 'testdroid_api/cloud_resource'
|
|
12
12
|
require 'testdroid_api/cloud_list_resource'
|
13
13
|
|
14
14
|
require 'testdroid_api/user'
|
15
|
+
require 'testdroid_api/frameworks'
|
15
16
|
require 'testdroid_api/projects'
|
16
17
|
require 'testdroid_api/runs'
|
17
18
|
require 'testdroid_api/devices'
|
18
19
|
require 'testdroid_api/device_groups'
|
19
|
-
require 'testdroid_api/device_runs'
|
20
20
|
require 'testdroid_api/device_sessions'
|
21
21
|
require 'testdroid_api/device_session_connections'
|
22
22
|
require 'testdroid_api/labels'
|
23
23
|
require 'testdroid_api/label_groups'
|
24
24
|
require 'testdroid_api/files'
|
25
|
-
require 'testdroid_api/file_sets'
|
26
|
-
require 'testdroid_api/config'
|
27
|
-
require 'testdroid_api/parameters'
|
28
25
|
require 'testdroid_api/properties'
|
29
26
|
require 'testdroid_api/services'
|
30
27
|
|
data/lib/testdroid_api/admin.rb
CHANGED
@@ -1,24 +1,24 @@
|
|
1
1
|
module TestdroidAPI
|
2
2
|
class Admin < CloudResource
|
3
|
-
def initialize(uri, client, params= {})
|
3
|
+
def initialize(uri, client, params = {})
|
4
4
|
super uri, client, "admin", params
|
5
5
|
@uri, @client = uri, client
|
6
6
|
end
|
7
7
|
|
8
8
|
def device_statuses
|
9
|
-
AdminDeviceStatuses.new(@uri+"/device/statuses", @client)
|
9
|
+
AdminDeviceStatuses.new(@uri + "/device/statuses", @client)
|
10
10
|
end
|
11
11
|
|
12
12
|
def device_problems
|
13
|
-
AdminDeviceProblems.new(@uri+"/device-problems", @client)
|
13
|
+
AdminDeviceProblems.new(@uri + "/device-problems", @client)
|
14
14
|
end
|
15
15
|
|
16
16
|
def device_models
|
17
|
-
AdminDeviceModels.new(@uri+"/device-models", @client)
|
17
|
+
AdminDeviceModels.new(@uri + "/device-models", @client)
|
18
18
|
end
|
19
19
|
|
20
20
|
def devices
|
21
|
-
AdminDevices.new(@uri+"/devices", @client)
|
21
|
+
AdminDevices.new(@uri + "/devices", @client)
|
22
22
|
end
|
23
23
|
|
24
24
|
end
|
@@ -2,7 +2,7 @@ module TestdroidAPI
|
|
2
2
|
class AdminDeviceModels < CloudListResource
|
3
3
|
end
|
4
4
|
class AdminDeviceModel < CloudResource
|
5
|
-
def initialize(uri, client, params= {})
|
5
|
+
def initialize(uri, client, params = {})
|
6
6
|
super uri, client, "adminDeviceModel", params
|
7
7
|
@uri, @client = uri, client
|
8
8
|
end
|
@@ -5,8 +5,7 @@ module TestdroidAPI
|
|
5
5
|
attr_accessor :logger
|
6
6
|
|
7
7
|
API_VERSION = 'api/v2'
|
8
|
-
CLOUD_ENDPOINT = 'https://cloud.
|
9
|
-
ACCEPT_HEADERS = {'Accept' => 'application/json'}
|
8
|
+
CLOUD_ENDPOINT = 'https://cloud.bitbar.com'
|
10
9
|
|
11
10
|
def initialize(api_key, cloud_url = CLOUD_ENDPOINT, logger = nil)
|
12
11
|
# Instance variables
|
@@ -21,33 +20,34 @@ module TestdroidAPI
|
|
21
20
|
end
|
22
21
|
|
23
22
|
def authorize
|
24
|
-
|
25
|
-
if
|
26
|
-
@cloud_user = TestdroidAPI::User.new(
|
27
|
-
@cloud_user = TestdroidAPI::User.new(
|
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
|
28
27
|
|
29
28
|
end
|
30
29
|
@cloud_user
|
31
30
|
end
|
31
|
+
|
32
32
|
# Basic methods
|
33
33
|
|
34
|
-
def request_factory(method, uri, http_params = {})
|
34
|
+
def request_factory(method, uri, http_params = {}, headers = {})
|
35
35
|
default_http_params = {
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
36
|
+
:method => method,
|
37
|
+
:url => uri,
|
38
|
+
:user => @api_key,
|
39
|
+
:password => "",
|
40
|
+
:headers => headers
|
41
41
|
}
|
42
42
|
request_http_params = default_http_params.deep_merge!(http_params)
|
43
43
|
|
44
44
|
RestClient::Request.new(request_http_params)
|
45
45
|
end
|
46
46
|
|
47
|
-
def get(uri, params={}, http_params={})
|
48
|
-
uri = @cloud_url+uri
|
47
|
+
def get(uri, params = {}, http_params = {})
|
48
|
+
uri = @cloud_url + uri
|
49
49
|
begin
|
50
|
-
http_params = http_params.deep_merge({
|
50
|
+
http_params = http_params.deep_merge({:headers => {:params => params}})
|
51
51
|
request = self.request_factory(:get, uri, http_params)
|
52
52
|
resp = request.execute
|
53
53
|
rescue => e
|
@@ -57,11 +57,13 @@ module TestdroidAPI
|
|
57
57
|
JSON.parse(resp.body)
|
58
58
|
end
|
59
59
|
|
60
|
-
def post(uri, params={}, http_params={})
|
61
|
-
uri = @cloud_url+uri
|
60
|
+
def post(uri, params = {}, http_params = {})
|
61
|
+
uri = @cloud_url + uri
|
62
62
|
begin
|
63
|
-
|
64
|
-
|
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)
|
65
67
|
resp = request.execute
|
66
68
|
rescue => e
|
67
69
|
@logger.error "Failed to post resource #{uri} #{e}"
|
@@ -76,7 +78,7 @@ module TestdroidAPI
|
|
76
78
|
end
|
77
79
|
|
78
80
|
def delete(uri)
|
79
|
-
uri = @cloud_url+uri
|
81
|
+
uri = @cloud_url + uri
|
80
82
|
begin
|
81
83
|
request = self.request_factory(:delete, uri)
|
82
84
|
resp = request.execute
|
@@ -85,26 +87,26 @@ module TestdroidAPI
|
|
85
87
|
return nil
|
86
88
|
end
|
87
89
|
|
88
|
-
if
|
90
|
+
if resp.code != 204
|
89
91
|
@logger.error "Failed to delete resource #{uri} #{e}"
|
90
|
-
return nil
|
91
92
|
else
|
92
|
-
@logger.info "response: #{resp.
|
93
|
+
@logger.info "response: #{resp.code}"
|
93
94
|
end
|
94
95
|
end
|
95
96
|
|
96
97
|
def upload(uri, file_name)
|
97
98
|
self.post(uri, {
|
98
|
-
|
99
|
-
|
99
|
+
:multipart => true,
|
100
|
+
:file => ::File.new(file_name, 'rb')
|
100
101
|
})
|
101
102
|
end
|
102
103
|
|
103
|
-
def download(uri, file_name, params={}, http_params={})
|
104
|
+
def download(uri, file_name, params = {}, http_params = {})
|
104
105
|
begin
|
105
|
-
File.open(file_name, "w+b") do |file|
|
106
|
-
|
107
|
-
|
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)
|
108
110
|
resp = request.execute
|
109
111
|
file.write(resp.body)
|
110
112
|
end
|
@@ -114,7 +116,5 @@ module TestdroidAPI
|
|
114
116
|
end
|
115
117
|
end
|
116
118
|
|
117
|
-
|
118
|
-
|
119
119
|
end
|
120
120
|
end
|