Introduce Product Resource - #39
Conversation
b8686e4 to
e4434cf
Compare
83e0c90 to
c99e65f
Compare
|
the authentication changes need to be their own PR... |
|
This needs to be refactored after this PR is merged: #41 |
ac7eff9 to
8b4e783
Compare
f5022c0 to
8db3d7c
Compare
dd091b3 to
2ba0d70
Compare
| as_packaged = NutritionFact. | ||
| build_from_array(data[:nutrition_facts][:as_packaged]) | ||
| as_cooked = NutritionFact. | ||
| build_from_array(data[:nutrition_facts]. | ||
| fetch(:as_cooked, [])) |
There was a problem hiding this comment.
i guess as packaged always exists and as cooked only exists sometimes?
There was a problem hiding this comment.
Yes, exactly that. as_cooked is optionally returned, so using fetch to guard against that
2ba0d70 to
df0a45b
Compare
The Core API supports retrieval of products by its Product ID. This PR introduces the new Product resource, along with child resources needed to build the main Product object. These child resources include Allergens, Ingredient, Dietary Tag. This change addresses the need by: * Introducing a CoreObject resource which can be used by all core (v2) objects * Introducing a Product resource
df0a45b to
2943511
Compare
|
|
||
| module Bls | ||
| module Core | ||
| class DietaryTag < Bls::Core::ObjectV2; end |
There was a problem hiding this comment.
DietaryTag is kind of confusing naming... what is this and what is it used for?
There was a problem hiding this comment.
It's the naming which is returned by the core api, and is an array of diets which the meal abides by ex: ["PESCATARIAN"].
If the naming is not clear, perhaps the api should not return this key, and I can adjust this PR accordingly?
There was a problem hiding this comment.
yeah it sounds like this needs to be thought about at the API level. make a note for you to revisit this with them. i think it's worth you reviewing naming across the entire product resource to comment on what might still sound sunbasket specific in the response
| end | ||
|
|
||
| def self.build_from_response(data) | ||
| product = build(data) |
There was a problem hiding this comment.
pretty big method, consider extracting a factory class to use in here instead (will make testing way easier too)
There was a problem hiding this comment.
you actually didn't write any tests for this...
There was a problem hiding this comment.
Calling .retrieve on Product utilizes ApiOperations::Retrieve and if the response is successful it calls build_from_response.
Like other resources, I wrote tests for .retrieve and am testing to see if the object gets built successfully. But ill move to using a factory class

The Core API supports retrieval of products by its Product ID. This PR
introduces the new Product resource, along with child resources needed
to build the main Product object. These child resources include
Allergens, Ingredient, Dietary Tag & Nutrition Fact.
This change addresses the need by:
objects