Class: PurchaseKit::Product::Remote

Inherits:
Object
  • Object
show all
Defined in:
lib/purchasekit/product/remote.rb

Overview

Production implementation of Product that fetches from PurchaseKit API.

Class Method Summary collapse

Class Method Details

.find(id) ⇒ Object



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/purchasekit/product/remote.rb', line 7

def find(id)
  response = ApiClient.new.get("/products/#{id}")

  case response.code
  when 200
    Product.new(
      id: response["id"],
      apple_product_id: response["apple_product_id"],
      google_product_id: response["google_product_id"],
      google_base_plan_id: response["google_base_plan_id"]
    )
  when 404
    raise PurchaseKit::NotFoundError, "Product not found: #{id}"
  else
    raise PurchaseKit::Error, "API error: #{response.code} #{response.message}"
  end
end