Sha256: 9e4849048956adfc70d07ef26395d2534d503ddbf1a26e31231a9d9c4f9d1093
Contents?: true
Size: 1.53 KB
Versions: 2
Compression:
Stored size: 1.53 KB
Contents
module Eucalyptus class Resource def self.api_path raise "You must implement #{__method__.to_s}" end def self.known_fields raise "You must implement #{__method__.to_s}" end def self.parent Account.all.last end def self.find(id, fields: [], graph: Eucalyptus.graph) fields.concat(self.known_fields).uniq response = graph.get_object(id, fields: fields) self.new(response) end def self.all(graph: Eucalyptus.graph, parent: self.parent, options: {}) if options[:fields] options[:fields].concat(self.known_fields).uniq else options[:fields] = self.known_fields end options[:limit] = 5000 response = graph.get_connection(parent.id, api_path, options) response.collect{ |res| self.new(res) } end def initialize(response) @response = Response.new(response) end def method_missing(method_sym, *args, &block) @response.send(method_sym) end def respond_to?(method_sym, include_private = false) @response.respond_to?(method_sym) end def update(graph: Eucalyptus.graph, fields:) graph.put_connections(self.id, "", fields) end def ads(options={}) Ad.all(parent: self, options: options) end def campaigns(options={}) Campaign.all(parent: self, options: options) end def ad_sets(options={}) AdSet.all(parent: self, options: options) end def insights(options={}) Insight.all(parent: self, options: options) end end end
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
eucalyptus-0.2.10 | lib/eucalyptus/resource.rb |
eucalyptus-0.2.9 | lib/eucalyptus/resource.rb |