Created
July 12, 2013 15:05
-
-
Save jimjh/5985170 to your computer and use it in GitHub Desktop.
Caching with github_api, faraday-http-cache, and moneta
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env ruby | |
# Usage: | |
# load './github.rb' | |
# 10.times { fire } | |
require 'github_api' | |
require 'faraday-http-cache' | |
require 'moneta' | |
require 'active_support/cache/moneta_store' | |
require 'logger' | |
@store = ActiveSupport::Cache::MonetaStore.new store: :LRUHash | |
@github = Github::Repos::Contents.new do |config| | |
config.stack.insert_before Github::Response::Jsonize, Faraday::HttpCache, @store | |
end | |
def fire | |
resp = @github.get user: 'jimjh', repo: 'floating-point-lesson', path: 'manifest.yml' | |
puts "x-ratelimit-remaining: #{resp.headers.ratelimit_remaining}" | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment