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.5.2"
Class Attribute Summary collapse
-
.configuration ⇒ Object
A Swagger configuration object.
-
.logger ⇒ Object
Returns the value of attribute logger.
-
.resources ⇒ Object
Returns the value of attribute resources.
Class Method Summary collapse
- .authenticate ⇒ Object
- .authenticated? ⇒ Boolean
-
.configure {|configuration| ... } ⇒ Object
Call this method to modify defaults in your initializers.
- .de_authenticate ⇒ Object
Class Attribute Details
.configuration ⇒ Object
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 |
.logger ⇒ Object
Returns the value of attribute logger.
7 8 9 |
# File 'lib/tpaga/swagger.rb', line 7 def logger @logger end |
.resources ⇒ Object
Returns the value of attribute resources.
13 14 15 |
# File 'lib/tpaga/swagger.rb', line 13 def resources @resources end |
Class Method Details
.authenticate ⇒ Object
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
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.
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_authenticate ⇒ Object
45 46 47 |
# File 'lib/tpaga/swagger.rb', line 45 def de_authenticate Swagger.configuration.auth_token = nil end |