travis-client 0.1.0 → 3.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (62) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +4 -2
  3. data/.rspec +3 -2
  4. data/.travis.yml +2 -9
  5. data/.yardopts +2 -0
  6. data/Gemfile +1 -3
  7. data/Gemfile.lock +59 -0
  8. data/lib/travis/client.rb +20 -104
  9. data/lib/travis/client/action.rb +128 -0
  10. data/lib/travis/client/collection.rb +66 -0
  11. data/lib/travis/client/connection.rb +104 -0
  12. data/lib/travis/client/context.rb +52 -0
  13. data/lib/travis/client/entity.rb +77 -0
  14. data/lib/travis/client/error.rb +47 -0
  15. data/lib/travis/client/generated.rb +2073 -0
  16. data/lib/travis/client/link.rb +34 -0
  17. data/lib/travis/client/session.rb +101 -0
  18. data/lib/travis/client/unknown.rb +5 -0
  19. data/lib/travis/client/version.rb +6 -0
  20. data/readme.md +187 -0
  21. data/script/generate +44 -0
  22. data/spec/http_responses/default/branches.http +715 -0
  23. data/spec/http_responses/default/find_owner.http +23 -0
  24. data/spec/http_responses/default/index.http +1518 -0
  25. data/spec/http_responses/default/repo.http +44 -0
  26. data/spec/http_responses/default/repo_branches_10.http +347 -0
  27. data/spec/http_responses/default/repo_branches_10_0.http +347 -0
  28. data/spec/http_responses/default/repo_branches_10_10.http +351 -0
  29. data/spec/http_responses/default/repo_branches_10_20.http +99 -0
  30. data/spec/http_responses/default/sync.http +12 -0
  31. data/spec/http_responses/default/user_repos.http +6315 -0
  32. data/spec/spec_helper.rb +4 -2
  33. data/spec/support/coverage.rb +8 -0
  34. data/spec/support/generate_http_response.rb +16 -0
  35. data/spec/support/http.rb +54 -0
  36. data/spec/travis/collection_spec.rb +19 -0
  37. data/spec/travis/connection_spec.rb +26 -0
  38. data/spec/travis/entity_spec.rb +27 -0
  39. data/spec/travis_spec.rb +18 -0
  40. data/travis-client.gemspec +21 -21
  41. metadata +103 -75
  42. data/README.textile +0 -111
  43. data/Rakefile +0 -8
  44. data/bin/travis +0 -21
  45. data/features/repositories.feature +0 -117
  46. data/features/step_definitions/repositories_steps.rb +0 -51
  47. data/features/support/env.rb +0 -2
  48. data/lib/travis.rb +0 -2
  49. data/lib/travis/api.rb +0 -3
  50. data/lib/travis/api/client.rb +0 -95
  51. data/lib/travis/api/client/repositories.rb +0 -234
  52. data/lib/travis/api/entity.rb +0 -44
  53. data/lib/travis/api/entity/build.rb +0 -129
  54. data/lib/travis/api/entity/repository.rb +0 -79
  55. data/lib/travis/client/repositories.rb +0 -345
  56. data/spec/travis/api/client/repositories_spec.rb +0 -2
  57. data/spec/travis/api/client_spec.rb +0 -15
  58. data/spec/travis/api/entity/build_spec.rb +0 -84
  59. data/spec/travis/api/entity/repository_spec.rb +0 -79
  60. data/spec/travis/api/entity_spec.rb +0 -46
  61. data/spec/travis/api/shared_client_examples.rb +0 -3
  62. data/spec/travis/api/shared_entity_examples.rb +0 -16
