deanpcmad / lemonsqueezy

Ruby library for the Lemon Squeezy API
27 stars 7 forks source link

Keep associations #11

Open excid3 opened 1 month ago

excid3 commented 1 month ago

Currently, the API responses delete the association data.

For example, it would be helpful to be able to retrieve an Order and ask for it's associated subscriptions. Same for all the other associations.

order = LemonSqueezy::Order.retrieve(id: "x")
order.subscriptions => [<LemonSqueezy::Subscription>, ...}

If this is implemented using the JSON API data, this can be future proofed for any other associations added.

deanpcmad commented 1 month ago

I remove relationships and links as they don't contain any useful information really.

An example of a product:

"relationships"=>
    {"store"=>
      {"links"=>
        {"related"=>"https://api.lemonsqueezy.com/v1/products/166741/store",
         "self"=>"https://api.lemonsqueezy.com/v1/products/166741/relationships/store"}},
     "variants"=>
      {"links"=>
        {"related"=>"https://api.lemonsqueezy.com/v1/products/166741/variants",
         "self"=>"https://api.lemonsqueezy.com/v1/products/166741/relationships/variants"}}},
"links"=>{"self"=>"https://api.lemonsqueezy.com/v1/products/166741"}}}
excid3 commented 1 month ago

You can use that to generate the associations and connect them to the other models.