Class: FacebookDecoder

Inherits:
Object
  • Object
show all
Defined in:
lib/fbauth/decoder.rb

Class Method Summary collapse

Class Method Details

.balance(input) ⇒ Object



21
22
23
24
# File 'lib/fbauth/decoder.rb', line 21

def self.balance input
  input += '"' * (input.count('"') % 2)
  input += "}" * (input.count('{') - input.count('}'))
end

.decode(data) ⇒ Object



6
7
8
9
10
11
12
13
14
15
16
17
18
19
# File 'lib/fbauth/decoder.rb', line 6

def self.decode data
  unless data.nil?
    sig, b64udata = data.split('.')
    unless b64udata.nil?
      json = b64udata.tr('-_', '+/').unpack('m')[0]
      begin
        parms = JSON.parse(balance(json))
      rescue => e
        raise "Unable to parse json structure - '#{json}'"
      end
    end
  end
  parms
end