authentication - Authorization and fetching data from api in ruby -


i trying hit api fetch values, api prompts me authentication shoud provide username , password. if try other apis, able data. wondering how authentication. pretty new ruby , how doing:

require 'open-uri' require 'json'  result = json.parse(open("http://api.geonames.org/searchjson?q=london&maxrows=10&username=demo").read) puts "#{result}" 

i'm not familiar service, can try basic authentication

result = json.parse(open("http://username:password@api.geonames.org/searchjson?q=london&maxrows=10&username=demo").read) 

as @slicedpan suggested, can use opens options arguments:

result = json.parse(open("http://api.geonames.org/searchjson?q=london&maxrows=10&username=demo", :http_basic_authentication=>['user', 'password']).read) 

if ssl errors, @ blog post:

errors --- have seen 1 of these error messages?

openssl::ssl::sslerror: ssl_connect returned=1 errno=0 state=sslv3 read server certificate b: certificate verify failed  not load openssl. must recompile ruby openssl support or change sources in gemfile 'https' 'http'. 

instructions compiling openssl using rvm available @ rvm.io/packages/openssl.

use rvm fix ssl certificates --- recent versions of rvm, ruby version manager, include utility diagnose , resolve errors caused outdated certificate files. see article installing rails instructions , advice. rvm website explains how install rvm.

if you’ve installed rvm, try this:

$ rvm -v # rvm 1.19.1 (stable) $ rvm osx-ssl-certs status # certificates for... $ rvm osx-ssl-certs update # updating certificates... 

Comments

Popular posts from this blog

c# - How to get the current UAC mode -

postgresql - Lazarus + Postgres: incomplete startup packet -

javascript - Ajax jqXHR.status==0 fix error -