Class: Geni::Base

Inherits:
Object
  • Object
show all
Defined in:
lib/geni/base.rb

Direct Known Subclasses

Document, Photo, Profile, Project, Union, Video

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(params = {}) ⇒ Base

Returns a new instance of Base.



5
6
7
8
9
10
11
12
13
14
15
# File 'lib/geni/base.rb', line 5

def initialize(params = {})
  @id = params[:id]
  @client = params[:client]
  @fetched = params[:fetched] || false
  
  if params.has_key?(:attrs)
    params[:attrs].each_pair do |key, value|
      instance_variable_set("@#{key}", value)
    end
  end
end

Instance Attribute Details

#clientObject (readonly)

Returns the value of attribute client.



3
4
5
# File 'lib/geni/base.rb', line 3

def client
  @client
end

#idObject (readonly)

Returns the value of attribute id.



3
4
5
# File 'lib/geni/base.rb', line 3

def id
  @id
end

Class Method Details

.has_fetchable_attributes(attribute_names) ⇒ Object



29
30
31
32
33
34
35
36
# File 'lib/geni/base.rb', line 29

def has_fetchable_attributes(attribute_names)
  attribute_names.each do |attribute_name|
    define_method "#{attribute_name}" do
      self.fetch unless self.fetched?
      instance_variable_get("@#{attribute_name}")
    end
  end
end

Instance Method Details

#fetchObject



21
22
23
24
25
26
# File 'lib/geni/base.rb', line 21

def fetch
  client.access_token.get("/api/#{id}").each_pair do |attr, value|
    instance_variable_set("@#{attr}".to_sym, value)
  end
  @fetched = true
end

#fetched?Boolean

Returns:

  • (Boolean)


17
18
19
# File 'lib/geni/base.rb', line 17

def fetched?
  @fetched
end