Module: Nimbu::Request::Validations::Token

Included in:
Nimbu::Request::Validations
Defined in:
lib/nimbu-api/request/validations/token.rb

Constant Summary collapse

TOKEN_REQUIRED =
[
  'get /sites',
  'get /channels'
]
TOKEN_REQUIRED_REGEXP =
[
  /channels\/.*\/.*\/entries/,
]

Instance Method Summary collapse

Instance Method Details

#validates_token_for(method, path) ⇒ Object

Ensures that required authentication token is present before request is sent.



20
21
22
23
24
25
26
27
28
29
30
# File 'lib/nimbu-api/request/validations/token.rb', line 20

def validates_token_for(method, path)
  return true unless TOKEN_REQUIRED.grep("#{method} #{path}").empty?

  token_required = false
  TOKEN_REQUIRED_REGEXP.each do |regex|
    if "#{method} #{path}" =~ regex
      token_required = true
    end
  end
  return token_required
end