Sha256: 03534fc4cf61275b4a0d896339206f922f321613c2e81b6116669e0bee6a22e6
Contents?: true
Size: 943 Bytes
Versions: 26
Compression:
Stored size: 943 Bytes
Contents
require 'uri' require_relative 'request' require_relative 'response' require_relative 'helpers' module Tickethub class Endpoint attr_reader :options, :url def initialize(url, options) @url = _normalize_path url @options = options end def [](*parts) parts = parts.compact.map { |part| _normalize_path part.to_s } self.class.new URI.join(url, *parts).to_s, @options end [:get, :post, :delete, :patch].each do |method| define_method method do |params = {}| request params, options.merge(method: method) end end def url(params = {}) params.any?? "#{@url}?#{Helpers.to_param(params)}" : @url end def request(params, options) raise 'this endpoint is readonly' if frozen? Tickethub::Request.new(url, options.merge(params: params)).execute end def _normalize_path(str) str.match(/\/$/) ? str : "#{str}/" end end end
Version data entries
26 entries across 26 versions & 1 rubygems