class GogoKit::Client

Client for the viagogo API

@see developer.viagogo.net

Public Class Methods

new(options = {}) { |self| ... } click to toggle source

Initializes a new {GogoKit::Client}

@param options [Hash] @option options [String] :client_id Client Id of your application @option options [String] :client_secret Client Secret of your application @option options [String] :api_root_endpoint Endpoint where the API root is located @option options [String] :oauth_token_endpoint Endpoint for obtaining OAuth access tokens @raise [GogoKit::Error::ConfigurationError] Error is raised when supplied client credentials are not a String or Symbol. @return [GogoKit::Client]

# File lib/gogokit/client.rb, line 58
def initialize(options = {})
  reset!

  options.each do |key, value|
    send(:"#{key}=", value)
  end
  yield self if block_given?

  validate_configuration_credentials!
  validate_configuration_api_environment!
  validate_configuration_endpoints!
end

Public Instance Methods

delete(url, options = {}) click to toggle source

Perform an HTTP DELETE request

@return [Hash] object containing response information

# File lib/gogokit/client.rb, line 81
def delete(url, options = {})
  request(:delete, url, options)
end
get(url, options = {}) click to toggle source

Perform an HTTP GET request

@return [Hash] object containing response information

# File lib/gogokit/client.rb, line 88
def get(url, options = {})
  request(:get, url, options)
end
head(url, options = {}) click to toggle source

Perform an HTTP HEAD request

@return [Hash] object containing response information

# File lib/gogokit/client.rb, line 95
def head(url, options = {})
  request(:head, url, options)
end
patch(url, options = {}) click to toggle source

Perform an HTTP PATCH request

@return [Hash] object containing response information

# File lib/gogokit/client.rb, line 102
def patch(url, options = {})
  request(:patch, url, options)
end
post(url, options = {}) click to toggle source

Perform an HTTP POST request

@return [Hash] object containing response information

# File lib/gogokit/client.rb, line 109
def post(url, options = {})
  request(:post, url, options)
end
put(url, options = {}) click to toggle source

Perform an HTTP PUT request

@return [Hash] object containing response information

# File lib/gogokit/client.rb, line 116
def put(url, options = {})
  request(:put, url, options)
end
user_agent() click to toggle source

The User-Agent header used when making HTTP requests

@return [String]

# File lib/gogokit/client.rb, line 74
def user_agent
  @user_agent ||= "GogoKit Ruby Gem #{GogoKit::VERSION}"
end

Private Instance Methods

expand_url(url, params) click to toggle source

Expands a URI template with the given parameters

# File lib/gogokit/client.rb, line 134
def expand_url(url, params)
  params ||= {}
  template = url.respond_to?(:expand) ? url : Addressable::Template.new(url)
  if template.variables.empty? && !params.empty?
    # the URI isn't templated so just append the query parameters
    non_templated_url = Addressable::URI.parse(url)
    existing_query_values = non_templated_url.query_values(Hash) || {}
    non_templated_url.query_values = existing_query_values.merge(params)
    return non_templated_url.to_s
  end

  template.expand(params || {}).to_s
end
request(method, url, options = {}) click to toggle source

Perform an HTTP request

@return [Hash] object containing response information

# File lib/gogokit/client.rb, line 125
def request(method, url, options = {})
  options ||= {}
  url = expand_url(url, options[:params])
  try_add_authorization_header(options)

  connection.send(method.to_sym, url, options[:body], options[:headers]).env
end
try_add_authorization_header(options) click to toggle source
# File lib/gogokit/client.rb, line 148
def try_add_authorization_header(options)
  options[:headers] ||= {}
  return unless options[:headers]['Authorization'].nil? &&
                options[:headers][:authorization].nil?

  # Add an Authorization header since we don't have one yet
  options[:headers]['Authorization'] = "Bearer #{access_token}"
end