trav3 0.0.5 → 0.1.0

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: 0aafa22212b53bac7b091d13ffccbfbee54ac0757f6d0271f7090fb1586dcc31
4
- data.tar.gz: 1b754a8ba61877f424a66e6a16268d42958b363c397f83663085e5d2052f3a24
3
+ metadata.gz: a86b57df53d43247e95ff1613a8d274e05357db91679014d892373efcb97c5b0
4
+ data.tar.gz: da07e2429e707b577eba7a86b91cec5b2c577734346d68d01ca5b4d7670a6acc
5
5
  SHA512:
6
- metadata.gz: dfa80306d50c55d3bd3602a0e79688c61144a2a79a92e14becb511171908a97e9399a9b3f2963f19b39f6e12055b9ede4dca60cad0081e0c5840a44bf3ed6723
7
- data.tar.gz: 852fee66e709450e4e1666b96be8f0085df8b394374fd3f996462c4f6580545d62ba0eadfbf9e01df1e367ed9984b76d985e1055b28141bb13575c436c8534e0
6
+ metadata.gz: dcba0aaf3064b230bfdf1e8fefc360bb2d6476c0312116f7a17b60b750decbdae0c889f08ca1ef233e525ca15e1eac4af461fc7026fb32e3775051275cd1704f
7
+ data.tar.gz: 89ad1cc944a9492086799d0493257bf236da88d1e68c58df61bb07b76c82fc850578b5928ba4765dce8da07ca74288f673c11e2d98edf6aabec1694919f36acb
data/.gitignore CHANGED
@@ -8,3 +8,4 @@
8
8
  /tmp/
