Module: ActsAsGraphObject::Base::InstanceMethods

Defined in:
lib/acts_as_graph_object/base.rb

Instance Method Summary collapse

Instance Method Details

#action(name = '') ⇒ Object

helper for sending custom actions, e.g. (using Koala): user.put_connections(‘me’, action(‘watch’), movie: @movie.url)



28
29
30
# File 'lib/acts_as_graph_object/base.rb', line 28

def action(name = '')
  [configuration.namespace, name].join(':') unless name.empty?
end

#graph_propertiesObject



32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
# File 'lib/acts_as_graph_object/base.rb', line 32

def graph_properties
  # standard object properties & alternative names
  default_properties = {
    :title           => [:name, :label],
    :type            => [:kind, :group],
    :image           => [:picture, :photo],
    :url             => [:permalink, :link],
    :description     => [:info, :details],
    :site_name       => [:site],
    :latitude        => [:lat],
    :longitude       => [:lng],
    :street_address  => [:address],
    :locality        => [:locale, :area],
    :region          => [:province, :territory],
    :postal_code     => [:post_code, :zip_code, :zip],
    :country_name    => [:country],
    :email           => [:email_address],
    :phone_number    => [:phone],
    :fax_number      => [:fax],
    :determiner      => [:prefix]
  }

  # property/content pairs
  # we build this up to contain our final values
  properties = {
    :og => {},
    :fb => {
      :app_id => configuration.app_id,
      :admins => configuration.admins.join(',')
    }
  }
      
  # try all the default og properties first
  default_properties.each do |property_name, alternatives|
    ([property_name] + alternatives).each do |property|
      if self.respond_to?(property)
        properties[:og][property_name] = self.send(property)
      end
    end
  end
      
  # add any custom properties..
  properties[configuration.namespace] ||= {} unless options[:custom].nil?
  Array(options[:custom]).each do |property|
    properties[configuration.namespace][property] = self.send(property)
  end
  
  properties
end

#typeObject



22
23
24
# File 'lib/acts_as_graph_object/base.rb', line 22

def type
  [configuration.namespace, self.class.name.underscore].join(':')
end

#url(*args) ⇒ Object

requires routes.default_url_options to be set! in nested associations parent is passed, e.g. @review.url(@movie)



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

def url(*args)
  logger.warn "Using #{self.class.name}.url directly not recommended: please override in your model/view."
  url_helpers.send([self].unshift(*args).map(&:class).join('_').downcase + '_url', *args.push(self)) rescue nil
end