0

Hi guys i'm new on RoR and have question, i'm getting this error on my Terminal when i'm trying to run > ruby api_controller.rb

undefined local variable or method `api' for main:Object (NameError)

Here my code:

 require 'rubygems'  
 require 'httparty'

 url = https://api.coinmarketcap.com/v2/listings/ 
 response = HTTParty.get(url) 
 response.parsed_response


 class Coinmarketcap
    include HTTParty
    base_uri 'api.coinmarketcap.com'

   def listings
     self.class.get('/v2/listings/')
   end 
 end


 coinmarketcap = Coinmarketcap.new 
 puts coinmarketcap.listings

 coinmarketcap.listings.each do |post|   
  #puts "Id: #{post['id']        
 end
Sergio Tulentsev
  • 226,338
  • 43
  • 373
  • 367

1 Answers1

1

Missing quote arround the url

Should be:

url = 'https://api.coinmarketcap.com/v2/listings'

I copy/paste your code and it's working with above modification

LolWalid
  • 515
  • 5
  • 15
  • i tried it and now i received the error "cannot load such file -- httparty" i researched about it and tried also with: gem install httparty, or manuely i add gem 'httparty', '0.16.2' and bundle install – Henrik Zakaryan Sep 28 '18 at 14:05
  • @HenrikZakaryan Ok you have a problem with your gems, `httparty` seems to not be installed, tape `gem install httparty`, then `gem list httparty` to check that it has been well installed – LolWalid Sep 28 '18 at 14:33
  • i just found the problem, i had to start the server new :). after start i got this problem: SSL_connect returned=1 errno=0 state=error: certificate verify failed.... for sure i researched about it and found this: https://stackoverflow.com/questions/34629333/restclientsslcertificatenotverified-ssl-connect-returned-1-errno-0-state-sslv i added it but receive another problem: uninitialized constant RestClient (NameError) __ Thank you for helping – Henrik Zakaryan Sep 28 '18 at 14:41