Class: Beintoo::Vgood
- Inherits:
-
Object
- Object
- Beintoo::Vgood
- Defined in:
- lib/beintoo/vgood.rb
Constant Summary collapse
- RESOURCE =
"vgood"
- ATTRIBUTES =
%w{getRealURL showURL description descriptionSmall id imageUrl imageSmallUrl startdate enddate name bedollars discount VgoodPoiWrapper whoAlsoConverted categories isBanner contentType content rewardText shareURL uvext vgoodPOIs}
Class Method Summary collapse
-
.accept(user = nil, reward = nil) ⇒ Object
User can accept a given reward previously fetched with self.byuser.
-
.byplayer(player = nil) ⇒ Object
see documentation.beintoo.com/home/api-docs/resources/vgood Returns a vgood, this method act as Vgood.getByUser but providing player guid instead of userExt.
-
.byuser(user = nil) ⇒ Object
Get a list of POTENTIAL rewards for the user Should return an array of Beintoo::Vgood objects.
-
.showbyuser(user = nil) ⇒ Object
return the vgoods owned by the current user not yet converted.
Instance Method Summary collapse
- #==(other) ⇒ Object
-
#convert ⇒ Object
return the friends of the given user.
-
#getVgoodByGuid ⇒ Object
Returns a vgood, this method act as Vgood.getByUser but providing player guid instead of userExt.
-
#initialize(params = {}) ⇒ Vgood
constructor
A new instance of Vgood.
-
#sendAsGift ⇒ Object
return the friends of the given user.
- #to_s ⇒ Object
Constructor Details
#initialize(params = {}) ⇒ Vgood
Returns a new instance of Vgood.
11 12 13 14 15 |
# File 'lib/beintoo/vgood.rb', line 11 def initialize(params = {}) params.each do |a,v| self.send("#{a}=", v) rescue nil end end |
Class Method Details
.accept(user = nil, reward = nil) ⇒ Object
User can accept a given reward previously fetched with self.byuser
53 54 55 56 57 58 59 60 61 62 63 64 |
# File 'lib/beintoo/vgood.rb', line 53 def self.accept(user = nil, reward = nil) raise Beintoo::ApiException, "Called Vgood.accept_reward without passing a user!" if user.nil? raise Beintoo::ApiException, "Called Vgood.accept_reward without passing a reward!" if reward.nil? headers = Beintoo::build_headers if reward.is_a? Beintoo::Vgood result = Beintoo::get "#{RESOURCE}/accept/#{reward.id}/#{user.id}", headers else result = Beintoo::get "#{RESOURCE}/accept/#{reward}/#{user.id}", headers end # XXX WE SHOULD DETECT ERRORS HERE true end |
.byplayer(player = nil) ⇒ Object
see documentation.beintoo.com/home/api-docs/resources/vgood Returns a vgood, this method act as Vgood.getByUser but providing player guid instead of userExt.
68 69 70 71 72 73 74 75 76 77 |
# File 'lib/beintoo/vgood.rb', line 68 def self.byplayer(player = nil) raise Beintoo::ApiException, "Called Vgood.byplayer without passing a player!" if !player.logged_in? headers = Beintoo::build_headers result = Beintoo::get "#{RESOURCE}/byguid/#{player.guid}", headers vgoods = [] result[:vgoods].each do |vgood| vgoods << Beintoo::Vgood.new(vgood) end vgoods end |
.byuser(user = nil) ⇒ Object
Get a list of POTENTIAL rewards for the user Should return an array of Beintoo::Vgood objects
41 42 43 44 45 46 47 48 49 50 |
# File 'lib/beintoo/vgood.rb', line 41 def self.byuser(user = nil) raise Beintoo::ApiException, "Called Vgood.byuser without passing a user!" if user.nil? headers = Beintoo::build_headers result = Beintoo::get "#{RESOURCE}/byuser/#{user.id}", headers vgoods = [] result[:vgoods].each do |vgood| vgoods << Beintoo::Vgood.new(vgood) end vgoods end |
.showbyuser(user = nil) ⇒ Object
return the vgoods owned by the current user not yet converted.
28 29 30 31 32 33 34 35 36 37 |
# File 'lib/beintoo/vgood.rb', line 28 def self.showbyuser(user = nil) raise Beintoo::ApiException, "Called Vgood.byuser without passing a user!" if user.nil? headers = Beintoo::build_headers result = Beintoo::get "#{RESOURCE}/show/byuser/#{user.id}", headers vgoods = [] result.each do |vgood| vgoods << Beintoo::Vgood.new(vgood) end vgoods end |
Instance Method Details
#==(other) ⇒ Object
21 22 23 |
# File 'lib/beintoo/vgood.rb', line 21 def == (other) self.id == other.id end |
#convert ⇒ Object
return the friends of the given user
85 86 |
# File 'lib/beintoo/vgood.rb', line 85 def convert end |
#getVgoodByGuid ⇒ Object
Returns a vgood, this method act as Vgood.getByUser but providing player guid instead of userExt.
81 82 |
# File 'lib/beintoo/vgood.rb', line 81 def getVgoodByGuid end |
#sendAsGift ⇒ Object
return the friends of the given user
89 90 |
# File 'lib/beintoo/vgood.rb', line 89 def sendAsGift end |
#to_s ⇒ Object
17 18 19 |
# File 'lib/beintoo/vgood.rb', line 17 def to_s ATTRIBUTES.inject(''){|s,a| s << "#{a}: #{self.send(a).to_s}\n"} end |