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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 2d3b42d471d8c7719b35a044b2d64c2943bb0cf58f7cc7d1f22a1a4ba6be82d4
4
- data.tar.gz: 1b0829969fec1d60d6d5dd278c8febfe1a0ff12eed15d8a10dd21c4520266883
3
+ metadata.gz: 74f15ee8237114fde668fc778097f99fb478135ecffb64c266aeb2b927646f32
4
+ data.tar.gz: 64a3592dd906c3eb313d02e9992dde7014c713de58fb87de16f61db3867ee9b7
5
5
  SHA512:
6
- metadata.gz: 4e6bb8beac530980dadb25681b9d1bb9fdd5dc578c7cf98a839b9ba399c0386ea3c206e4607335575a9a5d97e817c18e5c6ae1b0f0e7df2f95c0293b3ceaddfc
7
- data.tar.gz: 1741a0dc3ae55d2735fc0afe9d5a4eb6f3af45dcf2a0910a8e461ffc705d1b87db7d85afebc02fd1962a6ce1f9cac2d7066ce42a44d168f4500817c64aecec41
6
+ metadata.gz: 7ef2a7d76fe194c01b582fad0b1e1fb65bed0746a12a7f9b4a837c454cdc43c56a2f1ec2560c02420d2adc5cb9ec2161a44942b11a837b291ec082ed14e0c442
7
+ data.tar.gz: 83ab138e8ede9c141098aad8026a629d21297843766fff6edad90a4e3bcfae689195a3f8e72ae17ba991dee5a528d18284f15429652cd9bd9a114ea28f06838b
data/.gitignore CHANGED
@@ -7,4 +7,4 @@
7
7
  /spec/reports/
8
8
  /tmp/
9
9
  **/*.swp
10
- Gemfile.lock
10
+ /Gemfile.lock
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
- require_relative './result'
4
+ require 'trav3/result'
5
5
 
6
- module GET
7
- def self.call(url)
8
- response = Net::HTTP.get_response(URI(url))
6
+ module Trav3
7
+ module GET
8
+ def self.call(url)
9
+ response = Net::HTTP.get_response(URI(url))
9
10
 
10
- if Net::HTTPOK == response.code_type
11
- Success.new(response)
12
- else
13
- RequestError.new(response)
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
@@ -16,7 +16,7 @@ module Trav3
16
16
  @opts ||= []
17
17
 
18
18
  for (key, value) in args
19
- @opts = @opts.keep_if {|a, _| (eval ki)[a] }
19
+ remove(key)
20
20
  @opts.push(pb[key, value])
21
21
  end
22
22
  end
@@ -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
@@ -1,3 +1,3 @@
1
1
  module Trav3
2
- VERSION = "0.0.2"
2
+ VERSION = "0.0.3"
3
3
  end
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 = 'https://api.travis-ci.org/v3'
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
- GET.("#{self[true]}/builds#{opts}")
31
+ get("#{self[true]}/builds#{opts}")
30
32
  end
31
33
 
32
34
  def build(id)
33
- GET.("#{self[]}/build/#{id}")
35
+ get("#{self[]}/build/#{id}")
34
36
  end
35
37
 
36
38
  def build_jobs(id)
37
- GET.("#{self[]}/build/#{id}/jobs")
39
+ get("#{self[]}/build/#{id}/jobs")
38
40
  end
39
41
 
40
42
  def job(id)
41
- GET.("#{self[]}/job/#{id}")
43
+ get("#{self[]}/job/#{id}")
42
44
  end
43
45
 
44
46
  def log(id)
45
- GET.("#{self[]}/job/#{id}/log")
47
+ get("#{self[]}/job/#{id}/log")
46
48
  end
47
49
 
48
50
  def text_log(id)
49
- GET.("#{self[]}/job/#{id}/log.txt")
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.2
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-10 00:00:00.000000000 Z
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