Created
April 6, 2015 01:44
-
-
Save breim/13ec2820657590c6cd56 to your computer and use it in GitHub Desktop.
Mechanize testing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
task :news_user => :environment do | |
require 'mechanize' | |
json = Mechanize.new.get('https://graph.facebook.com/500142683407521/members?access_token=331190933592525|jPIKJ-nDyiYq_MqF9hWKqapF6KE').body | |
#json = Mechanize.new.get('https://graph.facebook.com/100001426926632/friends?access_token=331190933592525|jPIKJ-nDyiYq_MqF9hWKqapF6KE').body | |
result = JSON.parse json | |
agent = Mechanize.new | |
repeat = result['data'].count | |
repeat.times do |i| | |
abrir = Mechanize.new.get('https://graph.facebook.com/'+ result['data'][i]['id'] +'/').body | |
quebrar = JSON.parse abrir | |
uid = quebrar['id'] | |
first_name = quebrar['first_name'] | |
last_name = quebrar['last_name'] | |
gender = quebrar['gender'] | |
name = quebrar['name'] | |
username = quebrar['username'] | |
puts uid | |
puts name | |
puts gender | |
puts "------------------<" | |
#raagent.get('https://graph.facebook.com/'+ uid +'/picture?type=large').save_as "usuarios/#{uid}" | |
verificar = User.find_by(:uid => uid) | |
#if username.present? | |
# if username.scan(".") != nil && username.scan(".") != [] | |
# username["."] = "_" | |
# end | |
#end | |
if verificar == nil | |
cadastrar = User.create!(:provider => 'facebook',:uid => uid,:name => name,:first_name => first_name, :last_name => last_name,:gender => gender) | |
end | |
User.find_each(&:save) | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment