class GemUpdater::RubyGemsFetcher
RubyGemsFetcher
is a wrapper around rubygems API.
Constants
- HTTP_TOO_MANY_REQUESTS
Attributes
gem_name[R]
Public Class Methods
new(gem_name)
click to toggle source
@param gem_name
[String] name of the gem
# File lib/gem_updater/ruby_gems_fetcher.rb, line 15 def initialize(gem_name) @gem_name = gem_name end
Public Instance Methods
changelog_uri()
click to toggle source
Finds the changelog uri. It asks rubygems.org for changelog_uri
of gem. See API: guides.rubygems.org/rubygems-org-api/#gem-methods
@return [String|nil] uri of changelog
# File lib/gem_updater/ruby_gems_fetcher.rb, line 24 def changelog_uri response = query_rubygems response.to_h['changelog_uri'] end
Private Instance Methods
parse_remote_json(url)
click to toggle source
Parse JSON from a remote url.
@param url [String] remote url @return [Hash] parsed JSON
# File lib/gem_updater/ruby_gems_fetcher.rb, line 35 def parse_remote_json(url) JSON.parse(URI.parse(url).open.read) end
query_rubygems(tries = 0)
click to toggle source
Make the real query to rubygems It may fail in case we trigger too many requests
@param tries [Integer|nil] (optional) how many times we tried
# File lib/gem_updater/ruby_gems_fetcher.rb, line 43 def query_rubygems(tries = 0) parse_remote_json("https://rubygems.org/api/v1/gems/#{gem_name}.json") rescue OpenURI::HTTPError => e # We may trigger too many requests, in which case give rubygems a break if e.io.status.include?(HTTP_TOO_MANY_REQUESTS) tries += 1 sleep 1 && retry if tries < 2 end end