-
Notifications
You must be signed in to change notification settings - Fork 468
/
koala.rb
executable file
·69 lines (58 loc) · 2.06 KB
/
koala.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
# useful tools
require 'digest/md5'
require 'multi_json'
# include koala modules
require 'koala/errors'
require 'koala/api'
require 'koala/oauth'
require 'koala/realtime_updates'
require 'koala/test_users'
# HTTP module so we can communicate with Facebook
require 'koala/http_service'
# miscellaneous
require 'koala/utils'
require 'koala/version'
require 'ostruct'
module Koala
# A Ruby client library for the Facebook Platform.
# See http://github.com/arsduo/koala/wiki for a general introduction to Koala
# and the Graph API.
# Making HTTP requests
class << self
# Control which HTTP service framework Koala uses.
# Primarily used to switch between the mock-request framework used in testing
# and the live framework used in real life (and live testing).
# In theory, you could write your own HTTPService module if you need different functionality,
# but since the switch to {https://github.com/arsduo/koala/wiki/HTTP-Services Faraday} almost all such goals can be accomplished with middleware.
attr_accessor :http_service
def configure
yield config
end
# Allows you to control various Koala configuration options.
# Notable options:
# * server endpoints: you can override any or all the server endpoints
# (see HTTPService::DEFAULT_SERVERS) if you want to run requests through
# other servers.
# * api_version: controls which Facebook API version to use (v1.0, v2.0,
# etc)
def config
@config ||= OpenStruct.new(HTTPService::DEFAULT_SERVERS)
end
# Used for testing.
def reset_config
@config = nil
end
end
# @private
# Switch the HTTP service -- mostly used for testing.
def self.http_service=(service)
# if it's a real http_service, use it
@http_service = service
end
# An convenenient alias to Koala.http_service.make_request.
def self.make_request(path, args, verb, options = {})
http_service.make_request(path, args, verb, options)
end
# we use Faraday as our main service, with mock as the other main one
self.http_service = HTTPService
end