rubygems_downloads 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: a8013507b8f44b7bebbe80c83bce9caed10c389cccd73d1a09a3f097c51f828f
4
+ data.tar.gz: 659d616c1726788db7f69969394397de7163b5c2f774b294c3d959690b33ae8d
5
+ SHA512:
6
+ metadata.gz: dbb0ce98c060e2ae3fb253670401cf90985ca91846e997bb43c2c6925c715702c17ceeb70a358ee15982ff68ebc5f2738b43d9a02098cc80e0ced282173e7b28
7
+ data.tar.gz: '09a22693e31af7252e5b5784e68b049c81e289e11a711bb2ed5f51fa9f8a242e4d5b64906d0b9dede8c8134e559dcb9da515703db2eaaaf4f410c5c2d8c6512b'
@@ -0,0 +1,8 @@
1
+ version: "2"
2
+ plugins:
3
+ rubymotion:
4
+ enabled: true
5
+ rubocop:
6
+ enabled: true
7
+ config:
8
+ file: .rubocop.yml
@@ -0,0 +1,12 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /_yardoc/
4
+ /coverage/
5
+ /doc/
6
+ /pkg/
7
+ /spec/reports/
8
+ /tmp/
9
+
10
+ # rspec failure tracking
11
+ .rspec_status
12
+ .rubocop-https*
@@ -0,0 +1,7 @@
1
+ build
2
+ clean
3
+ clobber
4
+ install
5
+ install:local
6
+ release[remote]
7
+ spec
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --format progress
2
+ --color
3
+ --require spec_helper
@@ -0,0 +1 @@
1
+ inherit_from: https://raw.githubusercontent.com/laurentzziu/utils/master/gems/.rubocop.yml
@@ -0,0 +1 @@
1
+ 2.4
@@ -0,0 +1,16 @@
1
+ sudo: false
2
+ env:
3
+ global:
4
+ - CC_TEST_REPORTER_ID=e25396485a01beb8f29f46e1da9fc663cc424e168e33c26b6acd82eaacdfeb9a
5
+ language: ruby
6
+ rvm:
7
+ - 2.4.3
8
+ before_install: gem install bundler -v 1.16.1
9
+ before_script:
10
+ - curl -L https://codeclimate.com/downloads/test-reporter/test-reporter-latest-linux-amd64 > ./cc-test-reporter
11
+ - chmod +x ./cc-test-reporter
12
+ - ./cc-test-reporter before-build
13
+ script:
14
+ - bundle exec rspec
15
+ after_script:
16
+ - ./cc-test-reporter after-build --exit-code $TRAVIS_TEST_RESULT
@@ -0,0 +1,74 @@
1
+ # Contributor Covenant Code of Conduct
2
+
3
+ ## Our Pledge
4
+
5
+ In the interest of fostering an open and welcoming environment, we as
6
+ contributors and maintainers pledge to making participation in our project and
7
+ our community a harassment-free experience for everyone, regardless of age, body
8
+ size, disability, ethnicity, gender identity and expression, level of experience,
9
+ nationality, personal appearance, race, religion, or sexual identity and
10
+ orientation.
11
+
12
+ ## Our Standards
13
+
14
+ Examples of behavior that contributes to creating a positive environment
15
+ include:
16
+
17
+ * Using welcoming and inclusive language
18
+ * Being respectful of differing viewpoints and experiences
19
+ * Gracefully accepting constructive criticism
20
+ * Focusing on what is best for the community
21
+ * Showing empathy towards other community members
22
+
23
+ Examples of unacceptable behavior by participants include:
24
+
25
+ * The use of sexualized language or imagery and unwelcome sexual attention or
26
+ advances
27
+ * Trolling, insulting/derogatory comments, and personal or political attacks
28
+ * Public or private harassment
29
+ * Publishing others' private information, such as a physical or electronic
30
+ address, without explicit permission
31
+ * Other conduct which could reasonably be considered inappropriate in a
32
+ professional setting
33
+
34
+ ## Our Responsibilities
35
+
36
+ Project maintainers are responsible for clarifying the standards of acceptable
37
+ behavior and are expected to take appropriate and fair corrective action in
38
+ response to any instances of unacceptable behavior.
39
+
40
+ Project maintainers have the right and responsibility to remove, edit, or
41
+ reject comments, commits, code, wiki edits, issues, and other contributions
42
+ that are not aligned to this Code of Conduct, or to ban temporarily or
43
+ permanently any contributor for other behaviors that they deem inappropriate,
44
+ threatening, offensive, or harmful.
45
+
46
+ ## Scope
47
+
48
+ This Code of Conduct applies both within project spaces and in public spaces
49
+ when an individual is representing the project or its community. Examples of
50
+ representing a project or community include using an official project e-mail
51
+ address, posting via an official social media account, or acting as an appointed
52
+ representative at an online or offline event. Representation of a project may be
53
+ further defined and clarified by project maintainers.
54
+
55
+ ## Enforcement
56
+
57
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be
58
+ reported by contacting the project team at florin@floringorgan.com. All
59
+ complaints will be reviewed and investigated and will result in a response that
60
+ is deemed necessary and appropriate to the circumstances. The project team is
61
+ obligated to maintain confidentiality with regard to the reporter of an incident.
62
+ Further details of specific enforcement policies may be posted separately.
63
+
64
+ Project maintainers who do not follow or enforce the Code of Conduct in good
65
+ faith may face temporary or permanent repercussions as determined by other
66
+ members of the project's leadership.
67
+
68
+ ## Attribution
69
+
70
+ This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
71
+ available at [http://contributor-covenant.org/version/1/4][version]
72
+
73
+ [homepage]: http://contributor-covenant.org
74
+ [version]: http://contributor-covenant.org/version/1/4/
data/Gemfile ADDED
@@ -0,0 +1,6 @@
1
+ source 'https://rubygems.org'
2
+
3
+ git_source(:github) { |repo_name| "https://github.com/#{repo_name}" }
4
+
5
+ # Specify your gem's dependencies in rubygems_downloads.gemspec
6
+ gemspec
@@ -0,0 +1,97 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ rubygems_downloads (0.1.0)
5
+ callable_class
6
+ httparty (~> 0.16.2)
7
+ terminal-table
8
+ thor
9
+
10
+ GEM
11
+ remote: https://rubygems.org/
12
+ specs:
13
+ ansi (1.5.0)
14
+ ast (2.4.0)
15
+ callable_class (0.1.1)
16
+ coderay (1.1.2)
17
+ diff-lcs (1.3)
18
+ docile (1.3.1)
19
+ hirb (0.7.3)
20
+ httparty (0.16.4)
21
+ mime-types (~> 3.0)
22
+ multi_xml (>= 0.5.2)
23
+ jaro_winkler (1.5.2)
24
+ json (2.2.0)
25
+ method_source (0.9.2)
26
+ mime-types (3.2.2)
27
+ mime-types-data (~> 3.2015)
28
+ mime-types-data (3.2019.0331)
29
+ multi_xml (0.6.0)
30
+ parallel (1.14.0)
31
+ parser (2.6.0.0)
32
+ ast (~> 2.4.0)
33
+ powerpack (0.1.2)
34
+ pry (0.12.2)
35
+ coderay (~> 1.1.0)
36
+ method_source (~> 0.9.0)
37
+ psych (3.1.0)
38
+ rainbow (3.0.0)
39
+ rake (10.5.0)
40
+ rspec (3.7.0)
41
+ rspec-core (~> 3.7.0)
42
+ rspec-expectations (~> 3.7.0)
43
+ rspec-mocks (~> 3.7.0)
44
+ rspec-core (3.7.1)
45
+ rspec-support (~> 3.7.0)
46
+ rspec-expectations (3.7.0)
47
+ diff-lcs (>= 1.2.0, < 2.0)
48
+ rspec-support (~> 3.7.0)
49
+ rspec-mocks (3.7.0)
50
+ diff-lcs (>= 1.2.0, < 2.0)
51
+ rspec-support (~> 3.7.0)
52
+ rspec-support (3.7.1)
53
+ rubocop (0.65.0)
54
+ jaro_winkler (~> 1.5.1)
55
+ parallel (~> 1.10)
56
+ parser (>= 2.5, != 2.5.1.1)
57
+ powerpack (~> 0.1)
58
+ psych (>= 3.1.0)
59
+ rainbow (>= 2.2.2, < 4.0)
60
+ ruby-progressbar (~> 1.7)
61
+ unicode-display_width (~> 1.4.0)
62
+ rubocop-performance (1.0.0)
63
+ rubocop (>= 0.58.0)
64
+ rubocop-rspec (1.32.0)
65
+ rubocop (>= 0.60.0)
66
+ ruby-progressbar (1.10.0)
67
+ simplecov (0.16.1)
68
+ docile (~> 1.1)
69
+ json (>= 1.8, < 3)
70
+ simplecov-html (~> 0.10.0)
71
+ simplecov-console (0.4.2)
72
+ ansi
73
+ hirb
74
+ simplecov
75
+ simplecov-html (0.10.2)
76
+ terminal-table (1.8.0)
77
+ unicode-display_width (~> 1.1, >= 1.1.1)
78
+ thor (0.20.3)
79
+ unicode-display_width (1.4.1)
80
+
81
+ PLATFORMS
82
+ ruby
83
+
84
+ DEPENDENCIES
85
+ bundler
86
+ pry
87
+ rake (~> 10.0)
88
+ rspec (~> 3.0)
89
+ rubocop
90
+ rubocop-performance
91
+ rubocop-rspec
92
+ rubygems_downloads!
93
+ simplecov
94
+ simplecov-console
95
+
96
+ BUNDLED WITH
97
+ 2.0.2
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2018 Florinel Gorgan
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
@@ -0,0 +1,105 @@
1
+ [![Build Status](https://travis-ci.org/laurentzziu/rubygems_downloads.svg?branch=master)](https://travis-ci.org/laurentzziu/rubygems_downloads)
2
+ [![Gem Version](https://badge.fury.io/rb/rubygems_downloads.svg)](https://rubygems.org/gems/rubygems_downloads)
3
+ [![Maintainability](https://api.codeclimate.com/v1/badges/8236c6291fe8d7cb7521/maintainability)](https://codeclimate.com/github/laurentzziu/rubygems_downloads/maintainability)
4
+ [![Test Coverage](https://api.codeclimate.com/v1/badges/8236c6291fe8d7cb7521/test_coverage)](https://codeclimate.com/github/laurentzziu/rubygems_downloads/test_coverage)
5
+
6
+ # RubyGems Downloads
7
+
8
+ ## Installation
9
+
10
+ Add this line to your application's Gemfile:
11
+
12
+ ```ruby
13
+ gem 'rubygems_downloads'
14
+ ```
15
+
16
+ And then execute:
17
+
18
+ $ bundle
19
+
20
+ Or install it yourself as:
21
+
22
+ $ gem install rubygems_downloads
23
+
24
+ ## Usage
25
+
26
+ ### CLI Usage
27
+
28
+ #### Get information about a specific author's gems
29
+ ```bash
30
+ rubygems_downloads author laurentzziu # (that's me)
31
+ # +---+----------------------+-----------------+-------------------+-----------------+-----------------+
32
+ # | # | Gem Name | Total Downloads | Version Downloads | Current Version | Author |
33
+ # +---+----------------------+-----------------+-------------------+-----------------+-----------------+
34
+ # | 1 | hash2lrtemplate | 30 | 30 | 0.1.0 | Florinel Gorgan |
35
+ # +---+----------------------+-----------------+-------------------+-----------------+-----------------+
36
+ # | 2 | procreate-swatches | 588 | 279 | 0.1.2 | Florinel Gorgan |
37
+ # +---+----------------------+-----------------+-------------------+-----------------+-----------------+
38
+ # | 3 | permitted_attributes | 388 | 388 | 0.1.0 | Florin Gorgan |
39
+ # +---+----------------------+-----------------+-------------------+-----------------+-----------------+
40
+ # | 4 | acv2lrtemplate | 1055 | 427 | 0.2.1 | Florinel Gorgan |
41
+ # +---+----------------------+-----------------+-------------------+-----------------+-----------------+
42
+ # | 5 | universities | 375 | 214 | 0.1.1 | Florinel Gorgan |
43
+ # +---+----------------------+-----------------+-------------------+-----------------+-----------------+
44
+ # | 6 | callable_class | 429 | 260 | 0.1.1 | Florinel Gorgan |
45
+ # +---+----------------------+-----------------+-------------------+-----------------+-----------------+
46
+ # | 7 | to_human | 213 | 213 | 0.1.0 | Florinel Gorgan |
47
+ # +---+----------------------+-----------------+-------------------+-----------------+-----------------+
48
+ ```
49
+
50
+ ```bash
51
+ rubygems_downloads gem callable_class # (that's my gem)
52
+ # +---+----------------+-----------------+-------------------+-----------------+-----------------+
53
+ # | # | Gem Name | Total Downloads | Version Downloads | Current Version | Author |
54
+ # +---+----------------+-----------------+-------------------+-----------------+-----------------+
55
+ # | 1 | callable_class | 435 | 264 | 0.1.1 | Florinel Gorgan |
56
+ # +---+----------------+-----------------+-------------------+-----------------+-----------------+
57
+ ```
58
+
59
+ ### Code usage
60
+ First, require the gem:
61
+ ```ruby
62
+ require 'rubygems_downloads'
63
+ ```
64
+
65
+ Then use the needed functionality:
66
+
67
+ ```ruby
68
+ RubygemsDownloads.for_author('laurentzziu')
69
+ # which is the same as calling
70
+ RubygemsDownloads::Stats::Author.call('laurentzziu')
71
+
72
+ # => [#<RubygemsDownloads::Gem:0x007fa856c2a730 @author="Florinel Gorgan", @name="hash2lrtemplate", @total_downloads=156, @url="https://rubygems.org/gems/hash2lrtemplate", @version="0.1.0", @version_downloads=156>,
73
+ # #<RubygemsDownloads::Gem:0x007fa856c2a708 @author="Florinel Gorgan", @name="procreate-swatches", @total_downloads=635, @url="https://rubygems.org/gems/procreate-swatches", @version="0.1.2", @version_downloads=302>,
74
+ # #<RubygemsDownloads::Gem:0x007fa856c2a6e0 @author="Florin Gorgan", @name="permitted_attributes", @total_downloads=393, @url="https://rubygems.org/gems/permitted_attributes", @version="0.1.0", @version_downloads=393>,
75
+ # #<RubygemsDownloads::Gem:0x007fa856c2a6b8 @author="Florinel Gorgan", @name="acv2lrtemplate", @total_downloads=1062, @url="https://rubygems.org/gems/acv2lrtemplate", @version="0.2.1", @version_downloads=430>,
76
+ # #<RubygemsDownloads::Gem:0x007fa856c2a690 @author="Florinel Gorgan", @name="universities", @total_downloads=384, @url="https://rubygems.org/gems/universities", @version="0.1.1", @version_downloads=220>,
77
+ # #<RubygemsDownloads::Gem:0x007fa856c2a668 @author="Florinel Gorgan", @name="callable_class", @total_downloads=435, @url="https://rubygems.org/gems/callable_class", @version="0.1.1", @version_downloads=264>,
78
+ # #<RubygemsDownloads::Gem:0x007fa856c2a640 @author="Florinel Gorgan", @name="to_human", @total_downloads=219, @url="https://rubygems.org/gems/to_human", @version="0.1.0", @version_downloads=219>]
79
+ ```
80
+
81
+ ```ruby
82
+ RubygemsDownloads.for_gem('callable_class')
83
+ # which is the same as calling
84
+ RubygemsDownloads::Stats::Gem.call('callable_class')
85
+
86
+ # => #<RubygemsDownloads::Gem:0x007fa8559a86c0 @author="Florinel Gorgan", @name="callable_class", @total_downloads=435, @url="https://rubygems.org/gems/callable_class", @version="0.1.1", @version_downloads=264>
87
+ ```
88
+
89
+ ## Development
90
+
91
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
92
+
93
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
94
+
95
+ ## Contributing
96
+
97
+ Bug reports and pull requests are welcome on GitHub at https://github.com/laurentzziu/rubygems_downloads. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
98
+
99
+ ## License
100
+
101
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
102
+
103
+ ## Code of Conduct
104
+
105
+ Everyone interacting in the _RubygemsDownloads_ project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/laurentzziu/rubygems_downloads/blob/master/CODE_OF_CONDUCT.md).
@@ -0,0 +1,13 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'bundler/gem_tasks'
4
+ require 'rspec/core/rake_task'
5
+
6
+ RSpec::Core::RakeTask.new(:spec)
7
+
8
+ # https://stackoverflow.com/a/23779044
9
+ task :console do
10
+ exec 'pry -r rubygems_downloads -I ./lib'
11
+ end
12
+
13
+ task default: :spec
@@ -0,0 +1,15 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'bundler/setup'
4
+ require 'rubygems_downloads'
5
+ require 'pry'
6
+
7
+ # You can add fixtures and/or initialization code here to make experimenting
8
+ # with your gem easier. You can also use a different console, if you like.
9
+
10
+ # (If you use this, don't forget to add pry to your Gemfile!)
11
+ # require 'pry'
12
+ Pry.start
13
+
14
+ require 'irb'
15
+ IRB.start(__FILE__)
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,6 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require_relative '../lib/rubygems_downloads'
4
+
5
+ result = RubygemsDownloads::CLI::Handler.start(ARGV)
6
+ print result
@@ -0,0 +1,9 @@
1
+ # frozen_string_literal: true
2
+
3
+ class Hash
4
+ # File activesupport/lib/active_support/core_ext/hash/slice.rb, line 21
5
+ def slice(*keys)
6
+ keys.map! { |key| convert_key(key) } if respond_to?(:convert_key, true)
7
+ keys.each_with_object(self.class.new) { |k, hash| hash[k] = self[k] if key?(k) }
8
+ end
9
+ end
@@ -0,0 +1,9 @@
1
+ # frozen_string_literal: true
2
+
3
+ class Object
4
+ def present?
5
+ return false if nil?
6
+
7
+ respond_to?(:empty?) ? !empty? : !blank?
8
+ end
9
+ end
@@ -0,0 +1,27 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative 'core_ext/object'
4
+ require_relative 'core_ext/hash'
5
+
6
+ require_relative 'rubygems_downloads/version'
7
+
8
+ require_relative 'rubygems_downloads/gem'
9
+
10
+ require_relative 'rubygems_downloads/stats/base'
11
+ require_relative 'rubygems_downloads/stats/author'
12
+ require_relative 'rubygems_downloads/stats/gem'
13
+
14
+ require_relative 'rubygems_downloads/cli/base'
15
+ require_relative 'rubygems_downloads/cli/handler'
16
+ require_relative 'rubygems_downloads/cli/author'
17
+ require_relative 'rubygems_downloads/cli/gem'
18
+
19
+ module RubygemsDownloads
20
+ def self.for_author(author_name)
21
+ RubygemsDownloads::Stats::Author.call(author_name)
22
+ end
23
+
24
+ def self.for_gem(gem_name)
25
+ RubygemsDownloads::Stats::Gem.call(gem_name)
26
+ end
27
+ end
@@ -0,0 +1,6 @@
1
+ # frozen_string_literal: true
2
+
3
+ module RubygemsDownloads
4
+ module CLI
5
+ end
6
+ end
@@ -0,0 +1,28 @@
1
+ # frozen_string_literal: true
2
+
3
+ module RubygemsDownloads
4
+ module CLI
5
+ class Author < Base
6
+ private
7
+
8
+ def error_message
9
+ 'User not found.'
10
+ end
11
+
12
+ def retrieve_data
13
+ @data = Stats::Author.call(@name)
14
+ end
15
+
16
+ def rows
17
+ return nil unless @data.present?
18
+
19
+ @data.map.with_index(1) do |gem, index|
20
+ [
21
+ index,
22
+ *data_from_gem(gem)
23
+ ]
24
+ end
25
+ end
26
+ end
27
+ end
28
+ end
@@ -0,0 +1,33 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'terminal-table'
4
+ require 'pry'
5
+
6
+ module RubygemsDownloads
7
+ module CLI
8
+ class Base
9
+ def initialize(name)
10
+ @name = name
11
+ end
12
+
13
+ def call
14
+ retrieve_data
15
+ generate_table_data
16
+ end
17
+
18
+ protected
19
+
20
+ TABLE_HEADER = ['#', 'Gem Name', 'Total Downloads', 'Version Downloads', 'Current Version', 'Author'].freeze
21
+
22
+ def generate_table_data
23
+ return error_message unless rows.present?
24
+
25
+ Terminal::Table.new(headings: TABLE_HEADER, rows: rows, style: { all_separators: true })
26
+ end
27
+
28
+ def data_from_gem(gem)
29
+ gem.to_h.values_at(:name, :total_downloads, :version_downloads, :version, :author)
30
+ end
31
+ end
32
+ end
33
+ end
@@ -0,0 +1,25 @@
1
+ # frozen_string_literal: true
2
+
3
+ module RubygemsDownloads
4
+ module CLI
5
+ class Gem < Base
6
+ private
7
+
8
+ def error_message
9
+ 'Gem not found.'
10
+ end
11
+
12
+ def retrieve_data
13
+ @data = Stats::Gem.call(@name)
14
+ end
15
+
16
+ def rows
17
+ return nil unless @data.present?
18
+
19
+ [
20
+ [1, *data_from_gem(@data)]
21
+ ]
22
+ end
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,19 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'thor'
4
+
5
+ module RubygemsDownloads
6
+ module CLI
7
+ class Handler < Thor
8
+ desc 'author AUTHOR_USER_NAME', 'display gem downloads data for a specific author (username)'
9
+ def author(name)
10
+ RubygemsDownloads::CLI::Author.new(name).call
11
+ end
12
+
13
+ desc 'gem GEM_NAME', 'display downloads data for a specific gem'
14
+ def gem(name)
15
+ RubygemsDownloads::CLI::Gem.new(name).call
16
+ end
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,45 @@
1
+ # frozen_string_literal: true
2
+
3
+ module RubygemsDownloads
4
+ class Gem
5
+ attr_accessor :name, :author, :total_downloads, :version_downloads, :version, :url
6
+
7
+ def self.from_json(entry)
8
+ new do |gem|
9
+ gem.name = entry[:name]
10
+ gem.total_downloads = entry[:downloads]
11
+ gem.version_downloads = entry[:version_downloads]
12
+ gem.version = entry[:version]
13
+ gem.author = entry[:authors]
14
+ gem.url = entry[:project_uri]
15
+ end
16
+ end
17
+
18
+ def initialize
19
+ yield self
20
+ end
21
+
22
+ def to_h
23
+ {
24
+ name: name,
25
+ author: author,
26
+ total_downloads: total_downloads,
27
+ version_downloads: version_downloads,
28
+ version: version,
29
+ url: url
30
+ }
31
+ end
32
+
33
+ def blank?
34
+ !(name && author && total_downloads && version_downloads && version)
35
+ end
36
+
37
+ def ==(other)
38
+ other.class == self.class && other.state == state
39
+ end
40
+
41
+ def state
42
+ instance_variables.map { |variable| instance_variable_get(variable) }
43
+ end
44
+ end
45
+ end
@@ -0,0 +1,33 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'httparty'
4
+
5
+ module RubygemsDownloads
6
+ module Stats
7
+ class Author < Base
8
+ def call
9
+ response = super
10
+
11
+ return invalid_response_return_value if response.nil?
12
+
13
+ response.map do |entry|
14
+ RubygemsDownloads::Gem.from_json(entry)
15
+ end
16
+ end
17
+
18
+ protected
19
+
20
+ def placeholder
21
+ '#|AUTHOR_NAME|#'
22
+ end
23
+
24
+ def endpoint
25
+ "https://rubygems.org/api/v1/owners/#{placeholder}/gems.json"
26
+ end
27
+
28
+ def invalid_response_return_value
29
+ []
30
+ end
31
+ end
32
+ end
33
+ end
@@ -0,0 +1,34 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'httparty'
4
+ require 'callable_class'
5
+
6
+ module RubygemsDownloads
7
+ module Stats
8
+ class Base
9
+ include CallableClass
10
+
11
+ attr_reader :name
12
+
13
+ def initialize(name)
14
+ @name = name
15
+
16
+ raise(ArgumentError, '`name` parameter invalid.') unless name.present?
17
+ end
18
+
19
+ def call
20
+ response = HTTParty.get(url, format: :plain)
21
+
22
+ return nil if response.code == 404
23
+
24
+ JSON.parse(response, symbolize_names: true)
25
+ end
26
+
27
+ protected
28
+
29
+ def url
30
+ endpoint.sub(placeholder, name)
31
+ end
32
+ end
33
+ end
34
+ end
@@ -0,0 +1,29 @@
1
+ # frozen_string_literal: true
2
+
3
+ module RubygemsDownloads
4
+ module Stats
5
+ class Gem < Base
6
+ def call
7
+ response = super
8
+
9
+ return invalid_response_return_value if response.nil?
10
+
11
+ RubygemsDownloads::Gem.from_json(response)
12
+ end
13
+
14
+ protected
15
+
16
+ def placeholder
17
+ '#|GEM_NAME|#'
18
+ end
19
+
20
+ def endpoint
21
+ "https://rubygems.org/api/v1/gems/#{placeholder}.json"
22
+ end
23
+
24
+ def invalid_response_return_value
25
+ nil
26
+ end
27
+ end
28
+ end
29
+ end
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ module RubygemsDownloads
4
+ VERSION = '0.1.0'
5
+ end
@@ -0,0 +1,38 @@
1
+ # frozen_string_literal: true
2
+
3
+ lib = File.expand_path('../lib', __FILE__)
4
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
5
+ require 'rubygems_downloads/version'
6
+
7
+ Gem::Specification.new do |spec|
8
+ spec.name = 'rubygems_downloads'
9
+ spec.version = RubygemsDownloads::VERSION
10
+ spec.authors = ['Florinel Gorgan']
11
+ spec.email = ['florin@floringorgan.com']
12
+
13
+ spec.summary = 'View statistics about gem downloads from RubyGems.org'
14
+ spec.homepage = 'https://github.com/laurentzziu/rubygems_downloads'
15
+ spec.license = 'MIT'
16
+
17
+ spec.files = `git ls-files -z`.split("\x0").reject do |f|
18
+ f.match(%r{^(test|spec|features)/})
19
+ end
20
+ spec.bindir = 'exe'
21
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
22
+ spec.require_paths = ['lib']
23
+
24
+ spec.add_dependency 'callable_class'
25
+ spec.add_dependency 'httparty', '~> 0.16.2'
26
+ spec.add_dependency 'terminal-table'
27
+ spec.add_dependency 'thor'
28
+
29
+ spec.add_development_dependency 'bundler'
30
+ spec.add_development_dependency 'pry'
31
+ spec.add_development_dependency 'rake', '~> 10.0'
32
+ spec.add_development_dependency 'rspec', '~> 3.0'
33
+ spec.add_development_dependency 'rubocop'
34
+ spec.add_development_dependency 'rubocop-performance'
35
+ spec.add_development_dependency 'rubocop-rspec'
36
+ spec.add_development_dependency 'simplecov'
37
+ spec.add_development_dependency 'simplecov-console'
38
+ end
metadata ADDED
@@ -0,0 +1,257 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: rubygems_downloads
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Florinel Gorgan
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2019-07-05 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: callable_class
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: httparty
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: 0.16.2
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: 0.16.2
41
+ - !ruby/object:Gem::Dependency
42
+ name: terminal-table
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: thor
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :runtime
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: bundler
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: pry
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ">="
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
97
+ - !ruby/object:Gem::Dependency
98
+ name: rake
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - "~>"
102
+ - !ruby/object:Gem::Version
103
+ version: '10.0'
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - "~>"
109
+ - !ruby/object:Gem::Version
110
+ version: '10.0'
111
+ - !ruby/object:Gem::Dependency
112
+ name: rspec
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - "~>"
116
+ - !ruby/object:Gem::Version
117
+ version: '3.0'
118
+ type: :development
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - "~>"
123
+ - !ruby/object:Gem::Version
124
+ version: '3.0'
125
+ - !ruby/object:Gem::Dependency
126
+ name: rubocop
127
+ requirement: !ruby/object:Gem::Requirement
128
+ requirements:
129
+ - - ">="
130
+ - !ruby/object:Gem::Version
131
+ version: '0'
132
+ type: :development
133
+ prerelease: false
134
+ version_requirements: !ruby/object:Gem::Requirement
135
+ requirements:
136
+ - - ">="
137
+ - !ruby/object:Gem::Version
138
+ version: '0'
139
+ - !ruby/object:Gem::Dependency
140
+ name: rubocop-performance
141
+ requirement: !ruby/object:Gem::Requirement
142
+ requirements:
143
+ - - ">="
144
+ - !ruby/object:Gem::Version
145
+ version: '0'
146
+ type: :development
147
+ prerelease: false
148
+ version_requirements: !ruby/object:Gem::Requirement
149
+ requirements:
150
+ - - ">="
151
+ - !ruby/object:Gem::Version
152
+ version: '0'
153
+ - !ruby/object:Gem::Dependency
154
+ name: rubocop-rspec
155
+ requirement: !ruby/object:Gem::Requirement
156
+ requirements:
157
+ - - ">="
158
+ - !ruby/object:Gem::Version
159
+ version: '0'
160
+ type: :development
161
+ prerelease: false
162
+ version_requirements: !ruby/object:Gem::Requirement
163
+ requirements:
164
+ - - ">="
165
+ - !ruby/object:Gem::Version
166
+ version: '0'
167
+ - !ruby/object:Gem::Dependency
168
+ name: simplecov
169
+ requirement: !ruby/object:Gem::Requirement
170
+ requirements:
171
+ - - ">="
172
+ - !ruby/object:Gem::Version
173
+ version: '0'
174
+ type: :development
175
+ prerelease: false
176
+ version_requirements: !ruby/object:Gem::Requirement
177
+ requirements:
178
+ - - ">="
179
+ - !ruby/object:Gem::Version
180
+ version: '0'
181
+ - !ruby/object:Gem::Dependency
182
+ name: simplecov-console
183
+ requirement: !ruby/object:Gem::Requirement
184
+ requirements:
185
+ - - ">="
186
+ - !ruby/object:Gem::Version
187
+ version: '0'
188
+ type: :development
189
+ prerelease: false
190
+ version_requirements: !ruby/object:Gem::Requirement
191
+ requirements:
192
+ - - ">="
193
+ - !ruby/object:Gem::Version
194
+ version: '0'
195
+ description:
196
+ email:
197
+ - florin@floringorgan.com
198
+ executables:
199
+ - rubygems_downloads
200
+ extensions: []
201
+ extra_rdoc_files: []
202
+ files:
203
+ - ".codeclimate.yml"
204
+ - ".gitignore"
205
+ - ".rake_tasks"
206
+ - ".rspec"
207
+ - ".rubocop.yml"
208
+ - ".ruby-version"
209
+ - ".travis.yml"
210
+ - CODE_OF_CONDUCT.md
211
+ - Gemfile
212
+ - Gemfile.lock
213
+ - LICENSE.txt
214
+ - README.md
215
+ - Rakefile
216
+ - bin/console
217
+ - bin/setup
218
+ - exe/rubygems_downloads
219
+ - lib/core_ext/hash.rb
220
+ - lib/core_ext/object.rb
221
+ - lib/rubygems_downloads.rb
222
+ - lib/rubygems_downloads/cli.rb
223
+ - lib/rubygems_downloads/cli/author.rb
224
+ - lib/rubygems_downloads/cli/base.rb
225
+ - lib/rubygems_downloads/cli/gem.rb
226
+ - lib/rubygems_downloads/cli/handler.rb
227
+ - lib/rubygems_downloads/gem.rb
228
+ - lib/rubygems_downloads/stats/author.rb
229
+ - lib/rubygems_downloads/stats/base.rb
230
+ - lib/rubygems_downloads/stats/gem.rb
231
+ - lib/rubygems_downloads/version.rb
232
+ - rubygems_downloads.gemspec
233
+ homepage: https://github.com/laurentzziu/rubygems_downloads
234
+ licenses:
235
+ - MIT
236
+ metadata: {}
237
+ post_install_message:
238
+ rdoc_options: []
239
+ require_paths:
240
+ - lib
241
+ required_ruby_version: !ruby/object:Gem::Requirement
242
+ requirements:
243
+ - - ">="
244
+ - !ruby/object:Gem::Version
245
+ version: '0'
246
+ required_rubygems_version: !ruby/object:Gem::Requirement
247
+ requirements:
248
+ - - ">="
249
+ - !ruby/object:Gem::Version
250
+ version: '0'
251
+ requirements: []
252
+ rubyforge_project:
253
+ rubygems_version: 2.7.3
254
+ signing_key:
255
+ specification_version: 4
256
+ summary: View statistics about gem downloads from RubyGems.org
257
+ test_files: []