A proof of concept retail RESTful service
  • Ruby 99.9%
  • Procfile 0.1%
Find a file
2018-02-06 10:04:03 -06:00
app Include RedskyAPI in controller 2018-02-01 19:17:29 -06:00
bin Generate barebones API only Rails application (RSpec for tests) 2018-01-30 11:54:33 -06:00
config Implement REST endpoints for getting / updating a product 2018-01-31 11:19:58 -06:00
fixtures/vcr_cassettes Integrate redsky information into REST JSON responses 2018-02-01 18:58:13 -06:00
lib Add RedskyAPI to get product details & associated tests 2018-02-01 16:20:28 -06:00
log Generate barebones API only Rails application (RSpec for tests) 2018-01-30 11:54:33 -06:00
public Generate barebones API only Rails application (RSpec for tests) 2018-01-30 11:54:33 -06:00
spec Add simplecov 2018-02-06 10:04:03 -06:00
tmp Generate barebones API only Rails application (RSpec for tests) 2018-01-30 11:54:33 -06:00
vendor Generate barebones API only Rails application (RSpec for tests) 2018-01-30 11:54:33 -06:00
.gitignore Add simplecov 2018-02-06 10:04:03 -06:00
.rspec Generate barebones API only Rails application (RSpec for tests) 2018-01-30 11:54:33 -06:00
config.ru Generate barebones API only Rails application (RSpec for tests) 2018-01-30 11:54:33 -06:00
Gemfile Add simplecov 2018-02-06 10:04:03 -06:00
Gemfile.lock Add simplecov 2018-02-06 10:04:03 -06:00
Procfile Add Procfile 2018-02-01 11:59:56 -06:00
Rakefile Generate barebones API only Rails application (RSpec for tests) 2018-01-30 11:54:33 -06:00
README.md Update README.md 2018-02-01 20:07:35 -06:00

retail-restful-poc

A proof-of-concept application that supports storing pricing data for products & combines stored price with other product information from external source.

Dependencies

  • Ruby on Rails
  • Redis

Getting started (skip to Heroku instructions if you don't want to run locally)

  • Install Ruby (try this how-to if you need instructions)
  • Install & start Redis - sudo apt-get install redis-server (Ubuntu) or follow the Redis guide
  • Install bundler gem - gem install bundler
  • Clone this repo
  • Run bundle install from the repo directory to install all gem dependencies

Starting the application

  • bundle exec rails server will start the application

Usage

After having started the server locally, you can make requests to http://localhost:3000/products/{#id}. Both APIs require that the product ID has an entry in Redis.

Fetch

  • Fetches data about a particular product ID
  • curl https://desolate-gorge-89429.herokuapp.com/products/13860428

Update

  • Updates the information for a product ID & also returns the same data as the fetch API on success
  • curl -X PUT http://localhost:3000/products/13860428 -H "Content-Type: application/json" -d '{"current_price":{"value":1.99,"currency_code":"USD"}}'

Running tests

  • This assumes you've completed the Getting started section above
  • Run bundle exec rspec to run RSpec tests

Heroku setup

  • Clone this repo
  • Install the Heroku toolbelt. Follow this guide
  • Create a Heroku application from the repo directory via heroku create
  • Add the Redis addon to the Heroku application heroku addons:create heroku-redis:hobby-dev
  • Push the master branch to Heroku, git push heroku master
  • Heroku will deploy your application & provide you its URL

How to populate Redis with product information

There is no way to currently populate data into Redis externally.

Local

To manually test locally, start the Rails application as instructed above & then run rails console from the repo directory in another shell window. To add an entry to Redis, I suggested executing something like this from the live Rails console:

Product.new(id: 13860428, price: 19.99, currency: 'USD').save

Be aware that the changes you make to Redis will be wiped (when in a development environment) on next Rails application start.

Heroku

After having deployed to Heroku, you can get to the Rails console on the Heroku instance via heroku run rails console from the repo directory. After the console comes up, you can create entries the same way as locally (see above).

Live example

This application is live @ https://desolate-gorge-89429.herokuapp.com as an example. It's currently only populated with one product ID (13860428). You're welcome to play with it via https://desolate-gorge-89429.herokuapp.com/products/13860428

Main Ruby gems used

  • Rails (main application framework)
  • RSpec (testing framework)
  • factory_bot (creating adhoc model instances)
  • VCR (record & playback HTTP requests)
  • redis-namespace (provides an redis interface with a namespace prepended)
  • money (used to verify valid currency)

Source code locations of interest

  • app/controllers/products_controllers.rb - Implements controller for Products REST API
  • app/models/product.rb - Product model (interfaces to Redis as well)
  • lib/redsky_api.rb - Module that provides an interface to Redsky API
  • spec - RSpec specs testing all implemented modules/classes