class XporterOnDemand::Endpoint
Attributes
endpoint[RW]
id[RW]
options[RW]
pagination[RW]
parameters[RW]
uri[RW]
Public Class Methods
create(endpoint, args = {})
click to toggle source
# File lib/xporter_on_demand/endpoint.rb, line 9 def self.create(endpoint, args = {}) endpoint_name = endpoint.to_s.classify unless const_defined?(endpoint_name, false) class_name = Class.new(self) endpoint_class = const_set(endpoint_name, class_name) end const_get(endpoint_name).new(args).tap do |s| s.instance_variable_set(:@endpoint, endpoint) end end
new(args = {})
click to toggle source
# File lib/xporter_on_demand/endpoint.rb, line 22 def initialize(args = {}) @options = args.fetch(:options, []) @parameters = args.fetch(:parameters, {}) @parameters[:page] ||= 1 @parameters[:page_size] ||= 25 @id = args[:id] # Check that all the options are valid? # Check that the parameters are valid? # Check the pagination params are valid? end
Public Instance Methods
build_query()
click to toggle source
# File lib/xporter_on_demand/endpoint.rb, line 36 def build_query URI.escape(resource + "?" + build_parameters) end
Private Instance Methods
build_options()
click to toggle source
# File lib/xporter_on_demand/endpoint.rb, line 45 def build_options @options.any? ? ["options=" + @options.map{ |o| parameterize(o) }.join(',')] : [] end
build_parameters()
click to toggle source
# File lib/xporter_on_demand/endpoint.rb, line 49 def build_parameters (@parameters.map{ |k, v| parameterize(k) + "=" + v.to_s } + build_options).join('&') end
resource()
click to toggle source
# File lib/xporter_on_demand/endpoint.rb, line 41 def resource endpoint.to_s.camelize + "/" + (@id || "") end