将 curl 更改为 httparty Rails

Change curl to httparty Rails

你能帮我把下面的命令转换成httparty吗

curl -u username:token https://api.github.com/user

我尝试了以下操作,但出现“需要身份验证”错误。

class GitApi
      include HTTParty

      base_uri 'https://api.github.com'

      def initialize
        @auth = { :username => "username", :token => "token" }
      end

      def user
        self.class.get("/user", @auth)
      end

    end
class GitApi
  include HTTParty

  base_uri 'https://api.github.com'
  basic_auth 'username', 'token'

  def user
    self.class.get("/user")
  end

end