You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The **github_api** provides ability to specify global configruation options. These options will be available to all api calls.
@@ -340,6 +366,28 @@ ssl: {
340
366
341
367
For instance, download CA root certificates from Mozilla [cacert](http://curl.haxx.se/ca/cacert.pem) and point ca_file at your certificate bundle location. This will allow the client to verify the github.com ssl certificate as authentic.
342
368
369
+
### 2.4 Caching
370
+
371
+
Caching is supported through the [`faraday-http-cache` gem](https://github.com/plataformatec/faraday-http-cache).
372
+
373
+
Add the gem to your Gemfile:
374
+
375
+
```ruby
376
+
gem 'faraday-http-cache'
377
+
```
378
+
379
+
You can now configure cache parameters as follows
380
+
381
+
```ruby
382
+
Github.configure do |config|
383
+
config.stack do |builder|
384
+
builder.use Faraday::HttpCache, store:Rails.cache
385
+
end
386
+
end
387
+
```
388
+
389
+
More details on the available options can be found in the gem's own documentation: https://github.com/plataformatec/faraday-http-cache#faraday-http-cache
Any request that returns multiple items will be paginated to 30 items by default. You can specify custom `page` and `per_page` query parameters to alter default behavior. For instance:
Then you can query the pagination information included in the link header by:
469
494
470
495
```ruby
471
-
res.links.first # Shows the URL of the first page of results.
472
-
res.links.next # Shows the URL of the immediate next page of results.
473
-
res.links.prev # Shows the URL of the immediate previous page of results.
474
-
res.links.last # Shows the URL of the last page of results.
496
+
response.links.first # Shows the URL of the first page of results.
497
+
response.links.next # Shows the URL of the immediate next page of results.
498
+
response.links.prev # Shows the URL of the immediate previous page of results.
499
+
response.links.last # Shows the URL of the last page of results.
475
500
```
476
501
477
502
In order to iterate through the entire result set page by page, you can use convenience methods:
478
503
479
504
```ruby
480
-
res.each_page do |page|
505
+
response.each_page do |page|
481
506
page.each do |repo|
482
507
puts repo.name
483
508
end
484
509
end
485
510
```
486
511
487
-
or use `has_next_page?` and `next_page` like in the following:
512
+
or use `has_next_page?` and `next_page`helper methods like in the following:
488
513
489
514
```ruby
490
-
whileres.has_next_page?
515
+
whileresponse.has_next_page?
491
516
... process response ...
492
517
res.next_page
493
518
end
494
519
```
495
520
496
-
Alternatively, you can retrieve all pages in one invocation by passing the `auto_pagination` option like so:
497
-
498
-
```ruby
499
-
github =Github.newauto_pagination:true
500
-
```
501
-
502
-
Depending at what stage you pass the `auto_pagination` it will affect all or only a single request:
503
-
504
-
```ruby
505
-
Github::Repos.newauto_pagination:true# affects Repos part of API
506
-
507
-
Github::Repos.new.list user:'...', auto_pagination:true# affects a single request
508
-
```
509
-
510
521
One can also navigate straight to the specific page by:
511
522
512
523
```ruby
@@ -518,31 +529,27 @@ res.prev_page # Get previous page
518
529
res.last_page # Get last page
519
530
```
520
531
521
-
## 11 Caching
522
-
523
-
Caching is supported through the [`faraday-http-cache` gem](https://github.com/plataformatec/faraday-http-cache).
532
+
### 4.1 Auto pagination
524
533
525
-
Add the gem to your Gemfile:
534
+
You can retrieve all pages in one invocation by passing the `auto_pagination` option like so:
526
535
527
-
gem 'faraday-http-cache'
536
+
```ruby
537
+
github =Github.newauto_pagination:true
538
+
```
528
539
529
-
You can now configure cache parameters as follows
540
+
Depending at what stage you pass the `auto_pagination` it will affect all or only a single request. For example, in order to auto paginate all Repository API methods do:
530
541
531
542
```ruby
532
-
Github.configure do |config|
533
-
config.stack do |builder|
534
-
builder.use Faraday::HttpCache, store:Rails.cache
535
-
end
536
-
end
543
+
Github::Repos.newauto_pagination:true
537
544
```
538
545
539
-
More details on the available options can be found in the gem's own documentation: https://github.com/plataformatec/faraday-http-cache#faraday-http-cache
540
-
541
-
## 12 Debugging
546
+
However, to only auto paginate results for a single request do:
542
547
543
-
run with ENV['DEBUG'] flag or include middleware by passing `debug` flag
The generic error class `Github::Error::GithubError` will handle both the client (`Github::Error::ClientError`) and service (`Github::Error::ServiceError`) side errors. For instance in your code you can catch errors like
548
555
@@ -560,40 +567,9 @@ rescue Github::Error::GithubError => e
560
567
end
561
568
```
562
569
570
+
## 6 Examples
563
571
564
-
## 15 Examples
565
-
566
-
Some API methods require input parameters. These are simply added as a hash of properties, for instance
0 commit comments