-1

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
AMBasra
  • 969
  • 8
  • 24
  • Have you read the documentation? What have you tried already so the community can help you out? https://github.com/jnunemaker/httparty – Dan Rubio Nov 11 '16 at 21:03
  • @DanRubio Well i think it was a simple enough question. But still i have updated my question to help people like you. And yes i read the docs but couldnt find an answer. I didnt post the question for fun. – AMBasra Nov 11 '16 at 21:17
  • kudos to you for finding the solution to your own question. The reason it is important to post what you've tried is because it narrows down your problem into something specific that developers in the community can help you with. For example, in your updated question, you revealed that the specific problem you were having was an authentication error compared to before it was only an open ended question. Take it from someone who has done this before, open ended questions usually get downvoted. – Dan Rubio Nov 11 '16 at 22:29

1 Answers1

2
class GitApi
  include HTTParty

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

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

end
AMBasra
  • 969
  • 8
  • 24