GithubHelp home page GithubHelp logo

Question: about koala HOT 3 CLOSED

arsduo avatar arsduo commented on May 21, 2024
Question:

from koala.

Comments (3)

arsduo avatar arsduo commented on May 21, 2024

Hey Nerian,

I'm actually not that familiar with JSON.pretty_generate. get_object returns a hash, whereas get_connection returns an Array (actually a GraphCollection < Array), which has to be the source of the difference. If you're still having the problem (sorry about the delay in getting back to you!) can you send me the backtrace from the error, and I'll try to track it down? (I'm curious now.)

Thanks!

Alex

from koala.

Nerian avatar Nerian commented on May 21, 2024

Hi Alex,

No problem :) I used facebook_oauth where there was a conflict, but it would be much better to just use koala :)

In order to reproduce the issue you can just open a rails console:

ruby-1.9.2-p180 :010 > graph = Koala::Facebook::GraphAPI.new('2227470867|2.ZLyg_CgA867kqMpt2ElbTw__.3600.1305219600.0-100000024399383|3AHpb63iBhifIcb6v2SDpREW6t4')
=> #<Koala::Facebook::GraphAPI:0x00000101d58c50 @access_token="2227470867|2.ZLyg_CgA867kqMpt2ElbTw__.3600.1305219600.0-100000024399383|3AHpb63iBhifIcb6v2SDpREW6t4">

ruby-1.9.2-p180 :016 > puts JSON.pretty_generate(graph.get_connections('me', 'friends'))
 NoMethodError: undefined method `merge' for #<JSON::Ext::Generator::State:0x00000101c9cbe0>
from /Users/Nerian/.rvm/gems/ruby-1.9.2-p180@goofb/gems/activesupport-3.0.7/lib/active_support/json/encoding.rb:61:in `options_for'
from /Users/Nerian/.rvm/gems/ruby-1.9.2-p180@goofb/gems/activesupport-3.0.7/lib/active_support/json/encoding.rb:46:in `block in encode'
from /Users/Nerian/.rvm/gems/ruby-1.9.2-p180@goofb/gems/activesupport-3.0.7/lib/active_support/json/encoding.rb:77:in `check_for_circular_references'
from /Users/Nerian/.rvm/gems/ruby-1.9.2-p180@goofb/gems/activesupport-3.0.7/lib/active_support/json/encoding.rb:45:in `encode'
from /Users/Nerian/.rvm/gems/ruby-1.9.2-p180@goofb/gems/activesupport-3.0.7/lib/active_support/json/encoding.rb:30:in `encode'
from /Users/Nerian/.rvm/gems/ruby-1.9.2-p180@goofb/gems/activesupport-3.0.7/lib/active_support/core_ext/object/to_json.rb:20:in `to_json'
from /Users/Nerian/.rvm/gems/ruby-1.9.2-p180@goofb/gems/json-1.5.1/lib/json/common.rb:266:in `generate'
from /Users/Nerian/.rvm/gems/ruby-1.9.2-p180@goofb/gems/json-1.5.1/lib/json/common.rb:266:in `pretty_generate'
from (irb):16
from /Users/Nerian/.rvm/gems/ruby-1.9.2-p180@goofb/gems/railties-3.0.7/lib/rails/commands/console.rb:44:in `start'
from /Users/Nerian/.rvm/gems/ruby-1.9.2-p180@goofb/gems/railties-3.0.7/lib/rails/commands/console.rb:8:in `start'
from /Users/Nerian/.rvm/gems/ruby-1.9.2-p180@goofb/gems/railties-3.0.7/lib/rails/commands.rb:23:in `<top (required)>'
from script/rails:6:in `require'
from script/rails:6:in `<main>'

JSON.pretty_generate expects a hash like object. I think the solution is to define the method to_hash in Koala::Facebook::GraphCollection. Basically instead of returning an array of hashes, return a hash with an array of hashes.

The generate method api:
http://ruby-doc.org/ruby-1.9/classes/JSON.html#M006170

from koala.

arsduo avatar arsduo commented on May 21, 2024

Hey Norian,

Thanks for the update. It's strange that pretty_generate doesn't support arrays, since arrays are valid JSON just as much as hashes. While we can't change what the gem returns (that would break all the apps that use Koala, plus returning an array makes more sense for most cases), you should be easily able to wrap the array in a hash before calling pretty_generate.

Let me know if that works, and if we can help with anything else!

Best,

Alex

from koala.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.