gems 1.0.0 → 1.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: 27bd2da368ca93d2b8ac32fd25465987368be2b0
4
- data.tar.gz: c53afd6178dfab27ca122e9b144b441e71f69a47
2
+ SHA256:
3
+ metadata.gz: a5b059ed35aca287a6a7761233c2515f195ea6c89642c10c4e31f189d9ba6733
4
+ data.tar.gz: 6c80735a10bb701b213edda1274a3f542d985b369623f4cded91de5c3e697447
5
5
  SHA512:
6
- metadata.gz: 2bd0758a749c07093478dea04fe356f39e4be8158892b9a97f7b4e7bdd965cfd4b4cd28bdc422d5a2471acb88663cdc56883286f541032e9c639cbe6e15d65d9
7
- data.tar.gz: 8a60367eec5ed9cd320909e8cc706091b0e4aaed76f19b9f95f9673f9b2d4fa2161638af876390bbb0d2bbf4c91ddb10c5b3537d1d93608130a00ab0ec761cf5
6
+ metadata.gz: 2d1b6b6fa564e20654d4883581c596db744b9a34cc188471e1030a3dab597c3905b35da32f9a3f4100213a5f4e0f897a7beec862ca8d10c04fd10d5303022297
7
+ data.tar.gz: e33fa8637f8b0f76b909f231f118f1ca29b0cf480cf03069032b87c7dc446bb7cc351d0666b17168a469538b1bb18aa19756df01886dbda012bcfceed5c630b6
data/README.md CHANGED
@@ -50,13 +50,13 @@ Ruby wrapper for the RubyGems.org API.
50
50
  # Return an array of version details for coulda.
51
51
  Gems.versions 'coulda'
52
52
 
53
+ # Return an hash of latest version for coulda.
54
+ Gems.latest_version 'coulda'
55
+
53
56
  # Return the total number of downloads for rails_admin 0.0.1.
54
57
  # (Defaults to the latest version if no version is specified.)
55
58
  Gems.total_downloads 'rails_admin', '0.0.1'
56
59
 
57
- # Returns an array containing the top 50 downloaded gem versions for today.
58
- Gems.most_downloaded_today
59
-
60
60
  # Returns an array containing the top 50 downloaded gem versions of all time.
61
61
  Gems.most_downloaded
62
62
 
@@ -66,7 +66,7 @@ Ruby wrapper for the RubyGems.org API.
66
66
 
67
67
  # Return the number of downloads by day for coulda 0.6.3 for the past 90 days.
68
68
  # (Defaults to the latest version if no version is specified.)
69
- Gems.downloads 'coulda', '0.6.3'
69
+ Gems.downloads 'coulda', '0.6.3', Date.today - 90, Date.today
70
70
 
71
71
  # Return the number of downloads by day for coulda 0.6.3 for the past year.
72
72
  Gems.downloads 'coulda', '0.6.3', Date.today - 365, Date.today
@@ -1,4 +1,5 @@
1
1
  # coding: utf-8
2
+
2
3
  lib = File.expand_path('../lib', __FILE__)
3
4
  $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
5
  require 'gems/version'
@@ -9,11 +10,11 @@ Gem::Specification.new do |spec|
9
10
  spec.authors = ['Erik Michaels-Ober']
10
11
  spec.description = 'Ruby wrapper for the RubyGems.org API'
11
12
  spec.email = ['sferik@gmail.com']
12
- spec.files = %w(.yardopts CONTRIBUTING.md LICENSE.md README.md gems.gemspec) + Dir['lib/**/*.rb']
13
+ spec.files = %w[.yardopts CONTRIBUTING.md LICENSE.md README.md gems.gemspec] + Dir['lib/**/*.rb']
13
14
  spec.homepage = 'https://github.com/rubygems/gems'
14
- spec.licenses = %w(MIT)
15
+ spec.licenses = %w[MIT]
15
16
  spec.name = 'gems'
16
- spec.require_paths = %w(lib)
17
+ spec.require_paths = %w[lib]
17
18
  spec.required_ruby_version = '>= 2.1.9'
18
19
  spec.summary = spec.description
19
20
  spec.version = Gems::VERSION
@@ -25,6 +25,8 @@ module Gems
25
25
  def info(gem_name)
26
26
  response = get("/api/v1/gems/#{gem_name}.json")
27
27
  JSON.parse(response)
28
+ rescue JSON::ParserError
29
+ []
28
30
  end