@@ -1,2 +1,4 @@
1
- require './lib/travis'
2
-
1
+ require 'bundler/setup'
2
+ require 'support/coverage' unless ENV['SKIP_COVERAGE']
3
+ require 'support/http'
4
+ require 'travis/client'
@@ -0,0 +1,8 @@
1
+ unless ENV['SKIP_COVERAGE']
2
+ require 'simplecov'
3
+
4
+ SimpleCov.start do
5
+ coverage_dir '.coverage'
6
+ add_filter '/spec/'
7
+ end
8
+ end
@@ -0,0 +1,16 @@
1
+ if ARGV.size != 2
2
+ $stderr.puts "Usage:\t#$0 [URI]", "\tExample: #$0 GET https://api.travis-ci.org/example"
3
+ exit 1
4
+ end
5
+
6
+ require 'http'
7
+ response = HTTP.headers('Accept' => 'application/json', 'Travis-API-Version' => '3').request(ARGV[0], ARGV[1])
8
+ keep_headers = %w[Content-Type Location]
9
+
10
+ puts "#{ARGV[0]} #{ARGV[1]} HTTP/1.1", "Accept: application/json", "Travis-API-Version: 3", "", "HTTP/1.1 #{response.status}"
11
+ keep_headers.each do |header|
12
+ next unless response.headers.include? header
13
+ puts "#{header}: #{response.headers[header]}"
14
+ end
15
+
16
+ puts '', response.body
@@ -0,0 +1,54 @@
1
+ module Support
2
+ class FakeHTTP
3
+ Response = Struct.new(:body)
4
+ def self.new(directory = 'default')
5
+ @instances ||= {}
6
+ @instances[directory] ||= super
7
+ end
8
+
9
+ def initialize(directory)
10
+ @headers = {}
11
+ @endpoints = []
12
+ Dir.glob("#{__dir__}/../http_responses/#{directory}/**.http").sort.each { |file| self << File.read(file) }
13
+ end
14
+
15
+ def <<(raw_http)
16
+ entries = raw_http.gsub("\n", "\r\n").split(%r{(?=^HTTP/1.1)})
17
+ return unless entries.size == 2
18
+
19
+ @endpoints << entries.map do |raw|
20
+ parser = HTTP::Parser.new
21
+ body = ""
22
+ parser.on_body = proc { |chunk| body << chunk }
23
+ parser << raw
24
+ [parser, body]
25
+ end
26
+ end
27
+
28
+ def request(method, uri, options = {})
29
+ # TODO: options
30
+ response, body = response_for(method, uri, @headers)
31
+ Response.new(body)
32
+ end
33
+
34
+ def response_for(method, uri, headers)
35
+ @endpoints.each do |(request, request_body), (response, response_body)|
36
+ next unless request.http_method == method.to_s.upcase
37
+ next unless request.request_url == uri.to_s
38
+ next unless request.headers.all? { |k, v| headers[k] == v }
39
+ return [response, response_body]
40
+ end
41
+
42
+ raise RuntimeError, "could not find matching request: #{method} #{uri}"
43
+ end
44
+
45
+ def persistent(uri)
46
+ self
47
+ end
48
+
49
+ def headers(headers = {})
50
+ @headers = headers
51
+ self
52
+ end
53
+ end
54
+ end
@@ -0,0 +1,19 @@
1
+ describe Travis::Client::Collection do
2
+ let(:session) { Travis::Client::Connection.new(http_factory: Support::FakeHTTP.new).create_session }
3
+ let(:repository) { session.find_repository(slug: 'travis-ci/travis.rb') }
4
+ subject(:branches) { session.find_branches(repository: repository, limit: 10) }
5
+
6
+ example { expect(branches.size).to be == 22 }
7
+ example { expect(branches.to_a.size).to be == 22 }
8
+
9
+ example { expect(branches).to be_first_page }
10
+ example { expect(branches).not_to be_last_page }
11
+
12
+ example { expect(branches.last_page.first_page).to be == branches }
13
+ example { expect(branches.pagination_info['first'].fetch) .to be == branches }
14
+ example { expect(branches.pagination_info['first'].to_entity) .to be == branches }
15
+ example { expect(branches.pagination_info['first'].offset) .to be == 0 }
16
+ example { expect(branches.pagination_info['first'].limit) .to be == 10 }
17
+ example { expect(branches.pagination_info['first'].inspect) .to include('/repo/409371/branches?limit=10') }
18
+ example { expect(branches.pagination_info['first'].to_h) .to include('@href') }
19
+ end
@@ -0,0 +1,26 @@
1
+ describe Travis::Client::Connection do
2
+ subject(:connection) { Travis::Client::Connection.new(http_factory: Support::FakeHTTP.new) }
3
+
4
+ describe :resource_types do
5
+ example { expect(connection.resource_types).to include('repository') }
6
+ example { expect(connection.resource_types[ 'repository' ].superclass).to be == Travis::Client::Entity }
7
+ example { expect(connection.resource_types[ 'repositories' ].superclass).to be == Travis::Client::Collection }
8
+ end
9
+
10
+ [:before_request, :after_request].each do |callback_type|
11
+ describe callback_type do
12
+ let(:requests) { [] }
13
+ before { connection.public_send(callback_type) { |request| requests << request } }
14
+ example do
15
+ connection.create_session.request('GET', 'https://api.travis-ci.org')
16
+ expect(requests.first.uri.to_s).to be == 'https://api.travis-ci.org'
17
+ end
18
+ end
19
+ end
20
+
21
+ describe :action do
22
+ example { expect(connection.action(:user, :find)).to be_a(Travis::Client::Action) }
23
+ example { expect { connection.action(:foo, :bar) }.to raise_exception(ArgumentError) }
24
+ example { expect { connection.action(:user, :bar) }.to raise_exception(ArgumentError) }
25
+ end
26
+ end
@@ -0,0 +1,27 @@
1
+ describe Travis::Client::Entity do
2
+ let(:session) { Travis::Client::Connection.new(http_factory: Support::FakeHTTP.new).create_session }
3
+ subject(:user) { session.find_owner(login: 'rkh') }
4
+
5
+ describe :inspect do
6
+ example { expect(user.inspect).to include('/user/267') }
7
+ end
8
+
9
+ describe :to_h do
10
+ let(:json) { session.connection.http_factory.request('GET', 'https://api.travis-ci.org/owner/rkh').body }
11
+ example { expect(user.to_h).to be == JSON.load(json) }
12
+ end
13
+
14
+ describe :to_entity do
15
+ example { expect(user.to_entity).to be == user }
16
+ end
17
+
18
+ describe :permission do
19
+ example { expect(user).to be_permission(:read) }
20
+ example { expect(user).not_to be_permission(:sync) }
21
+ end
22
+
23
+ describe 'lazy loading' do
24
+ example { expect(user.repositories.first.name) .to be == 'almost-sinatra' }
25
+ example { expect(user.repositories.first.owner) .to be == user }
26
+ end
27
+ end
@@ -0,0 +1,18 @@
1
+ describe Travis do
2
+ describe 'generated constants' do
3
+ before(:all) { Travis.connect(http_factory: Support::FakeHTTP.new) }
4
+ before { @stderr, $stderr = $stderr, StringIO.new }
5
+ after { $stderr = @stderr }
6
+
7
+ example { expect(Travis::Owner.find(login: 'rkh')).to be == Travis.session.find_user(id: 267, include: 'user.repositories') }
8
+ example { expect { Travis::Owner.find(login: 'rkh').sync }.to raise_exception(Travis::LoginRequired) }
9
+ example { expect { Travis::Missing }.to raise_exception(NameError) }
10
+ example { expect(Travis::Repository.find(slug: 'travis-ci/travis.rb').find_branches) .to be == Travis.session.branches_find('repository.id' => 409371) }
11
+ example { expect(Travis::Repository.find(slug: 'travis-ci/travis.rb').branches) .to be == Travis.session.branches_find('repository.id' => 409371) }
12
+
13
+ example do
14
+ Travis.connect(http_factory: Support::FakeHTTP.new)
15
+ expect($stderr.string).to include('WARNING: It is not recommended to call Travis.connect more than once')
16
+ end
17
+ end
18
+ end
@@ -1,26 +1,26 @@
1
- Gem::Specification.new do |gem|
1
+ $:.unshift File.expand_path('../lib', __FILE__)
2
+ require 'travis/client/version'
2
3
 
