This repository has been archived on 2024-03-16. You can view files and clone it, but cannot push or open issues or pull requests.
orbit-4-1/app/controllers/facebook_controller.rb

31 lines
874 B
Ruby
Raw Normal View History

require "net/http"
require "uri"
require 'json'
class FacebookController< ApplicationController
def register_fb
user = User.find(params[:user])
if !user.facebook
user.build_facebook(fb_identifier: params[:identifier],connected: true)
user.save!
end
render :json=>{"success"=>true,"user"=>user.facebook.fb_identifier}.to_json
end
def get_friends
@url = "http://fb.tp.rulingcom.com/get_friends?identifier=" + current_user.facebook.fb_identifier
uri = URI.parse(@url)
http = Net::HTTP.new(uri.host, uri.port)
request = Net::HTTP::Get.new(uri.request_uri)
response = http.request(request)
friends = response.body
friends = JSON.parse(friends)
output = Array.new
friends.each do |friend|
output << friend['name']
end
render :json=>{"count"=>friends.count,"friends"=>output}.to_json
end
end