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.
Files changed (125) hide show
  1. checksums.yaml +5 -5
  2. data/.gitignore +2 -2
  3. data/.travis.yml +8 -0
  4. data/Gemfile.lock +39 -37
  5. data/README.md +26 -41
  6. data/lib/testdroid-api-client.rb +1 -4
  7. data/lib/testdroid-api-filter-builder.rb +1 -1
  8. data/lib/testdroid_api/admin.rb +5 -5
  9. data/lib/testdroid_api/admin_device_models.rb +1 -1
  10. data/lib/testdroid_api/admin_device_problems.rb +1 -1
  11. data/lib/testdroid_api/admin_device_statuses.rb +1 -1
  12. data/lib/testdroid_api/admin_devices.rb +1 -1
  13. data/lib/testdroid_api/apikey_client.rb +31 -31
  14. data/lib/testdroid_api/client.rb +39 -47
  15. data/lib/testdroid_api/cloud_list_resource.rb +11 -15
  16. data/lib/testdroid_api/cloud_resource.rb +7 -7
  17. data/lib/testdroid_api/device_groups.rb +2 -1
  18. data/lib/testdroid_api/device_session_connections.rb +1 -1
  19. data/lib/testdroid_api/device_sessions.rb +11 -2
  20. data/lib/testdroid_api/devices.rb +1 -1
  21. data/lib/testdroid_api/files.rb +8 -47
  22. data/lib/testdroid_api/frameworks.rb +11 -0
  23. data/lib/testdroid_api/label_groups.rb +1 -1
  24. data/lib/testdroid_api/labels.rb +1 -1
  25. data/lib/testdroid_api/projects.rb +2 -7
  26. data/lib/testdroid_api/properties.rb +1 -1
  27. data/lib/testdroid_api/runs.rb +12 -3
  28. data/lib/testdroid_api/services.rb +1 -1
  29. data/lib/testdroid_api/user.rb +7 -2
  30. data/sample/BitbarSampleApp.apk +0 -0
  31. data/sample/BitbarSampleAppTest.apk +0 -0
  32. data/sample/sample.rb +22 -27
  33. data/spec/client_spec.rb +7 -7
  34. data/spec/device_groups_spec.rb +30 -17
  35. data/spec/files_spec.rb +29 -20
  36. data/spec/fixtures/apk.apk +0 -0
  37. data/spec/fixtures/cassettes/device_groups_authorize.json +1 -0
  38. data/spec/fixtures/cassettes/device_groups_create.json +1 -0
  39. data/spec/fixtures/cassettes/device_groups_delete.json +1 -0
  40. data/spec/fixtures/cassettes/device_groups_get_all.json +1 -0
  41. data/spec/fixtures/cassettes/device_groups_get_one.json +1 -0
  42. data/spec/fixtures/cassettes/files_authorize.json +1 -0
  43. data/spec/fixtures/cassettes/files_delete.json +1 -0
  44. data/spec/fixtures/cassettes/files_get_all.json +1 -0
  45. data/spec/fixtures/cassettes/files_get_one.json +1 -0
  46. data/spec/fixtures/cassettes/files_upload.json +1 -0
  47. data/spec/fixtures/cassettes/label_groups_authorize.json +1 -0
  48. data/spec/fixtures/cassettes/label_groups_create.json +1 -0
  49. data/spec/fixtures/cassettes/label_groups_delete.json +1 -0
  50. data/spec/fixtures/cassettes/label_groups_get_all.json +1 -0
  51. data/spec/fixtures/cassettes/label_groups_get_labels.json +1 -0
  52. data/spec/fixtures/cassettes/label_groups_get_one.json +1 -0
  53. data/spec/fixtures/cassettes/projects_authorize.json +1 -0
  54. data/spec/fixtures/cassettes/projects_create.json +1 -0
  55. data/spec/fixtures/cassettes/projects_delete.json +1 -0
  56. data/spec/fixtures/cassettes/projects_get_all.json +1 -0
  57. data/spec/fixtures/cassettes/projects_get_one.json +1 -0
  58. data/spec/fixtures/cassettes/runs_abort_run.json +1 -0
  59. data/spec/fixtures/cassettes/runs_authorize.json +1 -0
  60. data/spec/fixtures/cassettes/runs_get_project_runs.json +1 -0
  61. data/spec/fixtures/cassettes/runs_start_run.json +1 -0
  62. data/spec/label_groups_spec.rb +35 -42
  63. data/spec/projects_spec.rb +41 -0
  64. data/spec/runs_spec.rb +41 -0
  65. data/spec/spec_helper.rb +3 -4
  66. data/testdroid-api-client.gemspec +12 -12
  67. metadata +53 -162
  68. data/lib/testdroid_api/config.rb +0 -9
  69. data/lib/testdroid_api/device_runs.rb +0 -22
  70. data/lib/testdroid_api/file_sets.rb +0 -11
  71. data/lib/testdroid_api/parameters.rb +0 -10
  72. data/spec/device_runs_spec.rb +0 -25
  73. data/spec/file_sets_spec.rb +0 -47
  74. data/spec/fixtures/cassettes/dg_all_device_groups.json +0 -1
  75. data/spec/fixtures/cassettes/dg_device_group_4165.json +0 -1
  76. data/spec/fixtures/cassettes/dg_oauth2_auth_device_groups.json +0 -1
  77. data/spec/fixtures/cassettes/dr_all_run_171221_device_runs.json +0 -1
  78. data/spec/fixtures/cassettes/dr_device_run_33044722.json +0 -1
  79. data/spec/fixtures/cassettes/dr_oauth2_auth_device_runs.json +0 -1
  80. data/spec/fixtures/cassettes/dr_run_33044722_device_runs.json +0 -1
  81. data/spec/fixtures/cassettes/f_add_file_set.json +0 -1
  82. data/spec/fixtures/cassettes/f_android_app_file.json +0 -1
  83. data/spec/fixtures/cassettes/f_file_sets.json +0 -1
  84. data/spec/fixtures/cassettes/f_oauth2_auth_files.json +0 -1
  85. data/spec/fixtures/cassettes/f_upload_files.json +0 -1
  86. data/spec/fixtures/cassettes/fs_add_file_set.json +0 -1
  87. data/spec/fixtures/cassettes/fs_add_file_to_fileset.json +0 -1
  88. data/spec/fixtures/cassettes/fs_delete_file_set.json +0 -1
  89. data/spec/fixtures/cassettes/fs_file_sets.json +0 -1
  90. data/spec/fixtures/cassettes/fs_get_file_set.json +0 -1
  91. data/spec/fixtures/cassettes/fs_oauth2_auth_files.json +0 -1
  92. data/spec/fixtures/cassettes/fs_update_file_set.json +0 -1
  93. data/spec/fixtures/cassettes/fu_oauth2_auth_files.json +0 -1
  94. data/spec/fixtures/cassettes/lg_all_label_groups.json +0 -1
  95. data/spec/fixtures/cassettes/lg_get_resources_by_label.json +0 -1
  96. data/spec/fixtures/cassettes/lg_label_group_1058800.json +0 -1
  97. data/spec/fixtures/cassettes/lg_labels_of_group_1058800.json +0 -1
  98. data/spec/fixtures/cassettes/lg_oauth2_auth_label_groups.json +0 -1
  99. data/spec/fixtures/cassettes/p_all_projects.json +0 -1
  100. data/spec/fixtures/cassettes/p_create_project.json +0 -1
  101. data/spec/fixtures/cassettes/p_get_run_devices.json +0 -1
  102. data/spec/fixtures/cassettes/p_oauth2_auth.json +0 -1
  103. data/spec/fixtures/cassettes/p_oauth2_local.json +0 -1
  104. data/spec/fixtures/cassettes/p_project_id_33029366.json +0 -1
  105. data/spec/fixtures/cassettes/p_run_project.json +0 -1
  106. data/spec/fixtures/cassettes/pc_get_current.json +0 -1
  107. data/spec/fixtures/cassettes/pc_oauth2_auth_config.json +0 -1
  108. data/spec/fixtures/cassettes/pc_set_current_config.json +0 -1
  109. data/spec/fixtures/cassettes/pc_validate_config.json +0 -1
  110. data/spec/fixtures/cassettes/pcp_delete_params.json +0 -1
  111. data/spec/fixtures/cassettes/pcp_get_current.json +0 -1
  112. data/spec/fixtures/cassettes/pcp_oauth2_auth_config.json +0 -1
  113. data/spec/fixtures/cassettes/pcp_set_current_config.json +0 -1
  114. data/spec/fixtures/cassettes/pcp_validate_config.json +0 -1
  115. data/spec/fixtures/cassettes/r_all_project_33029366_runs.json +0 -1
  116. data/spec/fixtures/cassettes/r_delete_test_run.json +0 -1
  117. data/spec/fixtures/cassettes/r_oauth2_auth_runs.json +0 -1
  118. data/spec/fixtures/cassettes/r_run_171221.json +0 -1
  119. data/spec/fixtures/cassettes/r_run_project.json +0 -1
  120. data/spec/fixtures/cassettes/upload_files.json +0 -1
  121. data/spec/fixtures/project.json +0 -8
  122. data/spec/project_config_parameters_spec.rb +0 -44
  123. data/spec/project_config_spec.rb +0 -36
  124. data/spec/project_spec.rb +0 -56
  125. data/spec/run_spec.rb +0 -33
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: d5c7a42a956383ae541715024734d6b399371345
4
- data.tar.gz: ea7415755cc3ac14aef3974529b65978a0a8cd2f
2
+ SHA256:
3
+ metadata.gz: 59a3631deeb2d0ef505009b5987c7e5af5b0c8d2f7056c1fde16e24bbccae782
4
+ data.tar.gz: 02b39bb056e015a3ff4bbec687ffaa12ed3f1e9f8b5340754b54c80c2b54cb56
5
5
  SHA512:
