module Tpaga::Swagger

Constants

VERSION

Attributes

configuration[RW]

A Swagger configuration object. Must act like a hash and return sensible values for all Swagger configuration options. See Swagger::Configuration.

logger[RW]
resources[RW]

Public Class Methods

authenticate() click to toggle source
# File lib/tpaga/swagger.rb, line 49
def authenticate
  return if Swagger.authenticated?

  if Swagger.configuration.username.blank? || Swagger.configuration.password.blank?
    raise ClientError, "Username and password are required to authenticate."
  end

  request = Swagger::Request.new(
    :get,
    "account/authenticate/{username}",
    :params => {
      :username => Swagger.configuration.username,
      :password => Swagger.configuration.password
    }
  )

  response_body = request.response.body
  Swagger.configuration.auth_token = response_body['token']
end
authenticated?() click to toggle source
# File lib/tpaga/swagger.rb, line 41
def authenticated?
  Swagger.configuration.auth_token.present?
end
configure() { |configuration| ... } click to toggle source

Call this method to modify defaults in your initializers.

@example

Swagger.configure do |config|
  config.api_key = '1234567890abcdef'     # api key authentication
  config.format = 'json'                  # optional, defaults to 'json'
end
# File lib/tpaga/swagger.rb, line 23
def configure
  yield(configuration) if block_given?

  # Configure logger.  Default to use Rails
  self.logger ||= configuration.logger || (defined?(Rails) ? Rails.logger : Logger.new(STDOUT))

  # remove :// from scheme
  configuration.scheme.sub!(/:\/\//, '')

  # remove http(s):// and anything after a slash
  configuration.host.sub!(/https?:\/\//, '')
  configuration.host = configuration.host.split('/').first

  # Add leading and trailing slashes to base_path
  configuration.base_path = "/#{configuration.base_path}".gsub(/\/+/, '/')
  configuration.base_path = "" if configuration.base_path == "/"
end
de_authenticate() click to toggle source
# File lib/tpaga/swagger.rb, line 45
def de_authenticate
  Swagger.configuration.auth_token = nil
end