Sha256: fb65df24698baef2ed30c9485e08282fc4d9d4349ce5c6e2db7054911567bcf9

Contents?: true

Size: 899 Bytes

Versions: 16

Compression:

Stored size: 899 Bytes

Contents

require_relative 'request'
require_relative 'response'
require_relative 'helpers'

module Tickethub
  class Endpoint
    attr_reader :options, :url

    def initialize(url, options = {})
      @url     = url
      @options = options
    end

    def [](suburl, options = {})
      url = (if suburl.nil? then self.url
        else
          suburl = suburl.to_s
          base   = self.url
          base  += "/" unless base =~ /\/$/
          URI.join(base, suburl).to_s
        end)

      self.class.new url, Tickethub::Helpers.deep_merge(@options, options)
    end

    [:get, :post, :delete, :patch].each do |method|
      define_method method do |params = {}, options = {}|
        request options.merge(method: method, params: params)
      end
    end

    def request(options = {})
      Tickethub::Request.new(url, Tickethub::Helpers.deep_merge(@options, options)).execute
    end
  end
end

Version data entries

16 entries across 16 versions & 1 rubygems

Version Path
tickethub-0.1.4 lib/tickethub/endpoint.rb
tickethub-0.1.3 lib/tickethub/endpoint.rb
tickethub-0.1.2 lib/tickethub/endpoint.rb
tickethub-0.0.14 lib/tickethub/endpoint.rb
tickethub-0.0.12 lib/tickethub/endpoint.rb
tickethub-0.0.11 lib/tickethub/endpoint.rb
tickethub-0.0.10 lib/tickethub/endpoint.rb
tickethub-0.0.9 lib/tickethub/endpoint.rb
tickethub-0.0.8 lib/tickethub/endpoint.rb
tickethub-0.0.7 lib/tickethub/endpoint.rb
tickethub-0.0.6 lib/tickethub/endpoint.rb
tickethub-0.0.5 lib/tickethub/endpoint.rb
tickethub-0.0.4 lib/tickethub/endpoint.rb
tickethub-0.0.3 lib/tickethub/endpoint.rb
tickethub-0.0.2 lib/tickethub/endpoint.rb
tickethub-0.0.1 lib/tickethub/endpoint.rb