Module: Gems::API

Defined in:
lib/gemverse/api.rb

Constant Summary collapse

BASE =
'https://rubygems.org/api/v1'

Class Method Summary collapse

Class Method Details

.call(src) ⇒ Object

get response as (parsed) json (hash table)



21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/gemverse/api.rb', line 21

def self.call( src )   ## get response as (parsed) json (hash table)

  headers = {
    # 'User-Agent' => "Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/100.0.4896.127 Safari/537.36",
    'User-Agent' => "ruby v#{RUBY_VERSION}",
   }

  response = Webclient.get( src, headers: headers )

  if response.status.ok?
    puts "#{response.status.code} #{response.status.message} -  content_type: #{response.content_type}, content_length: #{response.content_length}"

    response.json
  else
    puts "!! HTTP ERROR:"
    puts "#{response.status.code} #{response.status.message}"
    exit 1
  end
end

.gems_by(owner) ⇒ Object



7
8
9
10
# File 'lib/gemverse/api.rb', line 7

def self.gems_by( owner )
  src = "#{BASE}/owners/#{owner}/gems.json"
  call( src )
end

.versions(name) ⇒ Object



13
14
15
16
17
18
# File 'lib/gemverse/api.rb', line 13

def self.versions( name )
  ## note: will NOT include yanked versions
  ##   check if there's a query parameter ???
  src = "#{BASE}/versions/#{name}.json"
  call( src )
end