cider_client 0.1.0 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (3) hide show
  1. checksums.yaml +4 -4
  2. data/lib/cider_client.rb +38 -29
  3. metadata +3 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: b7badeb8e7fe4e1f1e5f92fd2d3c77c68dc43298
4
- data.tar.gz: cbad76cedde3f4e55a34bc990a058036e1864feb
3
+ metadata.gz: a68079e2b028d9656a70a5cb100094f0b934254b
4
+ data.tar.gz: 8195a2a3659451056149902d1928ed5db02deb05
5
5
  SHA512:
6
- metadata.gz: 3992118565cb51083efcc34725ccbaf25caef0c53421d15d16818aee452b66e2738aca2516dfba83fb80b93f88a9a9d29b2e062502b3dca2281edf129c243774
7
- data.tar.gz: 7dc8046005962131739117bb2217fe0788e954c1613291920061e24bfb625c5a91f14b367f6e00f85841b175acd6c37fa4cd936c5a1cba8402f188cc002a7878
6
+ metadata.gz: c6954a91d028fb093a3fca3b84562b3d9cb04218362fdbafb735fc8800d6f6d9bf4a927dbb92ec74ede204e460b306826103936650cd2d057b22648021aa41d9
7
+ data.tar.gz: 1a21d6c5fb3490f7632b81b4fc02cebc81fe35ef79172eab598fc231de4b8876c5aba4c9fa56ab398498c6351b775e1f348b138e68153f93c66256f302a62955
data/lib/cider_client.rb CHANGED
@@ -7,29 +7,25 @@ require 'fileutils'
7
7
  class CiderClient
8
8
  attr_accessor :execution_id, :host
9
9
  attr_writer :username, :password
10
+ attr_reader :base_url
10
11
 
11
12
  def initialize(options = {})
12
13
  @host = options.fetch(:host)
13
14
  @username = options.fetch(:username)
14
15
  @password = options.fetch(:password)
15
- fail "The server at #{@host} does not provide the\
16
- correct API version. v2 is required." unless api_compatible?
17
- end
18
16
 
19
- # Returns the base URL including usernames and passwords. Always uses usernames
20
- # and passwords, because you can't do anything on Cider without basic auth anyhow.
21
- # Is used in all further url_* methods.
22
- def base_url
23
- "http://#{@username}:#{@password}@#{@host}"
24
- end
17
+ @base_url = if @host =~ /^https?:\/\//
18
+ @host
19
+ else
20
+ "http://" + @host
21
+ end
25
22
 
26
- # URL starting from the base URL root, with the passed path appended
27
- def url(path)
28
- "#{base_url}#{path}"
23
+ fail "The server at #{@host} does not provide the\
24
+ correct API version. v2 is required." unless api_compatible?
29
25
  end
30
26
 
31
27
  def api_url(path = '')
32
- url("/cider-ci/api/v2/#{path}")
28
+ "/cider-ci/api/v2/#{path}"
33
29
  end
34
30
 
35
31
  # URL starting from the execution, with the passed path appended
@@ -42,7 +38,7 @@ class CiderClient
42
38
  begin
43
39
  # Try to get the API root URL. If it 404s out, this server probably
44
40
  # doesn't offer that API version.
45
- RestClient.get(api_url)
41
+ get(api_url)
46
42
  api_version_matches = true
47
43
  rescue RestClient::ResourceNotFound
48
44
  api_version_matches = false
@@ -56,7 +52,7 @@ class CiderClient
56
52
  end
57
53
  if data['_links']['next']
58
54
  puts "Retrieved #{tasks.count} tasks total so far."
59
- data = JSON.parse(RestClient.get(url(data['_links']['next']['href'])))
55
+ data = JSON.parse(get(data['_links']['next']['href']))
60
56
  tasks = recurse_tasks(tasks, data)
61
57
  end
62
58
  tasks
