Tea leaf is a JSON API 1.0 spec-compliant REST API built in Rails with endpoints for users to subscribe a customer to a tea subscription, cancel a customer's tea subscription, and to see all of a customer's tea subscriptions (including active and cancelled). In addition, users can create customers and create teas. for purposes of exposing and consuming.
This project requires Ruby 2.7.2.
- Fork and clone this repository
- Change into the
tea_leafdirectory - From the command line, install gems and set up your DB:
bundle install && bundle updaterails db:{create,migrate,seed}
- Run the test suite with
bundle exec rspec -fd
-
Ruby version
$ ruby -v ruby 2.7.2p137 (2020-10-01 revision 5445e04352) [x86_64-darwin20]
-
$ rails -v Rails 6.1.4.4
-
Database creation
$ rails db:{drop,create,migrate,seed} Created database 'tea_leaf_development' Created database 'tea_leaf_test'$ bundle install
-
How to run the test suite
$ bundle exec rspec -fd
For a more responsive and enteractive response installing/using Postman will enhance the experience. For accessing these end points provided you will have to run rails server or rails s to spin up your localhost url. Then utilizing the base path of http://localhost:3000/ the end points get supplied at the end of this url and can get the response that the front end desires depending on the type of call.
- Request:
POST /api/v1/customers/:customer_id/subscriptions - Accepted in Body:
{
"tea_id": 1,
"title": "so long oolong",
"price": 65.00,
"frequency": 1
}- Response:
{
"data": {
"id": "4",
"type": "subscriptions",
"attributes": {
"customer_id": 1,
"tea_id": 1,
"title": "run with rooibos part 2",
"price": 65.0,
"frequency": "bimonthly",
"status": "active"
}
}
}With update, a user may change the frequency and/or status columns, which are coded as enums inside the subscription model
- Request:
PATCH /api/v1/customers/:customer_id/subscriptions/:subscription_id - Accepted in body:
{
"frequency": 1
"status": 0
}- Response:
{
"data": {
"customer_id": 1,
"tea_id": 1,
"title": "green tea guru",
"price": 40.0,
"frequency": "monthly",
"status": "cancelled"
}
}-
Request:
GET /api/v1/customers/:customer_id/subscriptions -
Response:
{
"data": [
{
"id": "1",
"type": "subscriptions",
"attributes": {
"customer_id": 1,
"tea_id": 1,
"title": "green tea guru",
"price": 40.0,
"frequency": "monthly",
"status": "cancelled"
}
},
{
"id": "2",
"type": "subscriptions",
"attributes": {
"customer_id": 1,
"tea_id": 1,
"title": "run with rooibos",
"price": 65.0,
"frequency": "bimonthly",
"status": "active"
}
},
{
"id": "4",
"type": "subscriptions",
"attributes": {
"customer_id": 1,
"tea_id": 1,
"title": "run with rooibos part 2",
"price": 65.0,
"frequency": "bimonthly",
"status": "active"
}
}
]
}- Request:
POST /api/v1/customers - Accepted in body:
{
"first_name": "cat",
"last_name": "ishungry",
"email": "cat@cats.biz",
"address": "101 Your House Way, Littleton, CO"
}- Response:
{
"data": {
"id": 2,
"first_name": "dane",
"last_name": "brophy",
"email": "dbrophy@cats.biz",
"address": "101 Generic Drive, Ware, CO"
}
}- Request:
POST /api/v1/teas - Accepted in body:
{
"name": "super oolong tea party",
"image": "www.pixiv.com/wowgreentea",
"description": "a greenish hue and lovely scent",
"keywords": "earthy, calming",
"origin": "?",
"brew_time": 3,
"temperature": 92.2
}- Response:
{
"data": {
"id": 2,
"name": "green tea",
"image": "www.pixiv.com/wowgreentea",
"description": "a greenish hue and lovely scent",
"keywords": "earthy, calming",
"origin": "?",
"brew_time": 3,
"temperature": 92.2
}
}Get a Tea (Consuming T-API Endpoint)
-
Request:
GET /api/v1/teas/?name=samplename -
(Must include query parameter in URI:
?name=oolong!) -
Response:
{
"data": {
"id": "5fa3ffbbd5ba620017ec1c0f",
"type": "teas",
"attributes": {
"name": "oolong",
"image": "uploads/oolong.png",
"description": "Lowers risk of cancer and prevents diabetes.",
"keywords": "bitter, herbal, china",
"origin": "China",
"brew_time": 2,
"temperature": 80
}
}
}

