Class: Tickethub::Endpoint
- Inherits:
-
Object
- Object
- Tickethub::Endpoint
- Defined in:
- lib/tickethub/endpoint.rb
Instance Attribute Summary collapse
-
#options ⇒ Object
readonly
Returns the value of attribute options.
Instance Method Summary collapse
- #[](*parts) ⇒ Object
- #_normalize_path(str) ⇒ Object
-
#initialize(url, options) ⇒ Endpoint
constructor
A new instance of Endpoint.
- #request(params, options) ⇒ Object
- #uri ⇒ Object
- #url(params = {}) ⇒ Object
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, ) @url = _normalize_path url @options = end |
Instance Attribute Details
#options ⇒ Object (readonly)
Returns the value of attribute options.
9 10 11 |
# File 'lib/tickethub/endpoint.rb', line 9 def @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, ) raise 'this endpoint is readonly' if frozen? Tickethub::Request.new(url, .merge(params: params)).execute end |
#uri ⇒ Object
27 28 29 |
# File 'lib/tickethub/endpoint.rb', line 27 def uri URI.parse @url end |