GigihHub is a simple social media to share information with other people in the same community. This repository contains GigihHub APIs, built in Ruby without any frameworks 🤓🚀. This project is intended for learning purposes in Model-View-Controller (MVC) design pattern, practicing Test Driven Development (TDD), and Clean Code.
The Gigih Hub Social Media contains six functional requirements.
- Saves user details (username, email, bio)
- Lets user make a new post with hashtag
- Lets user comment in a post with hashtag
- Lets user attach media (jpg, png, mp4) in a post or comment
- Lets user get posts with a hashtag
- Shows 5 trending hashtags in the past 24 hours
There are four tables created in the database.
- User, represents our social media user which contains user informations.
- Post, represents user's post. A post with
parent_post_id
is a comment to the parent post, meanwhile a parent withoutparent_post_id
is the parent post. - PostHashtag, represents the pivot entity of Post and Hashtag.
- Hashtag, represents hashtag (text initialized with
#
) in a post.
- Ruby v3.0.1 (recommended to install using rbenv)
- MySQL (installation reference)
These libraries are bundled in a Gemfile
.
- Sinatra, for simple web server
- Mysql2, for database connector
- RSpec, for unit test
- SimpleCov, for test coverage
- Rubocop, for code linter, based on Ruby Guide Style
-
Clone this project on your machine.
-
Setup database by creating a new database for this project
mysql -u <your-mysql-username> -p mysql> CREATE DATABASE gigih_hub_db; mysql> exit
Then, import our database dump file in the
/db
directorymysql -u <your-mysql-username> -p gigih_hub_db < db/gigih_hub_db_dump.sql
-
Setup environment variable by creating a
.env
file. The example file is available in.env.example
.cp .env.example .env
Initialize the variables in the file with your environment setup.
-
Install dependency libraries by executing the command below.
bundle install --path vendor/bundle
This command will locally install the libraries in the root project directory.
-
To run linter, execute rubocop.
bundle exec rubocop
-
To run test suites and test coverage, execute rspec.
bundle exec rspec
-
To run the application, execute using ruby, with personallized host binding below.
bundle exec ruby main.rb
-
Our app will be listening in
localhost:4567
.
This application contains APIs to run the functionalities defined above. It is run with base path localhost:4567/api
. To see the documentation, check out the Postman API Documentation, or the Postman Collection.
Check the live version of this app in http://34.101.85.67:4567/ (for a period of time).
Erma Safira Nurmasyita