class TicketSharing::Client
Public Class Methods
new(base_url, credentials=nil)
click to toggle source
# File lib/ticket_sharing/client.rb, line 7 def initialize(base_url, credentials=nil) @base_url = base_url @credentials = credentials @requester = TicketSharing::Request.new(TicketSharing.connection) end
Public Instance Methods
delete(path, options={})
click to toggle source
# File lib/ticket_sharing/client.rb, line 22 def delete(path, options={}) send_request(:delete, path, '', options) end
post(path, body, options={})
click to toggle source
# File lib/ticket_sharing/client.rb, line 14 def post(path, body, options={}) send_request(:post, path, body, options) end
put(path, body, options={})
click to toggle source
# File lib/ticket_sharing/client.rb, line 18 def put(path, body, options={}) send_request(:put, path, body, options) end
success?()
click to toggle source
# File lib/ticket_sharing/client.rb, line 26 def success? @success end
Private Instance Methods
handle_response(response)
click to toggle source
# File lib/ticket_sharing/client.rb, line 40 def handle_response(response) @success = case response.status when (200..299) true when 401, 403, 404, 405, 408, 410, 422, 500..599 false else raise TicketSharing::Error.new(%Q{#{response.status}\n\n#{response.body}}) end response end
send_request(method, path, body, options)
click to toggle source
# File lib/ticket_sharing/client.rb, line 32 def send_request(method, path, body, options) headers = {'X-Ticket-Sharing-Token' => @credentials} if @credentials options = options.merge(:body => body, :headers => headers) response = @requester.request(method, @base_url + path, options) handle_response(response) end