trav3 0.0.2 → 0.0.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +1 -1
- data/README.md +10 -0
- data/lib/trav3/get.rb +10 -8
- data/lib/trav3/options.rb +1 -1
- data/lib/trav3/pagination.rb +30 -0
- data/lib/trav3/result.rb +10 -0
- data/lib/trav3/version.rb +1 -1
- data/lib/trav3.rb +14 -7
- metadata +3 -3
- data/Gemfile.lock +0 -48
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 74f15ee8237114fde668fc778097f99fb478135ecffb64c266aeb2b927646f32
|
4
|
+
data.tar.gz: 64a3592dd906c3eb313d02e9992dde7014c713de58fb87de16f61db3867ee9b7
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7ef2a7d76fe194c01b582fad0b1e1fb65bed0746a12a7f9b4a837c454cdc43c56a2f1ec2560c02420d2adc5cb9ec2161a44942b11a837b291ec082ed14e0c442
|
7
|
+
data.tar.gz: 83ab138e8ede9c141098aad8026a629d21297843766fff6edad90a4e3bcfae689195a3f8e72ae17ba991dee5a528d18284f15429652cd9bd9a114ea28f06838b
|
data/.gitignore
CHANGED
data/README.md
CHANGED
@@ -32,9 +32,19 @@ require 'trav3'
|
|
32
32
|
project = Trav3::Travis.new("name/example")
|
33
33
|
project.builds
|
34
34
|
project.build(12345)
|
35
|
+
project.build_jobs(12345)
|
35
36
|
project.job(1234)
|
36
37
|
project.log(1234)
|
37
38
|
project.text_log(1234)
|
39
|
+
|
40
|
+
# API Request Options
|
41
|
+
project.defaults(limit: 25)
|
42
|
+
|
43
|
+
# Pagination
|
44
|
+
builds = project.builds
|
45
|
+
builds.page.next
|
46
|
+
builds.page.first
|
47
|
+
builds.page.last
|
38
48
|
```
|
39
49
|
|
40
50
|
## Development
|
data/lib/trav3/get.rb
CHANGED
@@ -1,16 +1,18 @@
|
|
1
1
|
require 'net/http'
|
2
2
|
require 'uri'
|
3
3
|
require 'json'
|
4
|
-
|
4
|
+
require 'trav3/result'
|
5
5
|
|
6
|
-
module
|
7
|
-
|
8
|
-
|
6
|
+
module Trav3
|
7
|
+
module GET
|
8
|
+
def self.call(url)
|
9
|
+
response = Net::HTTP.get_response(URI(url))
|
9
10
|
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
11
|
+
if Net::HTTPOK == response.code_type
|
12
|
+
Success.new(response)
|
13
|
+
else
|
14
|
+
RequestError.new(response)
|
15
|
+
end
|
14
16
|
end
|
15
17
|
end
|
16
18
|
end
|
data/lib/trav3/options.rb
CHANGED
@@ -0,0 +1,30 @@
|
|
1
|
+
require 'trav3/get'
|
2
|
+
|
3
|
+
module Trav3
|
4
|
+
class Pagination
|
5
|
+
def initialize(result)
|
6
|
+
@result = result
|
7
|
+
end
|
8
|
+
|
9
|
+
def dig(opt)
|
10
|
+
@result.dig(opt)
|
11
|
+
end
|
12
|
+
|
13
|
+
def next
|
14
|
+
get("#{API_ROOT}#{self.dig("@pagination").dig("next").dig("@href")}")
|
15
|
+
end
|
16
|
+
|
17
|
+
def first
|
18
|
+
get("#{API_ROOT}#{self.dig("@pagination").dig("first").dig("@href")}")
|
19
|
+
end
|
20
|
+
|
21
|
+
def last
|
22
|
+
get("#{API_ROOT}#{self.dig("@pagination").dig("last").dig("@href")}")
|
23
|
+
end
|
24
|
+
|
25
|
+
def get(x)
|
26
|
+
Trav3::GET.(x)
|
27
|
+
end
|
28
|
+
private :get
|
29
|
+
end
|
30
|
+
end
|
data/lib/trav3/result.rb
CHANGED
@@ -1,5 +1,6 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
require 'forwardable'
|
3
|
+
require 'trav3/pagination'
|
3
4
|
|
4
5
|
class InvalidRepository < StandardError
|
5
6
|
def message
|
@@ -27,11 +28,20 @@ class Response
|
|
27
28
|
@response = response
|
28
29
|
@json = JSON.parse(response.body)
|
29
30
|
end
|
31
|
+
|
32
|
+
def inspect
|
33
|
+
"<#{self.class} Response>"
|
34
|
+
end
|
35
|
+
|
30
36
|
def success?; raise Unimplemented end
|
31
37
|
def failure?; raise Unimplemented end
|
32
38
|
end
|
33
39
|
|
34
40
|
class Success < Response
|
41
|
+
def page
|
42
|
+
Trav3::Pagination.new(self)
|
43
|
+
end
|
44
|
+
|
35
45
|
def success?; true end
|
36
46
|
def failure?; false end
|
37
47
|
end
|
data/lib/trav3/version.rb
CHANGED
data/lib/trav3.rb
CHANGED
@@ -5,8 +5,10 @@ require 'trav3/result'
|
|
5
5
|
require 'trav3/get'
|
6
6
|
|
7
7
|
module Trav3
|
8
|
+
API_ROOT = 'https://api.travis-ci.org'
|
9
|
+
|
8
10
|
class Travis
|
9
|
-
API_ENDPOINT =
|
11
|
+
API_ENDPOINT = "#{API_ROOT}/v3"
|
10
12
|
def initialize(repo)
|
11
13
|
raise InvalidRepository unless repo.is_a?(String) and
|
12
14
|
Regexp.new(/(^\d+$)|(^\w+(?:\/|%2F){1}\w+$)/) === repo
|
@@ -26,32 +28,37 @@ module Trav3
|
|
26
28
|
end
|
27
29
|
|
28
30
|
def builds
|
29
|
-
|
31
|
+
get("#{self[true]}/builds#{opts}")
|
30
32
|
end
|
31
33
|
|
32
34
|
def build(id)
|
33
|
-
|
35
|
+
get("#{self[]}/build/#{id}")
|
34
36
|
end
|
35
37
|
|
36
38
|
def build_jobs(id)
|
37
|
-
|
39
|
+
get("#{self[]}/build/#{id}/jobs")
|
38
40
|
end
|
39
41
|
|
40
42
|
def job(id)
|
41
|
-
|
43
|
+
get("#{self[]}/job/#{id}")
|
42
44
|
end
|
43
45
|
|
44
46
|
def log(id)
|
45
|
-
|
47
|
+
get("#{self[]}/job/#{id}/log")
|
46
48
|
end
|
47
49
|
|
48
50
|
def text_log(id)
|
49
|
-
|
51
|
+
get("#{self[]}/job/#{id}/log.txt")
|
50
52
|
end
|
51
53
|
|
52
54
|
def opts
|
53
55
|
@options
|
54
56
|
end
|
55
57
|
private :opts
|
58
|
+
|
59
|
+
def get(x)
|
60
|
+
Trav3::GET.(x)
|
61
|
+
end
|
62
|
+
private :get
|
56
63
|
end
|
57
64
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: trav3
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Daniel P. Clark
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2018-03-
|
11
|
+
date: 2018-03-15 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -62,7 +62,6 @@ files:
|
|
62
62
|
- ".gitignore"
|
63
63
|
- ".travis.yml"
|
64
64
|
- Gemfile
|
65
|
-
- Gemfile.lock
|
66
65
|
- LICENSE
|
67
66
|
- README.md
|
68
67
|
- Rakefile
|
@@ -71,6 +70,7 @@ files:
|
|
71
70
|
- lib/trav3.rb
|
72
71
|
- lib/trav3/get.rb
|
73
72
|
- lib/trav3/options.rb
|
73
|
+
- lib/trav3/pagination.rb
|
74
74
|
- lib/trav3/result.rb
|
75
75
|
- lib/trav3/version.rb
|
76
76
|
- trav3.gemspec
|
data/Gemfile.lock
DELETED
@@ -1,48 +0,0 @@
|
|
1
|
-
PATH
|
2
|
-
remote: .
|
3
|
-
specs:
|
4
|
-
trav3 (0.0.2)
|
5
|
-
|
6
|
-
GEM
|
7
|
-
remote: https://rubygems.org/
|
8
|
-
specs:
|
9
|
-
ansi (1.5.0)
|
10
|
-
builder (3.2.3)
|
11
|
-
codeclimate-test-reporter (1.0.8)
|
12
|
-
simplecov (<= 0.13)
|
13
|
-
color_pound_spec_reporter (0.0.9)
|
14
|
-
bundler
|
15
|
-
minitest
|
16
|
-
minitest-reporters (>= 0.14.24)
|
17
|
-
rake
|
18
|
-
docile (1.1.5)
|
19
|
-
json (2.1.0)
|
20
|
-
minitest (5.11.3)
|
21
|
-
minitest-reporters (1.1.19)
|
22
|
-
ansi
|
23
|
-
builder
|
24
|
-
minitest (>= 5.0)
|
25
|
-
ruby-progressbar
|
26
|
-
rake (10.5.0)
|
27
|
-
ruby-progressbar (1.9.0)
|
28
|
-
simplecov (0.13.0)
|
29
|
-
docile (~> 1.1.0)
|
30
|
-
json (>= 1.8, < 3)
|
31
|
-
simplecov-html (~> 0.10.0)
|
32
|
-
simplecov-html (0.10.2)
|
33
|
-
|
34
|
-
PLATFORMS
|
35
|
-
ruby
|
36
|
-
|
37
|
-
DEPENDENCIES
|
38
|
-
bundler (~> 1.16)
|
39
|
-
codeclimate-test-reporter (~> 1.0.0)
|
40
|
-
color_pound_spec_reporter (~> 0.0.6)
|
41
|
-
minitest (~> 5.10)
|
42
|
-
minitest-reporters (~> 1.1)
|
43
|
-
rake (~> 10.0)
|
44
|
-
simplecov
|
45
|
-
trav3!
|
46
|
-
|
47
|
-
BUNDLED WITH
|
48
|
-
1.16.1
|