class Milkman::Authorizer

Attributes

options[RW]
shared_secret[RW]

Public Class Methods

authorize(options) click to toggle source
# File lib/milkman/authorizer.rb, line 13
def self.authorize(options)
  new(options).authorize
end
new(attributes) click to toggle source
# File lib/milkman/authorizer.rb, line 8
def initialize(attributes)
  @shared_secret = attributes.delete(:shared_secret)
  @options       = attributes.merge! default_options
end

Public Instance Methods

authorize() click to toggle source
# File lib/milkman/authorizer.rb, line 17
def authorize
  puts I18n.t("milkman.authorization.frob_message", url: frob_message_url)
  puts I18n.t("milkman.authorization.auth_token_message", username: response["rsp"]["auth"]["user"]["username"], api_key: options[:api_key], shared_secret: shared_secret, auth_token: response["rsp"]["auth"]["token"])
end

Private Instance Methods

authorization_url(parameters) click to toggle source
# File lib/milkman/authorizer.rb, line 40
def authorization_url(parameters)
  [ AUTH_URL, encode(parameters) ].join "?"
end
frob() click to toggle source
# File lib/milkman/authorizer.rb, line 32
def frob
  STDIN.gets.strip
end
frob_message_url() click to toggle source
# File lib/milkman/authorizer.rb, line 36
def frob_message_url
  authorization_url sign(shared_secret, options.except(:format))
end
response() click to toggle source
# File lib/milkman/authorizer.rb, line 24
def response
  @response ||= Milkman::Request.call request_url(signed_options)
end
signed_options() click to toggle source
# File lib/milkman/authorizer.rb, line 28
def signed_options
  sign shared_secret, options.merge!(method: "rtm.auth.getToken", frob: frob)
end