@@ -65,7 +61,7 @@ class CiderClient
65
61
  def tasks
66
62
  tasks = []
67
63
  recurse_tasks(tasks,
68
- JSON.parse(RestClient.get(execution_url('tasks'))))
64
+ JSON.parse(get(execution_url('tasks'))))
69
65
  end
70
66
 
71
67
  # I've got a long thing, what can I say...
@@ -73,11 +69,11 @@ class CiderClient
73
69
  def trials
74
70
  trials = []
75
71
  tasks.each do |task|
76
- task_url = url(task['href'])
77
- details = JSON.parse(RestClient.get(task_url))
78
- trials_url = url(details['_links']['cici:trials']['href'])
72
+ task_url = task['href']
73
+ details = JSON.parse(get(task_url))
74
+ trials_url = details['_links']['cici:trials']['href']
79
75
  puts "Need to retrieve all trials for #{details['_links']['cici:trials']['href']}"
80
- single_trial = JSON.parse(RestClient.get(trials_url))
76
+ single_trial = JSON.parse(get(trials_url))
81
77
  single_trial['_links']['cici:trial'].each do |st|
82
78
  trials << st
83
79
  end
@@ -96,9 +92,9 @@ class CiderClient
96
92
  puts 'Retrieving trial details to find all attachments, this may take a long time.'
97
93
  trial_attachment_groups = []
98
94
  trials.each do |trial|
99
- trial_url = url(trial['href'])
95
+ trial_url = trial['href']
100
96
  puts "Retrieving trial details for #{trial_url}."
101
- single_trial = JSON.parse(RestClient.get(trial_url))
97
+ single_trial = JSON.parse(get(trial_url))
102
98
  trial_attachment_groups << \
103
99
  single_trial['_links']['cici:trial-attachments']
104
100
  end
@@ -110,8 +106,8 @@ class CiderClient
110
106
  def trial_attachment_hrefs(pattern = /.*/)
111
107
  matching_tas = []
112
108
  trial_attachment_groups.each do |tag|
113
- trial_attachment_url = url(tag['href'])
114
- trial_attachment_details = JSON.parse(RestClient.get(trial_attachment_url))
109
+ trial_attachment_url = tag['href']
110
+ trial_attachment_details = JSON.parse(get(trial_attachment_url))
115
111
  matching_tas << trial_attachment_details['_links']['cici:trial-attachment'].select do |ta|
116
112
  ta if ta['href'].match(pattern)
117
113
  end
@@ -120,12 +116,25 @@ class CiderClient
120
116
  end
121
117
 
122
118
  def attachment_data(href)
123
- attachment_details = JSON.parse(RestClient.get(url(href)))
119
+ attachment_details = JSON.parse(get(href))
124
120
  stream_url = attachment_details['_links']['data-stream']['href']
121
+ get(stream_url)
122
+ end
123
+
125
124
 
126
- # Stupid fix because the CI hosts seem to return their own IP instead of hostname
127
- # in these responses
128
- stream_url.gsub!('https://195.176.254.43', base_url)
129
- RestClient.get(stream_url)
125
+ def get(url)
126
+ full_url = if url =~ /^https?:\/\//
127
+ url
128
+ else
129
+ @base_url + url
130
+ end
131
+
132
+ RestClient::Request.new(
133
+ method: :get,
134
+ url: full_url,
135
+ user: @username,
136
+ password: @password
137
+ ).execute
130
138
  end
139
+
131
140
  end
metadata CHANGED
@@ -1,14 +1,15 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: cider_client
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ramón Cahenzli
8
+ - Thomas Schank
8
9
  autorequire:
9
10
  bindir: bin
10
11
  cert_chain: []
11
- date: 2014-10-30 00:00:00.000000000 Z
12
+ date: 2014-11-07 00:00:00.000000000 Z
12
13
  dependencies:
13
14
  - !ruby/object:Gem::Dependency
14
15
  name: json