Class: SupplierSecurity::API
- Inherits:
-
Object
- Object
- SupplierSecurity::API
- Includes:
- HTTParty
- Defined in:
- lib/suppliersecurity_gem.rb
Instance Method Summary collapse
-
#initialize(token) ⇒ API
constructor
A new instance of API.
- #search(product_url) ⇒ Object
Constructor Details
#initialize(token) ⇒ API
Returns a new instance of API.
12 13 14 15 16 17 18 19 20 |
# File 'lib/suppliersecurity_gem.rb', line 12 def initialize(token) @options = { headers: { "Accept" => "application/json", "Authorization" => "Bearer #{token}", "Content-type" => "application/json" } } end |
Instance Method Details
#search(product_url) ⇒ Object
22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/suppliersecurity_gem.rb', line 22 def search(product_url) body = { product: { url: product_url } }.to_json response = self.class.post("/search", @options.merge({ body: body })) # Raise a custom exception for a 404 response raise NotFoundException, "The product was not found" if response.code == 404 # Parse the JSON response into a hash JSON.parse(response.body)["products"] end |