twingly / twingly-search-api-ruby

:gem: Twingly Blog Search API in Ruby
https://developer.twingly.com/
MIT License
4 stars 0 forks source link

Crash when pattern is empty string #17

Closed dentarg closed 9 years ago

dentarg commented 9 years ago
$ dotenv bundle exec ruby hello_world.rb
/Users/dentarg/twingly/ruby/twingly-analytics-api-ruby/lib/twingly-analytics/parser.rb:13:in `parse': undefined method `value' for nil:NilClass (NoMethodError)
    from /Users/dentarg/twingly/ruby/twingly-analytics-api-ruby/lib/twingly-analytics/query.rb:20:in `execute'
    from hello_world.rb:8:in `<main>'
$ cat hello_world.rb
Bundler.require

# Set environment variable TWINGLY_ANALYTICS_KEY
client = Twingly::Analytics::Client.new
query = client.query
query.pattern = ""
query.start_time = Time.now - (24 * 3600) # search last day
result = query.execute
dentarg commented 9 years ago

Oh, the body from the API is empty...

#<Faraday::Response:0x007fb82ce94300
 @env=
  #<struct Faraday::Env
   method=:get,
   body="",
   url=
    #<URI::HTTPS:0x007fb82cea4e30 URL:https://api.twingly.com/analytics/Analytics.ashx?documentlang=&key=KEY_REMOVED&searchpattern=&ts=2015-09-21+12%3A37%3A12&tsTo=&xmloutputversion=2>,
   request=
    #<struct Faraday::RequestOptions
     params_encoder=nil,
     proxy=nil,
     bind=nil,
     timeout=nil,
     open_timeout=nil,
     boundary=nil,
     oauth=nil>,
   request_headers={"User-Agent"=>"Twingly Analytics Ruby Client/2.0.0"},
   ssl=
    #<struct Faraday::SSLOptions
     verify=true,
     ca_file=nil,
     ca_path=nil,
     verify_mode=nil,
     cert_store=nil,
     client_cert=nil,
     client_key=nil,
     certificate=nil,
     private_key=nil,
     verify_depth=nil,
     version=nil>,
   parallel_manager=nil,
   params=nil,
   response=nil,
   response_headers=
    {"server"=>"nginx",
     "date"=>"Tue, 22 Sep 2015 10:37:14 GMT",
     "content-length"=>"0",
     "connection"=>"close",
     "cache-control"=>"private",
     "set-cookie"=>"SERVERID=web01; path=/"},
   status=200>,
 @on_complete_callbacks=[]>