Class: Tickethub::Endpoint

Inherits:
Object
  • Object
show all
Defined in:
lib/tickethub/endpoint.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(url, options) ⇒ Endpoint

Returns a new instance of Endpoint.



11
12
13
14
# File 'lib/tickethub/endpoint.rb', line 11

def initialize(url, options)
  @url     = _normalize_path url
  @options = options
end

Instance Attribute Details

#optionsObject (readonly)

Returns the value of attribute options.



9
10
11
# File 'lib/tickethub/endpoint.rb', line 9

def options
  @options
end

Instance Method Details

#[](*parts) ⇒ Object



16
17
18
19
# File 'lib/tickethub/endpoint.rb', line 16

def [](*parts)
  parts = parts.compact.map { |part| _normalize_path part.to_s }
  self.class.new URI.join(url, *parts).to_s, @options
end

#_normalize_path(str) ⇒ Object



40
41
42
# File 'lib/tickethub/endpoint.rb', line 40

def _normalize_path(str)
  str.match(/\/$/) ? str : "#{str}/"
end

#request(params, options) ⇒ Object



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

def request(params, options)
  raise 'this endpoint is readonly' if frozen?
  Tickethub::Request.new(url, options.merge(params: params)).execute
end

#uriObject



27
28
29
# File 'lib/tickethub/endpoint.rb', line 27

def uri
  URI.parse @url
end

#url(params = {}) ⇒ Object



31
32
33
# File 'lib/tickethub/endpoint.rb', line 31

def url(params = {})
  return params.empty?? @url : "#{@url}?#{Helpers.to_param(params)}"
end