super_p && web

my little piece of "work memory"

Posts tagged ruby on rails

16 notes &

Ruby wrapper for startmobile sms service

This gem provide the easy way to send and check a single sms with startmobile.com.ua service.

Install

gem 'startmobile_sms'

Configure

StartmobileSms.setup do |config|
  config.login = 'login'
  config.password = 'password'
  config.out_number = 'out_number'
end

Usage

# 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

Filed under ruby on rails ruby sms startmobile git

3 notes &

Select album photos likes from Facebook by FQL query

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]}”}

Filed under facebook ruby ruby on rails fb_graph fql

3 notes &

Publish stream in Facebook & Twitter with OmniAuth

First of all, include OmniAuth to your rails app by this railscast or this.

Then add to Gemfile this gem:

gem ‘fb_graph’, ‘1.5.4’


After, you should turn on permission in your apps:

for Facebook:

for Twitter:

twitter read & write access

When your login from OmniAuth, social app ask your permission on update wall in Facebook and post tweet in Twitter.

Paste to you authentication model (my model named Person):

Publish message:

@person.publish(“Hello, my Facebook or Twitter friends!”)

Filed under rails omniauth twitter facebook fb_graph ruby on rails publish_stream