class OAuth::RequestToken
  getter token : String
  getter secret : String

  def initialize(@token : String, @secret : String)
  end

  def self.from_response(response : String) : self
    token = nil
    secret = nil

    URI::Params.parse(response) do |key, value|
      case key
      when "oauth_token"        then token = value
      when "oauth_token_secret" then secret = value
      else
        # Not a key we are interested in
      end
    end

    unless token && secret
      values = [] of String
      values << "token" if token.nil?
      values << "secret" if secret.nil?
      raise Error.new("Missing #{values.join(" and ")}")
    end

    new token, secret
  end

  def_equals_and_hash @token, @secret
end
