This is a Rails-based versioned REST API built using ActiveRecord. It currently only supports GET requests that allow users to consume data from the SalesEngine data schema. All output is currently in JSON format.
To use this application clone the following repository:
$ git clone https://github.com/brickstar/rails_engine
From the application directory, run the following commands to install and update all necessary gem dependencies:
$ bundle
$ bundle update
Run the following commands to create the database and import CSV data:
$ rake db:{create,migrate}
$ rake import:all
And initialize a server
$ rails s
Ruby 2.4.1
Rails 5.2.1
ActiveRecord 5.2.1
RSpec-Rails 3.8.0
* All references to :id in endpoints should be replaced with an integer corresponding to the desired record
localhost:3000/api/v1/merchants
[
{
"id":1,
"name":"Schroeder-Jerde"
},
{
"id":2,
"name":"Klein, Rempel and Jones"
},
{
"id":3,
"name":"Willms and Sons"
}
]
localhost:3000/api/v1/merchants/:id
{
"id":1,
"name":"Schroeder-Jerde"
}
localhost:3000/api/v1/items
[
{
"id": 1,
"description": "Nihil autem sit odio inventore deleniti. Est laudantium ratione distinctio laborum. Minus voluptatem nesciunt assumenda dicta voluptatum porro.",
"merchant_id": 1,
"name": "Item Qui Esse",
"unit_price": "751.07"
},
{
"id": 2,
"description": "Cumque consequuntur ad. Fuga tenetur illo molestias enim aut iste. Provident quo hic aut. Aut quidem voluptates dolores. Dolorem quae ab alias tempora.",
"merchant_id": 1,
"name": "Item Autem Minima",
"unit_price": "670.76"
},
{
"id": 3,
"description": "Sunt officia eum qui molestiae. Nesciunt quidem cupiditate reiciendis est commodi non. Atque eveniet sed. Illum excepturi praesentium reiciendis voluptatibus eveniet odit perspiciatis. Odio optio nisi rerum nihil ut.",
"merchant_id": 1,
"name": "Item Ea Voluptatum",
"unit_price": "323.01"
}
]
localhost:3000/api/v1/items/:id
{
"id": 1,
"description": "Nihil autem sit odio inventore deleniti. Est laudantium ratione distinctio laborum. Minus voluptatem nesciunt assumenda dicta voluptatum porro.",
"merchant_id": 1,
"name": "Item Qui Esse",
"unit_price": "751.07"
}
localhost:3000/api/v1/invoices
[
{
"id": 1,
"customer_id": 1,
"merchant_id": 26,
"status": "shipped"
},
{
"id": 2,
"customer_id": 1,
"merchant_id": 75,
"status": "shipped"
},
{
"id": 3,
"customer_id": 1,
"merchant_id": 78,
"status": "shipped"
}
]
localhost:3000/api/v1/invoices/:id
{
"id": 1,
"customer_id": 1,
"merchant_id": 26,
"status": "shipped"
}
localhost:3000/api/v1/invoice_items
[
{
"id": 1,
"invoice_id": 1,
"item_id": 539,
"unit_price": "136.35",
"quantity": 5
},
{
"id": 2,
"invoice_id": 1,
"item_id": 528,
"unit_price": "233.24",
"quantity": 9
},
{
"id": 3,
"invoice_id": 1,
"item_id": 523,
"unit_price": "348.73",
"quantity": 8
}
]
localhost:3000/api/v1/invoice_items/:id
{
"id": 3,
"invoice_id": 1,
"item_id": 523,
"unit_price": "348.73",
"quantity": 8
}
localhost:3000/api/v1/transactions
[
{
"id": 1,
"invoice_id": 1,
"credit_card_number": "4654405418249632",
"result": "success"
},
{
"id": 2,
"invoice_id": 2,
"credit_card_number": "4580251236515201",
"result": "success"
},
{
"id": 3,
"invoice_id": 4,
"credit_card_number": "4354495077693036",
"result": "success"
}
]
localhost:3000/api/v1/transactions/:id
{
"id": 1,
"invoice_id": 1,
"credit_card_number": "4354495077693036",
"result": "success"
}
localhost:3000/api/v1/customers
[
{
"id": 1,
"first_name": "Joey",
"last_name": "Ondricka"
},
{
"id": 2,
"first_name": "Cecelia",
"last_name": "Osinski"
},
{
"id": 3,
"first_name": "Mariah",
"last_name": "Toy"
}
]
localhost:3000/api/v1/customers/:id
{
"id": 1,
"first_name": "Joey",
"last_name": "Ondricka"
}
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 is case insensitive.
Note: All finder examples are represented by Merchant endpoints
localhost:3000/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 |
localhost:3000/api/v1/merchants/find?name=Schroeder-Jerde
{
"id":1,
"name":"Schroeder-Jerde"
}
Each data category offers find_all
finders which returns all matches for the given query. It works with any of the attributes defined on the data type and is case insensitive.
localhost:3000/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 |
localhost:3000/api/v1/merchants/find_all?name=Cummings-Thiel
[
{
"id":4,
"name":"Cummings-Thiel"
}
]
Returns a random resource.
localhost:3000/api/v1/merchants/random.json
{
"id": 50,
"name": "Nader-Hyatt"
}
In addition to queries to single resources, relationship data is also available
localhost:3000/api/v1/merchants/:id/items
returns a collection of items associated with that merchantlocalhost:3000/api/v1/merchants/:id/invoices
returns a collection of invoices associated with that merchant from their known orderslocalhost:3000/api/v1/invoices/:id/transactions
returns a collection of associated transactionslocalhost:3000/api/v1/invoices/:id/invoice_items
returns a collection of associated invoice itemslocalhost:3000/api/v1/invoices/:id/items
returns a collection of associated itemslocalhost:3000/api/v1/invoices/:id/customer
returns the associated customerlocalhost:3000/api/v1/invoices/:id/merchant
returns the associated merchantlocalhost:3000/api/v1/invoice_items/:id/invoice
returns the associated invoicelocalhost:3000/api/v1/invoice_items/:id/item
returns the associated itemlocalhost:3000/api/v1/items/:id/invoice_items
returns a collection of associated invoice itemslocalhost:3000/api/v1/items/:id/merchant
returns the associated merchantlocalhost:3000/api/v1/transactions/:id/invoice
returns the associated invoicelocalhost:3000/api/v1/customers/:id/invoices
returns a collection of associated invoiceslocalhost:3000/api/v1/customers/:id/transactions
returns a collection of associated transactionslocalhost:3000/api/v1/merchants/most_revenue?quantity=x
returns the top x
merchants ranked by total revenuelocalhost:3000/api/v1/merchants/most_items?quantity=x
returns the top x
merchants ranked by total number of items soldlocalhost:3000/api/v1/merchants/revenue?date=x
returns the total revenue for date x
across all merchantsAssume the dates provided match the format of a standard ActiveRecord timestamp.
localhost:3000/api/v1/merchants/:id/revenue
returns the total revenue for that merchant across all transactionslocalhost:3000/api/v1/merchants/:id/revenue?date=x
returns the total revenue for that merchant for a specific invoice date x
localhost:3000/api/v1/merchants/:id/favorite_customer
returns the customer who has conducted the most total number of successful transactions.localhost:3000/api/v1/items/most_revenue?quantity=x
returns the top x
items ranked by total revenue generatedlocalhost:3000/api/v1/items/most_items?quantity=x
returns the top x
item instances ranked by total number sold#
This README is adapted from Turing School Examples Rails Engine