Class: RubyGems

Inherits:
Object
  • Object
show all
Defined in:
lib/ruby_gems.rb

Instance Method Summary collapse

Constructor Details

#initialize(gem_name) ⇒ RubyGems

Returns a new instance of RubyGems.



6
7
8
9
# File 'lib/ruby_gems.rb', line 6

def initialize(gem_name)
  @response = Faraday.get "https://rubygems.org/api/v1/gems/#{gem_name}.json"
  @body = JSON.parse(@response.body)
end

Instance Method Details

#authorsObject



54
55
56
# File 'lib/ruby_gems.rb', line 54

def authors
  @body["authors"].split(",").map { |author| author.strip }
end

#dependenciesObject



46
47
48
# File 'lib/ruby_gems.rb', line 46

def dependencies
  Hash[@body["dependencies"].map{|(k,v)| [k.to_sym,[Hash[v.first.map{|(k,v)| [k.to_sym,v]}]]]}]
end

#descriptionObject



42
43
44
# File 'lib/ruby_gems.rb', line 42

def description
  @body["info"]
end

#downloadsObject



15
16
17
# File 'lib/ruby_gems.rb', line 15

def downloads
  @body["downloads"]
end

#licensesObject



50
51
52
# File 'lib/ruby_gems.rb', line 50

def licenses
  @body["licenses"]
end

#nameObject



58
59
60
# File 'lib/ruby_gems.rb', line 58

def name
  @body["name"]
end

#platformObject



62
63
64
# File 'lib/ruby_gems.rb', line 62

def platform
  @body["platform"]
end

#statusObject



11
12
13
# File 'lib/ruby_gems.rb', line 11

def status
  @response.status
end

#urlsObject



27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/ruby_gems.rb', line 27

def urls
  url_hash = {}

  url_hash[:bug_tracker_uri] = @body["bug_tracker_uri"] if @body["bug_tracker_uri"]
  url_hash[:documentation_uri] = @body["documentation_uri"] if @body["documentation_uri"]
  url_hash[:gem_uri] = @body["gem_uri"] if @body["gem_uri"]
  url_hash[:homepage_uri] = @body["homepage_uri"] if @body["homepage_uri"]
  url_hash[:mailing_list_uri] = @body["mailing_list_uri"] if @body["mailing_list_uri"]
  url_hash[:project_uri] = @body["project_uri"] if @body["project_uri"]
  url_hash[:source_code_uri] = @body["source_code_uri"] if @body["source_code_uri"]
  url_hash[:wiki_uri] = @body["wiki_uri"] if @body["wiki_uri"]

  url_hash
end

#versionObject



19
20
21
# File 'lib/ruby_gems.rb', line 19

def version
  @body["version"]
end

#version_downloadsObject



23
24
25
# File 'lib/ruby_gems.rb', line 23

def version_downloads
  @body["version_downloads"]
end