Sha256: 16013668c0cd2de138199f758a1ab2a49903f95806cb0b1c0b5633611416f344

Contents?: true

Size: 1.8 KB

Versions: 2

Compression:

Stored size: 1.8 KB

Contents

require_relative 'connection'
require_relative 'request'

module TicketingHub
  class Client
    include TicketingHub::Connection
    include TicketingHub::Request

    attr_accessor *Configuration::VALID_OPTIONS_KEYS

    def initialize options={}
      options = TicketingHub.options.merge options
      Configuration::VALID_OPTIONS_KEYS.each do |key|
        send "#{key}=", options[key]
      end
    end

    def get_token code
      post('token', grant_type: 'code', client_id: client_id,
        client_secret: client_secret, code: code, endpoint: oauth_endpoint)['access_token']
    end

    def venue
      get 'venue'
    end

    def user
      get 'user'
    end

    def orders
      get 'orders'
    end

    def order order_id
      get "orders/#{_normalize_object_id order_id}"
    end

    def tiers date, starts_at
      get 'tiers', { date: date, starts_at: starts_at }
    end

    def options date=nil
      date = Date.parse(date.to_s) if date
      get 'options', { date: date }
    end

    def consumer_fields order_id, ticket_id=nil
      ticket_id.nil?? get("orders/#{_normalize_object_id order_id}/fields") :
        get("tickets/#{_normalize_object_id ticket_id}/fields")
    end

    def create_order order_attributes
      post 'orders', order_attributes
    end

    def cancel_order order_id
      delete "orders/#{_normalize_object_id order_id}"
    end

    def update_order order_id, order_attributes
      patch "orders/#{_normalize_object_id order_id}", order_attributes
    end

    def confirm_order order_id, order_attributes=nil
      update_order order_id, order_attributes if order_attributes
      post "orders/#{_normalize_object_id order_id}/confirm"
    end

    private

      def _normalize_object_id object_id
        (object_id.is_a?(Hash) ? object_id['id'] : object_id).to_i
      end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
ticketinghub-1.0.0 lib/ticketing_hub/client.rb
ticketinghub-0.0.4 lib/ticketing_hub/client.rb