Module: Facebooker

Defined in:
lib/facebooker/version.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, RevokeExtendedPermission, SendRequest, ServerCache, Service, Session, SetAppProperties, SetCookie, SetPreference, SetRefHandle, SetRestrictionInfo, SetStatus, SmsCanSend, SmsSend, StreamAddComment, StreamAddLike, StreamPost, StreamPublish, Tag, UnregisterUsers, UploadNativeStrings, 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



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

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

.path_prefixObject (readonly)

Returns the value of attribute path_prefix.



191
192
193
# File 'lib/facebooker.rb', line 191

def path_prefix
  @path_prefix
end

.set_asset_host_to_callback_urlObject

Returns the value of attribute set_asset_host_to_callback_url.



174
175
176
# File 'lib/facebooker.rb', line 174

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.



175
176
177
# File 'lib/facebooker.rb', line 175

def use_curl
  @use_curl
end

Class Method Details

.all_api_keysObject



117
118
119
120
121
122
123
124
125
# File 'lib/facebooker.rb', line 117

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.



70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
# File 'lib/facebooker.rb', line 70

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



166
167
168
# File 'lib/facebooker.rb', line 166

def facebook_path_prefix
  current_adapter.facebook_path_prefix
end

.facebook_path_prefix=(path) ⇒ Object



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

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

.facebooker_configObject



88
89
90
# File 'lib/facebooker.rb', line 88

def facebooker_config
  @facebooker_configuration
end

.fetch_config_for(api_key) ⇒ Object



135
136
137
138
139
140
141
142
143
144
# File 'lib/facebooker.rb', line 135

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)


170
171
172
# File 'lib/facebooker.rb', line 170

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

.load_adapter(params) ⇒ Object



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

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

.load_configuration(facebooker_yaml_file) ⇒ Object



57
58
59
60
61
62
63
64
65
# File 'lib/facebooker.rb', line 57

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



210
211
212
213
214
215
216
217
218
# File 'lib/facebooker.rb', line 210

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



182
183
184
# File 'lib/facebooker.rb', line 182

def timeout
  @timeout
end

.timeout=(val) ⇒ Object



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

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

.with_all_applications(&block) ⇒ Object



127
128
129
130
131
132
133
# File 'lib/facebooker.rb', line 127

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



92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
# File 'lib/facebooker.rb', line 92

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



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

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