Class: Kontena::PluginManager::RubygemsClient

Inherits:
Object
  • Object
show all
Defined in:
lib/kontena/plugin_manager/rubygems_client.rb

Constant Summary collapse

RUBYGEMS_URL =
'https://rubygems.org'
HEADERS =
{
  'Content-Type' => 'application/json',
  'Accept' => 'application/json'
}

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize ⇒ RubygemsClient

Returns a new instance of RubygemsClient.



16
17
18
# File 'lib/kontena/plugin_manager/rubygems_client.rb', line 16

def initialize
  @client = Excon.new(RUBYGEMS_URL)
end

Instance Attribute Details

#client ⇒ Object (readonly)

Returns the value of attribute client.



14
15
16
# File 'lib/kontena/plugin_manager/rubygems_client.rb', line 14

def client
  @client
end

Instance Method Details

#search(pattern = nil) ⇒ Object



20
21
22
23
24
25
26
27
# File 'lib/kontena/plugin_manager/rubygems_client.rb', line 20

def search(pattern = nil)
  response = client.get(
    path: "/api/v1/search.json?query=#{pattern}",
    headers: HEADERS
  )

  JSON.parse(response.body)
end

#versions(gem_name) ⇒ Object



29
30
31
32
33
34
35
36
# File 'lib/kontena/plugin_manager/rubygems_client.rb', line 29

def versions(gem_name)
  response = client.get(
    path: "/api/v1/versions/#{gem_name}.json",
    headers: HEADERS
  )
  versions = JSON.parse(response.body)
  versions.map { |version| Gem::Version.new(version["number"]) }.sort.reverse
end