firebaserubymotion

RubyMotion Firebase (motion-firebase) How to retrieve data?


Using the motion-firebase library for RubyMotion Firebase (https://github.com/colinta/motion-firebase) I can set data easy enough either by doing:

firebase.set({ full_name: ['first_name' => 'Fred', 'last_name' => 'Flintstone'] })

or

firebase['first_name'] = 'Fred'

But I'm having trouble figuring out how to retrieve data.

I've tried the different firebase.query methods listed in the reponse readme but I'm definitely missing something.

I'd hoped it would be as simple as:

firebase.query['first_name']
=> 'Fred'

Could someone please explain how I might go about querying Firebase with a key and returning the value.


Solution

  • colinta here! You'll need to attach an observer (https://github.com/colinta/motion-firebase#attaching-observers-to-read-data).

    firebase_ref.once(:value) { |snapshot| snapshot.value }

    See https://www.firebase.com/docs/ios-api/Classes/FDataSnapshot.html for info on the FDataSnapshot type.