Class: PhotoService

Inherits:
Object
  • Object
show all
Defined in:
app/services/photo_service.rb

Instance Method Summary collapse

Constructor Details

#initialize(user = nil, deny_raw_files = true) ⇒ PhotoService

Returns a new instance of PhotoService.


4
5
6
7
# File 'app/services/photo_service.rb', line 4

def initialize(user=nil, deny_raw_files=true)
  @user = user
  @deny_raw_files = deny_raw_files
end

Instance Method Details

#create_from_params_and_file(base_params, uploaded_file) ⇒ Object

Raises:

  • (RuntimeError)

13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'app/services/photo_service.rb', line 13

def create_from_params_and_file(base_params, uploaded_file)
  photo_params = build_params(base_params)
  raise RuntimeError if @deny_raw_files && !confirm_uploaded_file_settings(uploaded_file)

  photo_params[:user_file] = uploaded_file
  photo = @user.build_post(:photo, photo_params)
  raise RuntimeError unless photo.save

  send_messages(photo, photo_params)
  update_profile_photo(photo) if photo_params[:set_profile_photo]

  photo
end

#visible_photo(photo_guid) ⇒ Object


9
10
11
# File 'app/services/photo_service.rb', line 9

def visible_photo(photo_guid)
  Photo.owned_or_visible_by_user(@user).where(guid: photo_guid).first
end