0
votes

I am trying to connect to a website by using a token-based authentication. I was using Net::HTTP to connect, but on the API page I could not find a way to authenticate myself with a token. I only saw something for user/password.

How do I do this?

EDIT:

Code Sample:

`require 'rubygems'
 require 'rest_client'
 require 'base64'

  require 'rubygems'
 require 'rest_client'
 require 'base64'

require 'net/http'
require 'net/https'
require 'logger'

url ="https://redcap.org/redcap/api/"
my_token= 'token value'
RestClient.post url, :token=>my_token`

This where I get an error.

The error I receive is: c:/Ruby193/lib/ruby/gems/1.9.1/gems/rest-client-1.6.7/lib/restclient/request.rb: 111:in parse_url': undefined methodmatch' for # (NoMeth odError)

1
We need to see a code sample, along with the URL you are trying to authenticate to.the Tin Man

1 Answers

0
votes

You can use Net::HTTP, but there exist several gems that make interfacing with an API easy. These include HTTParty and rest-client.

See more here: https://www.ruby-toolbox.com/categories/http_clients

As for the token, different APIs deal with tokens in different ways. If you provide details (and preferably a code sample where you demonstrate what you've tried) you'll get more specific help.