Class: PryGem::GemStat

Inherits:
Pry::ClassCommand
  • Object
show all
Defined in:
lib/pry-gem/gem_stat.rb

Overview

Since:

  • 1.0.0

Constant Summary collapse

STAT_HOST =

Since:

  • 1.0.0

"rubygems.org".freeze
STAT_PORT =

Since:

  • 1.0.0

443
STAT_PATH =

Since:

  • 1.0.0

"/api/v1/gems/%s.json".freeze
FAIL_WHALE =

Since:

  • 1.0.0

<<-FAILWHALE.freeze
W     W      W
W        W  W     W
          '.  W
  .-""-._     \ \.--|
 /       "-..__) .-'
|     _         /
\'-.__,   .__.,'
 `'----'._\--'
VVVVVVVVVVVVVVVVVVVVV
FAILWHALE

Instance Method Summary collapse

Instance Method Details

#process(name) ⇒ Object

Since:

  • 1.0.0



32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
# File 'lib/pry-gem/gem_stat.rb', line 32

def process(name)
  client = Net::HTTP.start STAT_HOST, STAT_PORT, use_ssl: true
  res = client.get STAT_PATH % URI.encode_www_form_component(name)
  case res
  when Net::HTTPOK
    _pry_.pager.page format_gem(JSON.parse(res.body))
  when Net::HTTPServiceUnavailable
    _pry_.pager.page <<-FAILURE
#{bright_blue(FAIL_WHALE)}
#{bright_red('Ruby On Rails')}
#{bright_red('Net::HTTPServiceUnavailable')}
    FAILURE
  else
    raise Pry::CommandError, "Bad response (#{res.class})"
  end
ensure
  client.finish if client
end