A JSON API that exposes the SalesEngine data schema built with Rails and ActiveRecord.
These instructions will get you a copy of the project up and running on your local machine for development and testing purposes.
What things you need to install the software and how to install them
Rails 5.0.0.1
A step by step series of examples that tell you have to get a development env running
Step 1 - clone down the project and cd into the directory:
git clone git@github.com:kctrlv/rails_engine.git
cd rails_engine
bundle
Step 2 - clear your existing database (just in case):
rake import:rebuild
This is the same as performing rake db:{drop,create,migrate}
.
Step 3 - import the CSV data from SalesEngine:
rake import:all
Use rspec
to run the test suite.
Each data category includes an index action which renders a JSON representation of all the appropriate records:
Request URL
GET /api/v1/merchants.json
(The following is an example of a response if only three records were saved in the database)
[
{
"id":1,
"name":"Schroeder-Jerde"
},
{
"id":2,
"name":"Klein, Rempel and Jones"
},
{
"id":3,
"name":"Willms and Sons"
}
]
Each data category also includes a show action which renders a JSON representation of the appropriate record:
Request URL
GET /api/v1/merchants/1.json
JSON Output
{
"id":1,
"name":"Schroeder-Jerde"
}
Each data category offers find
finders to return a single object representation. The finder works with any of the attributes defined on the data type and always be case insensitive.
GET /api/v1/merchants/find?parameters
parameter | description |
---|---|
id | search based on the primary key |
name | search based on the name attribute |
created_at | search based on created_at timestamp |
updated_at | search based on updated_at timestamp |
GET /api/v1/merchants/find?name=Schroeder-Jerde
{
"id":1,
"name":"Schroeder-Jerde"
}
Each category offers find_all
finders which should return all matches for the given query. It works with any of the attributes defined on the data type and always be case insensitive.
GET /api/v1/merchants/find_all?parameters
parameter | description |
---|---|
id | search based on the primary key |
name | search based on the name attribute |
created_at | search based on created_at timestamp |
updated_at | search based on updated_at timestamp |
GET /api/v1/merchants/find_all?name=Cummings-Thiel
[
{
"id":4,
"name":"Cummings-Thiel"
}
]
Returns a random resource.
api/v1/merchants/random.json
{
"id": 50,
"name": "Nader-Hyatt"
}
GET /api/v1/merchants/:id/items
returns a collection of items associated with that merchantGET /api/v1/merchants/:id/invoices
returns a collection of invoices associated with that merchant from their known orders
GET /api/v1/invoices/:id/transactions
returns a collection of associated transactionsGET /api/v1/invoices/:id/invoice_items
returns a collection of associated invoice itemsGET /api/v1/invoices/:id/items
returns a collection of associated itemsGET /api/v1/invoices/:id/customer
returns the associated customerGET /api/v1/invoices/:id/merchant
returns the associated merchant
GET /api/v1/invoice_items/:id/invoice
returns the associated invoiceGET /api/v1/invoice_items/:id/item
returns the associated item
GET /api/v1/items/:id/invoice_items
returns a collection of associated invoice itemsGET /api/v1/items/:id/merchant
returns the associated merchant
GET /api/v1/transactions/:id/invoice
returns the associated invoice
GET /api/v1/customers/:id/invoices
returns a collection of associated invoicesGET /api/v1/customers/:id/transactions
returns a collection of associated transactions
GET /api/v1/merchants/most_revenue?quantity=x
returns the topx
merchants ranked by total revenueGET /api/v1/merchants/most_items?quantity=x
returns the topx
merchants ranked by total number of items soldGET /api/v1/merchants/revenue?date=x
returns the total revenue for datex
across all merchants
GET /api/v1/merchants/:id/revenue
returns the total revenue for that merchant across all transactionsGET /api/v1/merchants/:id/revenue?date=x
returns the total revenue for that merchant for a specific invoice datex
GET /api/v1/merchants/:id/favorite_customer
returns the customer who has conducted the most total number of successful transactions.GET /api/v1/merchants/:id/customers_with_pending_invoices
returns a collection of customers which have pending (unpaid) invoices
GET /api/v1/items/most_revenue?quantity=x
returns the topx
items ranked by total revenue generatedGET /api/v1/items/most_items?quantity=x
returns the topx
item instances ranked by total number soldGET /api/v1/items/:id/best_day
returns the date with the most sales for the given item using the invoice date. If there are multiple days with equal number of sales, return the most recent day.
GET /api/v1/customers/:id/favorite_merchant
returns a merchant where the customer has conducted the most successful transactions
- Hat tip to Black Thursday