Class: Dreamstime

Inherits:
GenericSite show all
Defined in:
lib/multistockphoto/site_dreamstime.rb

Constant Summary collapse

FTP_HOST =
'upload.dreamstime.com'
SITENAME =
'dreamstime'
@@errors =
0

Constants inherited from GenericSite

GenericSite::MAX_ERRORS, GenericSite::SENDLIST

Instance Attribute Summary collapse

Attributes inherited from GenericSite

#name, #password, #user

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from GenericSite

#already_sent_site?, #heute_schon_gesendet, #photos_fuer_heute_uebrig?

Constructor Details

#initialize(name) ⇒ Dreamstime

Kennwort: das selbe wie Ihr Dreamstime Kontokennwort



18
19
20
21
22
23
24
25
26
# File 'lib/multistockphoto/site_dreamstime.rb', line 18

def initialize(name)
  super
  @config = load_config
  @user = @config[:dreamstime][:user]
  @password = @config[:dreamstime][:password]
  @ftp_user = @config[:dreamstime][:ftp_user]
  @ftp_password = @config[:dreamstime][:ftp_password]
  @total_per_day = @config[:dreamstime][:total_per_day]
end

Instance Attribute Details

#ftp_passwordObject

Returns the value of attribute ftp_password.



10
11
12
# File 'lib/multistockphoto/site_dreamstime.rb', line 10

def ftp_password
  @ftp_password
end

#ftp_userObject

Returns the value of attribute ftp_user.



10
11
12
# File 'lib/multistockphoto/site_dreamstime.rb', line 10

def ftp_user
  @ftp_user
end

#max_errorsObject

Returns the value of attribute max_errors.



10
11
12
# File 'lib/multistockphoto/site_dreamstime.rb', line 10

def max_errors
  @max_errors
end

#total_per_dayObject (readonly)

Returns the value of attribute total_per_day.



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

def total_per_day
  @total_per_day
end

Class Method Details

.can_handle_orientation?Boolean

can site handle orientation?

Returns:

  • (Boolean)


95
96
97
# File 'lib/multistockphoto/site_dreamstime.rb', line 95

def self.can_handle_orientation?
  false
end

Instance Method Details

#already_sent?(photo) ⇒ Boolean

wurde dieses Photo schon gesendet?

Returns:

  • (Boolean)


90
91
92
# File 'lib/multistockphoto/site_dreamstime.rb', line 90

def already_sent?(photo)
  already_sent_site?(photo,SITENAME) 
end

#sent_todayObject

Anzahl heute schon gesendeter Photos



84
85
86
87
# File 'lib/multistockphoto/site_dreamstime.rb', line 84

def sent_today
  site = SITENAME
  return sent_today_site(site)
end

#transfer(photo, dont_send = nil, dont_log = nil) ⇒ Object



28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
# File 'lib/multistockphoto/site_dreamstime.rb', line 28

def transfer(photo, dont_send=nil, dont_log=nil)
  # falls nicht in config Datei eingetragen dann nicht senden
  if @user == nil or @password == nil
    return
  end
  unless photo.class == Photo
    raise 'not a Photo object'
  end
  unless File.exist?(photo.filename)
    raise "file #{photo.filename} does not exist"
  end
  if @ftp_user == nil or @ftp_password == nil
    raise "ftp_user/ftp_password not set"
  end
  print "#{SITENAME}:#{photo.filename} ... "
  $stdout.flush
  g = grep(SENDLIST, /#{SITENAME}\t#{photo.filename}/)
  if g.size > 0
    puts "already sent"
    return :duplicate
  end
  if photo.portrait? and ! Dreamstime.can_handle_orientation?
    photo.drehen
  end
  if site_can_handle_keywords?
    photo.set_keywords
  end
  if ! dont_send
    begin
      ftp = Net::FTP.new(FTP_HOST)
      ftp.(@ftp_user,@ftp_password) 
      files=ftp.list('*')
      if photo.portrait?
        p photo.rotated_filename
        res = ftp.putbinaryfile(photo.rotated_filename)
      else
        res = ftp.putbinaryfile(photo.filename)
      end
      files =ftp.list('*')
      p files
      ftp.close
    rescue Errno::EPIPE
      raise UploadException
    end
  end
  @@errors = 0
  puts 'OK'
  if ! dont_log
    File.open(SENDLIST,'a') {|f|
      f.puts "#{SITENAME}\t#{photo.filename}\t#{Time.now}"
    }
  end
  true
end