Class: Vendor::Product

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options, buy_class, &block) ⇒ Product

Returns a new instance of Product.

Raises:

  • (ArgumentError)


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

def initialize(options, buy_class, &block)

  # Set params and block
  @buy = buy_class
  @params = options
  @block = block

  # Raise argument error if id is not included
  raise ArgumentError, "VENDOR WARNING: You forgot to write in your item id. You can't sell item without an id." if @params.id == "no_id"
  raise ArgumentError, "VENDOR WARNING: You're missing your subscriptions shared secret. Subscriptions must have a shared secret." if @params.subscription && @params.secret == "no_secret"

  # Update product and set exists variable
  @info = Vendor::Info.new(@params) do |block|
    @exists = block.success
    @params[:sk_product] = block.response.products.first if block.success
    @block.call(block) unless @block.nil?
  end
end

Instance Attribute Details

#blockObject (readonly)

Returns the value of attribute block.



3
4
5
# File 'lib/project/product.rb', line 3

def block
  @block
end

#buyObject (readonly)

Returns the value of attribute buy.



3
4
5
# File 'lib/project/product.rb', line 3

def buy
  @buy
end

#existsObject (readonly)

Returns the value of attribute exists.



3
4
5
# File 'lib/project/product.rb', line 3

def exists
  @exists
end

#infoObject (readonly)

Returns the value of attribute info.



3
4
5
# File 'lib/project/product.rb', line 3

def info
  @info
end

#paramsObject (readonly)

Returns the value of attribute params.



3
4
5
# File 'lib/project/product.rb', line 3

def params
  @params
end

Instance Method Details

#bought?Boolean

Returns:

  • (Boolean)


58
59
60
# File 'lib/project/product.rb', line 58

def bought?
  @info.bought?
end

#descriptionObject



50
51
52
# File 'lib/project/product.rb', line 50

def description
  @info.description
end

#exists?Boolean

Returns:

  • (Boolean)


54
55
56
# File 'lib/project/product.rb', line 54

def exists?
  @exists || false
end

#priceObject

INFO METHODS



38
39
40
# File 'lib/project/product.rb', line 38

def price
  @info.price
end

#price_localeObject



42
43
44
# File 'lib/project/product.rb', line 42

def price_locale
  @info.price_locale
end

#purchase(&block) ⇒ Object

PURCHASE METHODS



27
28
29
# File 'lib/project/product.rb', line 27

def purchase(&block)
  @buy.purchase(@params) { |result| block.call(result)}
end

#restore(&block) ⇒ Object



31
32
33
# File 'lib/project/product.rb', line 31

def restore(&block)
  @buy.restore(@params) { |result| block.call(result)}
end

#subscribed?Boolean

Returns:

  • (Boolean)


66
67
68
# File 'lib/project/product.rb', line 66

def subscribed?
  @info.subscribed?
end

#subscription?Boolean

Returns:

  • (Boolean)


62
63
64
# File 'lib/project/product.rb', line 62

def subscription?
  @info.subscription?
end

#titleObject



46
47
48
# File 'lib/project/product.rb', line 46

def title
  @info.title
end