stf-client 0.1.1 → 0.1.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (4) hide show
  1. checksums.yaml +4 -4
  2. data/lib/stf/client.rb +22 -7
  3. data/lib/stf/version.rb +1 -1
  4. metadata +3 -3
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 4f9b3ce6ad9c3916d43cb47627e3dbd19f869c75
4
- data.tar.gz: 1f4207153981a50780298b11a3bb314043325990
3
+ metadata.gz: 0b55ff5a67a849151ac73d524d6086e11468ccf8
4
+ data.tar.gz: 890d3966ce8dbaa65842dc8f14b5b434358d3d28
5
5
  SHA512:
6
- metadata.gz: fcc2ff2f6819a8a806ba31f462026b82a60a0258e024758af8059fafaa5e1fe54164938e47153e514d8122b46f23d5631468d664ac0764864dda86115092ad8d
7
- data.tar.gz: 16932ec663fa1881b6184207ae477d1df0dc147c7399939c0e14af0f4e4fddf7021c80e48b93d2526b66e03aded5d7224438ef73fbe60368d73a3402e6b48124
6
+ metadata.gz: 8e895e08348b578ae4e3182aed554a02237c9a84e2c2a290146df0b8e4ed594077ee5759c7358d9802b74466662c73e110974cb20d504a3d01f3a61bb3ed41c8
7
+ data.tar.gz: 3eb12ca9218b4da7aedf6c6f7d8058b993e717a45375e29aa904792777e29aa84e07fbf5c5d052247db1a153940e76bbc047bfe120298ec6c3c1f08a5fc31f29
data/lib/stf/client.rb CHANGED
@@ -58,18 +58,33 @@ module Stf
58
58
  private
59
59
 
60
60
  def execute(relative_url, type, body='')
61
- uri = URI.parse(@base_url + relative_url)
62
- http = Net::HTTP.new(uri.host)
63
- request = type.new(uri.request_uri, 'Authorization' => "Bearer #{@token}", 'Content-Type' => 'application/json')
61
+ return execute_absolute @base_url + relative_url, type, body
62
+ end
63
+
64
+ def execute_absolute(url, type, body='', limit = 10)
65
+ raise ArgumentError, 'too many HTTP redirects' if limit == 0
66
+
67
+ uri = URI.parse(url)
68
+ http = Net::HTTP.new(uri.host, uri.port)
69
+ http.use_ssl = true if uri.scheme == 'https'
70
+ request = type.new(uri, 'Authorization' => "Bearer #{@token}", 'Content-Type' => 'application/json')
64
71
  request.body = body
65
72
  response = http.request(request)
66
73
 
74
+ case response
75
+ when Net::HTTPSuccess then
76
+ json = JSON.parse(response.body, object_class: OpenStruct)
67
77
 
68
- json = JSON.parse(response.body, object_class: OpenStruct)
69
-
70
- logger.debug "API returned #{json}"
78
+ logger.debug "API returned #{json}"
79
+ when Net::HTTPRedirection then
80
+ location = response['location']
81
+ logger.debug "redirected to #{location}"
82
+ return execute_absolute(location, type, body, limit - 1)
83
+ else
84
+ logger.error "API returned #{response.value}"
85
+ end
71
86
 
72
87
  return json
73
88
  end
74
89
  end
75
- end
90
+ end
data/lib/stf/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Stf
2
- VERSION = '0.1.1'
2
+ VERSION = '0.1.2'
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: stf-client
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Anton Malinskiy
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-07-29 00:00:00.000000000 Z
11
+ date: 2017-08-21 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: gli
@@ -156,7 +156,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
156
156
  version: '0'
157
157
  requirements: []
158
158
  rubyforge_project:
159
- rubygems_version: 2.5.1
159
+ rubygems_version: 2.6.12
160
160
  signing_key:
161
161
  specification_version: 4
162
162
  summary: Request devices from Smartphone Test Farm for adb connection