Sha256: 5e2520b9f899113d0fbdea0956ff24d5cc07fdcb6e08db80bcab043a1179437b

Contents?: true

Size: 960 Bytes

Versions: 26

Compression:

Stored size: 960 Bytes

Contents

class LogicalModel
  module ApiKey
    def self.included(base)
      base.send(:extend, ClassMethods)
    end

    module ClassMethods
      attr_accessor :api_key, :api_key_name, :use_api_key

      # Set api_key
      # @param name [Symbol] name for api_key. Eg: app_key, token, etc.
      # @param value [String] value of key. Eg: 1o2u3hqkfd, secret, etc.
      #
      # @example
      #   class Client < LogicalModel
      #     set_api_key(:token, 'asdfasdf')
      #     ...
      #   end
      def set_api_key(name,value)
        @use_api_key = true
        @api_key_name = name
        @api_key = value
      end

      def use_api_key
        @use_api_key ||= false
      end

      # if needed will merge api_key into given hash
      # returns merged hash
      def merge_key(params = {})
        if self.use_api_key
          params.merge({self.api_key_name => self.api_key})
        else
          params
        end
      end

    end
  end
end

Version data entries

26 entries across 26 versions & 1 rubygems

Version Path
logical_model-0.7.6 lib/logical_model/api_key.rb
logical_model-0.7.5 lib/logical_model/api_key.rb
logical_model-0.7.4 lib/logical_model/api_key.rb
logical_model-0.7.3 lib/logical_model/api_key.rb
logical_model-0.7.2 lib/logical_model/api_key.rb
logical_model-0.7.1 lib/logical_model/api_key.rb
logical_model-0.7.0 lib/logical_model/api_key.rb
logical_model-0.6.6 lib/logical_model/api_key.rb
logical_model-0.6.5 lib/logical_model/api_key.rb
logical_model-0.6.4 lib/logical_model/api_key.rb
logical_model-0.6.3 lib/logical_model/api_key.rb
logical_model-0.6.2 lib/logical_model/api_key.rb
logical_model-0.6.1 lib/logical_model/api_key.rb
logical_model-0.6.0 lib/logical_model/api_key.rb
logical_model-0.5.13 lib/logical_model/api_key.rb
logical_model-0.5.12 lib/logical_model/api_key.rb
logical_model-0.5.11 lib/logical_model/api_key.rb
logical_model-0.5.10 lib/logical_model/api_key.rb
logical_model-0.5.8 lib/logical_model/api_key.rb
logical_model-0.5.7 lib/logical_model/api_key.rb