9
9
  **/*.swp
10
10
  /Gemfile.lock
11
+ .byebug_history
data/.yardopts ADDED
@@ -0,0 +1,2 @@
1
+ --charset utf-8
2
+ --markup markdown
data/README.md CHANGED
@@ -1,5 +1,6 @@
1
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)
2
+ [![Build Status](https://travis-ci.org/danielpclark/trav3.svg?branch=master)](https://travis-ci.org/danielpclark/trav3)
3
+ [![Inline docs](http://inch-ci.org/github/danielpclark/trav3.svg?branch=master)](http://inch-ci.org/github/danielpclark/trav3)
3
4
  [![SayThanks.io](https://img.shields.io/badge/SayThanks.io-%E2%98%BC-1EAEDB.svg)](https://saythanks.io/to/danielpclark)
4
5
 
5
6
  # Trav3
@@ -27,35 +28,32 @@ Or install it yourself as:
27
28
 
28
29
  ## Usage
29
30
 
30
- ```ruby
31
- require 'trav3'
32
- project = Trav3::Travis.new("name/example")
33
- project.owner
34
- project.owner("owner")
35
- project.repositories
36
- project.repositories("owner")
37
- project.repository
38
- project.repository("owner/repo")
39
- project.builds
40
- project.build(12345)
41
- project.build_jobs(12345)
42
- project.job(1234)
43
- project.log(1234)
44
- project.text_log(1234)
45
-
46
- # API Request Options
47
- project.defaults(limit: 25)
48
-
49
- # Pagination
50
- builds = project.builds
51
- builds.page.next
52
- builds.page.first
53
- builds.page.last
54
-
55
- # Recommended inspection
56
- builds.keys
57
- builds.dig("some_key")
58
- ```
31
+ require 'trav3'
32
+ project = Trav3::Travis.new("name/example")
33
+ project.owner
34
+ project.owner("owner")
35
+ project.repositories
36
+ project.repositories("owner")
37
+ project.repository
38
+ project.repository("owner/repo")
39
+ project.builds
40
+ project.build(12345)
41
+ project.build_jobs(12345)
42
+ project.job(1234)
43
+ project.log(1234)
44
+
45
+ # API Request Options
46
+ project.defaults(limit: 25)
47
+
48
+ # Pagination
49
+ builds = project.builds
50
+ builds.page.next
51
+ builds.page.first
52
+ builds.page.last
53
+
54
+ # Recommended inspection
55
+ builds.keys
56
+ builds.dig("some_key")
59
57
 
60
58
  ## Development
61
59
 
data/lib/trav3.rb CHANGED
@@ -1,34 +1,140 @@
1
1
  # frozen_string_literal: true
2
2
  require 'trav3/version'
3
3
  require 'trav3/options'
4
+ require 'trav3/headers'
4
5
  require 'trav3/result'
6
+ require 'trav3/post'
5
7
  require 'trav3/get'
6
8
 
9
+ # Trav3 project namespace
7
10
  module Trav3
8
11
  API_ROOT = 'https://api.travis-ci.org'
9
12
 
13
+ # An abstraction for the Travis CI v3 API
14
+ #
15
+ # @author Daniel P. Clark https://6ftdan.com
16
+ # @!attribute [r] options
17
+ # @return [Options] Request options object
18
+ # @!attribute [r] headers
19
+ # @return [Headers] Request headers object
10
20
  class Travis
11
- API_ENDPOINT = "#{API_ROOT}/v3"
21
+ API_ENDPOINT = API_ROOT
12
22
  attr_reader :options
23
+ attr_reader :headers
24
+
25
+ # @param repo [String] github_username/repository_name
26
+ # @raise [InvalidRepository] if given input does not
27
+ # conform to valid repository identifier format
28
+ # @return [Travis]
13
29
  def initialize(repo)
14
30
  raise InvalidRepository unless repo.is_a?(String) and
15
31
  Regexp.new(/(^\d+$)|(^\w+(?:\/|%2F){1}\w+$)/) === repo
16
32
 
17
33
  @repo = repo.gsub(/\//, '%2F')
18
34
  defaults(limit: 25)
35
+ h("Travis-API-Version": 3)
19
36
  end
20
37
 
21
- def [](repository = false)
22
- [API_ENDPOINT].tap {|a| a.push("repo/#{@repo}") if repository }.join('/')
23
- end
24
- private :[]
25
-
38
+ # @overload defaults(key: value, ...)
39
+ # Set as many options as you'd like for collections queried via an API request
40
+ # @param key [Symbol, String] name for value to set
41
+ # @param value [Symbol, String, Integer] value for key
42
+ # @return [self]
26
43
  def defaults(**args)
27
44
  (@options ||= Options.new).build(**args)
28
45
  self
29
46
  end
30
47
 
31
- def owner(owner = @repo[/.*?(?=(?:\/|%2F)|$)/])
48
+ # Set as many headers as you'd like for API requests
49
+ #
50
+ # h("Authorization": "token xxxxxxxxxxxxxxxxxxxxxx")
51
+ #
52
+ # @overload h(key: value, ...)
53
+ # @param key [Symbol, String] name for value to set
54
+ # @param value [Symbol, String, Integer] value for key
55
+ # @return [self]
56
+ def h(**args)
57
+ (@headers ||= Headers.new).build(**args)
58
+ self
59
+ end
60
+
61
+ # This will be either a user or organization.
62
+ #
63
+ # ## Attributes
64
+ #
65
+ # **Minimal Representation**
66
+ #
67
+ # Included when the resource is returned as part of another resource.
68
+ #
69
+ # Name Type Description
70
+ # id Integer Value uniquely identifying the owner.
71
+ # login String User or organization login set on GitHub.
72
+ #
73
+ # **Standard Representation**
74
+ #
75
+ # Included when the resource is the main response of a request, or is eager loaded.
76
+ #
77
+ # Name Type Description
78
+ # id Integer Value uniquely identifying the owner.
79
+ # login String User or organization login set on GitHub.
80
+ # name String User or organization name set on GitHub.
81
+ # github_id Integer User or organization id set on GitHub.
82
+ # avatar_url String Link to user or organization avatar (image) set on GitHub.
83
+ #
84
+ # **Additional Attributes**
85
+ #
86
+ # Name Type Description
87
+ # repositories [Repository] Repositories belonging to this account.
88
+ #
89
+ # ## Actions
90
+ #
91
+ # **Find**
92
+ #
93
+ # This returns an individual owner. It is possible to use the GitHub login or github_id in the request.
94
+ #
95
+ # GET <code>/owner/{owner.login}</code>
96
+ #
97
+ # Template Variable Type Description
98
+ # owner.login String User or organization login set on GitHub.
99
+ #
100
+ # Query Parameter Type Description
101
+ # include [String] List of attributes to eager load.
102
+ #
103
+ # Example: GET /owner/danielpclark
104
+ #
105
+ # GET <code>/owner/{user.login}</code>
106
+ #
107
+ # Template Variable Type Description
108
+ # user.login String Login set on Github.
109
+ #
110
+ # Query Parameter Type Description
111
+ # include [String] List of attributes to eager load.
112
+ #
113
+ # Example: GET /owner/danielpclark
114
+ #
115
+ # GET <code>/owner/{organization.login}</code>
116
+ #
117
+ # Template Variable Type Description
118
+ # organization.login String Login set on GitHub.
119
+ #
120
+ # Query Parameter Type Description
121
+ # include [String] List of attributes to eager load.
122
+ #
123
+ # Example: GET /owner/travis-ci
124
+ #
125
+ # GET <code>/owner/github_id/{owner.github_id}</code>
126
+ #
127
+ # Template Variable Type Description
128
+ # owner.github_id Integer User or organization id set on GitHub.
129
+ #
130
+ # Query Parameter Type Description
131
+ # include [String] List of attributes to eager load.
132
+ #
133
+ # Example: GET /owner/github_id/639823
134
+ #
135
+ # @param owner [String] username or github ID
136
+ # @return [Success, RequestError]
137
+ def owner(owner = username)
32
138
  if /^\d+$/ === owner
33
139
  get("#{self[]}/owner/github_id/#{owner}")
34
140
  else
@@ -36,7 +142,145 @@ module Trav3
36
142
  end
37
143
  end
38
144
 
39
- def repositories(owner = @repo[/.*?(?=(?:\/|%2F)|$)/])
145
+ # A list of repositories for the current user.
146
+ #
147
+ # ## Attributes
148
+ #
149
+ # Name Type Description
150
+ # repositories [Repository] List of repositories.
151
+ #
152
+ # **Collection Items**
153
+ #
154
+ # Each entry in the repositories array has the following attributes:
155
+ #
156
+ # Name Type Description
157
+ # id Integer Value uniquely identifying the repository.
158
+ # name String The repository's name on GitHub.
159
+ # slug String Same as {repository.owner.name}/{repository.name}.
160
+ # description String The repository's description from GitHub.
161
+ # github_language String The main programming language used according to GitHub.
162
+ # active Boolean Whether or not this repository is currently enabled on Travis CI.
163
+ # private Boolean Whether or not this repository is private.
164
+ # owner Owner GitHub user or organization the repository belongs to.
165
+ # default_branch Branch The default branch on GitHub.
166
+ # starred Boolean Whether or not this repository is starred.
167
+ # current_build Build The most recently started build (this excludes builds that have been created but have not yet started).
168
+ # last_started_build Build Alias for current_build.
169
+ #
170
+ # ## Actions
171
+ #
172
+ # **For Owner**
173
+ #
174
+ # This returns a list of repositories an owner has access to.
175
+ #
176
+ # GET <code>/owner/{owner.login}/repos</code>
177
+ #
178
+ # Template Variable Type Description
179
+ # owner.login String User or organization login set on GitHub.
180
+ #
181
+ # Query Parameter Type Description
182
+ # active [Boolean] Alias for repository.active.
183
+ # include [String] List of attributes to eager load.
184
+ # limit Integer How many repositories to include in the response. Used for pagination.
185
+ # offset Integer How many repositories to skip before the first entry in the response. Used for pagination.
186
+ # private [Boolean] Alias for repository.private.
187
+ # repository.active [Boolean] Filters repositories by whether or not this repository is currently enabled on Travis CI.
188
+ # repository.private [Boolean] Filters repositories by whether or not this repository is private.
189
+ # repository.starred [Boolean] Filters repositories by whether or not this repository is starred.
190
+ # sort_by [String] Attributes to sort repositories by. Used for pagination.
191
+ # starred [Boolean] Alias for repository.starred.
192
+ #
193
+ # Example: GET /owner/danielpclark/repos?limit=5&sort_by=active,name
194
+ #
195
+ # **Sortable by:** id, github_id, owner_name, name, active, default_branch.last_build, append :desc to any attribute to reverse order.
196
+ #
197
+ # GET <code>/owner/{user.login}/repos</code>
198
+ #
199
+ # Template Variable Type Description
200
+ # user.login String Login set on Github.
201
+ #
202
+ # Query Parameter Type Description
203
+ # active [Boolean] Alias for repository.active.
204
+ # include [String] List of attributes to eager load.
205
+ # limit Integer How many repositories to include in the response. Used for pagination.
206
+ # offset Integer How many repositories to skip before the first entry in the response. Used for pagination.
207
+ # private [Boolean] Alias for repository.private.
208
+ # repository.active [Boolean] Filters repositories by whether or not this repository is currently enabled on Travis CI.
209
+ # repository.private [Boolean] Filters repositories by whether or not this repository is private.
210
+ # repository.starred [Boolean] Filters repositories by whether or not this repository is starred.
211
+ # sort_by [String] Attributes to sort repositories by. Used for pagination.
212
+ # starred [Boolean] Alias for repository.starred.
213
+ #
214
+ # Example: GET /owner/danielpclark/repos?limit=5&sort_by=active,name
215
+ #
216
+ # **Sortable by:** id, github_id, owner_name, name, active, default_branch.last_build, append :desc to any attribute to reverse order.
217
+ #
218
+ # GET <code>/owner/{organization.login}/repos</code>
219
+ #
220
+ # Template Variable Type Description
221
+ # organization.login String Login set on GitHub.
222
+ #
223
+ # Query Parameter Type Description
224
+ # active [Boolean] Alias for repository.active.
225
+ # include [String] List of attributes to eager load.
226
+ # limit Integer How many repositories to include in the response. Used for pagination.
227
+ # offset Integer How many repositories to skip before the first entry in the response. Used for pagination.
228
+ # private [Boolean] Alias for repository.private.
229
+ # repository.active [Boolean] Filters repositories by whether or not this repository is currently enabled on Travis CI.
230
+ # repository.private [Boolean] Filters repositories by whether or not this repository is private.
231
+ # repository.starred [Boolean] Filters repositories by whether or not this repository is starred.
232
+ # sort_by [String] Attributes to sort repositories by. Used for pagination.
233
+ # starred [Boolean] Alias for repository.starred.
234
+ #
235
+ # Example: GET /owner/travis-ci/repos?limit=5&sort_by=active,name
236
+ #
237
+ # **Sortable by:** id, github_id, owner_name, name, active, default_branch.last_build, append :desc to any attribute to reverse order.
238
+ #
239
+ # GET <code>/owner/github_id/{owner.github_id}/repos</code>
240
+ #
241
+ # Template Variable Type Description
242
+ # owner.github_id Integer User or organization id set on GitHub.
243
+ #
244
+ # Query Parameter Type Description
245
+ # active [Boolean] Alias for repository.active.
246
+ # include [String] List of attributes to eager load.
247
+ # limit Integer How many repositories to include in the response. Used for pagination.
248
+ # offset Integer How many repositories to skip before the first entry in the response. Used for pagination.
249
+ # private [Boolean] Alias for repository.private.
250
+ # repository.active [Boolean] Filters repositories by whether or not this repository is currently enabled on Travis CI.
251
+ # repository.private [Boolean] Filters repositories by whether or not this repository is private.
252
+ # repository.starred [Boolean] Filters repositories by whether or not this repository is starred.
253
+ # sort_by [String] Attributes to sort repositories by. Used for pagination.
254
+ # starred [Boolean] Alias for repository.starred.
255
+ #
256
+ # Example: GET /owner/github_id/639823/repos?limit=5&sort_by=active,name
257
+ #
258
+ # **Sortable by:** id, github_id, owner_name, name, active, default_branch.last_build, append :desc to any attribute to reverse order.
259
+ #
260
+ # **For Current User**<br />
261
+ # This returns a list of repositories the current user has access to.
262
+ #
263
+ # GET <code>/repos</code>
264
+ #
265
+ # Query Parameter Type Description
266
+ # active [Boolean] Alias for repository.active.
267
+ # include [String] List of attributes to eager load.
268
+ # limit Integer How many repositories to include in the response. Used for pagination.
269
+ # offset Integer How many repositories to skip before the first entry in the response. Used for pagination.
270
+ # private [Boolean] Alias for repository.private.
271
+ # repository.active [Boolean] Filters repositories by whether or not this repository is currently enabled on Travis CI.
272
+ # repository.private [Boolean] Filters repositories by whether or not this repository is private.
273
+ # repository.starred [Boolean] Filters repositories by whether or not this repository is starred.
274
+ # sort_by [String] Attributes to sort repositories by. Used for pagination.
275
+ # starred [Boolean] Alias for repository.starred.
276
+ #
277
+ # Example: GET /repos?limit=5&sort_by=active,name
278
+ #
279
+ # **Sortable by:** id, github_id, owner_name, name, active, default_branch.last_build, append :desc to any attribute to reverse order.
280
+ #
281
+ # @param owner [String] username or github ID
282
+ # @return [Success, RequestError]
283
+ def repositories(owner = username)
40
284
  if /^\d+$/ === owner
41
285
  get("#{self[]}/owner/github_id/#{owner}/repos#{opts}")
42
286
  else
@@ -44,45 +288,638 @@ module Trav3
44
288
  end
45
289
  end
46
290
 
47
- def repository(repo = @repo)
291
+ # An individual repository.
292
+ #
293
+ # ## Attributes
294
+ #
295
+ # **Minimal Representation**
296
+ #
297
+ # Included when the resource is returned as part of another resource.
298
+ #
299
+ # Name Type Description
300
+ # id Integer Value uniquely identifying the repository.
301
+ # name String The repository's name on GitHub.
302
+ # slug String Same as {repository.owner.name}/{repository.name}.
303
+ #
304
+ # **Standard Representation**
305
+ #
306
+ # Included when the resource is the main response of a request, or is eager loaded.
307
+ #
308
+ # Name Type Description
309
+ # id Integer Value uniquely identifying the repository.
310
+ # name String The repository's name on GitHub.
311
+ # slug String Same as {repository.owner.name}/{repository.name}.
312
+ # description String The repository's description from GitHub.
313
+ # github_language String The main programming language used according to GitHub.
314
+ # active Boolean Whether or not this repository is currently enabled on Travis CI.
315
+ # private Boolean Whether or not this repository is private.
316
+ # owner Owner GitHub user or organization the repository belongs to.
317
+ # default_branch Branch The default branch on GitHub.
318
+ # starred Boolean Whether or not this repository is starred.
319
+ #
320
+ # ## Actions
321
+ #
322
+ # **Find**
323
+ #
324
+ # This returns an individual repository.
325
+ #
326
+ # GET <code>/repo/{repository.id}</code>
327
+ #
328
+ # Template Variable Type Description
329
+ # repository.id Integer Value uniquely identifying the repository.
330
+ #
331
+ # Query Parameter Type Description
332
+ # include [String] List of attributes to eager load.
333
+ #
334
+ # Example: GET /repo/891
335
+ #
336
+ # GET <code>/repo/{repository.slug}</code>
337
+ #
338
+ # Template Variable Type Description
339
+ # repository.slug String Same as {repository.owner.name}/{repository.name}.
340
+ #
341
+ # Query Parameter Type Description
342
+ # include [String] List of attributes to eager load.
343
+ #
344
+ # Example: GET /repo/rails%2Frails
345
+ #
346
+ # **Activate**
347
+ #
348
+ # This will activate a repository, allowing its tests to be run on Travis CI.
349
+ #
350
+ # POST <code>/repo/{repository.id}/activate</code>
351
+ #
352
+ # Template Variable Type Description
353
+ # repository.id Integer Value uniquely identifying the repository.
354
+ #
355
+ # Example: POST /repo/891/activate
356
+ #
357
+ # POST <code>/repo/{repository.slug}/activate</code>
358
+ #
359
+ # Template Variable Type Description
360
+ # repository.slug String Same as {repository.owner.name}/{repository.name}.
361
+ #
362
+ # Example: POST /repo/rails%2Frails/activate
363
+ #
364
+ # **Deactivate**
365
+ #
366
+ # This will deactivate a repository, preventing any tests from running on Travis CI.
367
+ #
368
+ # POST <code>/repo/{repository.id}/deactivate</code>
369
+ #
370
+ # Template Variable Type Description
371
+ # repository.id Integer Value uniquely identifying the repository.
372
+ #
373
+ # Example: POST /repo/891/deactivate
374
+ #
375
+ # POST <code>/repo/{repository.slug}/deactivate</code>
376
+ #
377
+ # Template Variable Type Description
378
+ # repository.slug String Same as {repository.owner.name}/{repository.name}.
379
+ #
380
+ # Example: POST /repo/rails%2Frails/deactivate
381
+ #
382
+ # **Star**
383
+ #
384
+ # This will star a repository based on the currently logged in user.
385
+ #
386
+ # POST <code>/repo/{repository.id}/star</code>
387
+ #
388
+ # Template Variable Type Description
389
+ # repository.id Integer Value uniquely identifying the repository.
390
+ #
391
+ # Example: POST /repo/891/star
392
+ #
393
+ # POST <code>/repo/{repository.slug}/star</code>
394
+ #
395
+ # Template Variable Type Description
396
+ # repository.slug String Same as {repository.owner.name}/{repository.name}.
397
+ #
398
+ # Example: POST /repo/rails%2Frails/star
399
+ #
400
+ # **Unstar**
401
+ #
402
+ # This will unstar a repository based on the currently logged in user.
403
+ #
404
+ # POST <code>/repo/{repository.id}/unstar</code>
405
+ #
406
+ # Template Variable Type Description
407
+ # repository.id Integer Value uniquely identifying the repository.
408
+ #
409
+ # Example: POST /repo/891/unstar
410
+ #
411
+ # POST <code>/repo/{repository.slug}/unstar</code>
412
+ #
413
+ # Template Variable Type Description
414
+ # repository.slug String Same as {repository.owner.name}/{repository.name}.
415
+ #
416
+ # Example: POST /repo/rails%2Frails/unstar
417
+ #
418
+ # @note POST requests require an authorization token set in the headers. See: {h}
419
+ #
420
+ # @param repo [String] github_username/repository_name
421
+ # @param action [String, Symbol] Optional argument for star/unstar/activate/deactivate
422
+ # @raise [InvalidRepository] if given input does not
423
+ # conform to valid repository identifier format
424
+ # @return [Success, RequestError]
425
+ def repository(repo = repository_name, action = nil)
48
426
  raise InvalidRepository unless repo.is_a?(String) and
49
427
  Regexp.new(/(^\d+$)|(^\w+(?:\/|%2F){1}\w+$)/) === repo
50
428
 
51
- get("#{self[]}/repo/#{repo.gsub(/\//, '%2F')}")
429
+ repo = repo.gsub(/\//, '%2F')
430
+
431
+ action = '' if !%w(star unstar activate deavtivate).include? "#{action}"
432
+
433
+ if action.empty?
434
+ get("#{self[]}/repo/#{repo}")
435
+ else
436
+ post("#{self[]}/repo/#{repo}/#{action}")
437
+ end
52
438
  end
53
439
 
440
+ # A list of builds.
441
+ #
442
+ # ## Attributes
443
+ #
444
+ # Name Type Description
445
+ # builds [Build] List of builds.
446
+ #
447
+ # **Collection Items**
448
+ #
449
+ # Each entry in the builds array has the following attributes:
450
+ #
451
+ # Name Type Description
452
+ # id Integer Value uniquely identifying the build.
453
+ # number String Incremental number for a repository's builds.
454
+ # state String Current state of the build.
455
+ # duration Integer Wall clock time in seconds.
456
+ # event_type String Event that triggered the build.
457
+ # previous_state String State of the previous build (useful to see if state changed).
458
+ # pull_request_title String Title of the build's pull request.
459
+ # pull_request_number Integer Number of the build's pull request.
460
+ # started_at String When the build started.
461
+ # finished_at String When the build finished.
462
+ # repository Repository GitHub user or organization the build belongs to.
463
+ # branch Branch The branch the build is associated with.
464
+ # tag Unknown The build's tag.
465
+ # commit Commit The commit the build is associated with.
466
+ # jobs Jobs List of jobs that are part of the build's matrix.
467
+ # stages [Stage] The stages of a build.
468
+ # created_by Owner The User or Organization that created the build.
469
+ # updated_at Unknown The build's updated_at.
470
+ # request Unknown The build's request.
471
+ #
472
+ # ## Actions
473
+ #
474
+ # **For Current User**
475
+ #
476
+ # This returns a list of builds for the current user. The result is paginated.
477
+ #
478
+ # GET <code>/builds</code>
479
+ #
480
+ # Query Parameter Type Description
481
+ # include [String] List of attributes to eager load.
482
+ # limit Integer How many builds to include in the response. Used for pagination.
483
+ # limit Integer How many builds to include in the response. Used for pagination.
484
+ # offset Integer How many builds to skip before the first entry in the response. Used for pagination.
485
+ # offset Integer How many builds to skip before the first entry in the response. Used for pagination.
486
+ # sort_by [String] Attributes to sort builds by. Used for pagination.
487
+ # sort_by [String] Attributes to sort builds by. Used for pagination.
488
+ #
489
+ # Example: GET /builds?limit=5
490
+ #
491
+ # **Sortable by:** id, started_at, finished_at, append :desc to any attribute to reverse order.
492
+ #
493
+ # **Find**
494
+ #
495
+ # This returns a list of builds for an individual repository. It is possible to use the repository id or slug in the request. The result is paginated. Each request will return 25 results.
496
+ #
497
+ # GET <code>/repo/{repository.id}/builds</code>
498
+ #
499
+ # Template Variable Type Description
500
+ # repository.id Integer Value uniquely identifying the repository.
501
+ #
502
+ # Query Parameter Type Description
503
+ # branch.name [String] Filters builds by name of the git branch.
504
+ # build.created_by [Owner] Filters builds by the User or Organization that created the build.
505
+ # build.event_type [String] Filters builds by event that triggered the build.
506
+ # build.previous_state [String] Filters builds by state of the previous build (useful to see if state changed).
507
+ # build.state [String] Filters builds by current state of the build.
508
+ # created_by [Owner] Alias for build.created_by.
509
+ # event_type [String] Alias for build.event_type.
510
+ # include [String] List of attributes to eager load.
511
+ # limit Integer How many builds to include in the response. Used for pagination.
512
+ # offset Integer How many builds to skip before the first entry in the response. Used for pagination.
513
+ # previous_state [String] Alias for build.previous_state.
514
+ # sort_by [String] Attributes to sort builds by. Used for pagination.
515
+ # state [String] Alias for build.state.
516
+ #
517
+ # Example: GET /repo/891/builds?limit=5
518
+ #
519
+ # **Sortable by:** id, started_at, finished_at, append :desc to any attribute to reverse order.
520
+ #
521
+ # GET <code>/repo/{repository.slug}/builds</code>
522
+ #
523
+ # Template Variable Type Description
524
+ # repository.slug String Same as {repository.owner.name}/{repository.name}.
525
+ #
526
+ # Query Parameter Type Description
527
+ # branch.name [String] Filters builds by name of the git branch.
528
+ # build.created_by [Owner] Filters builds by the User or Organization that created the build.
529
+ # build.event_type [String] Filters builds by event that triggered the build.
530
+ # build.previous_state [String] Filters builds by state of the previous build (useful to see if state changed).
531
+ # build.state [String] Filters builds by current state of the build.
532
+ # created_by [Owner] Alias for build.created_by.
533
+ # event_type [String] Alias for build.event_type.
534
+ # include [String] List of attributes to eager load.
535
+ # limit Integer How many builds to include in the response. Used for pagination.
536
+ # offset Integer How many builds to skip before the first entry in the response. Used for pagination.
537
+ # previous_state [String] Alias for build.previous_state.
538
+ # sort_by [String] Attributes to sort builds by. Used for pagination.
539
+ # state [String] Alias for build.state.
540
+ #
541
+ # Example: GET /repo/rails%2Frails/builds?limit=5
542
+ #
543
+ # **Sortable by:** id, started_at, finished_at, append :desc to any attribute to reverse order.
544
+ #
545
+ # @return [Success, RequestError]
54
546
  def builds
55
547
  get("#{self[true]}/builds#{opts}")
56
548
  end
57
549
 
550
+ # An individual build.
551
+ #
552
+ # ## Attributes
553
+ #
554
+ # **Minimal Representation**
555
+ #
556
+ # Included when the resource is returned as part of another resource.
557
+ #
558
+ # Name Type Description
559
+ # id Integer Value uniquely identifying the build.
560
+ # number String Incremental number for a repository's builds.
561
+ # state String Current state of the build.
562
+ # duration Integer Wall clock time in seconds.
563
+ # event_type String Event that triggered the build.
564
+ # previous_state String State of the previous build (useful to see if state changed).
565
+ # pull_request_title String Title of the build's pull request.
566
+ # pull_request_number Integer Number of the build's pull request.
567
+ # started_at String When the build started.
568
+ # finished_at String When the build finished.
569
+ #
570
+ # **Standard Representation**
571
+ #
572
+ # Included when the resource is the main response of a request, or is eager loaded.
573
+ #
574
+ # Name Type Description
575
+ # id Integer Value uniquely identifying the build.
576
+ # number String Incremental number for a repository's builds.
577
+ # state String Current state of the build.
578
+ # duration Integer Wall clock time in seconds.
579
+ # event_type String Event that triggered the build.
580
+ # previous_state String State of the previous build (useful to see if state changed).
581
+ # pull_request_title String Title of the build's pull request.
582
+ # pull_request_number Integer Number of the build's pull request.
583
+ # started_at String When the build started.
584
+ # finished_at String When the build finished.
585
+ # repository Repository GitHub user or organization the build belongs to.
586
+ # branch Branch The branch the build is associated with.
587
+ # tag Unknown The build's tag.
588
+ # commit Commit The commit the build is associated with.
589
+ # jobs Jobs List of jobs that are part of the build's matrix.
590
+ # stages [Stage] The stages of a build.
591
+ # created_by Owner The User or Organization that created the build.
592
+ # updated_at Unknown The build's updated_at.
593
+ #
594
+ # ## Actions
595
+ #
596
+ # **Find**
597
+ #
598
+ # This returns a single build.
599
+ #
600
+ # GET <code>/build/{build.id}</code>
601
+ #
602
+ # Template Variable Type Description
603
+ # build.id Integer Value uniquely identifying the build.
604
+ #
605
+ # Query Parameter Type Description
606
+ # include [String] List of attributes to eager load.
607
+ #
608
+ # Example: GET /build/86601346
609
+ #
610
+ # **Cancel**
611
+ #
612
+ # This cancels a currently running build. It will set the build and associated jobs to "state": "canceled".
613
+ #
614
+ # POST <code>/build/{build.id}/cancel</code>
615
+ #
616
+ # Template Variable Type Description
617
+ # build.id Integer Value uniquely identifying the build.
618
+ #
619
+ # Example: POST /build/86601346/cancel
620
+ #
621
+ # **Restart**
622
+ #
623
+ # This restarts a build that has completed or been canceled.
624
+ #
625
+ # POST <code>/build/{build.id}/restart</code>
626
+ #
627
+ # Template Variable Type Description
628
+ # build.id Integer Value uniquely identifying the build.
629
+ #
630
+ # Example: POST /build/86601346/restart
631
+ #
632
+ # @note POST requests require an authorization token set in the headers. See: {h}
633
+ #
634
+ # @param id [String, Integer] the build id number
635
+ # @return [Success, RequestError]
58
636
  def build(id)
59
637
  get("#{self[]}/build/#{id}")
60
638
  end
61
639
 
640
+ # A list of jobs.
641
+ #
642
+ # ## Attributes
643
+ #
644
+ # Name Type Description
645
+ # jobs [Job] List of jobs.
646
+ #
647
+ # **Collection Items**
648
+ #
649
+ # Each entry in the jobs array has the following attributes:
650
+ #
651
+ # Name Type Description
652
+ # id Integer Value uniquely identifying the job.
653
+ # allow_failure Unknown The job's allow_failure.
654
+ # number String Incremental number for a repository's builds.
655
+ # state String Current state of the job.
656
+ # started_at String When the job started.
657
+ # finished_at String When the job finished.
658
+ # build Build The build the job is associated with.
659
+ # queue String Worker queue this job is/was scheduled on.
660
+ # repository Repository GitHub user or organization the job belongs to.
661
+ # commit Commit The commit the job is associated with.
662
+ # owner Owner GitHub user or organization the job belongs to.
663
+ # stage [Stage] The stages of a job.
664
+ # created_at String When the job was created.
665
+ # updated_at String When the job was updated.
666
+ # config Object The job's config.
667
+ #
668
+ # ## Actions
669
+ #
670
+ # **Find**
671
+ #
672
+ # This returns a list of jobs belonging to an individual build.
673
+ #
674
+ # GET <code>/build/{build.id}/jobs</code>
675
+ #
676
+ # Template Variable Type Description
677
+ # build.id Integer Value uniquely identifying the build.
678
+ #
679
+ # Query Parameter Type Description
680
+ # include [String] List of attributes to eager load.
681
+ #
682
+ # Example: GET /build/86601346/jobs
683
+ #
684
+ # **For Current User**
685
+ #
686
+ # This returns a list of jobs a current user has access to.
687
+ #
688
+ # GET <code>/jobs</code>
689
+ #
690
+ # Query Parameter Type Description
691
+ # active Unknown Alias for job.active.
692
+ # created_by Unknown Alias for job.created_by.
693
+ # include [String] List of attributes to eager load.
694
+ # job.active Unknown Documentation missing.
695
+ # job.created_by Unknown Documentation missing.
696
+ # job.state [String] Filters jobs by current state of the job.
697
+ # limit Integer How many jobs to include in the response. Used for pagination.
698
+ # offset Integer How many jobs to skip before the first entry in the response. Used for pagination.
699
+ # sort_by [String] Attributes to sort jobs by. Used for pagination.
700
+ # state [String] Alias for job.state.
701
+ #
702
+ # Example: GET /jobs?limit=5
703
+ #
704
+ # **Sortable by:** id, append :desc to any attribute to reverse order.
705
+ # The default value is id:desc.
706
+ #
707
+ # @param id [String, Integer] the build id number
708
+ # @return [Success, RequestError]
62
709
  def build_jobs(id)
63
710
  get("#{self[]}/build/#{id}/jobs")
64
711
  end
65
712
 
66
- def job(id)
67
- get("#{self[]}/job/#{id}")
713
+ # An individual job.
714
+ #
715
+ # ## Attributes
716
+ #
717
+ # **Minimal Representation**
718
+ #
719
+ # Included when the resource is returned as part of another resource.
720
+ #
721
+ # Name Type Description
722
+ # id Integer Value uniquely identifying the job.
723
+ #
724
+ # **Standard Representation**
725
+ #
726
+ # Included when the resource is the main response of a request, or is eager loaded.
727
+ #
728
+ # Name Type Description
729
+ # id Integer Value uniquely identifying the job.
730
+ # allow_failure Unknown The job's allow_failure.
731
+ # number String Incremental number for a repository's builds.
732
+ # state String Current state of the job.
733
+ # started_at String When the job started.
734
+ # finished_at String When the job finished.
735
+ # build Build The build the job is associated with.
736
+ # queue String Worker queue this job is/was scheduled on.
737
+ # repository Repository GitHub user or organization the job belongs to.
738
+ # commit Commit The commit the job is associated with.
739
+ # owner Owner GitHub user or organization the job belongs to.
740
+ # stage [Stage] The stages of a job.
741
+ # created_at String When the job was created.
742
+ # updated_at String When the job was updated.
743
+ #
744
+ # ## Actions
745
+ #
746
+ # **Find**
747
+ #
748
+ # This returns a single job.
749
+ #
750
+ # GET <code>/job/{job.id}</code>
751
+ #
752
+ # Template Variable Type Description
753
+ # job.id Integer Value uniquely identifying the job.
754
+ #
755
+ # Query Parameter Type Description
756
+ # include [String] List of attributes to eager load.
757
+ #
758
+ # Example: GET /job/86601347
759
+ #
760
+ # **Cancel**
761
+ #
762
+ # This cancels a currently running job.
763
+ #
764
+ # POST <code>/job/{job.id}/cancel</code>
765
+ #
766
+ # Template Variable Type Description
767
+ # job.id Integer Value uniquely identifying the job.
768
+ #
769
+ # Example: POST /job/86601347/cancel
770
+ #
771
+ # **Restart**
772
+ #
773
+ # This restarts a job that has completed or been canceled.
774
+ #
775
+ # POST <code>/job/{job.id}/restart</code>
776
+ #
777
+ # Template Variable Type Description
778
+ # job.id Integer Value uniquely identifying the job.
779
+ #
780
+ # Example: POST /job/86601347/restart
781
+ #
782
+ # **Debug**
783
+ #
784
+ # This restarts a job in debug mode, enabling the logged-in user to ssh into the build VM. Please note this feature is only available on the travis-ci.com domain, and those repositories on the travis-ci.org domain for which the debug feature is enabled. See this document for more details.
785
+ #
786
+ # POST <code>/job/{job.id}/debug</code>
787
+ #
788
+ # Template Variable Type Description
789
+ # job.id Integer Value uniquely identifying the job.
790
+ #
791
+ # Example: POST /job/86601347/debug
792
+ #
793
+ # @note POST requests require an authorization token set in the headers. See: {h}
794
+ #
795
+ # @param id [String, Integer] the job id number
796
+ # @param option [Symbol] options for :cancel, :restart, or :debug
797
+ # @return [Success, RequestError]
798
+ def job(id, option = nil)
799
+ case option
800
+ when :cancel
801
+ post("#{self[]}/job/#{id}/cancel")
802
+ when :restart
803
+ post("#{self[]}/job/#{id}/restart")
804
+ when :debug
805
+ post("#{self[]}/job/#{id}/debug")
806
+ else
807
+ get("#{self[]}/job/#{id}")
808
+ end
809
+ end
810
+
811
+ # An individual log.
812
+ #
813
+ # ## Attributes
814
+ #
815
+ # **Minimal Representation**
816
+ #
817
+ # Included when the resource is returned as part of another resource.
818
+ #
819
+ # Name Type Description
820
+ # id Unknown The log's id.
821
+ #
822
+ # **Standard Representation**
823
+ #
824
+ # Included when the resource is the main response of a request, or is eager loaded.
825
+ #
826
+ # Name Type Description
827
+ # id Unknown The log's id.
828
+ # content Unknown The log's content.
829
+ # log_parts Unknown The log's log_parts.
830
+ #
831
+ # ## Actions
832
+ #
833
+ # **Find**
834
+ #
835
+ # This returns a single log.
836
+ #
837
+ # It's possible to specify the accept format of the request as text/plain if required. This will return the content of the log as a single blob of text.
838
+ #
839
+ # curl -H "Travis-API-Version: 3" \
840
+ # -H "Accept: text/plain" \
841
+ # -H "Authorization: token xxxxxxxxxxxx" \
842
+ # https://api.travis-ci.org/job/{job.id}/log
843
+ #
844
+ # The default response type is application/json, and will include additional meta data such as @type, @representation etc. (see [https://developer.travis-ci.org/format](https://developer.travis-ci.org/format)).
845
+ #
846
+ # GET <code>/job/{job.id}/log</code>
847
+ #
848
+ # Template Variable Type Description
849
+ # job.id Integer Value uniquely identifying the job.
850
+ #
851
+ # Query Parameter Type Description
852
+ # include [String] List of attributes to eager load.
853
+ # log.token Unknown Documentation missing.
854
+ #
855
+ # Example: GET /job/86601347/log
856
+ #
857
+ # GET <code>/job/{job.id}/log.txt</code>
858
+ #
859
+ # Template Variable Type Description
860
+ # job.id Integer Value uniquely identifying the job.
861
+ #
862
+ # Query Parameter Type Description
863
+ # include [String] List of attributes to eager load.
864
+ # log.token Unknown Documentation missing.
865
+ #
866
+ # Example:GET/job/86601347/log.txt
867
+ #
868
+ # **Delete**
869
+ #
870
+ # This removes the contents of a log. It gets replace with the message: Log removed by XXX at 2017-02-13 16:00:00 UTC.
871
+ #
872
+ # curl -X DELETE \
873
+ # -H "Travis-API-Version: 3" \
874
+ # -H "Authorization: token xxxxxxxxxxxx" \
875
+ # https://api.travis-ci.org/job/{job.id}/log
876
+ #
877
+ # DELETE <code>/job/{job.id}/log</code>
878
+ #
879
+ # Template Variable Type Description
880
+ # job.id Integer Value uniquely identifying the job.
881
+ #
882
+ # Example: DELETE /job/86601347/log
883
+ #
884
+ # @note DELETE is unimplemented
885
+ #
886
+ # @param id [String, Integer] the job id number
887
+ # @param option [Symbol] options for :text or :delete
888
+ # @return [Success, RequestError]
889
+ def log(id, option = nil)
890
+ case option
891
+ when :text
892
+ get("#{self[]}/job/#{id}/log.txt")
893
+ when :delete
894
+ raise Unimplemented
895
+ else
896
+ get("#{self[]}/job/#{id}/log")
897
+ end
68
898
  end
69
899
 
70
- def log(id)
71
- get("#{self[]}/job/#{id}/log")
900
+ private # @private
901
+ def [](repository = false)
902
+ [API_ENDPOINT].tap {|a| a.push("repo/#{@repo}") if repository }.join('/')
72
903
  end
73
904
 
74
- def text_log(id)
75
- get("#{self[]}/job/#{id}/log.txt")
905
+ def repository_name
906
+ @repo
76
907
  end
77
908
 
78
909
  def opts
79
910
  @options
80
911
  end
81
- private :opts
82
912
 
83
913
  def get(x)
84
- Trav3::GET.(x)
914
+ Trav3::GET.(x, headers())
915
+ end
916
+
917
+ def post(x, fields = {})
918
+ Trav3::POST.(x, headers(), fields)
919
+ end
920
+
921
+ def username
922
+ @repo[/.*?(?=(?:\/|%2F)|$)/]
85
923
  end
86
- private :get
87
924
  end
88
925
  end
data/lib/trav3/get.rb CHANGED
@@ -5,8 +5,15 @@ require 'trav3/result'
5
5
 
6
6
  module Trav3
7
7
  module GET
8
- def self.call(url)
9
- response = Net::HTTP.get_response(URI(url))
8
+ def self.call(url, headers = {})
9
+ uri = URI(url)
10
+ req = Net::HTTP::Get.new(uri.request_uri)
11
+ headers.each_pair { |header, value|
12
+ req[header] = value
13
+ }
14
+ http = Net::HTTP.new(uri.host, uri.port)
15
+ http.use_ssl = (uri.scheme == "https")
16
+ response = http.request(req)
10
17
 
11
18
  if Net::HTTPOK == response.code_type
12
19
  Success.new(response)
@@ -0,0 +1,33 @@
1
+ require 'forwardable'
2
+
3
+ module Trav3
4
+ class Headers
5
+ extend Forwardable
6
+ def_delegators :@heads, :each_pair
7
+
8
+ def initialize(**args)
9
+ build(**args)
10
+ end
11
+
12
+ def build(**args)
13
+ @heads ||= {}
14
+
15
+ for (key, value) in args
16
+ @heads[key] = value
17
+ end
18
+ end
19
+
20
+ def remove(key)
21
+ @heads.delete(key)
22
+ end
23
+
24
+ def +(other)
25
+ raise ArgumentError, "Invalid type provided." unless other.is_a?(Headers)
26
+ @heads.merge(other.instance_variable_get(:@heads))
27
+ end
28
+
29
+ def to_h
30
+ @heads
31
+ end
32
+ end
33
+ end
data/lib/trav3/options.rb CHANGED
@@ -17,12 +17,14 @@ module Trav3
17
17
 
18
18
  for (key, value) in args
19
19
  remove(key)
20
- @opts.push(pb[key, value])
20
+ @opts.push("#{key}=#{value}")
21
21
  end
22
22
  end
23
23
 
24
24
  def remove(key)
25
- @opts = @opts.keep_if {|a, _| ki[key][a] }
25
+ @opts = @opts.keep_if {|item, _|
26
+ !(/^#{key}=/ === "#{item}")
27
+ }
26
28
  end
27
29
 
28
30
  def +(other)
@@ -34,14 +36,8 @@ module Trav3
34
36
  opts
35
37
  end
36
38
 
37
- def pb
38
- lambda {|param, arg| "#{param}=#{arg}" }
39
+ def to_h
40
+ @opts.map {|item| item.split("=") }.to_h
39
41
  end
40
- private :pb
41
-
42
- def ki
43
- lambda {|key| lambda {|item| !(/^#{key}=/ === "#{item}") } }
44
- end
45
- private :ki
46
42
  end
47
43
  end
data/lib/trav3/post.rb ADDED
@@ -0,0 +1,26 @@
1
+ require 'net/http'
2
+ require 'uri'
3
+ require 'json'
4
+ require 'trav3/result'
5
+
6
+ module Trav3
7
+ module POST
8
+ def self.call(url, headers = {}, fields={})
9
+ uri = URI( url.sub(/\?.*$/, '') )
10
+ req = Net::HTTP::Post.new(uri.request_uri)
11
+ headers.each_pair { |header, value|
12
+ req[header] = value
13
+ }
14
+ req.set_form_data(**fields)
15
+ http = Net::HTTP.new(uri.host, uri.port)
16
+ http.use_ssl = (uri.scheme == "https")
17
+ response = http.request(req)
18
+
19
+ if Net::HTTPOK == response.code_type
20
+ Success.new(response)
21
+ else
22
+ RequestError.new(response)
23
+ end
24
+ end
25
+ end
26
+ end
data/lib/trav3/result.rb CHANGED
@@ -31,7 +31,7 @@ module Trav3
31
31
  end
32
32
 
33
33
  def inspect
34
- "<#{self.class} Response>"
34
+ "<#{self.class} Response: keys = #{self.keys}>"
35
35
  end
36
36
 
37
37
  def success?; raise Unimplemented end
data/lib/trav3/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Trav3
2
- VERSION = "0.0.5"
2
+ VERSION = "0.1.0"
3
3
  end
data/trav3.gemspec CHANGED
@@ -21,6 +21,9 @@ Gem::Specification.new do |spec|
21
21
  spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
22
22
  spec.require_paths = ["lib"]
23
23
 
24
+ # Generate YARD DOC on install
25
+ spec.metadata["yard.run"] = "yri"
26
+
24
27
  spec.add_development_dependency "bundler", "~> 1.16"
25
28
  spec.add_development_dependency "rake", "~> 10.0"
26
29
  spec.add_development_dependency "minitest", "~> 5.0"
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.5
4
+ version: 0.1.0
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-20 00:00:00.000000000 Z
11
+ date: 2018-03-21 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -61,6 +61,7 @@ extra_rdoc_files: []
61
61
  files:
62
62
  - ".gitignore"
63
63
  - ".travis.yml"
64
+ - ".yardopts"
64
65
  - Gemfile
65
66
  - LICENSE
66
67
  - README.md
@@ -69,15 +70,18 @@ files:
69
70
  - bin/setup
70
71
  - lib/trav3.rb
71
72
  - lib/trav3/get.rb
73
+ - lib/trav3/headers.rb
72
74
  - lib/trav3/options.rb
73
75
  - lib/trav3/pagination.rb
76
+ - lib/trav3/post.rb
74
77
  - lib/trav3/result.rb
75
78
  - lib/trav3/version.rb
76
79
  - trav3.gemspec
77
80
  homepage: https://github.com/danielpclark/trav3
78
81
  licenses:
79
82
  - MIT
80
- metadata: {}
83
+ metadata:
84
+ yard.run: yri
81
85
  post_install_message:
82
86
  rdoc_options: []
83
87
  require_paths: