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.
- checksums.yaml +4 -4
- data/lib/cider_client.rb +38 -29
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a68079e2b028d9656a70a5cb100094f0b934254b
|
4
|
+
data.tar.gz: 8195a2a3659451056149902d1928ed5db02deb05
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
end
|
17
|
+
@base_url = if @host =~ /^https?:\/\//
|
18
|
+
@host
|
19
|
+
else
|
20
|
+
"http://" + @host
|
21
|
+
end
|
25
22
|
|
26
|
-
|
27
|
-
|
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
|
-
|
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
|
-
|
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(
|
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(
|
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 =
|
77
|
-
details = JSON.parse(
|
78
|
-
trials_url =
|
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(
|
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 =
|
95
|
+
trial_url = trial['href']
|
100
96
|
puts "Retrieving trial details for #{trial_url}."
|
101
|
-
single_trial = JSON.parse(
|
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 =
|
114
|
-
trial_attachment_details = JSON.parse(
|
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(
|
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
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
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.
|
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-
|
12
|
+
date: 2014-11-07 00:00:00.000000000 Z
|
12
13
|
dependencies:
|
13
14
|
- !ruby/object:Gem::Dependency
|
14
15
|
name: json
|