Module: Facebooker

Defined in:
lib/facebooker/version.rb,
lib/facebooker.rb,
lib/facebooker.rb,
lib/facebooker.rb,
lib/facebooker/data.rb,
lib/facebooker/feed.rb,
lib/facebooker/admin.rb,
lib/facebooker/model.rb,
lib/facebooker/mobile.rb,
lib/facebooker/parser.rb,
lib/facebooker/logging.rb,
lib/facebooker/service.rb,
lib/facebooker/session.rb,
lib/facebooker/models/tag.rb,
lib/facebooker/application.rb,
lib/facebooker/models/page.rb,
lib/facebooker/models/user.rb,
lib/facebooker/mock/service.rb,
lib/facebooker/mock/session.rb,
lib/facebooker/models/album.rb,
lib/facebooker/models/event.rb,
lib/facebooker/models/group.rb,
lib/facebooker/models/photo.rb,
lib/facebooker/models/video.rb,
lib/facebooker/server_cache.rb,
lib/facebooker/batch_request.rb,
lib/facebooker/models/cookie.rb,
lib/facebooker/rails/helpers.rb,
lib/facebooker/rails/routing.rb,
lib/facebooker/models/comment.rb,
lib/facebooker/rails/cucumber.rb,
lib/facebooker/models/location.rb,
lib/facebooker/rails/publisher.rb,
lib/facebooker/rails/utilities.rb,
lib/facebooker/models/info_item.rb,
lib/facebooker/models/work_info.rb,
lib/facebooker/rails/controller.rb,
lib/facebooker/models/affiliation.rb,
lib/facebooker/models/friend_list.rb,
lib/facebooker/rails/test_helpers.rb,
lib/facebooker/models/info_section.rb,
lib/facebooker/models/notifications.rb,
lib/facebooker/rails/cucumber/world.rb,
lib/facebooker/adapters/adapter_base.rb,
lib/facebooker/adapters/bebo_adapter.rb,
lib/facebooker/adapters/bebo_adapter.rb,
lib/facebooker/models/education_info.rb,
lib/facebooker/models/message_thread.rb,
lib/facebooker/rails/helpers/fb_connect.rb,
lib/facebooker/adapters/facebook_adapter.rb,
lib/facebooker/models/family_relative_info.rb,
lib/facebooker/rails/facebook_form_builder.rb,
lib/facebooker/models/applicationproperties.rb,
lib/facebooker/rails/helpers/stream_publish.rb,
lib/facebooker/models/applicationrestrictions.rb,
lib/facebooker/rails/profile_publisher_extensions.rb

Overview

Things that don’t actually work as expected in BEBO

Defined Under Namespace

Modules: Feed, Logging, Model, Rails, VERSION Classes: AdapterBase, AddTags, Admin, Affiliation, Album, Application, ApplicationProperties, ApplicationRestrictions, AreFriends, Attachment, BatchRequest, BatchRun, BeboAdapter, CanvasSession, Comment, CommentsAdd, CommentsGet, CommentsRemove, Cookie, CreateAlbum, CreateToken, DashboardAddGlobalNews, DashboardAddNews, DashboardClearGlobalNews, DashboardClearNews, DashboardDecrementCount, DashboardGetActivity, DashboardGetCount, DashboardGetGlobalNews, DashboardGetNews, DashboardIncrementCount, DashboardMultiAddNews, DashboardMultiClearNews, DashboardMultiDecrementCount, DashboardMultiGetCount, DashboardMultiGetNews, DashboardMultiIncrementCount, DashboardMultiSetCount, DashboardPublishActivity, DashboardRemoveActivity, DashboardSetCount, Data, DeactivateTemplateBundleByID, EducationInfo, Errors, Event, EventMembersGet, EventsCancel, EventsCreate, EventsGet, EventsRsvp, FacebookAdapter, FamilyRelativeInfo, FqlMultiquery, FqlQuery, FriendList, FriendListsGet, GetAlbums, GetAllocation, GetAppProperties, GetAppUsers, GetCookies, GetFriends, GetLoggedInUser, GetPhotos, GetPreference, GetPublicInfo, GetRegisteredTemplateBundles, GetRestrictionInfo, GetSession, GetStatus, GetStream, GetTags, GetUnconnectedFriendsCount, Group, GroupGetMembers, GroupsGet, InfoItem, InfoSection, IsAppUser, Location, MessageGetThreadsInFolder, MessageThread, Mobile, MockService, MockSession, NonSessionUser, Notifications, NotificationsGet, NotificationsSend, NotificationsSendEmail, Page, PagesGetInfo, PagesIsAdmin, PagesIsFan, Parser, Photo, ProfileFBML, ProfileFBMLSet, ProfileInfo, ProfileInfoSet, PublishActionOfUser, PublishStoryToUser, PublishTemplatizedAction, PublishUserAction, RefreshImgSrc, RefreshRefURL, RegisterTemplateBundle, RegisterUsers, RevokeAuthorization, SendRequest, ServerCache, Service, Session, SetAppProperties, SetCookie, SetPreference, SetRefHandle, SetRestrictionInfo, SetStatus, SmsCanSend, SmsSend, StreamAddComment, StreamAddLike, StreamPost, StreamPublish, Tag, UnregisterUsers, UploadPhoto, UploadVideo, User, UserHasPermission, UserInfo, UserStandardInfo, Video, WorkInfo

