trav3 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: c9b2622a1c00fd923d798afef081acfc70e4e588be456b1ee24349b1bc27c479
4
+ data.tar.gz: 9be45b68f827abfcd4ba695d73aa5f2ca31ba7578f07b3a44d97539e2188eb93
5
+ SHA512:
6
+ metadata.gz: aea9b81c77414914f0166358a2e4d6aba5ce17858fa1553704896640f3d3c851f89429790e058ec02748dfb0ce5290b70f91dc4a857fa0b4e76b461697359850
7
+ data.tar.gz: dfd1eec536501d01046644f6c72324643a4a5f884944b0a82849f36410a4b212525c136584e9c7132ebe255e2e618da17154f626c4731dd4d77d2506a675444c
@@ -0,0 +1,10 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /_yardoc/
4
+ /coverage/
5
+ /doc/
6
+ /pkg/
7
+ /spec/reports/
8
+ /tmp/
9
+ **/*.swp
10
+
@@ -0,0 +1,15 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.2.6
4
+ - 2.3.3
5
+ - 2.4.0
6
+ env:
7
+ global:
8
+ - secure: qXpWydxv6DHMrvGL8WH4wNRY4MTY7KV/x308Y5dHkZCrI7k9UOccvznp69KT3Z+tzYEFDXfUix5wA6pgyVcvrsQyiLSjGcyzHhxJKs1gk0gcxAkmhwHmUP9aiXWUe/mzpj7Uoc2DHwpPTpK1wQ5kV6eV+jzQLuN3nhfNr2sL8b4=
9
+ addons:
10
+ code_climate:
11
+ repo_token: TODO! UPDATE_THIS!
12
+ script: bundle exec rake test
13
+ after_success:
14
+ - bundle exec codeclimate-test-reporter
15
+
data/Gemfile ADDED
@@ -0,0 +1,17 @@
1
+ source "https://rubygems.org"
2
+
3
+ git_source(:github) {|repo_name| "https://github.com/#{repo_name}" }
4
+
5
+ # Specify your gem's dependencies in trav3.gemspec
6
+ gemspec
7
+ group :test do
8
+ gem 'simplecov'
9
+ gem 'codeclimate-test-reporter', '~> 1.0.0'
10
+ end
11
+
12
+ group :test do
13
+ gem 'minitest', '~> 5.10'
14
+ gem 'minitest-reporters', '~> 1.1'
15
+ gem 'color_pound_spec_reporter', '~> 0.0.6'
16
+ end
17
+
@@ -0,0 +1,48 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ trav3 (0.0.1)
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
data/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2018 Daniel P. Clark
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
@@ -0,0 +1,53 @@
1
+ [![Gem Version](https://badge.fury.io/rb/trav3.svg)](http://badge.fury.io/rb/trav3)
2
+ [![Build Status](https://travis-ci.org/danielpclark/trav3.svg)](https://travis-ci.org/danielpclark/trav3)
3
+ [![SayThanks.io](https://img.shields.io/badge/SayThanks.io-%E2%98%BC-1EAEDB.svg)](https://saythanks.io/to/danielpclark)
4
+
5
+ # Trav3
6
+
7
+ A simple abstraction layer for Travis CI API v3. The results from queries return either `Success`
8
+ or `RequestError` which both repsond with Hash like query methods for the JSON data or the Net::HTTP
9
+ resonse object methods.
10
+
11
+
12
+ ## Installation
13
+
14
+ Add this line to your application's Gemfile:
15
+
16
+ ```ruby
17
+ gem 'trav3'
18
+ ```
19
+
20
+ And then execute:
21
+
22
+ $ bundle
23
+
24
+ Or install it yourself as:
25
+
26
+ $ gem install trav3
27
+
28
+ ## Usage
29
+
30
+ ```ruby
31
+ require 'trav3'
32
+ project = Trav3::Travis.new("name/example")
33
+ project.builds
34
+ project.build(12345)
35
+ project.job(1234)
36
+ project.log(1234)
37
+ project.text_log(1234)
38
+ ```
39
+
40
+ ## Development
41
+
42
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake test` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
43
+
44
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
45
+
46
+ ## Contributing
47
+
48
+ Bug reports and pull requests are welcome on GitHub at https://github.com/danielpclark/trav3.
49
+
50
+ ## License
51
+
52
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
53
+
@@ -0,0 +1,10 @@
1
+ require "bundler/gem_tasks"
2
+ require "rake/testtask"
3
+
4
+ Rake::TestTask.new(:test) do |t|
5
+ t.libs << "test"
6
+ t.libs << "lib"
7
+ t.test_files = FileList["test/**/*_test.rb"]
8
+ end
9
+
10
+ task :default => :test
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "trav3"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start(__FILE__)
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,52 @@
1
+ # frozen_string_literal: true
2
+ require 'trav3/version'
3
+ require 'trav3/options'
4
+ require 'trav3/result'
5
+ require 'trav3/get'
6
+
7
+ module Trav3
8
+ class Travis
9
+ API_ENDPOINT = 'https://api.travis-ci.org/v3'
10
+ def initialize(repo)
11
+ raise InvalidRepository unless repo.is_a?(String) and
12
+ Regexp.new(/(^\d+$)|(^\w+(?:\/|%2F){1}\w+$)/) === repo
13
+
14
+ @repo = repo.gsub(/\//, '%2F')
15
+ defaults(limit: 25)
16
+ end
17
+
18
+ def [](repository = nil)
19
+ [API_ENDPOINT].tap {|a| a.push("repo/#{@repo}") if repository }.join('/')
20
+ end
21
+
22
+ def defaults(**args)
23
+ (@options ||= Options.new).build(**args)
24
+ self
25
+ end
26
+
27
+ def builds
28
+ GET.("#{self[true]}/builds#{opts}")
29
+ end
30
+
31
+ def build(id)
32
+ GET.("#{self[]}/build/#{id}")
33
+ end
34
+
35
+ def job(id)
36
+ GET.("#{self[]}/job/#{id}")
37
+ end
38
+
39
+ def log(id)
40
+ GET.("#{self[]}/job/#{id}/log")
41
+ end
42
+
43
+ def text_log(id)
44
+ GET.("#{self[]}/job/#{id}/log.txt")
45
+ end
46
+
47
+ def opts
48
+ @options
49
+ end
50
+ private :opts
51
+ end
52
+ end
@@ -0,0 +1,16 @@
1
+ require 'net/http'
2
+ require 'uri'
3
+ require 'json'
4
+ require_relative './result'
5
+
6
+ module GET
7
+ def self.call(url)
8
+ response = Net::HTTP.get_response(URI(url))
9
+
10
+ if Net::HTTPOK == response.code_type
11
+ Success.new(response)
12
+ else
13
+ RequestError.new(response)
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,47 @@
1
+ module Trav3
2
+ class Options
3
+ def initialize(**args)
4
+ build(**args)
5
+ end
6
+
7
+ def opts
8
+ if @opts.empty?
9
+ ""
10
+ else
11
+ "?#{@opts.join('&')}"
12
+ end
13
+ end
14
+
15
+ def build(**args)
16
+ @opts ||= []
17
+
18
+ for (key, value) in args
19
+ @opts = @opts.keep_if {|a, _| (eval ki)[a] }
20
+ @opts.push(pb[key, value])
21
+ end
22
+ end
23
+
24
+ def remove(key)
25
+ @opts = @opts.keep_if {|a, _| (eval ki)[a] }
26
+ end
27
+
28
+ def +(other)
29
+ raise ArgumentError, "Invalid type provided." unless other.is_a?(Options)
30
+ @opts += other.instance_variable_get(:@opts)
31
+ end
32
+
33
+ def to_s
34
+ opts
35
+ end
36
+
37
+ def pb
38
+ lambda {|param, arg| "#{param}=#{arg}" }
39
+ end
40
+ private :pb
41
+
42
+ def ki
43
+ 'lambda {|item| !(/^#{key}=/ === "#{item}") }'
44
+ end
45
+ private :ki
46
+ end
47
+ end
@@ -0,0 +1,42 @@
1
+ # frozen_string_literal: true
2
+ require 'forwardable'
3
+
4
+ class InvalidRepository < StandardError
5
+ def message
6
+ "The repository format was invlaid.
7
+ You must either provide the digit name for the repository,
8
+ or `user/repo` or `user%2Frepo` as the name."
9
+ end
10
+ end
11
+
12
+ class Unimplemented < StandardError
13
+ def message
14
+ "You need to implement this method"
15
+ end
16
+ end
17
+
18
+ class Response
19
+ extend Forwardable
20
+ def_delegators :@json, :[], :dig, :keys, :values, :has_key?
21
+ def_delegators :@response, :code, :code_type, :uri, :message, :read_header,
22
+ :header, :value, :entity, :response, :body,
23
+ :decode_content, :msg, :reading_body, :read_body,
24
+ :http_version, :connection_close?, :connection_keep_alive?,
25
+ :initialize_http_header, :get_fields, :each_header
26
+ def initialize(response)
27
+ @response = response
28
+ @json = JSON.parse(response.body)
29
+ end
30
+ def success?; raise Unimplemented end
31
+ def failure?; raise Unimplemented end
32
+ end
33
+
34
+ class Success < Response
35
+ def success?; true end
36
+ def failure?; false end
37
+ end
38
+
39
+ class RequestError < Response
40
+ def success?; false end
41
+ def failure?; true end
42
+ end
@@ -0,0 +1,3 @@
1
+ module Trav3
2
+ VERSION = "0.0.1"
3
+ end
@@ -0,0 +1,27 @@
1
+
2
+ lib = File.expand_path("../lib", __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require "trav3/version"
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "trav3"
8
+ spec.version = Trav3::VERSION
9
+ spec.authors = ["Daniel P. Clark"]
10
+ spec.email = ["6ftdan@gmail.com"]
11
+
12
+ spec.summary = %q{Simple Travis V3 API Client}
13
+ spec.description = %q{A Simple client abstraction for the Travis V3 API}
14
+ spec.homepage = "https://github.com/danielpclark/trav3"
15
+ spec.license = "MIT"
16
+
17
+ spec.files = `git ls-files -z`.split("\x0").reject do |f|
18
+ f.match(%r{^(test|spec|features)/})
19
+ end
20
+ spec.bindir = "exe"
21
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
22
+ spec.require_paths = ["lib"]
23
+
24
+ spec.add_development_dependency "bundler", "~> 1.16"
25
+ spec.add_development_dependency "rake", "~> 10.0"
26
+ spec.add_development_dependency "minitest", "~> 5.0"
27
+ end
metadata ADDED
@@ -0,0 +1,101 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: trav3
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Daniel P. Clark
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2018-03-10 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.16'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.16'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '10.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '10.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: minitest
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '5.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '5.0'
55
+ description: A Simple client abstraction for the Travis V3 API
56
+ email:
57
+ - 6ftdan@gmail.com
58
+ executables: []
59
+ extensions: []
60
+ extra_rdoc_files: []
61
+ files:
62
+ - ".gitignore"
63
+ - ".travis.yml"
64
+ - Gemfile
65
+ - Gemfile.lock
66
+ - LICENSE
67
+ - README.md
68
+ - Rakefile
69
+ - bin/console
70
+ - bin/setup
71
+ - lib/trav3.rb
72
+ - lib/trav3/get.rb
73
+ - lib/trav3/options.rb
74
+ - lib/trav3/result.rb
75
+ - lib/trav3/version.rb
76
+ - trav3.gemspec
77
+ homepage: https://github.com/danielpclark/trav3
78
+ licenses:
79
+ - MIT
80
+ metadata: {}
81
+ post_install_message:
82
+ rdoc_options: []
83
+ require_paths:
84
+ - lib
85
+ required_ruby_version: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ required_rubygems_version: !ruby/object:Gem::Requirement
91
+ requirements:
92
+ - - ">="
93
+ - !ruby/object:Gem::Version
94
+ version: '0'
95
+ requirements: []
96
+ rubyforge_project:
97
+ rubygems_version: 2.7.6
98
+ signing_key:
99
+ specification_version: 4
100
+ summary: Simple Travis V3 API Client
101
+ test_files: []