testdroid-api-client 0.2.3 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: ee583ae4568b99ed6849adc876c2b57f2f94325a
4
- data.tar.gz: 4373bcb422bf9ee563cb1ae89d78022fe346f7e0
3
+ metadata.gz: d5c7a42a956383ae541715024734d6b399371345
4
+ data.tar.gz: ea7415755cc3ac14aef3974529b65978a0a8cd2f
5
5
  SHA512:
6
- metadata.gz: 23fcec5757e7beab6f32c49731d9d4901ecd464e0b1cf5183734ad4afc7a97c3f4ce1cf7ff6de5bccc253ddb96ebe4cd0e15877bbd00178139e77b5c3b2e1a95
7
- data.tar.gz: 1005ce6b0a80b863b985eb147a6977916b2fc2bfb9c592a5c6ab292100ff977d84f02944df4900ea899e6bd5b63879127dad9dc75e7fc616d87dc626b20d9e20
6
+ metadata.gz: b9bd34e6151d413790e579c28223c5de4529c0c734cbf2908bb5b205576bcbaf202ce15416fb4ffeb9039f7ed99b06a0d521fe920dbf4b0203db5cd99d2749f9
7
+ data.tar.gz: b0b7417c78b9676670be5cb3c5193a4b994bc134f826c44161f0688a7ce39febad8bf2b9ab201fdbd340e4a128648ff6680be76439408e453c6e845d39e3f735
data/.gitignore CHANGED
@@ -11,9 +11,14 @@ spec/reports
11
11
  test/tmp
12
12
  test/version_tmp
13
13
  tmp
