Class: Fotolia

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

Constant Summary collapse

FTP_HOST =
'submit.fotolia.com'

Instance Attribute Summary collapse

Attributes inherited from GenericSite

#name, #password, #user

Instance Method Summary collapse

Constructor Details

#initialize(name) ⇒ Fotolia

Returns a new instance of Fotolia.



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/multistockphoto/site_fotolia.rb', line 9

def initialize(name)
  #p "creating a Fotolia object"
  super
  if ENV['MSP_CONFIG']
    @config = YAML.load_file(ENV['MSP_CONFIG'])
    #p "meine config: #{ENV['MSP_CONFIG']}"
  else
    #p "standard config"
    @config = YAML.load_file("config.yaml")
  end
  @user = @config[:fotolia][:user]
  @password = @config[:fotolia][:password]
  @ftp_user = @config[:fotolia][:ftp_user]
  @ftp_password = @config[:fotolia][:ftp_password]
  # kann vom Client ueberschrieben werden
end

Instance Attribute Details

#ftp_passwordObject

Returns the value of attribute ftp_password.



5
6
7
# File 'lib/multistockphoto/site_fotolia.rb', line 5

def ftp_password
  @ftp_password
end

#ftp_userObject

Returns the value of attribute ftp_user.



5
6
7
# File 'lib/multistockphoto/site_fotolia.rb', line 5

def ftp_user
  @ftp_user
end

Instance Method Details

#transfer(photo) ⇒ Object



26
27
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
# File 'lib/multistockphoto/site_fotolia.rb', line 26

def transfer(photo)
  # 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 "fotolia:#{photo.filename} ... "
  $stdout.flush
  g = `grep "fotolia\t#{photo.filename}" sendeliste.dat`
  if g.size > 0
    puts "already sent"
    return :duplicate
  end
  ftp = Net::FTP.new(FTP_HOST)
  ftp.(@ftp_user,@ftp_password) 
  files=ftp.list('*')
  res = ftp.putbinaryfile(photo.filename)
  files=ftp.list('*')
  #p files
  ftp.close
  puts 'OK'
  `echo "fotolia\t#{photo.filename}\t#{Time.now}" >>sendeliste.dat` #TODO:
  true
end