3
- gem.name = 'travis-client'
4
- gem.version = '0.1.0'
5
- gem.date = '2011-08-16'
6
- gem.authors = ['Roberto Decurnex']
7
- gem.email = 'nex.development@gmail.com'
8
- gem.description = %q{A Ruby wrapper for the Travis CI API}
9
- gem.summary = %q{A Ruby wrapper for the Travis CI API}
10
- gem.homepage = 'https://github.com/travis/travis-ruby-client'
4
+ Gem::Specification.new('travis-client', Travis::Client::VERSION) do |s|
5
+ s.author = 'Travis CI GmbH'
6
+ s.email = 'support@travis-ci.com'
7
+ s.homepage = 'https://developer.travis-ci.org'
8
+ s.summary = 'Travis CI API client'
9
+ s.description = 'Ruby client library for Travis CI API v3'
10
+ s.license = 'MIT'
11
+ s.required_ruby_version = '>= 2.3.0'
11
12
 
12
- gem.add_runtime_dependency 'faraday'
13
- gem.add_runtime_dependency 'hirb'
14
- gem.add_development_dependency 'rake'
15
- gem.add_development_dependency 'rspec'
16
- gem.add_development_dependency 'cucumber'
13
+ if File.exist? '.git'
14
+ s.files = `git ls-files`.split("\n")
15
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
16
+ s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
17
+ end
17
18
 