Constant Summary collapse

@@logger =
nil

Class Attribute Summary collapse

Class Method Summary collapse

Class Attribute Details

.current_adapterObject

Get the current adapter



139
140
141
# File 'lib/facebooker.rb', line 139

def current_adapter
  @current_adapter || Facebooker::AdapterBase.default_adapter
end

.path_prefixObject (readonly)

Returns the value of attribute path_prefix.



177
178
179
# File 'lib/facebooker.rb', line 177

def path_prefix
  @path_prefix
end

.set_asset_host_to_callback_urlObject

Returns the value of attribute set_asset_host_to_callback_url.



160
161
162
# File 'lib/facebooker.rb', line 160

def set_asset_host_to_callback_url
  @set_asset_host_to_callback_url
end

.use_curlObject Also known as: use_curl?

Returns the value of attribute use_curl.



161
162
163
# File 'lib/facebooker.rb', line 161

def use_curl
  @use_curl
end

Class Method Details

.all_api_keysObject



103
104
105
106
107
108
109
110
111
# File 'lib/facebooker.rb', line 103

def all_api_keys
  [
    @raw_facebooker_configuration['api_key']
  ] + (
    @raw_facebooker_configuration['alternative_keys'] ?
    @raw_facebooker_configuration['alternative_keys'].keys :
    []
  )
end

.apply_configuration(config) ⇒ Object

Sets the Facebook environment based on a hash of options. By default the hash passed in is loaded from facebooker.yml, but it can also be passed in manually every request to run multiple Facebook apps off one Rails app.



56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
# File 'lib/facebooker.rb', line 56

def apply_configuration(config)
  ENV['FACEBOOK_API_KEY']             = config['api_key']
  ENV['FACEBOOK_SECRET_KEY']          = config['secret_key']
  ENV['FACEBOOKER_RELATIVE_URL_ROOT'] = config['canvas_page_name']
  ENV['FACEBOOKER_API']               = config['api']
  if config.has_key?('set_asset_host_to_callback_url')
    Facebooker.set_asset_host_to_callback_url = config['set_asset_host_to_callback_url'] 
  end
  if Object.const_defined?("ActionController") and Facebooker.set_asset_host_to_callback_url
    ActionController::Base.asset_host = config['callback_url'] 
  end
  Facebooker.timeout = config['timeout']

  @facebooker_configuration = config  # must be set before adapter loaded
  load_adapter(:fb_sig_api_key => config['api_key'])
  facebooker_config
end

.facebook_path_prefixObject

Default is canvas_page_name in yml file



152
153
154
# File 'lib/facebooker.rb', line 152

def facebook_path_prefix
  current_adapter.facebook_path_prefix
end

.facebook_path_prefix=(path) ⇒ Object



147
148
149
# File 'lib/facebooker.rb', line 147

def facebook_path_prefix=(path)
  current_adapter.facebook_path_prefix = path
end

.facebooker_configObject



74
75
76
# File 'lib/facebooker.rb', line 74

def facebooker_config
  @facebooker_configuration
end

.fetch_config_for(api_key) ⇒ Object



121
122
123
124
125
126
127
128
129
130
# File 'lib/facebooker.rb', line 121

