Class: Facebooker::MockService

Inherits:
Service
  • Object
show all
Defined in:
lib/facebooker/mock/service.rb

Overview

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

Class Attribute Summary (collapse)

Instance Method Summary (collapse)

Methods inherited from Service

#active_service, active_service, active_service=, #initialize, #post_file, #post_form, #post_multipart_form, process_async, with_async, with_service

Constructor Details

This class inherits a constructor from Facebooker::Service

Class Attribute Details

+ (Object) fixture_path

Returns the value of attribute fixture_path



13
14
15
# File 'lib/facebooker/mock/service.rb', line 13

def fixture_path
  @fixture_path
end

Instance Method Details

- (Object) post(params)



31
32
33
34
35
# 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

- (Object) read_fixture(method, filename, original = nil)



16
17
18
19
20
21
22
23
24
25
26
27
28
29
# 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