examples/venue_search.rb in ncmb-ruby-client-0.1.7 vs examples/venue_search.rb in ncmb-ruby-client-0.2.0

- old
+ new

@@ -10,20 +10,25 @@ NCMB.initialize(application_key: yaml['application_key'], client_key: yaml['client_key'] ) json = JSON.parse(open(File.join(File.dirname(__FILE__), 'venues.json'), 'r').read) venues_class = NCMB::DataStore.new 'Venues' +venues_class.delete_all json['response']['venues'].each do |venue| + item = venues_class.new params = { name: venue['name'], location: { '__type' => 'GeoPoint', 'latitude' => venue['location']['lat'], 'longitude' => venue['location']['lng'] } } - puts venues_class.post(params).body + item.set('name', params[:name]) + item.set('location', params[:location]) + item.save + puts "#{item.objectId} saved." end params = {} params[:where] = { 'location' => { '$nearSphere' => { @@ -32,8 +37,13 @@ 'latitude' => 35.691152 }, '$maxDistanceInKilometers' => 10 } } -# -puts venues_class.get params -#puts venues_class.get queries +venues_class = venues_class.where("location", params[:where]['location']) +results = venues_class.get + +puts results.length + +results.each do |result| + puts result.objectId +end