Skip to content

Instantly share code, notes, and snippets.

@jimjh
Created July 12, 2013 15:05
Show Gist options
  • Save jimjh/5985170 to your computer and use it in GitHub Desktop.
Save jimjh/5985170 to your computer and use it in GitHub Desktop.
Caching with github_api, faraday-http-cache, and moneta
#!/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