Sha256: a1f41384e3c3f19119f24bd2ba8469e4cc28b4879156c1828de0a7052fd62dd6

Contents?: true

Size: 1.52 KB

Versions: 5

Compression:

Stored size: 1.52 KB

Contents

# encoding: utf-8

module Github
  module Validation

    VALID_API_KEYS = [
      'page',
      'per_page',
      'jsonp_callback'
    ]

    # Ensures that esential input parameters are present before request is made
    #
    def _validate_inputs(required, provided)
      result = required.all? do |key|
        provided.has_deep_key? key
      end
      if !result
        raise Github::Error::RequiredParams.new(provided, required)
      end
      result
    end

    # Ensures that esential arguments are present before request is made
    #
    def _validate_presence_of(*params)
      params.each do |param|
        raise ArgumentError, "parameter cannot be nil" if param.nil?
      end
    end

    # Check if user or repository parameters are passed
    #
    def _validate_user_repo_params(user_name, repo_name)
      raise ArgumentError, "[user] parameter cannot be nil" if user_name.nil?
      raise ArgumentError, "[repo] parameter cannot be nil" if repo_name.nil?
    end

    # Ensures that hash values contain predefined values
    #
    def _validate_params_values(permitted, params)
      params.each do |k, v|
        next unless permitted.keys.include?(k)
        if permitted[k].is_a?(Array) && !permitted[k].include?(params[k])
          raise ArgumentError, "Wrong value for #{k}, allowed: #{permitted[k].join(', ')}"
        elsif permitted[k].is_a?(Regexp) && !(permitted[k] =~ params[k])
          raise ArgumentError, "String does not match the parameter value."
        end
      end
    end

  end # Validation
end # Github

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
github_api-0.4.11 lib/github_api/validation.rb
github_api-0.4.10 lib/github_api/validation.rb
github_api-0.4.9 lib/github_api/validation.rb
github_api-0.4.8 lib/github_api/validation.rb
github_api-0.4.7 lib/github_api/validation.rb