Module: Tpaga::Swagger

Defined in:
lib/tpaga/swagger.rb,
lib/tpaga/swagger/request.rb,
lib/tpaga/swagger/version.rb,
lib/tpaga/swagger/response.rb,
lib/tpaga/swagger/configuration.rb

Defined Under Namespace

Classes: Configuration, Request, Response

Constant Summary collapse

VERSION =
"0.7.2"

Class Attribute Summary collapse

Class Method Summary collapse

Class Attribute Details

.configurationObject

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



11
12
13
# File 'lib/tpaga/swagger.rb', line 11

def configuration
  @configuration
end

.loggerObject

Returns the value of attribute logger.



7
8
9
# File 'lib/tpaga/swagger.rb', line 7

def logger
  @logger
end

.resourcesObject

Returns the value of attribute resources.



13
14
15
# File 'lib/tpaga/swagger.rb', line 13

def resources
  @resources
end

Class Method Details

.authenticateObject



49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
# 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?Boolean

Returns:

  • (Boolean)


41
42
43
# File 'lib/tpaga/swagger.rb', line 41

def authenticated?
  Swagger.configuration.auth_token.present?
end

.configure {|configuration| ... } ⇒ Object

Call this method to modify defaults in your initializers.

Examples:

Swagger.configure do |config|
  config.api_key = '1234567890abcdef'     # api key authentication
  config.format = 'json'                  # optional, defaults to 'json'
end

Yields:



23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# 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_authenticateObject



45
46
47
# File 'lib/tpaga/swagger.rb', line 45

def de_authenticate
  Swagger.configuration.auth_token = nil
end