18
- gem.required_ruby_version = '>= 1.8.7'
19
-
20
- gem.require_paths = ['lib']
21
- gem.files = `git ls-files`.split("\n")
22
- gem.bindir = 'bin'
23
- gem.executables = ['travis']
19
+ # run time dependencies
20
+ s.add_dependency 'http', '~> 2.1'
21
+ s.add_dependency 'addressable', '~> 2.5'
24
22
 
23
+ # development dependencies
24
+ s.add_development_dependency 'simplecov', '~> 0.12'
25
+ s.add_development_dependency 'rspec', '~> 3.5'
25
26
  end
26
-
metadata CHANGED
@@ -1,128 +1,156 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: travis-client
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
5
- prerelease:
4
+ version: 3.0.0
6
5
  platform: ruby
7
6
  authors:
8
- - Roberto Decurnex
7
+ - Travis CI GmbH
9
8
  autorequire:
10
9
  bindir: bin
11
10
  cert_chain: []
12
- date: 2011-08-16 00:00:00.000000000Z
11
+ date: 2017-04-04 00:00:00.000000000 Z
13
12
  dependencies:
14
13
  - !ruby/object:Gem::Dependency
15
- name: faraday
16
- requirement: &75768790 !ruby/object:Gem::Requirement
17
- none: false
14
+ name: http
15
+ requirement: !ruby/object:Gem::Requirement
18
16
  requirements:
19
- - - ! '>='
17
+ - - "~>"
20
18
  - !ruby/object:Gem::Version
21
- version: '0'
19
+ version: '2.1'
22
20
  type: :runtime
23
21
  prerelease: false
24
- version_requirements: *75768790
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '2.1'
25
27
  - !ruby/object:Gem::Dependency
26
- name: hirb
27
- requirement: &75768490 !ruby/object:Gem::Requirement
28
- none: false
28
+ name: addressable
29
+ requirement: !ruby/object:Gem::Requirement
29
30
  requirements:
30
- - - ! '>='
31
+ - - "~>"
31
32
  - !ruby/object:Gem::Version
32
- version: '0'
33
+ version: '2.5'
33
34
  type: :runtime
34
35
  prerelease: false
35
- version_requirements: *75768490
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '2.5'
36
41
  - !ruby/object:Gem::Dependency
37
- name: rake
38
- requirement: &75768190 !ruby/object:Gem::Requirement
39
- none: false
42
+ name: simplecov
43
+ requirement: !ruby/object:Gem::Requirement
40
44
  requirements:
41
- - - ! '>='
45
+ - - "~>"
42
46
  - !ruby/object:Gem::Version
43
- version: '0'
47
+ version: '0.12'
44
48
  type: :development
45
49
  prerelease: false
46
- version_requirements: *75768190
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '0.12'
47
55
  - !ruby/object:Gem::Dependency
48
56
  name: rspec
49
- requirement: &75767860 !ruby/object:Gem::Requirement
50
- none: false
57
+ requirement: !ruby/object:Gem::Requirement
51
58
  requirements:
52
- - - ! '>='
59
+ - - "~>"
53
60
  - !ruby/object:Gem::Version
54
- version: '0'
61
+ version: '3.5'
55
62
  type: :development
56
63
  prerelease: false
57
- version_requirements: *75767860
58
- - !ruby/object:Gem::Dependency
59
- name: cucumber
60
- requirement: &75767630 !ruby/object:Gem::Requirement
61
- none: false
64
+ version_requirements: !ruby/object:Gem::Requirement
62
65
  requirements:
63
- - - ! '>='
66
+ - - "~>"
64
67
  - !ruby/object:Gem::Version
65
- version: '0'
66
- type: :development
67
- prerelease: false
68
- version_requirements: *75767630
69
- description: A Ruby wrapper for the Travis CI API
70
- email: nex.development@gmail.com
71
- executables:
72
- - travis
68
+ version: '3.5'
69
+ description: Ruby client library for Travis CI API v3
70
+ email: support@travis-ci.com
71
+ executables: []
73
72
  extensions: []
74
73
  extra_rdoc_files: []
75
74
  files:
76
- - .gitignore
77
- - .rspec
78
- - .travis.yml
75
+ - ".gitignore"
76
+ - ".rspec"
77
+ - ".travis.yml"
78
+ - ".yardopts"
79
79
  - Gemfile