29
31
 
30
32
  # Returns an array of active gems that match the query
@@ -105,6 +107,18 @@ module Gems
105
107
  JSON.parse(response)
106
108
  end
107
109
 
110
+ # Returns an hash of gem latest version
111
+ #
112
+ # @authenticated false
113
+ # @param gem_name [String] The name of a gem.
114
+ # @return [Hash]
115
+ # @example
116
+ # Gems.latest_version 'coulda'
117
+ def latest_version(gem_name)
118
+ response = get("/api/v1/versions/#{gem_name}/latest.json")
119
+ JSON.parse(response)
120
+ end
121
+
108
122
  # Returns the total number of downloads for a particular gem
109
123
  #
110
124
  # @authenticated false
@@ -118,17 +132,6 @@ module Gems
118
132
  JSON.parse(response, :symbolize_names => true)
119
133
  end
120
134
 
121
- # Returns an array containing the top 50 downloaded gem versions for today
122
- #
123
- # @authenticated false
124
- # @return [Array]
125
- # @example
126
- # Gems.most_downloaded_today
127
- def most_downloaded_today
128
- response = get('/api/v1/downloads/top.json')
129
- JSON.parse(response)['gems']
130
- end
131
-
132
135
  # Returns an array containing the top 50 downloaded gem versions of all time
133
136
  #
134
137
  # @authenticated false
@@ -5,12 +5,12 @@ require 'yaml'
5
5
  module Gems
6
6
  module Configuration
7
7
  # An array of valid keys in the options hash when configuring a {Gems::Client}
8
- VALID_OPTIONS_KEYS = [
9
- :host,
10
- :key,
11
- :password,
12
- :user_agent,
13
- :username,
8
+ VALID_OPTIONS_KEYS = %i[
9
+ host
10
+ key
11
+ password
12
+ user_agent
13
+ username
14
14
  ].freeze
15
15
 
16
16
  # Set the default API endpoint
@@ -23,7 +23,7 @@ module Gems
23
23
  private
24
24
 
25
25
  def request(method, path, data, content_type, request_host = host) # rubocop:disable AbcSize, CyclomaticComplexity, MethodLength, ParameterLists, PerceivedComplexity
26
- path += hash_to_query_string(data) if [:delete, :get].include? method
26
+ path += hash_to_query_string(data) if %i[delete get].include? method
27
27
  uri = URI.parse [request_host, path].join
28
28
  request_class = Net::HTTP.const_get method.to_s.capitalize
29
29
  request = request_class.new uri.request_uri
@@ -35,7 +35,7 @@ module Gems
35
35
  request.content_type = content_type
36
36
  case content_type
37
37
  when 'application/x-www-form-urlencoded'
38
- request.form_data = data if [:post, :put].include? method
38
+ request.form_data = data if %i[post put].include? method
39
39
  when 'application/octet-stream'
40
40
  request.body = data
41
41
  request.content_length = data.size
@@ -59,9 +59,7 @@ module Gems
59
59
  def hash_to_query_string(hash)
60
60
  return '' if hash.empty?
61
61
 
62
- hash.keys.each_with_object('?') do |key, query_string|
63
- query_string << "#{URI.encode(key.to_s)}=#{URI.encode(hash[key])}&"
64
- end.chop!
62
+ '?' + URI.encode_www_form(hash)
65
63
  end
66
64
 
67
65
  def body_from_response(response, method, content_type)
@@ -1,7 +1,7 @@
1
1
  module Gems
2
2
  class Version
3
3
  MAJOR = 1 unless defined? Gems::Version::MAJOR
4
- MINOR = 0 unless defined? Gems::Version::MINOR
4
+ MINOR = 1 unless defined? Gems::Version::MINOR
5
5
  PATCH = 0 unless defined? Gems::Version::PATCH
6
6
  PRE = nil unless defined? Gems::Version::PRE
7
7
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: gems
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0
4
+ version: 1.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Erik Michaels-Ober
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-01-06 00:00:00.000000000 Z
11
+ date: 2018-02-26 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: json
@@ -75,7 +75,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
75
75
  version: '0'
76
76
  requirements: []
77
77
  rubyforge_project:
78
- rubygems_version: 2.5.2
78
+ rubygems_version: 2.7.6
79
79
  signing_key:
80
80
  specification_version: 4
81
81
  summary: Ruby wrapper for the RubyGems.org API