Class: FetchAppAPI::Product

Inherits:
Base
  • Object
show all
Defined in:
lib/fetchapp-api-ruby/product.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Base

basic_auth, can_connect?, key, time

Constructor Details

#initialize(id_or_attributes) ⇒ Product

:nodoc:



5
6
7
8
9
10
11
12
13
# File 'lib/fetchapp-api-ruby/product.rb', line 5

def initialize(id_or_attributes) #:nodoc:
  case id_or_attributes
    when Integer, String
      @attributes = get("/#{self.class.pluralized_class_name}/#{id_or_attributes.to_s}")
      @attributes = @attributes[self.class.singularized_class_name]
    when Hash
      @attributes = id_or_attributes
  end
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class FetchAppAPI::Base

Instance Attribute Details

#attributesObject

Returns the value of attribute attributes.



3
4
5
# File 'lib/fetchapp-api-ruby/product.rb', line 3

def attributes
  @attributes
end

#idObject

Returns the value of attribute id.



3
4
5
# File 'lib/fetchapp-api-ruby/product.rb', line 3

def id
  @id
end

Class Method Details

.create(options) ⇒ Object

Creates a new Product



27
28
29
# File 'lib/fetchapp-api-ruby/product.rb', line 27

def self.create(options)
  return FetchAppAPI::Product.new(execute(:post, "/products/create", :product => options)["product"])
end

.find(selector, params = {}) ⇒ Object

Find :all products or a specific SKU



21
22
23
# File 'lib/fetchapp-api-ruby/product.rb', line 21

def self.find(selector, params={})
  super(selector, params)
end

Instance Method Details

#destroyObject

Permanently deletes the Product



36
37
38
# File 'lib/fetchapp-api-ruby/product.rb', line 36

def destroy
  delete("/products/#{self.sku}/delete")
end

#downloadsObject

Returns all the downloads associated with this Product



47
48
49
50
51
52
# File 'lib/fetchapp-api-ruby/product.rb', line 47

def downloads
  downloads = get("/products/#{sku}/downloads")
  if downloads
    downloads["downloads"].map { |data| FetchAppAPI::Download.new(data) }
  end
end

#filesObject

Returns all the downloads associated with this Product



55
56
57
58
59
60
# File 'lib/fetchapp-api-ruby/product.rb', line 55

def files
  files = get("/products/#{sku}/files")
  if files
    files["files"].map { |data| FetchAppAPI::File.new(data) }
  end
end

#statsObject

Returns stats about this Product



63
64
65
66
67
68
# File 'lib/fetchapp-api-ruby/product.rb', line 63

def stats
  stats = get("/products/#{sku}/stats")
  if stats
    FetchAppAPI::Product.new(stats["product"])
  end
end

#update(options) ⇒ Object

Immediately updates the Product



41
42
43
44
# File 'lib/fetchapp-api-ruby/product.rb', line 41

def update(options)
  self.attributes = put("/products/#{self.sku}", :product => options)["product"]
  self.id = self.sku
end