80
- - README.textile
81
- - Rakefile
82
- - bin/travis
83
- - features/repositories.feature
84
- - features/step_definitions/repositories_steps.rb
85
- - features/support/env.rb
86
- - lib/travis.rb
87
- - lib/travis/api.rb
88
- - lib/travis/api/client.rb
89
- - lib/travis/api/client/repositories.rb
90
- - lib/travis/api/entity.rb
91
- - lib/travis/api/entity/build.rb
92
- - lib/travis/api/entity/repository.rb
80
+ - Gemfile.lock
93
81
  - lib/travis/client.rb
94
- - lib/travis/client/repositories.rb
82
+ - lib/travis/client/action.rb
83
+ - lib/travis/client/collection.rb
84
+ - lib/travis/client/connection.rb
85
+ - lib/travis/client/context.rb
86
+ - lib/travis/client/entity.rb
87
+ - lib/travis/client/error.rb
88
+ - lib/travis/client/generated.rb
89
+ - lib/travis/client/link.rb
90
+ - lib/travis/client/session.rb
91
+ - lib/travis/client/unknown.rb
92
+ - lib/travis/client/version.rb
93
+ - readme.md
94
+ - script/generate
95
+ - spec/http_responses/default/branches.http
96
+ - spec/http_responses/default/find_owner.http
97
+ - spec/http_responses/default/index.http
98
+ - spec/http_responses/default/repo.http
99
+ - spec/http_responses/default/repo_branches_10.http
100
+ - spec/http_responses/default/repo_branches_10_0.http
101
+ - spec/http_responses/default/repo_branches_10_10.http
102
+ - spec/http_responses/default/repo_branches_10_20.http
103
+ - spec/http_responses/default/sync.http
104
+ - spec/http_responses/default/user_repos.http
95
105
  - spec/spec_helper.rb
96
- - spec/travis/api/client/repositories_spec.rb
97
- - spec/travis/api/client_spec.rb
98
- - spec/travis/api/entity/build_spec.rb
99
- - spec/travis/api/entity/repository_spec.rb
100
- - spec/travis/api/entity_spec.rb
101
- - spec/travis/api/shared_client_examples.rb
102
- - spec/travis/api/shared_entity_examples.rb
106
+ - spec/support/coverage.rb
107
+ - spec/support/generate_http_response.rb
108
+ - spec/support/http.rb
109
+ - spec/travis/collection_spec.rb
110
+ - spec/travis/connection_spec.rb
111
+ - spec/travis/entity_spec.rb
112
+ - spec/travis_spec.rb
103
113
  - travis-client.gemspec
104
- homepage: https://github.com/travis/travis-ruby-client
105
- licenses: []
114
+ homepage: https://developer.travis-ci.org
115
+ licenses:
116
+ - MIT
117
+ metadata: {}
106
118
  post_install_message:
107
119
  rdoc_options: []
108
120
  require_paths:
109
121
  - lib
110
122
  required_ruby_version: !ruby/object:Gem::Requirement
111
- none: false
112
123
  requirements:
113
- - - ! '>='
124
+ - - ">="
114
125
  - !ruby/object:Gem::Version
115
- version: 1.8.7
126
+ version: 2.3.0
116
127
  required_rubygems_version: !ruby/object:Gem::Requirement
117
- none: false
118
128
  requirements:
119
- - - ! '>='
129
+ - - ">="
120
130
  - !ruby/object:Gem::Version
121
131
  version: '0'
122
132
  requirements: []
123
133
  rubyforge_project:
124
- rubygems_version: 1.8.10
134
+ rubygems_version: 2.6.8
125
135
  signing_key:
126
- specification_version: 3
127
- summary: A Ruby wrapper for the Travis CI API
128
- test_files: []
136
+ specification_version: 4
137
+ summary: Travis CI API client
138
+ test_files:
139
+ - spec/http_responses/default/branches.http
140
+ - spec/http_responses/default/find_owner.http
141
+ - spec/http_responses/default/index.http
142
+ - spec/http_responses/default/repo.http
143
+ - spec/http_responses/default/repo_branches_10.http
144
+ - spec/http_responses/default/repo_branches_10_0.http
145
+ - spec/http_responses/default/repo_branches_10_10.http
146
+ - spec/http_responses/default/repo_branches_10_20.http
147
+ - spec/http_responses/default/sync.http
148
+ - spec/http_responses/default/user_repos.http
149
+ - spec/spec_helper.rb
150
+ - spec/support/coverage.rb
151
+ - spec/support/generate_http_response.rb
152
+ - spec/support/http.rb
153
+ - spec/travis/collection_spec.rb
154
+ - spec/travis/connection_spec.rb
155
+ - spec/travis/entity_spec.rb
156
+ - spec/travis_spec.rb