Class: Vendor::Product
- Inherits:
-
Object
- Object
- Vendor::Product
- Defined in:
- lib/project/product.rb
Instance Attribute Summary collapse
-
#block ⇒ Object
readonly
Returns the value of attribute block.
-
#buy ⇒ Object
readonly
Returns the value of attribute buy.
-
#exists ⇒ Object
readonly
Returns the value of attribute exists.
-
#info ⇒ Object
readonly
Returns the value of attribute info.
-
#params ⇒ Object
readonly
Returns the value of attribute params.
Instance Method Summary collapse
- #bought? ⇒ Boolean
- #description ⇒ Object
- #exists? ⇒ Boolean
-
#initialize(options, buy_class, &block) ⇒ Product
constructor
A new instance of Product.
-
#price ⇒ Object
INFO METHODS.
- #price_locale ⇒ Object
-
#purchase(&block) ⇒ Object
PURCHASE METHODS.
- #restore(&block) ⇒ Object
- #subscribed? ⇒ Boolean
- #subscription? ⇒ Boolean
- #title ⇒ Object
Constructor Details
#initialize(options, buy_class, &block) ⇒ Product
Returns a new instance of Product.
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(, buy_class, &block) # Set params and block @buy = buy_class @params = @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
#block ⇒ Object (readonly)
Returns the value of attribute block.
3 4 5 |
# File 'lib/project/product.rb', line 3 def block @block end |
#buy ⇒ Object (readonly)
Returns the value of attribute buy.
3 4 5 |
# File 'lib/project/product.rb', line 3 def buy @buy end |
#exists ⇒ Object (readonly)
Returns the value of attribute exists.
3 4 5 |
# File 'lib/project/product.rb', line 3 def exists @exists end |
#info ⇒ Object (readonly)
Returns the value of attribute info.
3 4 5 |
# File 'lib/project/product.rb', line 3 def info @info end |
#params ⇒ Object (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
58 59 60 |
# File 'lib/project/product.rb', line 58 def bought? @info.bought? end |
#description ⇒ Object
50 51 52 |
# File 'lib/project/product.rb', line 50 def description @info.description end |
#exists? ⇒ Boolean
54 55 56 |
# File 'lib/project/product.rb', line 54 def exists? @exists || false end |
#price ⇒ Object
INFO METHODS
38 39 40 |
# File 'lib/project/product.rb', line 38 def price @info.price end |
#price_locale ⇒ Object
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
66 67 68 |
# File 'lib/project/product.rb', line 66 def subscribed? @info.subscribed? end |
#subscription? ⇒ Boolean
62 63 64 |
# File 'lib/project/product.rb', line 62 def subscription? @info.subscription? end |
#title ⇒ Object
46 47 48 |
# File 'lib/project/product.rb', line 46 def title @info.title end |