class Skroutz::CollectionProxy
Attributes
client[RW]
id[RW]
owner[RW]
Public Class Methods
new(id, client, owner = nil, options = {})
click to toggle source
# File lib/skroutz/collection_proxy.rb, line 7 def initialize(id, client, owner = nil, options = {}) if self.class == Skroutz::CollectionProxy raise RuntimeError.new('Attempted to initialize an abstract class') end @id = id @client = client @owner = owner @prefix = options[:prefix] end
Public Instance Methods
all(options = {}) { |response| ... }
click to toggle source
# File lib/skroutz/collection_proxy.rb, line 35 def all(options = {}) response = client.get(base_path, options) return parse(response) unless block_given? yield response end
find(id, options = {}) { |response| ... }
click to toggle source
# File lib/skroutz/collection_proxy.rb, line 18 def find(id, options = {}) response = client.get("#{base_path}/#{id}", options) return parse(response) unless block_given? yield response end
model_name()
click to toggle source
# File lib/skroutz/collection_proxy.rb, line 51 def model_name @model_name ||= "Skroutz::#{resource.classify}".constantize end
page(pagenum = 1, options = {}) { |response| ... }
click to toggle source
# File lib/skroutz/collection_proxy.rb, line 26 def page(pagenum = 1, options = {}) per = options[:per] || client.config[:pagination_page_size] response = client.get(base_path, { page: pagenum, per: per }.merge(options)) return parse(response) unless block_given? yield response end
resource()
click to toggle source
# File lib/skroutz/collection_proxy.rb, line 43 def resource @resource ||= self.class.to_s.demodulize.chomp('Collection').tableize.singularize end
resource_prefix()
click to toggle source
# File lib/skroutz/collection_proxy.rb, line 47 def resource_prefix @resource_prefix ||= @prefix || resource.pluralize end
Private Instance Methods
method_missing(method, *args) { |response| ... }
click to toggle source
# File lib/skroutz/collection_proxy.rb, line 57 def method_missing(method, *args) # rubocop:disable Metrics/CyclomaticComplexity options = args.first || {} url_prefix = options.delete(:url_prefix) || '' verb = options.delete(:verb) || options.delete(:via) || :get target_url = "#{base_path}/#{id}/#{method}" target_url.prepend("#{url_prefix}/") if url_prefix response = client.send(verb, target_url, options) return parse(response) unless block_given? yield response end