Class: GemUpdateChecker::Client

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

Constant Summary collapse

RUBYGEMS_API =
"https://rubygems.org/api/v1/versions"

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(gem_name, current_vesion) ⇒ Client

Returns a new instance of Client.



7
8
9
10
11
12
13
14
15
16
17
# File 'lib/gem_update_checker/client.rb', line 7

def initialize(gem_name, current_vesion)
  @gem_name = gem_name
  @current_version = current_vesion

  uri = URI("#{RUBYGEMS_API}/#{@gem_name}/latest.json")
  respose = Net::HTTP.get_response uri
  json = JSON.parse(respose.body)

  @latest_version = json["version"]
  @update_available = @latest_version && Gem::Version.new(@latest_version) > Gem::Version.new(@current_version)
end

Instance Attribute Details

#current_versionObject (readonly)

Returns the value of attribute current_version.



4
5
6
# File 'lib/gem_update_checker/client.rb', line 4

def current_version
  @current_version
end

#gem_nameObject (readonly)

Returns the value of attribute gem_name.



4
5
6
# File 'lib/gem_update_checker/client.rb', line 4

def gem_name
  @gem_name
end

#latest_versionObject (readonly)

Returns the value of attribute latest_version.



4
5
6
# File 'lib/gem_update_checker/client.rb', line 4

def latest_version
  @latest_version
end

#update_availableObject (readonly)

Returns the value of attribute update_available.



4
5
6
# File 'lib/gem_update_checker/client.rb', line 4

def update_available
  @update_available
end