def fetch_config_for(api_key)
  if @raw_facebooker_configuration['api_key'] == api_key
    return @raw_facebooker_configuration
  elsif @raw_facebooker_configuration['alternative_keys'] and
        @raw_facebooker_configuration['alternative_keys'].keys.include?(api_key)
    return @raw_facebooker_configuration['alternative_keys'][api_key].merge(
            'api_key' => api_key )
  end
  return false
end

.is_for?(application_container) ⇒ Boolean

Returns:

  • (Boolean)


156
157
158
# File 'lib/facebooker.rb', line 156

def is_for?(application_container)
  current_adapter.is_for?(application_container)
end

.json_decode(str) ⇒ Object



9
10
11
# File 'lib/facebooker.rb', line 9

def self.json_decode(str)
  JSON.parse(str)
end

.json_encode(o) ⇒ Object



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

def self.json_encode(o)
  JSON.dump(o)
end

.load_adapter(params) ⇒ Object



143
144
145
# File 'lib/facebooker.rb', line 143

def load_adapter(params)
  self.current_adapter = Facebooker::AdapterBase.load_adapter(params)
end

.load_configuration(facebooker_yaml_file) ⇒ Object



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

def load_configuration(facebooker_yaml_file)
  return false unless File.exist?(facebooker_yaml_file)
  @raw_facebooker_configuration = YAML.load(ERB.new(File.read(facebooker_yaml_file)).result)
  if defined? RAILS_ENV
    @raw_facebooker_configuration = @raw_facebooker_configuration[RAILS_ENV]
  end
  Thread.current[:fb_api_config] = @raw_facebooker_configuration unless Thread.current[:fb_api_config]
  apply_configuration(@raw_facebooker_configuration)
end

.loggerObject



7
8
9
# File 'lib/facebooker/logging.rb', line 7

def self.logger
  @@logger
end

.logger=(logger) ⇒ Object



4
5
6
# File 'lib/facebooker/logging.rb', line 4

def self.logger=(logger)
  @@logger = logger
end

.request_for_canvas(arg) ⇒ Object

prevent Facebooker from adding canvas name as prefix to URLs



196
197
198
199
200
201
202
203
204
# File 'lib/facebooker.rb', line 196

def request_for_canvas(is_canvas_request)
  original_path_prefix = @path_prefix 
  begin
    @path_prefix = facebook_path_prefix if is_canvas_request
    yield
  ensure
    @path_prefix = original_path_prefix
  end
end

.timeoutObject



168
169
170
# File 'lib/facebooker.rb', line 168

def timeout
  @timeout
end

.timeout=(val) ⇒ Object



164
165
166
# File 'lib/facebooker.rb', line 164

def timeout=(val)
  @timeout = val.to_i
end

.with_all_applications(&block) ⇒ Object



113
114
115
116
117
118
119
# File 'lib/facebooker.rb', line 113

def with_all_applications(&block)
  all_api_keys.each do |current_api_key|
    with_application(current_api_key) do
      block.call
    end
  end
end

.with_application(api_key, &block) ⇒ Object



78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
# File 'lib/facebooker.rb', line 78

def with_application(api_key, &block)
  config = fetch_config_for( api_key )

  unless config
    self.logger.info "Can't find facebooker config: '#{api_key}'" if self.logger
    yield if block_given?
    return
  end

  # Save the old config to handle nested activation. If no app context is
  # set yet, use default app's configuration.
  old = Thread.current[:fb_api_config] ? Thread.current[:fb_api_config].dup : @raw_facebooker_configuration

  if block_given?
    begin
      self.logger.info "Swapping facebooker config: '#{api_key}'" if self.logger
      Thread.current[:fb_api_config] = apply_configuration(config)
      yield
    ensure
      Thread.current[:fb_api_config] = old if old && !old.empty?
      apply_configuration(Thread.current[:fb_api_config])
    end
  end
end

.with_asset_path_for_canvasObject

Set the asset path to the canvas path for just this one request by definition, we will make this a canvas request



182
183
184
185
186
187
188
189
190
191
192
# File 'lib/facebooker.rb', line 182

def with_asset_path_for_canvas
  original_asset_host = ActionController::Base.asset_host
  begin
    ActionController::Base.asset_host = Facebooker.api_server_base_url
    request_for_canvas(true) do
      yield
    end
  ensure
    ActionController::Base.asset_host = original_asset_host
  end
end