Class: BigDoor::ResourceEndUser

Inherits:
Resource
  • Object
show all
Defined in:
lib/big_door/resource_end_user.rb

Overview

This module provides Resource class with EndUser Parent

Direct Known Subclasses

Award, CurrencyBalance, Good, Level, Profile

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Resource

#delete, end_point_from_classname, #get_id, #initialize, #instance_to_payload, #load, #response_to_instance, #save

Constructor Details

This class inherits a constructor from BigDoor::Resource

Class Method Details

.all(username, client) ⇒ Object

Loads all Resource objects by this type

@param [String] username
  end_user_login to be used as base API end point

@param [BigDoor::Client] client
  Initialized BigDoor::Client object

@return [Array] Array of BigDoor::Resource derieved objects


54
55
56
57
58
59
60
61
62
63
64
65
66
# File 'lib/big_door/resource_end_user.rb', line 54

def self.all( username, client )
    # FIXME code duplication
    uri = self.end_point( username )
    $log.debug( "end_point = #{uri}")
    response = client.get( uri, { 'format' => 'json' } )
    $log.debug( "response to all = #{response}")
    allobj = response.map{ |obj| 
        $log.debug("obj = #{obj.inspect}")
        self.new(obj) 
    }
    $log.debug( "allobj = #{allobj.inspect}")
    allobj
end

.end_point(username) ⇒ Object

Calculates Resource object API end point from its class name using parent_end_point and parent_id_attr (possibly overriden in child classes)



30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/big_door/resource_end_user.rb', line 30

def self.end_point( username )
    # FIXME code duplication
    $log.debug("parent_end_point = #{ResourceEndUser.parent_end_point}")

    # FIXME if parent_id_attr empty
    # FIXME if no self.#{parent_id_attr}
    ep = sprintf "%s/%s/%s", 
        ResourceEndUser.parent_end_point,
        username,
        Resource.end_point_from_classname( self.name )
    ep
end

.parent_end_pointObject

Gives default base parent_end_point for object. Can be overriden in inherited classes.



72
73
74
# File 'lib/big_door/resource_end_user.rb', line 72

def self.parent_end_point 
    'end_user'
end

Instance Method Details

#end_pointObject

Calculates Resource object API end point from its class name using parent_end_point and parent_id_attr (possibly overriden in child classes)



12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/big_door/resource_end_user.rb', line 12

def end_point
    $log.debug("parent_end_point = #{ResourceEndUser.parent_end_point}")
    $log.debug("parent_id_attr = #{parent_id_attr}")
    $log.debug("parent_id_attr value = #{self.instance_eval("self.#{parent_id_attr}")}")

    # FIXME if parent_id_attr empty
    # FIXME if no self.#{parent_id_attr}
    ep = sprintf "%s/%s/%s", 
        ResourceEndUser.parent_end_point,
        self.instance_eval("self.#{parent_id_attr}"),
        Resource.end_point_from_classname( self.class.name )
    ep
end

#parent_id_attrObject

Gives default parent_id attribute name for object. Can be overriden in inherited classes.



80
81
82
# File 'lib/big_door/resource_end_user.rb', line 80

def parent_id_attr
    'end_user_login'
end