module GithubReleases

Constants

LATEST_ID
RELEASES_KEY
RELEASE_KEY
VERSION

Public Class Methods

all() click to toggle source
# File lib/github_releases.rb, line 9
def all
  fetch(RELEASES_KEY, endpoint)
end
current_version() click to toggle source
# File lib/github_releases.rb, line 17
def current_version
  ENV['CURRENT_VERSION'] || find(LATEST_ID)['tag_name']
end
find(id) click to toggle source
# File lib/github_releases.rb, line 13
def find(id)
  fetch("#{RELEASE_KEY}-#{id}", "#{endpoint}/#{id}")
end
refresh() click to toggle source
# File lib/github_releases.rb, line 21
def refresh
  cache.write(RELEASES_KEY, get(endpoint))
  cache.write("#{RELEASE_KEY}-#{LATEST_ID}", get("#{endpoint}/#{LATEST_ID}"))
end
setup() { |self| ... } click to toggle source
# File lib/github_releases/engine.rb, line 17
def self.setup(&block)
  yield self
end

Private Class Methods

cache() click to toggle source
# File lib/github_releases.rb, line 52
def cache
  Rails.cache
end
endpoint() click to toggle source
# File lib/github_releases.rb, line 47
def endpoint
  "#{GithubReleases.github_api}/repos/#{GithubReleases.username}/" \
    "#{GithubReleases.repo}/releases"
end
fetch(key, resource) click to toggle source
# File lib/github_releases.rb, line 28
def fetch(key, resource)
  return cache.read(key) if cache.exist?(key)
  cache.write(key, get(resource))
  cache.read(key)
end
get(resource) click to toggle source
# File lib/github_releases.rb, line 34
def get(resource)
  JSON.parse(HTTParty.get(resource, headers: headers).body)
end
headers() click to toggle source
# File lib/github_releases.rb, line 38
def headers
  {
    'Content-Type'  => 'application/json',
    'Accept'        => 'application/vnd.github.v3+json',
    'User-Agent'    => GithubReleases.username,
    'Authorization' => "token #{ENV['GITHUB_API_TOKEN']}"
  }
end