Module: Facebooker

Defined in:
lib/facebooker/version.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/railtie.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, Railtie, 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



120
121
122
# File 'lib/facebooker.rb', line 120

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

.path_prefixObject (readonly)

Returns the value of attribute path_prefix.



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

def path_prefix
  @path_prefix
end

.set_asset_host_to_callback_urlObject

Returns the value of attribute set_asset_host_to_callback_url.



141
142
143
# File 'lib/facebooker.rb', line 141

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.



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

def use_curl
  @use_curl
end

Class Method Details

.all_api_keysObject



84
85
86
87
88
89
90
91
92
# File 'lib/facebooker.rb', line 84

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.



36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
# File 'lib/facebooker.rb', line 36

def apply_configuration(config)
  ENV['FACEBOOK_APP_ID']              = config['app_id'].to_s
  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



133
134
135
# File 'lib/facebooker.rb', line 133

def facebook_path_prefix
  current_adapter.facebook_path_prefix
end

.facebook_path_prefix=(path) ⇒ Object



128
129
130
# File 'lib/facebooker.rb', line 128

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

.facebooker_configObject



55
56
57
# File 'lib/facebooker.rb', line 55

def facebooker_config
  @facebooker_configuration
end

.fetch_config_for(api_key) ⇒ Object



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

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)


137
138
139
# File 'lib/facebooker.rb', line 137

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

.json_decode(str) ⇒ Object



2
3
4
# File 'lib/facebooker.rb', line 2

def self.json_decode(str)
  ActiveSupport::JSON.decode(str)
end

.json_encode(o) ⇒ Object



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

def self.json_encode(o)
  ActiveSupport::JSON.encode(o)
end

.load_adapter(params) ⇒ Object



124
125
126
# File 'lib/facebooker.rb', line 124

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

.load_configuration(facebooker_yaml_file) ⇒ Object



25
26
27
28
29
30
# File 'lib/facebooker.rb', line 25

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)[::Rails.env]
  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



175
176
177
178
179
180
181
182
183
# File 'lib/facebooker.rb', line 175

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



149
150
151
# File 'lib/facebooker.rb', line 149

def timeout
  @timeout
end

.timeout=(val) ⇒ Object



145
146
147
# File 'lib/facebooker.rb', line 145

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

.with_all_applications(&block) ⇒ Object



94
95
96
97
98
99
100
# File 'lib/facebooker.rb', line 94

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



59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
# File 'lib/facebooker.rb', line 59

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



161
162
163
164
165
166
167
168
169
170
171
# File 'lib/facebooker.rb', line 161

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