Class: Fboauth2::Newfbclient
- Inherits:
-
Object
- Object
- Fboauth2::Newfbclient
- Defined in:
- lib/Fboauth2.rb
Class Method Summary collapse
- .auth_callback(code, url) ⇒ Object
- .crate_new_m(info, params, user) ⇒ Object
- .get_auth(host, params) ⇒ Object
- .get_client ⇒ Object
- .get_conf_data ⇒ Object
- .get_path(type, params) ⇒ Object
- .get_url(host) ⇒ Object
- .send_fb_msg(cname, user) ⇒ Object
Class Method Details
.auth_callback(code, url) ⇒ Object
30 31 32 33 34 |
# File 'lib/Fboauth2.rb', line 30 def self.auth_callback(code, url) client = @facebook_client client..process_callback(code, :redirect_uri => url) client end |
.crate_new_m(info, params, user) ⇒ Object
54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 |
# File 'lib/Fboauth2.rb', line 54 def self.crate_new_m(info, params, user) cname = params[:config] model_type = info[cname]["model"]["name"] m_data = info[cname]["model"]["params"] puts "-"*50 puts "Creating #{model_type}..." m_data.each do |field, value| aux = value.to_s.split("_") if aux[0] == "fb" value = user["#{aux[1]}"] m_data[field] = value end end if info[cname]["hsubmodel"] == "t" #si tiene algun tipo de subcategoria? sm_data = info[cname]["submodel"]["params"] sm_name = info[cname]["submodel"]["name"] sm_data["#{sm_name}"][0].each do |field, value| aux = value.to_s.split("_") if aux[0] == "fb" sm_data["#{sm_name}"][0][field] = user["#{aux[1]}"] end if aux[0] == "pm" sm_data["#{sm_name}"][0][field] = params[aux[1].to_sym] end end m_data = m_data.merge(sm_data) end m_aux = model_type.constantize.create(m_data) puts "-> ID: " + m_aux.id.to_s puts "-> Ready!" puts "-"*50 end |
.get_auth(host, params) ⇒ Object
17 18 19 20 21 22 23 |
# File 'lib/Fboauth2.rb', line 17 def self.get_auth(host, params) @params = params @fb_data = Newfbclient.get_conf_data url = Newfbclient.get_url(host) @facebook_client = Newfbclient.get_client #creo un nuevo cliente @facebook_client..(:redirect_uri => url , :scope => @fb_data["credentials"][Rails.env]["permission"]) #pido autorizacion q me regresa una url a facebook end |
.get_client ⇒ Object
25 26 27 28 |
# File 'lib/Fboauth2.rb', line 25 def self.get_client @fb_data = Newfbclient.get_conf_data FBGraph::Client.new(:client_id => @fb_data["credentials"][Rails.env]["api_key"], :secret_id => @fb_data["credentials"][Rails.env]["api_secret"]) end |
.get_conf_data ⇒ Object
46 47 48 49 50 51 52 |
# File 'lib/Fboauth2.rb', line 46 def self.get_conf_data if Rails.env == 'test' YAML.load_file("#{File.dirname(__FILE__)}/../config/fbconfig_test.yml") else YAML.load_file("#{Rails.root}/config/fbconfig.yml") end end |
.get_path(type, params) ⇒ Object
101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 |
# File 'lib/Fboauth2.rb', line 101 def self.get_path(type, params) @fb_data = Newfbclient.get_conf_data url = @fb_data[params[:config]][type].split(" ") url_f = "" url.each do |value| aux = value.split("_") if aux[0] == "pm" url_f += params[aux[1].to_sym] else url_f += value end end puts url_f return url_f end |
.get_url(host) ⇒ Object
36 37 38 39 40 41 42 43 44 |
# File 'lib/Fboauth2.rb', line 36 def self.get_url(host) @aux_params = "" @params.delete("controller") @params.delete("action") @params.each do |key, value| @aux_params = @aux_params + key + "=" + value + "&" end "http://"+ host + "/oauth2_facebook/fb_callback?" + @aux_params #get url para el callback end |
.send_fb_msg(cname, user) ⇒ Object
95 96 97 98 99 |
# File 'lib/Fboauth2.rb', line 95 def self.send_fb_msg(cname, user) @fb_data = Newfbclient.get_conf_data @facebook_client.selection.user(user[:id]).feed.publish!(:message => @fb_data[cname]["facebook"]["message"], :name => @fb_data[cname]["facebook"]["title"], :link => @fb_data[cname]["facebook"]["link"], :picture => @fb_data[cname]["facebook"]["picture"], :description => @fb_data[cname]["facebook"]["description"]) puts "-> Facebook Message, successfully published..." end |