[英]Change curl to httparty Rails
Can you please help me convert following command to httparty. 您能帮我将以下命令转换为httparty吗?
curl -u username:token https://api.github.com/user
I tried following but i am getting Requires authentication error. 我尝试了以下操作,但是我收到了需要验证错误的提示。
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
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.