Posts tagged ruby
Posts tagged ruby
16 notes &
This gem provide the easy way to send and check a single sms with startmobile.com.ua service.
gem 'startmobile_sms'
StartmobileSms.setup do |config| config.login = 'login' config.password = 'password' config.out_number = 'out_number' end
# Send single sms (out_number is optional) sms_id = StartmobileSms.send(:phone => '30971234567', :text => 'Hello!', :out_number => 'service_name') # Check sms delivery status StartmobileSms.check(sms_id) # Or use instance object sms = StartmobileSms::Message.new(:phone => '30971234567', :text => 'Hello!') sms.phone # 30971234567 sms.text # Hello! sms.send # send sms to server sms.id # response id sms.status # check sms status (Accepted, Enroute, Delivered, Expired, Deleted, Undeliverable, Rejected
3 notes &
I have Facebook contest album with many photos. And I need to display rating of this photos by user likes.
This FQL query get a list of all likes (user_ids) by all photos:
SELECT user_id, object_id FROM like WHERE object_id IN (SELECT object_id FROM photo WHERE aid=’139307129471375_51887’ limit 5000) limit 100000
Then you can order results by object_id and sort by object_id count.
NOTE! Album ID (‘139307129471375_51887’) - is not facebook graph object id. 139307129471375 - is page id, 51887 - element id for this page.
For my example I use Ruby and fb_graph gem:
query = FbGraph::Query.new(“SELECT user_id, object_id FROM like WHERE object_id IN (SELECT object_id FROM photo WHERE aid=’139307129471375_51887’ limit 5000) limit 100000 “).fetch(SiteConfig.fb_token)
SiteConfig.fb_token - is my facebook app access_token with permissions user_photos (get it easy by using Graph API Explorer)
Then I order and sort my array:
photos = query.inject(Hash.new(0)){ |h, e| h[e[“object_id”]] += 1 ; h }.sort{|a,b| b[1]<=>a[1]}
photos.each {|p| puts “Object id - #{p[0]}, likes count - #{p[1]}”}
38 notes &
Редирект странички средствами Rails: