Class: XporterOnDemand::Endpoint

Inherits:
Object
  • Object
show all
Includes:
Utils
Defined in:
lib/xporter_on_demand/endpoint.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Utils

#assign_attributes, #configure_request, #create_result, #dont_raise_exception, #handle_exceptions, #parameterize, #unwrap

Constructor Details

#initialize(args = {}) ⇒ Endpoint

Returns a new instance of Endpoint.



22
23
24
25
26
27
28
29
30
31
32
33
34
# 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

Instance Attribute Details

#endpointObject

Returns the value of attribute endpoint.



7
8
9
# File 'lib/xporter_on_demand/endpoint.rb', line 7

def endpoint
  @endpoint
end

#idObject

Returns the value of attribute id.



7
8
9
# File 'lib/xporter_on_demand/endpoint.rb', line 7

def id
  @id
end

#optionsObject

Returns the value of attribute options.



7
8
9
# File 'lib/xporter_on_demand/endpoint.rb', line 7

def options
  @options
end

#paginationObject

Returns the value of attribute pagination.



7
8
9
# File 'lib/xporter_on_demand/endpoint.rb', line 7

def pagination
  @pagination
end

#parametersObject

Returns the value of attribute parameters.



7
8
9
# File 'lib/xporter_on_demand/endpoint.rb', line 7

def parameters
  @parameters
end

#uriObject

Returns the value of attribute uri.



7
8
9
# File 'lib/xporter_on_demand/endpoint.rb', line 7

def uri
  @uri
end

Class Method Details

.create(endpoint, args = {}) ⇒ Object



9
10
11
12
13
14
15
16
17
18
19
20
# 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

Instance Method Details

#build_queryObject



36
37
38
# File 'lib/xporter_on_demand/endpoint.rb', line 36

def build_query
  URI.escape(resource + "?" + build_parameters)
end