Class: Socialcast::CommandLine::ProvisionPhoto
- Inherits:
-
Object
- Object
- Socialcast::CommandLine::ProvisionPhoto
- Includes:
- Provisioner
- Defined in:
- lib/socialcast/command_line/provision_photo.rb
Defined Under Namespace
Classes: ApiSyncStrategy
Constant Summary
Constants included from Provisioner
Socialcast::CommandLine::Provisioner::DEFAULT_OUTPUT_FILE
Instance Attribute Summary collapse
-
#sync_strategy ⇒ Object
Returns the value of attribute sync_strategy.
Instance Method Summary collapse
- #default_profile_photo_id ⇒ Object
- #photo_data_to_file(profile_photo_data) ⇒ Object
- #sync(strategy_klass = ApiSyncStrategy) ⇒ Object
Methods included from Provisioner
Instance Attribute Details
#sync_strategy ⇒ Object
Returns the value of attribute sync_strategy.
6 7 8 |
# File 'lib/socialcast/command_line/provision_photo.rb', line 6 def sync_strategy @sync_strategy end |
Instance Method Details
#default_profile_photo_id ⇒ Object
53 54 55 |
# File 'lib/socialcast/command_line/provision_photo.rb', line 53 def default_profile_photo_id @default_profile_photo_id ||= Socialcast::CommandLine::Authenticate.current_user['community']['default_profile_photo_id'] end |
#photo_data_to_file(profile_photo_data) ⇒ Object
30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 |
# File 'lib/socialcast/command_line/provision_photo.rb', line 30 def photo_data_to_file(profile_photo_data) if profile_photo_data.start_with?('http') profile_photo_data = download_photo_data(profile_photo_data) return unless profile_photo_data end ## FORCE ENCODING profile_photo_data = profile_photo_data.force_encoding('binary') ## CONTENT TYPE unless content_type = binary_to_content_type(profile_photo_data) log "Skipping photo: unknown image format (supports .gif, .png, .jpg)" return end ## WRITE TEMP FILE Tempfile.new(["photo_upload", ".#{content_type}"]).tap do |tempfile| tempfile.binmode tempfile.write(profile_photo_data) tempfile.rewind end end |
#sync(strategy_klass = ApiSyncStrategy) ⇒ Object
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/socialcast/command_line/provision_photo.rb', line 8 def sync(strategy_klass = ApiSyncStrategy) assert_ldap_connections_support_photo! sync_strategy = strategy_klass.new(self) = { :http_config => http_config, :force_sync => [:force_sync] } user_photos = {} each_photo_hash do |photo_hash| email = photo_hash[LDAPConnector::EMAIL_ATTRIBUTE] user_photos[email] = photo_hash[LDAPConnector::PROFILE_PHOTO_ATTRIBUTE] if user_photos.size >= sync_strategy.batch_size sync_strategy.process(user_photos, ) user_photos = {} end end sync_strategy.process(user_photos, ) if user_photos.any? end |