14
+ sample/*.apk
15
+ sample/test.rb
14
16
 
15
17
  # YARD artifacts
16
18
  .yardoc
17
19
  _yardoc
18
20
  doc/
19
21
  .DS_Store
22
+
23
+ # IDE
24
+ .idea
@@ -1,52 +1,75 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- testdroid-api-client (0.2.3)
4
+ testdroid-api-client (0.3.0)
5
+ deep_merge (~> 1.1, >= 1.1.1)
5
6
  faraday (~> 0.8.8, >= 0.8.8)
6
7
  oauth2 (~> 0.9)
8
+ rest-client (~> 2.0, >= 2.0.0)
7
9
 
8
10
  GEM
9
11
  remote: https://rubygems.org/
10
12
  specs:
11
- addressable (2.3.6)
12
- bump (0.5.1)
13
- crack (0.4.2)
13
+ addressable (2.5.0)
14
+ public_suffix (~> 2.0, >= 2.0.2)
15
+ bump (0.5.3)
16
+ crack (0.4.3)
14
17
  safe_yaml (~> 1.0.0)
18
+ deep_merge (1.1.1)
15
19
  diff-lcs (1.2.5)
16
- faraday (0.8.9)
20
+ domain_name (0.5.20161021)
21
+ unf (>= 0.0.5, < 1.0.0)
22
+ faraday (0.8.11)
17
23
  multipart-post (~> 1.2.0)
18
- jwt (1.3.0)
19
- multi_json (1.10.1)
24
+ hashdiff (0.3.0)
25
+ http-cookie (1.0.3)
26
+ domain_name (~> 0.5)
27
+ jwt (1.5.6)
28
+ mime-types (3.1)
29
+ mime-types-data (~> 3.2015)
30
+ mime-types-data (3.2016.0521)
31
+ multi_json (1.12.1)
20
32
  multi_xml (0.5.5)
21
33
  multipart-post (1.2.0)
34
+ netrc (0.11.0)
22
35
  oauth2 (0.9.4)
23
36
  faraday (>= 0.8, < 0.10)
24
37
  jwt (~> 1.0)
25
38
  multi_json (~> 1.3)
26
39
  multi_xml (~> 0.5)
27
40
  rack (~> 1.2)
28
- rack (1.5.2)
29
- rake (10.4.0)
30
- rspec (3.1.0)
31
- rspec-core (~> 3.1.0)
32
- rspec-expectations (~> 3.1.0)
33
- rspec-mocks (~> 3.1.0)
41
+ public_suffix (2.0.4)
42
+ rack (1.6.5)
43
+ rake (11.3.0)
44
+ rest-client (2.0.0)
45
+ http-cookie (>= 1.0.2, < 2.0)
46
+ mime-types (>= 1.16, < 4.0)
47
+ netrc (~> 0.8)
48
+ rspec (3.5.0)
49
+ rspec-core (~> 3.5.0)
50
+ rspec-expectations (~> 3.5.0)
51
+ rspec-mocks (~> 3.5.0)
34
52
  rspec-collection_matchers (1.1.2)
35
53
  rspec-expectations (>= 2.99.0.beta1)
36
- rspec-core (3.1.7)
37
- rspec-support (~> 3.1.0)
38
- rspec-expectations (3.1.2)
54
+ rspec-core (3.5.4)
55
+ rspec-support (~> 3.5.0)
56
+ rspec-expectations (3.5.0)
39
57
  diff-lcs (>= 1.2.0, < 2.0)
40
- rspec-support (~> 3.1.0)
41
- rspec-mocks (3.1.3)
42
- rspec-support (~> 3.1.0)
43
- rspec-support (3.1.2)
58
+ rspec-support (~> 3.5.0)
59
+ rspec-mocks (3.5.0)
60
+ diff-lcs (>= 1.2.0, < 2.0)
61
+ rspec-support (~> 3.5.0)
62
+ rspec-support (3.5.0)
44
63
  safe_yaml (1.0.4)
64
+ unf (0.1.4)
65
+ unf_ext
66
+ unf_ext (0.0.7.2)
45
67
  vcr (2.9.3)
46
- webmock (1.20.4)
68
+ webmock (1.24.6)
47
69
  addressable (>= 2.3.6)
48
70
  crack (>= 0.3.2)
49
- yard (0.8.7.6)
71
+ hashdiff
72
+ yard (0.9.5)
50
73
 
51
74
  PLATFORMS
52
75
  ruby
@@ -60,3 +83,6 @@ DEPENDENCIES
60
83
  vcr (~> 2.9)
61
84
  webmock (~> 1.9)
62
85
  yard (~> 0.8)
86
+
87
+ BUNDLED WITH
88
+ 1.11.2
@@ -1,21 +1,37 @@
1
1
  #!/usr/bin/ruby
2
2
  require 'json'
3
+ require 'logger'
4
+ require 'rest-client'
5
+ require 'deep_merge'
6
+ require 'oauth2'
7
+
3
8
  require 'testdroid_api/client'
9
+ require 'testdroid_api/apikey_client'
10
+
4
11
  require 'testdroid_api/cloud_resource'
5
12
  require 'testdroid_api/cloud_list_resource'
13
+
6
14
  require 'testdroid_api/user'
7
- require 'testdroid_api/device_groups'
8
15
  require 'testdroid_api/projects'
9
16
  require 'testdroid_api/runs'
17
+ require 'testdroid_api/devices'
18
+ require 'testdroid_api/device_groups'
10
19
  require 'testdroid_api/device_runs'
11
- require 'testdroid_api/label_groups'
20
+ require 'testdroid_api/device_sessions'
21
+ require 'testdroid_api/device_session_connections'
12
22
  require 'testdroid_api/labels'
23
+ require 'testdroid_api/label_groups'
13
24
  require 'testdroid_api/files'
14
- require 'testdroid_api/devices'
15
- require 'testdroid_api/device_sessions'
16
25
  require 'testdroid_api/file_sets'
17
26
  require 'testdroid_api/config'
18
27
  require 'testdroid_api/parameters'
28
+ require 'testdroid_api/properties'
29
+ require 'testdroid_api/services'
19
30
 
20
- require 'oauth2'
21
- require 'logger'
31
+ require 'testdroid_api/admin'
32
+ require 'testdroid_api/admin_devices'
33
+ require 'testdroid_api/admin_device_models'
34
+ require 'testdroid_api/admin_device_statuses'
35
+ require 'testdroid_api/admin_device_problems'
36
+
37
+ require 'testdroid-api-filter-builder'
@@ -0,0 +1,145 @@
1
+ module TestdroidAPI
2
+ class FilterBuilder
3
+
4
+ def initialize
5
+ @filters = []
6
+ end
7
+
8
+ private
9
+ def check_type(subject)
10
+ if !!subject == subject # check if it's boolean
11
+ return 'b'
12
+ elsif (/^[0-9]{13}$/ =~ subject) != nil # check if it's timestamp
13
+ return 'd'
14
+ elsif (/^[0-9]+(?:\.[0-9]+)?$/ =~ subject) != nil # check if it's number
15
+ return 'n'
16
+ else
17
+ return 's'
18
+ end
19
+ end
20
+
21
+ def add(name, value, operand, type, check_nil=false)
22
+ unless value.is_a? Array
23
+ value = [value]
24
+ end
25
+
26
+ if value.length == 0
27
+ return self
28
+ end
29
+
30
+ # auto-convert
31
+ value.each_with_index do |val, index|
32
+ if val.is_a? Time
33
+ value[index] = val.to_i.to_s
34
+ elsif val.is_a? Fixnum
35
+ value[index] = val.to_s
36
+ end
37
+ end
38
+
39
+ # auto-check type
40
+ if type.nil?
41
+ value.each do |val|
42
+ next if val.nil?
43
+ type = check_type(val)
44
+ break
45
+ end
46
+
47
+ if operand == 'in'
48
+ type = 'l'+type
49
+ end
50
+ end
51
+
52
+ # check nil existance
53
+ if check_nil
54
+ is_nil = false
55
+ value.each do |val|
56
+ next unless val.nil?
57
+ is_nil = true
58
+ end
59
+
60
+ if is_nil
61
+ value = value.select { |item| !item.nil? }
62
+ operand += 'ornull'
63
+ end
64
+ end
65
+
66
+ # add filter
67
+ @filters.push(FilterItem.new(name, value, operand, type))
68
+ end
69
+
70
+ public
71
+ def gt(name, value)
72
+ add(name, value, 'gt', 'n')
73
+ end
74
+
75
+ def lt(name, value)
76
+ add(name, value, 'lt', 'n')
77
+ end
78
+
79
+ def after(name, value)
80
+ add(name, value, 'after', 'd', true)
81
+ end
82
+
83
+ def before(name, value)
84
+ add(name, value, 'before', 'd', true)
85
+ end
86
+
87
+ def on(name, value)
88
+ add(name, value, 'on', 'd')
89
+ end
90
+
91
+ def eq(name, value)
92
+ add(name, value, 'eq', nil)
93
+ end
94
+
95
+ def contains(name, value)
96
+ add(name, value, 'contains', 's')
97
+ end
98
+
99
+ def like(name, value)
100
+ nil # TODO (waiting for BE support)
101
+ end
102
+
103
+ def empty(name, value)
104
+ nil # TODO (waiting for BE support)
105
+ end
106
+
107
+ def isnull(name, operand)
108
+ add(name, nil, 'isnull', operand)
109
+ end
110
+
111
+ def in(name, value)
112
+ add(name, value, 'in', nil, true)
113
+ end
114
+
115
+
116
+ def to_s
117
+ parts = []
118
+ @filters.each do |filter|
119
+ val = ''
120
+ if filter.value.length > 1 or not filter.value.nil?
121
+ val = '_' + filter.values
122
+ end
123
+ parts.push( filter.to_s + val )
124
+ end
125
+ parts.join(';')
126
+ end
127
+
128
+ end
129
+
130
+ class FilterItem
131
+ attr_accessor :name, :value, :operand, :type
132
+
133
+ def initialize(name, value, operand, type)
134
+ @name, @value, @operand, @type = name, value, operand, type
135
+ end
136
+
137
+ def values
138
+ @value.join('|')
139
+ end
140
+
141
+ def to_s
142
+ "#{@type}_#{@name}_#{@operand}"
143
+ end
144
+ end
145
+ end
@@ -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,10 @@
1
+ module TestdroidAPI
2
+ class AdminDeviceModels < CloudListResource
3
+ end
4
+ class AdminDeviceModel < CloudResource
5
+ def initialize(uri, client, params= {})
6
+ super uri, client, "adminDeviceModel", params
7
+ @uri, @client = uri, client
8
+ end
9
+ end
10
+ end
@@ -0,0 +1,9 @@
1
+ module TestdroidAPI
2
+ class AdminDeviceProblems < CloudListResource
3
+ end
4
+ class AdminDeviceProblem < CloudResource
5
+ def initialize(uri, client, params= {})
6
+ super uri, client, "adminDeviceProblem", params
7
+ end
8
+ end
9
+ 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,10 @@
1
+ module TestdroidAPI
2
+ class AdminDevices < CloudListResource
3
+ end
4
+ class AdminDevice < CloudResource
5
+ def initialize(uri, client, params= {})
6
+ super uri, client, "adminDevice", params
7
+ @uri, @client = uri, client
8
+ end
9
+ end
10
+ 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.testdroid.com'
9
+ ACCEPT_HEADERS = {'Accept' => 'application/json'}
10
+
11
+ def initialize(api_key, cloud_url = CLOUD_ENDPOINT, logger = nil)
12
+ # Instance variables
13
+ @api_key = api_key
14
+ @cloud_url = cloud_url
15
+ @logger = logger
16
+
17
+ if @logger.nil?
18
+ @logger = Logger.new(STDOUT)
19
+ @logger.info("Logger is not defined => output to STDOUT")
20
+ end
21
+ end
22
+
23
+ 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
28
+
29
+ end
30
+ @cloud_user
31
+ end
32
+ # Basic methods
33
+
34
+ def request_factory(method, uri, http_params = {})
35
+ default_http_params = {
36
+ :method => method,
37
+ :url => uri,
38
+ :user => @api_key,
39
+ :password => "",
40
+ :headers => ACCEPT_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
+ http_params = http_params.deep_merge({ :payload => params })
64
+ request = self.request_factory(:post, uri, http_params)
65
+ resp = request.execute
66
+ rescue => e
67
+ @logger.error "Failed to post resource #{uri} #{e}"
68
+ return nil
69
+ end
70
+
71
+ if resp.body.nil? || resp.body.length == 0
72
+ return nil
73
+ end
74
+
75
+ JSON.parse(resp.body)
76
+ end
77
+
78
+ def delete(uri)
79
+ uri = @cloud_url+uri
80
+ begin
81
+ request = self.request_factory(:delete, uri)
82
+ resp = request.execute
83
+ rescue => e
84
+ @logger.error "Failed to delete resource #{uri} #{e}"
85
+ return nil
86
+ end
87
+
88
+ if (resp.status != 204)
89
+ @logger.error "Failed to delete resource #{uri} #{e}"
90
+ return nil
91
+ else
92
+ @logger.info "response: #{resp.status}"
93
+ end
94
+ end
95
+
96
+ def upload(uri, file_name)
97
+ self.post(uri, {
98
+ :multipart => true,
99
+ :file => File.new(file_name, 'rb')
100
+ })
101
+ end
102
+
103
+ def download(uri, file_name, params={}, http_params={})
104
+ 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)
108
+ resp = request.execute
109
+ file.write(resp.body)
110
+ end
111
+ rescue => e
112
+ @logger.error "Failed to get resource #{uri} #{e}"
113
+ return nil
114
+ end
115
+ end
116
+
117
+
118
+
119
+ end
120
+ end