Class: SmoothS3::Service

Inherits:
Object
  • Object
show all
Defined in:
lib/smooth_s3/service.rb

Constant Summary collapse

@@new_buckets =
{}

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(opts = {}) ⇒ Service

Returns a new instance of Service.



8
9
10
11
12
13
14
15
16
17
18
19
# File 'lib/smooth_s3/service.rb', line 8

def initialize(opts={})
  @aws_key = opts.delete(:aws_key)
  @aws_secret = opts.delete(:aws_secret)

  @ssl = opts.delete(:ssl) == true ? true : false
  @proxy_service = S3::Service.new(:access_key_id => @aws_key, :secret_access_key => @aws_secret, :use_ssl => @ssl)

  test_connection

  @buckets = gather_buckets
  @@new_buckets[@aws_key] = []
end

Instance Attribute Details

#aws_keyObject (readonly)

Returns the value of attribute aws_key.



3
4
5
# File 'lib/smooth_s3/service.rb', line 3

def aws_key
  @aws_key
end

#aws_secretObject (readonly)

Returns the value of attribute aws_secret.



3
4
5
# File 'lib/smooth_s3/service.rb', line 3

def aws_secret
  @aws_secret
end

#bucketsObject

Returns the value of attribute buckets.



4
5
6
# File 'lib/smooth_s3/service.rb', line 4

def buckets
  @buckets
end

#proxy_serviceObject (readonly)

Returns the value of attribute proxy_service.



3
4
5
# File 'lib/smooth_s3/service.rb', line 3

def proxy_service
  @proxy_service
end

#sslObject (readonly)

Returns the value of attribute ssl.



3
4
5
# File 'lib/smooth_s3/service.rb', line 3

def ssl
  @ssl
end

Class Method Details

.new_bucketsObject

Make @@new_buckets accessible outside of the class



75
76
77
# File 'lib/smooth_s3/service.rb', line 75

def self.new_buckets
  @@new_buckets
end

.new_buckets=(value) ⇒ Object



79
80
81
# File 'lib/smooth_s3/service.rb', line 79

def self.new_buckets=(value)
  @@new_buckets = value
end

Instance Method Details

#directory_sync(bucket, directory, options = {}) ⇒ Object Also known as: sync_directory



50
51
52
# File 'lib/smooth_s3/service.rb', line 50

def directory_sync(bucket, directory, options={})
  Uploader.directory_sync(self, bucket, directory, options)
end

#directory_sync!(bucket, directory, options = {}) ⇒ Object Also known as: sync_directory!



54
55
56
# File 'lib/smooth_s3/service.rb', line 54

def directory_sync!(bucket, directory, options={})
  Uploader.directory_sync!(self, bucket, directory, options)
end

#gather_bucketsObject



21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/smooth_s3/service.rb', line 21

def gather_buckets
  service_buckets = {}
  begin
    self.proxy_service.buckets.each { |b| service_buckets.merge!(b.name => b) }
  rescue
    puts "There was an error trying to fetch the service's buckets. Retrying..."
    sleep 1

    self.gather_buckets
  end

  service_buckets
end

#refreshObject



35
36
37
38
39
40
# File 'lib/smooth_s3/service.rb', line 35

def refresh
  new_buckets = @@new_buckets[self.aws_key]
  new_buckets.each {|nb| self.buckets[nb.name] = nb}
  
  return self
end

#timestamped_directory_sync(bucket, directory, options = {}) ⇒ Object



66
67
68
# File 'lib/smooth_s3/service.rb', line 66

def timestamped_directory_sync(bucket, directory, options={})
  Uploader.timestamped_directory_sync(self, bucket, directory, options)
end

#timestamped_directory_sync!(bucket, directory, options = {}) ⇒ Object



70
71
72
# File 'lib/smooth_s3/service.rb', line 70

def timestamped_directory_sync!(bucket, directory, options={})
  Uploader.timestamped_directory_sync!(self, bucket, directory, options)
end

#timestamped_upload(bucket, files, options = {}) ⇒ Object



58
59
60
# File 'lib/smooth_s3/service.rb', line 58

def timestamped_upload(bucket, files, options={})
  Uploader.timestamped_upload(self, bucket, files, options)
end

#timestamped_upload!(bucket, files, options = {}) ⇒ Object



62
63
64
# File 'lib/smooth_s3/service.rb', line 62

def timestamped_upload!(bucket, files, options={})
  Uploader.timestamped_upload!(self, bucket, files, options)
end

#upload(bucket, files, options = {}) ⇒ Object



42
43
44
# File 'lib/smooth_s3/service.rb', line 42

def upload(bucket, files, options={})
  Uploader.upload(self, bucket, files, options)
end

#upload!(bucket, files, options = {}) ⇒ Object



46
47
48
# File 'lib/smooth_s3/service.rb', line 46

def upload!(bucket, files, options={})
  Uploader.upload!(self, bucket, files, options)
end