Sha256: b9f80751ef0c8841cbb930fd1273791bbe10d73869d3b40e46bb193d3aa62d6c
Contents?: true
Size: 1.44 KB
Versions: 1
Compression:
Stored size: 1.44 KB
Contents
require "uri" require "net/http" module Foobara module RubyGemsApi class GetVersions < Foobara::Command API_URL = ->(gem_name) { "https://rubygems.org/api/v1/versions/#{gem_name}.json" } inputs do gem_name :string, :required end result [Version] def execute build_request_body build_request_headers issue_http_request parse_response build_versions versions end attr_accessor :request_body, :request_headers, :response, :response_body, :versions def build_request_body self.request_body = {} end def build_request_headers self.request_headers = { "Content-Type" => "application/json" } end def url API_URL.call(gem_name) end def issue_http_request uri = URI(url) uri.query = URI.encode_www_form(request_body) self.response = Net::HTTP.get_response(uri, request_headers) end def parse_response json = if response.is_a?(Net::HTTPSuccess) response.body else # :nocov: raise "Could not successfully hit #{url}: " \ "#{response.code} #{response.message}" # :nocov: end self.response_body = JSON.parse(json) end def build_versions self.versions = response_body end end end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
foobara-ruby-gems-api-0.0.1 | src/foobara/ruby_gems_api/get_versions.rb |