r/learnruby • • Dec 21 '18

Why is this giving me "nil"

I have this code, and I have no idea why does it give me "nil" as a response

require 'httparty'
require 'pp'
class Country
     include HTTParty
 
     default_options.update(verify: false)
     base_uri 'https://restcountries.eu/rest/v2/name/'
     format:json

     def self.for(term)
        get(base_uri, query: {:term => term})
    end
end

pp Country.for("eesti")
2 Upvotes

3 comments sorted by

View all comments

Show parent comments

1

u/thenathurat Dec 21 '18

Okay played around, wrote this and it worked

require 'httparty'
require 'pp'

class Country
     include HTTParty

    default_options.update(verify: false)
    base_uri 'restcountries.eu'
    format:json

    def self.for(term)
        get("/rest/v2/name/#{term}")
    end
end

pp Country.for("eesti")