Skip to content

Latest commit

 

History

History
311 lines (296 loc) · 8.98 KB

README.md

File metadata and controls

311 lines (296 loc) · 8.98 KB

Rales Engine

An API for sales data using Sinatra.

Setup

  • Download this project into a working directory.

  • Install the requirements using bundle:

bundle install

This will install the required gems for the project.

  • Create the local database using rake:

rake db:create

  • Rake tasks are written to import CSV data from the data directory. For convinience, the following task will import all data and reset the database tables:

rake import:all

Rake tasks to import individual resources are avalible under rake's import namespace.

  • To remove Sinatra's built-in warning about ActiveSupport set this environment variable in your terminal:

export SINATRA_ACTIVESUPPORT_WARNING=false

This is an optional step.

  • Sinatra has a known bug when using MacOS reguarding fork safety. To run this project on MacOS, set this environment variable.

export OBJC_DISABLE_INITIALIZE_FORK_SAFETY=YES

  • This project includes the shotgun gem as an alternitive to spring. To use this, start the server with the following command:

shotgun

  • As a Rack based app, you are also able to start the server using the following command:

rackup

Endpoints

The following resources are exposed on this API:

Merchants
The following record endpoints are exposed:

/api/v1/merchants
Returns an index of all merchant entries in the database.

/api/vi/merchants/:id
Returns a representation of an individual merchant from the database.

/api/vi/merchants/random
Returns a random individual merchant object.

These resources also have finders for both singular and all matching records. These are accessed using:

/api/v1/merchants/find?attribute=x

/api/v1/merchants/find_all?attribute=x

All attributes can be searched, using the same name and format that is recieved from the index page.

The following relationship endpoints are exposed:

/api/v1/merchants/:id/items
Returns a collection of items associated with that merchant.

/api/v1/merchants/:id/invoices
Returns a collection of invoices associated with that merchant from their known orders.

The following business logic endpoints are exposed:

/api/v1/merchants/most_revenue?quantity=x
Returns the top x merchants ranked by total revenue.

/api/v1/merchants/most_items?quantity=x
Returns the top x merchants ranked by total number of items sold.

/api/v1/merchants/revenue?date=x
Returns the total revenue for date x across all merchants.

/api/v1/merchants/:id/revenue
Returns the total revenue for that merchant across successful transactions.

/api/v1/merchants/:id/revenue?date=x
Returns the total revenue for that merchant for a specific invoice date x.

/api/v1/merchants/:id/favorite_customer
Returns the customer who has conducted the most total number of successful transactions.

/api/v1/merchants/:id/customers_with_pending_invoices
Returns a collection of customers which have pending (unpaid) invoices.

Items
The following record endpoints are exposed:

/api/v1/items
Returns an index of all item entries in the database.

/api/vi/items/:id
Returns a representation of an individual item from the database.

/api/vi/items/random
Returns a random individual item object.

These resources also have finders for both singular and all matching records. These are accessed using:

/api/v1/items/find?attribute=x

/api/v1/items/find_all?attribute=x

All attributes can be searched, using the same name and format that is recieved from the index page.

The following relationship endpoints are exposed:

/api/v1/items/:id/invoice_items
Returns a collection of associated invoice items.

/api/v1/items/:id/merchant
Returns the associated merchant.

The following business logic endpoints are exposed:

/api/v1/items/most_revenue?quantity=x
Returns the top x items ranked by total revenue generated.

/api/v1/items/most_items?quantity=x
Returns the top x item instances ranked by total number sold.

/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.

Invoices
The following record endpoints are exposed:

/api/v1/invoices
Returns an index of all invoice entries in the database.

/api/vi/invoices/:id
Returns a representation of an individual invoice from the database.

/api/vi/invoices/random
Returns a random individual invoice object.

These resources also have finders for both singular and all matching records. These are accessed using:

/api/v1/invoices/find?attribute=x

/api/v1/invoices/find_all?attribute=x

All attributes can be searched, using the same name and format that is recieved from the index page.

The following relationship endpoints are exposed:

/api/v1/invoices/:id/transactions
Returns a collection of associated transactions.

/api/v1/invoices/:id/invoices
Returns a collection of associated invoice items.

/api/v1/invoices/:id/items
Returns a collection of associated items.

/api/v1/invoices/:id/customer
Returns the associated customer.

/api/v1/invoices/:id/merchant
Returns the associated merchant.

Invoice_Items
The following record endpoints are exposed:

/api/v1/invoice_items
Returns an index of all invoice_item entries in the database.

/api/vi/invoice_items/:id
Returns a representation of an individual invoice_item from the database.

/api/vi/invoice_items/random
Returns a random individual invoice_item object.

These resources also have finders for both singular and all matching records. These are accessed using:

/api/v1/invoice_items/find?attribute=x

/api/v1/invoice_items/find_all?attribute=x

All attributes can be searched, using the same name and format that is recieved from the index page.

The following relationship endpoints are exposed:

/api/v1/invoice_items/:id/invoice
Returns the associated invoice.

/api/v1/invoice_items/:id/item
Returns the associated item.

Transactions
The following record endpoints are exposed:

/api/v1/transactions
Returns an index of all transaction entries in the database.

/api/vi/transactions/:id
Returns a representation of an individual transaction from the database.

/api/vi/transactions/random
Returns a random individual transaction object.

These resources also have finders for both singular and all matching records. These are accessed using:

/api/v1/transactions/find?attribute=x

/api/v1/transactions/find_all?attribute=x

All attributes can be searched, using the same name and format that is recieved from the index page.

The following relationship endpoints are exposed:

/api/v1/transactions/:id/invoice
Returns the associated invoice.

Customers
The following record endpoints are exposed:

/api/v1/customers
Returns an index of all transaction entries in the database.

/api/vi/customers/:id
Returns a representation of an individual transaction from the database.

/api/vi/customers/random
Returns a random individual transaction object.

These resources also have finders for both singular and all matching records. These are accessed using:

/api/v1/customers/find?attribute=x

/api/v1/customers/find_all?attribute=x

All attributes can be searched, using the same name and format that is recieved from the index page.

The following relationship endpoints are exposed:

/api/v1/customers/:id/invoices
Returns a collection of associated invoices.

/api/v1/customers/:id/transactions
Returns a collection of associated transactions.

The following business logic endpoints are exposed:

/api/v1/customers/:id/favorite_merchant
Returns a merchant where the customer has conducted the most successful transactions.