Class: Oss::Service

Inherits:
Object
  • Object
show all
Includes:
Util
Defined in:
lib/oss/service.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Util

#camelize, #hash_filter, #oss_headers_to_s, #set_query_string

Constructor Details

#initialize(client) ⇒ Service

Returns a new instance of Service.



14
15
16
# File 'lib/oss/service.rb', line 14

def initialize(client)
  @client = client
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(method) ⇒ Object

prefix, marker, max_keys, is_truncated, next_marker



50
51
52
53
54
55
56
57
58
59
# File 'lib/oss/service.rb', line 50

def method_missing(method)
  if @xml_obj.nil?
    super
  else
    camel = Util.camelize(method)
    value = @xml_obj.xpath(camel)
    raise "missing xml attribute #{camel}" if value.length == 0
    value.inner_text
  end
end

Instance Attribute Details

#clientObject

Returns the value of attribute client.



12
13
14
# File 'lib/oss/service.rb', line 12

def client
  @client
end

#xml_objObject

Returns the value of attribute xml_obj.



12
13
14
# File 'lib/oss/service.rb', line 12

def xml_obj
  @xml_obj
end

Instance Method Details

#bucketsObject



36
37
38
39
40
41
42
43
44
45
46
47
# File 'lib/oss/service.rb', line 36

def buckets
  buckets = @xml_obj.xpath('Buckets/Bucket')
  results = Array.new
  buckets.each do |bucket|
    results << {
        :location      => bucket.xpath('Location').text,
        :name          => bucket.xpath('Name').text,
        :creation_date => bucket.xpath('CreationDate').text
    }
  end
  results
end

#get_service(options = {}) ⇒ Object

params:

  • options:

    • prefix

    • marker

    • max_keys



23
24
25
26
# File 'lib/oss/service.rb', line 23

def get_service(options = {})
  @xml_obj = client.get(host: SERVICE_HOST, path: '/', query_string: options).xpath('ListAllMyBucketsResult')
  self
end

#ownerObject



28
29
30
31
32
33
34
# File 'lib/oss/service.rb', line 28

def owner
  owner = @xml_obj.xpath('Owner')
  {
      :id           => owner.xpath('ID').text,
      :display_name => owner.xpath('DisplayName').text
  }
end