Gh::Trending
A simple gem to parse trending repositories and developers from the github's trending page.
Installation
Add this line to your application's Gemfile:
gem 'gh-trending'
And then execute:
$ bundle
Or install it yourself as:
$ gem install gh-trending
Usage
There are two ways of using this gem:
- To fetch trending repositories:
Gh::Trending::Repositories.new.get(language:, time_period:)
- To fetch trending developers:
Gh::Trending::Developers.new.get(language:, time_period:)
The arguments language
and time_period
are provided in hash syntax, and they
are not required. Below there are simplified examples
Accepted values for the time_period
argument (as of Jun 2017):
:daily
(default) => Will return the trending developers/repositories in the last day:weekly
=> Will return the trending developers/repositories in the last week:monthly
=> Will return the trending developers/repositories in the last month.If you don't provide any value for the
time_period
argument, the value:daily
is used.If you don't provide any value for the
language
argument, it uses the default github's trending page option, which considers all languages.If you provide an unknown
time_period
argument, an error is raisedIf you don't provide any value for both arguments, this returns the trending developers/repositories for all languages, in the last day.
Examples
Trending developers
crawler = Gh::Trending::Developers.new
crawler.get
# => [
# <Gh::Trending::Developer:0x00000002f87760
# @full_name="Dawson Corwin",
# @hot_repository_url="http://denesiklehner.org/josianne",
# @user_profile_url="http://hane.co/camren"
# ,
# ...
# ]
full_name
=> The full name of the developerhot_repository_url
=> The name of the repository that is trending for this developer, in the providedtime_period
andlanguage
.- In the example above, since no
language
andtime_period
were provided, the repository"http://denesiklehner.org/josianne"
is the trending repository of this user, since the last day for any language.
- In the example above, since no
user_profile_url
=> The github user profile url.
Trending repositories
crawler = Gh::Trending::Repositories.new
crawler.get language: 'javascript'
# => [#<Gh::Trending::Repository:0x000000035231b0
# @description="Unicode's answer to Base64",
# @language="JavaScript",
# @name="/qntm/base65536",
# @period_stars=104,
# @url="https://github.com/qntm/base65536">,
# #<Gh::Trending::Repository:0x00000003511d70
# @description="Prettier is an opinionated JavaScript formatter.",
# @language="JavaScript",
# @name="/prettier/prettier",
# @period_stars=100,
# @url="https://github.com/prettier/prettier">,
# ]
description
=> The description of the repositorylanguage
=> Primary programming language of the repository (should match the one provided in thelanguage
argument, if provided)name
=> The name of the repositoryurl
=> The github's URL of the repositoryperiod_stars
=> The number of stars of the repository in the requestedtime_period
.
Development
After checking out the repo, run bin/setup
to install dependencies. You can also run bin/console
for an interactive prompt that will allow you to experiment.
Contributing
You can run bin/dev
to play around with the tool. You should run this command every time you make a change in the gem to test your modifications.
- If for some reason you can't run the
bin/dev
script, make sure the script has executions rights (chmod +x bin/dev
).
Bug reports and pull requests are welcome on GitHub at https://github.com/luispcosta/gh-trending. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the Contributor Covenant code of conduct.
Tests
To run the test suite:
rake spec
License
The gem is available as open source under the terms of the MIT License.