Class Facebooker::MockService
In: lib/facebooker/mock/service.rb
Parent: Service

A mock service that reads the Facebook response from fixtures Adapted from gist.github.com/44344

  Facebooker::MockService.fixture_path = 'path/to/dir'
  Facebooker::Session.current = Facebooker::MockSession.create

Methods

post   read_fixture  

Attributes

fixture_path  [RW] 

Public Instance methods

[Source]

# File lib/facebooker/mock/service.rb, line 31
    def post(params)
      method = params.delete(:method)
      params.delete_if {|k,_| [:v, :api_key, :call_id, :sig].include?(k) }
      Parser.parse(method, read_fixture(method, fixture_name(params)))
    end

[Source]

# File lib/facebooker/mock/service.rb, line 16
    def read_fixture(method, filename, original = nil)
      path = fixture_path(method, filename)
      File.read path
    rescue Errno::ENAMETOOLONG
      read_fixture(method, hash_fixture_name(filename), filename)
    rescue Errno::ENOENT => e
      if File.exists?(fixture_path(method, 'default'))
        File.read fixture_path(method, 'default')
      else
        e.message << "\n(Non-hashed path is #{original})" if original
        e.message << "\nFacebook API Reference: http://wiki.developers.facebook.com/index.php/#{method.sub(/^facebook\./, '')}#Example_Return_XML"
        raise e
      end
    end

[Validate]