Module: RFb

Extended by:
Configurable
Includes:
Exceptions, Methods
Defined in:
lib/r_fb.rb,
lib/r_fb/fql.rb,
lib/r_fb/user.rb,
lib/r_fb/parser.rb,
lib/r_fb/methods.rb,
lib/r_fb/session.rb,
lib/r_fb/exceptions.rb,
lib/r_fb/notification.rb

Defined Under Namespace

Modules: Exceptions, Methods Classes: Fql, Notification, Parser, Session, User

Constant Summary collapse

PATH =
"r_fb"
SERVER =
"www.facebook.com"
API_PATH =
"#{SERVER}/restserver.php"
LOGIN_PATH =
"http://#{SERVER}/login.php"

Constants included from Methods

Methods::AUTH_GET_SESSION, Methods::FRIENDS_ARE_FRIENDS, Methods::FRIENDS_GET, Methods::FRIENDS_GET_TYPED, Methods::MESSAGES_GET_COUNT, Methods::PHOTOS_GET_ALBUMS, Methods::PHOTOS_GET_COMMENT_COUNT, Methods::PHOTOS_GET_FROM_ALBUM, Methods::PHOTOS_GET_OF_USER, Methods::POKES_GET_COUNT, Methods::SESSION_PING, Methods::USERS_GET_INFO, Methods::WALL_GET_COUNT

Class Method Summary collapse

Methods included from Configurable

api_key, api_key=, app_name, app_name=, app_url, debug, debug=, environment, environment=, secret_key, secret_key=

Class Method Details

.get_session(auth_token) ⇒ Object



39
40
41
# File 'lib/r_fb.rb', line 39

def self.get_session(auth_token)
  response = request(method: Methods::AUTH_GET_SESSION, auth_token: auth_token)
end

.login_url(next_param = "") ⇒ Object



34
35
36
37
# File 'lib/r_fb.rb', line 34

def self.(next_param = "")
    next_param = "&next=#{next_param}" unless next_param.empty?
    "#{LOGIN_PATH}?api_key=#{api_key}&v=1.0#{next_param}"
end

.make_request(params) ⇒ Object



52
53
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
# File 'lib/r_fb.rb', line 52

def self.make_request(params)
  params.stringify_keys!
  params['api_key'] = api_key
  params['call_id'] = Time.new.to_f.to_s
  params['v'] = "1.0"
  params['format'] = "json"
  
  secure = false
  api_url = URI.parse("#{(secure ? 'https' : 'http')}://#{API_PATH}")

  # Generate signature and add it to the list of params
  params_str = params.sort.map! { |p| "#{p[0]}=#{p[1]}" }.join
  params['sig'] = Digest::MD5.hexdigest(params_str + ENV["rfb_secret"])

  # Prepare POST request with params
  req = Net::HTTP::Post.new(api_url.path)
  req.set_form_data(params)
  
  # Setup connection and make request. Use SSL if necessary.
  connection = Net::HTTP.new(api_url.host, api_url.port)
  connection.read_timeout = @http_read_timeout
  connection.open_timeout = @http_open_timeout
  if api_url.scheme == 'https'
      connection.use_ssl = true
      connection.verify_mode = OpenSSL::SSL::VERIFY_NONE
  end
  puts "calling #{params["method"]}" if debug
  puts "request params: #{params.inspect}" if debug
  request = connection.request(req)
end

.request(params) ⇒ Object



43
44
45
46
47
48
49
50
# File 'lib/r_fb.rb', line 43

def self.request(params)
  response = make_request(params)
  if debug
    puts "RESPONSE"
    puts response.body.inspect
  end
  parsed = Parser.parse(response)
end