class Serpscan::SerpscanObject
Public Class Methods
all(options = {})
click to toggle source
# File lib/serpscan/serpscan_object.rb, line 30 def all(options = {}) parent = options[:parent] child = options[:child] objects = options.fetch(:objects, []) url = options[:parent] ? "#{parent.api_path}/#{parent.id}#{child.api_path}" : api_path results = Serpscan::API.get(url, params: options[:params]) results['results'].map do |object| objects << new(object.merge(parent: options[:parent])) end consider_pagination(results, options, objects) objects end
api_path(object = self)
click to toggle source
# File lib/serpscan/serpscan_object.rb, line 26 def api_path(object = self) "/#{Serpscan::Utilities.object_to_string(object)}s" end
consider_pagination(results, options, objects)
click to toggle source
# File lib/serpscan/serpscan_object.rb, line 58 def consider_pagination(results, options, objects) if results['page'] && results['page'].to_i < results['total_pages'] (options[:child]).all(options.merge(objects: objects, params: { page: results['page'].to_i + 1 })) end end
create(params)
click to toggle source
# File lib/serpscan/serpscan_object.rb, line 51 def create(params) parent_object = params.delete(:parent) params = { Serpscan::Utilities.object_to_string(self) => params } results = Serpscan::API.post("#{api_path}?#{QueryParams.encode(params)}", params: params) new(results.merge(parent: parent_object)) end
find(id)
click to toggle source
# File lib/serpscan/serpscan_object.rb, line 46 def find(id) results = Serpscan::API.get("#{api_path}/#{id}") new(results) end
new(options = {})
click to toggle source
# File lib/serpscan/serpscan_object.rb, line 3 def initialize(options = {}) @raw_json ||= options assign_attributes(options) end
Public Instance Methods
api_path()
click to toggle source
# File lib/serpscan/serpscan_object.rb, line 8 def api_path SerpscanObject.api_path(self) end
delete()
click to toggle source
# File lib/serpscan/serpscan_object.rb, line 16 def delete Serpscan::API.delete("#{api_path}/#{id}") true end
object_name()
click to toggle source
# File lib/serpscan/serpscan_object.rb, line 12 def object_name Serpscan::Utilities.object_to_string(self) end
to_json()
click to toggle source
# File lib/serpscan/serpscan_object.rb, line 21 def to_json @raw_json.to_json end
Private Instance Methods
assign_attributes(options = {})
click to toggle source
# File lib/serpscan/serpscan_object.rb, line 67 def assign_attributes(options = {}) self.class::ATTRIBUTES.each do |attribute| send("#{attribute}=", options[attribute.to_s]) end end