1

Trying to "require 'uri'" in a utility class and it doesn't seem to be loading. Keep getting the error:

NoMethodError at / undefined method `query' for "https://api.twitter.com/1.1/search/tweets.json?q=%40twitterapi":String

Whereas the .query method should become available via: http://www.ruby-doc.org/stdlib-2.0/libdoc/uri/rdoc/URI.html

Any ideas on what I'm doing wrong?

Kyle Chadha
  • 3,741
  • 2
  • 33
  • 42
  • 4
    As the error message says, you are trying to call it on a String instead of URI. Can you paste in the method where you are trying to call this? IF you want to call those URI methods, you need to wrap the string `URI(your_url).query` – jstim Apr 28 '14 at 23:55
  • Yes -- you are absolutely right, thank you. Used: 'parsed_url = URI.parse('https://api.twitter.com/1.1/search/tweets.json?q=%40twitterapi')', and then passed that and it works. – Kyle Chadha Apr 29 '14 at 00:05

1 Answers1

2

The method you are trying to call is only available on the URI object, but you are trying to call it on a string. (the string representation of the uri)

If you want to be able to use those methods, you need to create a URI object.

uri = URI("https://api.twitter.com/1.1/search/tweets.json?q=%40twitterapi")
uri.query # => "q=%40twitterapi"
jstim
  • 2,432
  • 1
  • 21
  • 28