class Retentiongrid::Product

Constants

ATTRIBUTES_NAMES

The set of attributes defined by the API documentation

BASE_PATH

Public Class Methods

find(product_id) click to toggle source

Find a product with given id @param [Fixnum] product_id the prodct id to be found @return [Product] if found any

# File lib/retentiongrid/product.rb, line 32
def self.find(product_id)
  begin
    result = Api.get("#{BASE_PATH}/#{product_id}")
    new(result.parsed_response["rg_product"])
  rescue NotFound
    nil
  end
end
new(attribs={}) click to toggle source
Calls superclass method
# File lib/retentiongrid/product.rb, line 17
def initialize(attribs={})
  super
  if product_created_at.class == String && !product_created_at.nil?
    @product_created_at = Time.parse(product_created_at)
  end
  if @product_updated_at.class == String && !product_updated_at.nil?
    @product_updated_at = Time.parse(product_updated_at)
  end
end

Public Instance Methods

destroy() click to toggle source

Delete this product at retention grid @return [Boolean] successfully deleted?

# File lib/retentiongrid/product.rb, line 51
def destroy
  Api.delete("#{BASE_PATH}/#{product_id}")
  true
end
save!() click to toggle source

Create or update a product with given id @return [Product] if successfully created or updated @raise [Httparty::Error] for all sorts of HTTP statuses.

# File lib/retentiongrid/product.rb, line 44
def save!
  result = Api.post("#{BASE_PATH}/#{product_id}", body: attributes.to_json)
  Product.new(result.parsed_response["rg_product"])
end