class Blobstache::Client
Constants
- VERSION
Attributes
host[RW]
key[RW]
port[RW]
user_id[RW]
Public Class Methods
new(host: 'localhost', port: 1234, user_id: 'id', key: "key")
click to toggle source
# File lib/blobstache/client.rb, line 9 def initialize(host: 'localhost', port: 1234, user_id: 'id', key: "key") self.host = host self.port = port self.user_id = user_id self.key = key end
Public Instance Methods
create_bucket(name)
click to toggle source
BBBBB UU UU CCCCC KK KK EEEEEEE TTTTTTT BB B UU UU CC C KK KK EE TTT
BBBBBB UU UU CC KKKK EEEEE TTT
BB BB UU UU CC C KK KK EE TTT
BBBBBB UUUUU CCCCC KK KK EEEEEEE TTT
# File lib/blobstache/client.rb, line 40 def create_bucket(name) respond(connection.post("buckets") do |req| req.headers['Bucketid'] = name end ) end
create_object(bucket, name, body = "")
click to toggle source
OOOOO BBBBB JJJ EEEEEEE CCCCC TTTTTTT
OO OO BB B JJJ EE CC C TTT
OO OO BBBBBB JJJ EEEEE CC TTT
OO OO BB BB JJ JJJ EE CC C TTT
OOOO0 BBBBBB JJJJJ EEEEEEE CCCCC TTT
# File lib/blobstache/client.rb, line 65 def create_object(bucket, name, body = "") respond(connection.post("objects") do |req| req.headers['Bucketid'] = bucket req.headers['Objectalias'] = name req.body = body end) end
create_user()
click to toggle source
UU UU SSSSS EEEEEEE RRRRRR
UU UU SS EE RR RR UU UU SSSSS EEEEE RRRRRR
UU UU SS EE RR RR
UUUUU SSSSS EEEEEEE RR RR
# File lib/blobstache/client.rb, line 22 def create_user() respond(connection.post("users")) end
delete_bucket(id)
click to toggle source
# File lib/blobstache/client.rb, line 55 def delete_bucket(id) respond(connection.delete("buckets/#{id}")) end
delete_object(bucket, id)
click to toggle source
# File lib/blobstache/client.rb, line 104 def delete_object(bucket, id) respond(connection.delete("objects/#{id}") do |req| req.headers['Bucketid'] = bucket end) end
delete_user(id)
click to toggle source
# File lib/blobstache/client.rb, line 30 def delete_user(id) respond(connection.delete("users/#{id}")) end
get_bucket(id)
click to toggle source
# File lib/blobstache/client.rb, line 51 def get_bucket(id) respond(connection.get("buckets/#{id}")) end
get_object(bucket, id)
click to toggle source
# File lib/blobstache/client.rb, line 98 def get_object(bucket, id) connection.get("objects/#{id}") do |req| req.headers['Bucketid'] = bucket end end
get_object_info(bucket, id)
click to toggle source
# File lib/blobstache/client.rb, line 85 def get_object_info(bucket, id) respond(connection.get("info/objects/#{id}") do |req| req.headers['Bucketid'] = bucket end) end
get_object_size(bucket, id)
click to toggle source
# File lib/blobstache/client.rb, line 91 def get_object_size(bucket, id) r = connection.head("objects/#{id}") do |req| req.headers['Bucketid'] = bucket end r.headers["Object-Size"].to_i end
list_buckets()
click to toggle source
# File lib/blobstache/client.rb, line 47 def list_buckets respond(connection.get("buckets")) end
list_objects(bucket)
click to toggle source
# File lib/blobstache/client.rb, line 73 def list_objects(bucket) respond(connection.get("objects") do |req| req.headers['Bucketid'] = bucket end) end
list_users()
click to toggle source
# File lib/blobstache/client.rb, line 26 def list_users respond(connection.get("users")) end
set_object_public(bucket, id)
click to toggle source
# File lib/blobstache/client.rb, line 79 def set_object_public(bucket, id) respond(connection.put("public/objects/#{id}") do |req| req.headers['Bucketid'] = bucket end) end
Private Instance Methods
connection()
click to toggle source
# File lib/blobstache/client.rb, line 121 def connection @connection ||= ::Faraday.new( url: "http://#{host}:#{port}", ssl: {:verify => false}, headers: { "Userid" => user_id, "Key" => key } ) end
respond(response)
click to toggle source
# File lib/blobstache/client.rb, line 112 def respond(response) if response.status / 100 == 2 and response.body != nil and response.body != "" return JSON.parse(response.body) end response rescue response end