This application integrates with the GitHub API. Through it, the user can consult public GitHub repositories.
- Ruby: 2.7.1
- Rails: 6.0.3.2
- PostgreSQL: 11.4
- Install the dependencies above
- Clone this project:
$ git clone git@github.com:ramonlg/octo_search.git
- Go into the project folder:
$ cd octo_search
- Setup database:
$ rails db:create && rails db:migrate && rails db:seed
orrails db:setup
- First create a new User on
rails console
:
$ rails console
User.create(username: 'my_username' , password: 'my_password' , password_confirmation: 'my_password')
-
You can add a new user on the
seeds.rb
file and run$ rails db:seed
onrails console
-
After creating the
new User
we can start the rails server and use the application.
POST /api/v1/session
- To authenticate the user we need to inform the
username
andpassword
curl -H "Content-Type: application/json" -X POST -d '{"username":"my_username", "password":"my_password"}' http://localhost:3000/api/v1/session
- If the user is successfully authenticated we will have a return similar to this:
{
"auth_token": "2uw8uu8dus8dus8dufhh.eyJ1c2VyX2lkIjoyLCJleHAiOjE1OTc3MDM2NTZ9.aiIDNjArrozOvosoaojdjoaejjojdowodjdmznmnw12"
}
- If the user cannot be authenticated:
{
"error": {
"user_authentication": "Invalid username or password"
}
}
GET /api/v1/github/repositories
-
To perform a search, it is necessary to inform the token generated in the user authentication process.
-
We can filter the repositories with the following attributes:
q
: Some keyword that must be present on the repositoryusername
: Name of the author / owner of the repositorylanguage
: Repository programming language. (If the language is not informed,Ruby
will be used as the default)sort
: Attribute by which the result will be ordered. The value informed for this attribute could be:stars
: sort by number of stars;forks
: sort by number of forks;updated
: sort by update date;- If no value is given,
stars
will be used by default
order
: By which order the resulto will be sorted could be:asc
ordesc
(default:desc
)page
: Which results list page will be returnedper_page
: Number of items per page (default:10
)
-
Request example:
curl --location --request GET 'localhost:3000/api/v1/github/repositories' \
--header 'Authorization: 2uw8uu8dus8dus8dufhh.eyJ1c2VyX2lkIjoyLCJleHAiOjE1OTc3MDM2NTZ9.aiIDNjArrozOvosoaojdjoaejjojdowodjdmznmnw12' \
--data-raw '{ "q":"awesome", "username":"defunkt", "language":"rails", "sort":"forks", "order":"asc", "page":"1", "per_page":"20" }'
- Response example:
{
"repositories": [
{
"name": "lacampfire",
"description": "Logical Awesome Campfire userscript.",
"stars": 5,
"forks": 5,
"author": "defunkt"
},
{
"name": "my-awesome-framework",
"description": "A simple demonstration of how to effectively use Git submodules.",
"stars": 6,
"forks": 6,
"author": "defunkt"
},
{
"name": "textmate.el",
"description": "Basic emulation of awesome TextMate features for Emacs.",
"stars": 359,
"forks": 68,
"author": "defunkt"
}
]
}