Sha256: 255b7edf4f3557e84e4b5988a2d47de1852c3e464dc860262dfa48ccce50cf11

Contents?: true

Size: 734 Bytes

Versions: 9

Compression:

Stored size: 734 Bytes

Contents

module Rambo
  module RamlModels
    class SecurityScheme
      attr_accessor :schema, :title
      private :schema

      def initialize(raml, options={})
        @options        = options
        @schema, @title = raml.last.fetch("describedBy", {}), raml.first
        use_token!
      end

      def use_token!
        if schema.fetch("headers", nil)
          schema.fetch("headers")[api_token_header] = @options[:token]
        end
      end

      def api_token_header
        return unless h = schema.fetch("headers", nil)

        h.find {|key, value| key.match(/(token|key)/i) }.first
      end

      def headers
        @headers ||= Rambo::RamlModels::Headers.new(schema.fetch("headers") || {})
      end
    end
  end
end

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
rambo_ruby-0.7.1 lib/rambo/raml_models/security_scheme.rb
rambo_ruby-0.7.0 lib/rambo/raml_models/security_scheme.rb
rambo_ruby-0.6.0 lib/rambo/raml_models/security_scheme.rb
rambo_ruby-0.5.0 lib/rambo/raml_models/security_scheme.rb
rambo_ruby-0.4.0 lib/rambo/raml_models/security_scheme.rb
rambo_ruby-0.3.3 lib/rambo/raml_models/security_scheme.rb
rambo_ruby-0.3.2 lib/rambo/raml_models/security_scheme.rb
rambo_ruby-0.3.1 lib/rambo/raml_models/security_scheme.rb
rambo_ruby-0.3.0 lib/rambo/raml_models/security_scheme.rb