rubyforgood / playtime

Supporting children and families experiencing homelessness in Washington, DC. Live app - https://wishlist.playtimeproject.org Organization Website:
http://www.playtimeproject.org/
MIT License
89 stars 52 forks source link

Refactor Amazon Product API endpoints #174

Open leesharma opened 6 years ago

leesharma commented 6 years ago

Works towards #62 (part 2/3)

Description

I broke #62 into three PRs for easier review: this is part 2. (part 1: #173)

There were two main changes in this PR: refactoring the endpoints and adding documentation.

Refactoring the Endpoints

I had two main goals here:

  1. It should be easy to add new endpoints.
  2. It should be easy to fix general query-related bugs unrelated to a specific endpoint.

To do this, I extracted the general Amazon Product API logic into an Endpoint class. Adding a new endpoint is now as simple as subclassing Endpoint and specifying the request parameters and any response post-processing.

Documentation

The AmazonProductAPI lib is getting more complicated and self-contained, so I added a README with instructions on how to add a new endpoint. That way, we get the documentation without cluttering up the root README.

At some point, it might be worth extracting more API-related instructions from the root README into here, but I held off for now.

Risks/Tradeoffs

I'm not sure how you all feel about abstract superclasses with subclass callbacks in ruby. 😬 I may have written too much Java lately.

I think this implementation makes the API wrapper easier to extend/maintain (especially since we know we'll need to add more endpoints/fix some signing bugs soon), but let me know if you think it's needlessly complicated. We can just skip this PR; it won't affect the issue.

Type of change

How Has This Been Tested?

No new behavior was added, but the specs in spec/lib/amazon_product_api/*_spec.rb still pass (+ the rest of the test suite.)

mxygem commented 6 years ago

I'm all for modularization and templating, especially when it makes things easier in the future! :+1: