简体   繁体   中英

Change curl to httparty Rails

Can you please help me convert following command to 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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM