Class: TicketEvolution::Endpoint

Inherits:
Base
  • Object
show all
Includes:
RequestHandler, SingularClass
Defined in:
lib/ticket_evolution/core/endpoint.rb,
lib/ticket_evolution/core/endpoint/request_handler.rb

Defined Under Namespace

Modules: RequestHandler

Constant Summary

Constants included from RequestHandler

RequestHandler::CODES

Instance Method Summary collapse

Methods included from SingularClass

#singular_class

Methods included from RequestHandler

#build_request, #collection_handler, #naturalize_response, #raw_handler, #request, #upload_history_handler

Constructor Details

#initialize(options = nil) ⇒ Endpoint

Returns a new instance of Endpoint.



6
7
8
9
10
11
12
# File 'lib/ticket_evolution/core/endpoint.rb', line 6

def initialize(options = nil)
  raise EndpointConfigurationError, "#{self.class.to_s} instances require a hash as their first parameter" unless options.is_a? Hash
  raise EndpointConfigurationError, "The options hash must include a parent key / value pair" unless options[:parent].present?
  raise EndpointConfigurationError, "#{self.class.to_s} instances require a parent which inherits from TicketEvolution::Base" unless options[:parent].kind_of? TicketEvolution::Base
  @options = options.with_indifferent_access
  raise EndpointConfigurationError, "The parent passed in the options hash must be a TicketEvolution::Connection object or have one in it's parent chain" unless has_connection?
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(method, *args) ⇒ Object



40
41
42
43
# File 'lib/ticket_evolution/core/endpoint.rb', line 40

def method_missing(method, *args)
  name = method.to_s
  @options.keys.include?(name) ? @options[name] : super
end

Instance Method Details

#base_pathObject



14
15
16
17
18
19
20
# File 'lib/ticket_evolution/core/endpoint.rb', line 14

def base_path
  [].tap do |parts|
    parts << parent.base_path if parent.kind_of? TicketEvolution::Endpoint
    parts << "/"+endpoint_name
    parts << "/#{self.id}" if self.id.present?
  end.join
end

#connectionObject



22
23
24
25
26
27
28
29
30
# File 'lib/ticket_evolution/core/endpoint.rb', line 22

def connection
  if self.parent.is_a? TicketEvolution::Connection
    self.parent
  elsif self.parent.kind_of? TicketEvolution::Endpoint
    self.parent.connection
  else
    nil
  end
end

#endpoint_nameObject



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

def endpoint_name
  self.class.name.demodulize.underscore
end

#has_connection?Boolean

Returns:

  • (Boolean)


32
33
34
# File 'lib/ticket_evolution/core/endpoint.rb', line 32

def has_connection?
  connection.present?
end

#idObject

Ruby 1.8.7 / REE compatibility



46
47
48
# File 'lib/ticket_evolution/core/endpoint.rb', line 46

def id
  @options[:id]
end