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

#urlObject (readonly)

Returns the value of attribute url.



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

def url
  @url
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



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

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

#request(params, options) ⇒ Object



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

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