Class: Qinium::Object

Inherits:
Object
  • Object
show all
Includes:
Utils
Defined in:
lib/qinium/object.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Utils

#blank?, #encode_entry_uri, #logger, #to_query_string, #urlsafe_base64_decode, #urlsafe_base64_encode

Constructor Details

#initialize(client) ⇒ Object

Returns a new instance of Object.



7
8
9
# File 'lib/qinium/object.rb', line 7

def initialize(client)
  @client = client
end

Instance Attribute Details

#client ⇒ Object (readonly)

Returns the value of attribute client.



5
6
7
# File 'lib/qinium/object.rb', line 5

def client
  @client
end

Instance Method Details

#bucket ⇒ Object



13
# File 'lib/qinium/object.rb', line 13

def bucket; config.bucket end

#config ⇒ Object

rubocop: disable Style/SingleLineMethods



12
# File 'lib/qinium/object.rb', line 12

def config; client.config end

#copy(source_bucket, source_key, target_bucket, target_key) ⇒ Object



50
51
52
53
54
55
# File 'lib/qinium/object.rb', line 50

def copy(source_bucket, source_key, target_bucket, target_key)
  source_encoded_entry_uri = Utils.encode_entry_uri(source_bucket, source_key)
  target_encoded_entry_uri = Utils.encode_entry_uri(target_bucket, target_key)
  uri = %Q(/copy/#{source_encoded_entry_uri}/#{target_encoded_entry_uri})
  client.management_post(config.rs_host + uri)
end

#delete(key, bucket: self.bucket) ⇒ Object



38
39
40
41
42
# File 'lib/qinium/object.rb', line 38

def delete(key, bucket: self.bucket)
  client.management_post(config.rs_host + "/delete/" + Utils.encode_entry_uri(
    bucket, key
  ))
end

#fetch(target_url, key, bucket: self.bucket) ⇒ Object



44
45
46
47
48
# File 'lib/qinium/object.rb', line 44

def fetch(target_url, key, bucket: self.bucket)
  client.management_post(config.fetch_host(bucket) + '/fetch/' + urlsafe_base64_encode(target_url) + '/to/' + Utils.encode_entry_uri(
    bucket, key
  ))
end

#list(bucket: self.bucket, marker: "", limit: 1000, prefix: "", delimiter: "") ⇒ Object



57
58
59
60
61
# File 'lib/qinium/object.rb', line 57

def list(bucket: self.bucket, marker: "", limit: 1000, prefix: "", delimiter: "")
  query_string = to_query_string(bucket: bucket, marker: marker, limit: limit, prefix: prefix,
                                 delimiter: delimiter)
  client.management_get(config.rsf_host + "/list?" + query_string)
end

#mkblk(blk, token:, host: nil) ⇒ Object

rubocop: enable Style/SingleLineMethods



16
17
18
19
20
21
22
23
# File 'lib/qinium/object.rb', line 16

def mkblk(blk, token:, host: nil)
  host ||= config.up_host
  client.post("#{host}/mkblk/#{blk.size}", blk, headers: {
                "Content-Type" => "application/octet-stream",
                "Content-Length" => blk.size,
                "Authorization" => "UpToken #{token}"
              })
end

#mkfile(token:, file_size:, blocks:, key: nil, fname: nil, mime_type: nil, user_vars: nil) ⇒ Object



25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/qinium/object.rb', line 25

def mkfile(token:, file_size:, blocks:, key: nil, fname: nil, mime_type: nil, user_vars: nil)
  url = config.up_host
  url += "/mkfile/#{file_size}"
  url += "/key/#{urlsafe_base64_encode(key)}" if key
  url += "/fname/#{urlsafe_base64_encode(fname)}" if fname
  url += "/mimeType/#{urlsafe_base64_encode(mime_type)}" if mime_type
  url += "/x:user-var/#{urlsafe_base64_encode(user_vars)}" if user_vars
  client.post(url, blocks.join(","), headers: {
                "Context-Type" => "text/plain",
                "Authorization" => "UpToken #{token}"
              })
end