Sha256: 4371e1c75ebf463d5c5313f8d29d20c223bc700e5401faf9f4988f95792455ff
Contents?: true
Size: 845 Bytes
Versions: 19
Compression:
Stored size: 845 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 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
19 entries across 19 versions & 1 rubygems