This builds an API that lets you access a database of Farmers Markets and their Vendors. You can search for Markets with their city, state or name. You can also find nearby ATMs to those Markets.
- Download or clone this repo
- Open in your favorite code editor
- Add the below to your db/seeds.rb file
cmd = "pg_restore --verbose --clean --no-acl --no-owner -h localhost -U $(whoami) -d market_money_development db/data/market_money_development.pgdump"
puts "Loading PostgreSQL Data dump into local database with command:"
puts cmd
system(cmd)
- Run
$ rails db:{drop,create,migrate,seed}
and you may see lots of output including some warnings/errors frompg_restore
that you can ignore. - Run
$ rails db:schema:dump
- Sign up for a TomTom API key here: https://developer.tomtom.com/user/register?destination=/how-to-get-tomtom-api-key
- Run
$ EDITOR="code --wait" rails credentials:edit
- You may need to delete your
config/credentials.yml
andconfig/master.key
files if the temporarycredentials.yml
file does not open
- In your temporary
credentials.yml
file, enter your TomTom API key like so and then close thecredentials.yml
file
tomtom:
key: <your_api_key>
- Start a Rails server with
$ rails s
, and you can now access the various endpoints offered
Gets a list of all markets and their attributes along with the IDs of all of their vendors.
GET http://localhost:3000/api/v0/markets
Gets a single market's information by using their ID.
GET http://localhost:3000/api/v0/markets/{{market_id}}
Gets a list of all vendors and their attributes that belong to the market whose ID you pass.
GET http://localhost:3000/api/v0/markets/{{market_id}}/vendors
Gets a single vendor's information by using their ID.
GET http://localhost:3000/api/v0/vendors/{{vendor_id}}
Creates a new vendor record when passing all attributes for a vendor through params[:vendor]
{
"vendor":
{
"name": "Random Name",
"description": "Random Description",
"contact_name": "Random Contact Name",
"contact_number": "(123) 456 7890",
"credit_accepted": true,
}
}
POST http://localhost:3000/api/v0/vendors
Deletes a vendor when passing a valid vendor ID
DELETE http://localhost:3000/api/v0/vendors/{{vendor_id}}
Updates a vendor's information when passing any vendor attribute through params along with a valid vendor ID.
PATCH http://localhost:3000/api/v0/vendors/{{vendor_id}}
Creates a market vendor pair, linking a market with a vendor. Duplicate entries cannot be created, and a valid market ID AND vendor ID must be passed through params[:market_id]
and params[:vendor_id]
respectively.
{
"market_id": 234234,
"vendor_id": 22114
}
CREATE http://localhost:3000/api/v0/market_vendors
Deletes a market vendor pair. A valid market ID AND vendor ID must be passed through params[:market_id]
and params[:vendor_id]
respectively.
DELETE http://localhost:3000/api/v0/market_vendors
Searches for a market by sending a state, city and/or name through query params.
The following combination of parameters can be sent in at any time:
- state
- state, city
- state, city, name
- state, name
- name
The following combination of parameters can NOT be sent in at any time:
- city
- city, name
GET /api/v0/markets/search?city=albuquerque&state=new Mexico&name=Nob hill
Finds all nearby ATMs, and their attributes, to a market's location using its latitude and longitude by passing a valid market ID.
GET http://localhost:3000/api/v0/markets/{{market_id}}/nearest_atms