6
- metadata.gz: b9bd34e6151d413790e579c28223c5de4529c0c734cbf2908bb5b205576bcbaf202ce15416fb4ffeb9039f7ed99b06a0d521fe920dbf4b0203db5cd99d2749f9
7
- data.tar.gz: b0b7417c78b9676670be5cb3c5193a4b994bc134f826c44161f0688a7ce39febad8bf2b9ab201fdbd340e4a128648ff6680be76439408e453c6e845d39e3f735
6
+ metadata.gz: 5bc54840d45cd25008a0621119bf2f9fb567358ffb3b4a15811c341c526e133a126f09a54299c644672da94250830cff90de141306079d1b4eb092f21dc5a195
7
+ data.tar.gz: d5a7af777b03581c96b5b24626b912e2d6a89241000d0a5a1a2bef4b46e1efe031796b6f0b01da33243e5f7b54c5329f5cdde2529735386efd5e755528cd1c11
data/.gitignore CHANGED
@@ -11,8 +11,8 @@ spec/reports
11
11
  test/tmp
12
12
  test/version_tmp
13
13
  tmp
14
- sample/*.apk
15
- sample/test.rb
14
+
15
+ sample/results
16
16
 
17
17
  # YARD artifacts
18
18
  .yardoc
@@ -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
@@ -1,47 +1,49 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- testdroid-api-client (0.3.0)
5
- deep_merge (~> 1.1, >= 1.1.1)
6
- faraday (~> 0.8.8, >= 0.8.8)
7
- oauth2 (~> 0.9)
8
- rest-client (~> 2.0, >= 2.0.0)
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.5.0)
14
- public_suffix (~> 2.0, >= 2.0.2)
15
- bump (0.5.3)
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.1.1)
18
+ deep_merge (1.2.1)
19
19
  diff-lcs (1.2.5)
20
- domain_name (0.5.20161021)
20
+ domain_name (0.5.20190701)
21
21
  unf (>= 0.0.5, < 1.0.0)
22
- faraday (0.8.11)
23
- multipart-post (~> 1.2.0)
24
- hashdiff (0.3.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 (1.5.6)
28
- mime-types (3.1)
28
+ jwt (2.2.1)
29
+ mime-types (3.3)
29
30
  mime-types-data (~> 3.2015)
30
- mime-types-data (3.2016.0521)
31
- multi_json (1.12.1)
32
- multi_xml (0.5.5)
33
- multipart-post (1.2.0)
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 (0.9.4)
36
- faraday (>= 0.8, < 0.10)
37
- jwt (~> 1.0)
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 (~> 1.2)
41
- public_suffix (2.0.4)
42
- rack (1.6.5)
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.0.0)
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.4)
65
+ safe_yaml (1.0.5)
64
66
  unf (0.1.4)
65
67
  unf_ext
66
- unf_ext (0.0.7.2)
67
- vcr (2.9.3)
68
- webmock (1.24.6)
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.5)
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.5)
80
+ bump (~> 0.8)
79
81
  rake
80
82
  rspec
81
83
  rspec-collection_matchers
82
84
  testdroid-api-client!
83
- vcr (~> 2.9)
84
- webmock (~> 1.9)
85
- yard (~> 0.8)
85
+ vcr (~> 5.0)
86
+ webmock (~> 3.7)
87
+ yard (~> 0.9.20)
86
88
 
87
89
  BUNDLED WITH
88
- 1.11.2
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
- android_project = @user.projects.list.detect {|project| project.name.casecmp("Android Project") == 0 }
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
- test_run = project123.run
43
+ frameworks = @user.available_frameworks.list
43
44
  ```
44
45
 
45
- ## Check test run status
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
- test_run.device_runs.list({:params => {:limit => 100}}).each { |drun| drun.download_logs("#{drun.id}_log") }
48
+ framework = @user.available_frameworks.list({:filter => "s_osType_eq_ANDROID;s_name_like_%Instrumentation"})[0]
53
49
  ```
54
50
 
55
- ## Using device labels
51
+ ## Upload files
56
52
  ```ruby
57
- #Get label for android os version 2.1
58
- lg_android_version_2_1 = client.label_groups.list.detect {|lg| lg.display_name.casecmp("android version") == 0 }
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
- #create a new device session:
74
- device_session = @user.device_sessions.create({:params => {'deviceModelId' => '1'}})
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
- #get project and update project configuration
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.testdroid.com/swagger/index.html for more details about API V2
78
+ See https://cloud.bitbar.com/cloud/swagger-ui.html for more details about API V2
@@ -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
 
@@ -49,7 +49,7 @@ module TestdroidAPI
49
49
  end
50
50
  end
51
51
 
52
- # check nil existance
52
+ # check nil existence
53
53
  if check_nil
54
54
  is_nil = false
55
55
  value.each do |val|
@@ -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
@@ -2,7 +2,7 @@ module TestdroidAPI
2
2
  class AdminDeviceProblems < CloudListResource
3
3
  end
4
4
  class AdminDeviceProblem < CloudResource
5
- def initialize(uri, client, params= {})
5
+ def initialize(uri, client, params = {})
6
6
  super uri, client, "adminDeviceProblem", params
7
7
  end
8
8
  end
@@ -5,7 +5,7 @@ module TestdroidAPI
5
5
  end
6
6
  end
7
7
  class AdminDeviceStatus < CloudResource
8
- def initialize(uri, client, params= {})
8
+ def initialize(uri, client, params = {})
9
9
  super uri, client, "adminDeviceStatus", params
10
10
  end
11
11
  end
@@ -2,7 +2,7 @@ module TestdroidAPI
2
2
  class AdminDevices < CloudListResource
3
3
  end
4
4
  class AdminDevice < CloudResource
5
- def initialize(uri, client, params= {})
5
+ def initialize(uri, client, params = {})
6
6
  super uri, client, "adminDevice", 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.testdroid.com'
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 (@cloud_user.nil?)
26
- @cloud_user = TestdroidAPI::User.new( "/#{API_VERSION}/me", self ).refresh
27
- @cloud_user = TestdroidAPI::User.new( "/#{API_VERSION}/users/#{@cloud_user.id}", self ).refresh
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
- :method => method,
37
- :url => uri,
38
- :user => @api_key,
39
- :password => "",
40
- :headers => ACCEPT_HEADERS
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({ :headers => {:params => params} })
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
- http_params = http_params.deep_merge({ :payload => params })
64
- request = self.request_factory(:post, uri, http_params)
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 (resp.status != 204)
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.status}"
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
- :multipart => true,
99
- :file => File.new(file_name, 'rb')
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
- http_params = http_params.deep_merge({ :headers => {:params => params} })
107
- request = self.request_factory(:get, @cloud_url+"#{uri}", http_params)
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