class Micropub::Token

Public Class Methods

new(token) click to toggle source
# File lib/micropub/token.rb, line 8
def initialize(token)
  @token = token
end

Public Instance Methods

config() click to toggle source
# File lib/micropub/token.rb, line 51
def config
  Micropub.configuration
end
me() click to toggle source
# File lib/micropub/token.rb, line 33
def me
  begin
    URI.parse(response["me"])
  rescue URI::InvalidURIError
    raise ValidationError, "The token endpoint did not contain a valid 'me' URI"
  end
end
request() click to toggle source
# File lib/micropub/token.rb, line 47
def request
  HTTPClient.get(config.token_endpoint, {}, {'Authorization' => "Bearer #{@token}"})
end
response() click to toggle source
# File lib/micropub/token.rb, line 41
def response
  @response ||= begin
    URI::decode_www_form(request.body).to_h
  end
end
scope() click to toggle source
# File lib/micropub/token.rb, line 29
def scope
  response["scope"].split(",").map(&:to_sym)
end
valid?() click to toggle source
# File lib/micropub/token.rb, line 12
def valid?
  begin
    valid_host? &&
    valid_scope?
  rescue ValidationError
    false
  end
end
valid_host?() click to toggle source
# File lib/micropub/token.rb, line 25
def valid_host?
  me.host == config.me.host
end
valid_scope?() click to toggle source
# File lib/micropub/token.rb, line 21
def valid_scope?
  (config.allowed_scopes & scope).any?
end