Module: Zuck::FbObject::Read::ClassMethods
- Defined in:
- lib/zuck/fb_object/read.rb
Instance Method Summary collapse
-
#all(graph = Zuck.graph, parent = nil) ⇒ Object
Automatique all getter.
-
#find(id, graph = Zuck.graph) ⇒ Object
Finds by object id and checks type.
-
#validate_parent_object_class(parent) ⇒ Object
Makes sure the given parent matches what you defined in FbObject.parent_object.
Instance Method Details
#all(graph = Zuck.graph, parent = nil) ⇒ Object
Automatique all getter.
Let's say you want to fetch all campaigns
from facebook. This can happen in the context of an ad
account. In this gem, that context is called a parent. This method
would only be called on objects that inherit from Zuck::FbObject.
It asks the parent
for it's path (if it is given), and appends
it's own list_path
property that you have defined (see
list_path)
If, however, you want to fetch all ad creatives, regardless of
which ad group is their parent, you can omit the parent
parameter. The creatives returned by Zuck::AdCreative.all
will
return nil
when you call #ad_group
on them, though, because facebook
will not return this information. So if you can, try to fetch
objects through their direct parent, e.g.
my_ad_group.ad_creatives
.
105 106 107 108 109 110 111 |
# File 'lib/zuck/fb_object/read.rb', line 105 def all(graph = Zuck.graph, parent = nil) parent ||= parent_ad_account_fallback r = get(graph, path_with_parent(parent)) r.map do |c| new(graph, c, parent) end end |
#find(id, graph = Zuck.graph) ⇒ Object
Finds by object id and checks type
81 82 83 |
# File 'lib/zuck/fb_object/read.rb', line 81 def find(id, graph = Zuck.graph) new(graph, id: id).reload end |
#validate_parent_object_class(parent) ⇒ Object
Makes sure the given parent matches what you defined in FbObject.parent_object
115 116 117 118 119 |
# File 'lib/zuck/fb_object/read.rb', line 115 def validate_parent_object_class(parent) resolve_parent_object_class e = "Invalid parent_object: #{parent.class} is not a #{@parent_object_class}" raise e if @parent_object_class and !parent.is_a?(@parent_object_class) end |