Class: GStore::Client
- Inherits:
-
Object
- Object
- GStore::Client
- Defined in:
- lib/gstore/bucket.rb,
lib/gstore/client.rb,
lib/gstore/object.rb,
lib/gstore/request.rb
Instance Method Summary collapse
- #create_bucket(bucket, options = {}) ⇒ Object
- #delete_bucket(bucket, options = {}) ⇒ Object
- #delete_object(bucket, filename, options = {}) ⇒ Object
- #get_bucket(bucket, options = {}) ⇒ Object
- #get_object(bucket, filename, options = {}) ⇒ Object
- #get_object_metadata(bucket, filename, options = {}) ⇒ Object
-
#initialize(options = {}) ⇒ Client
constructor
A new instance of Client.
- #list_buckets(options = {}) ⇒ Object
- #put_object(bucket, filename, options = {}) ⇒ Object
- #signed_request(method, host, path, params = {}, headers = {}, options = {}) ⇒ Object
Constructor Details
#initialize(options = {}) ⇒ Client
Returns a new instance of Client.
8 9 10 11 12 13 |
# File 'lib/gstore/client.rb', line 8 def initialize( = {}) @access_key = [:access_key] @secret_key = [:secret_key] @debug = [:debug] and [:debug] == true @host = [:host] || 'commondatastorage.googleapis.com' end |
Instance Method Details
#create_bucket(bucket, options = {}) ⇒ Object
8 9 10 |
# File 'lib/gstore/bucket.rb', line 8 def create_bucket(bucket, ={}) put(bucket, '/', ) end |
#delete_bucket(bucket, options = {}) ⇒ Object
16 17 18 |
# File 'lib/gstore/bucket.rb', line 16 def delete_bucket(bucket, ={}) delete(bucket, '/', ) end |
#delete_object(bucket, filename, options = {}) ⇒ Object
17 18 19 |
# File 'lib/gstore/object.rb', line 17 def delete_object(bucket, filename, ={}) delete(bucket, "/#{filename}", ) end |
#get_bucket(bucket, options = {}) ⇒ Object
12 13 14 |
# File 'lib/gstore/bucket.rb', line 12 def get_bucket(bucket, ={}) get(bucket, '/', ) end |
#get_object(bucket, filename, options = {}) ⇒ Object
7 8 9 10 11 12 13 14 15 |
# File 'lib/gstore/object.rb', line 7 def get_object(bucket, filename, ={}) outfile = .delete(:outfile) res = get(bucket, "/#{filename}", ) if outfile File.open(outfile, 'w') {|f| f.write(res) } else res end end |
#get_object_metadata(bucket, filename, options = {}) ⇒ Object
21 22 23 |
# File 'lib/gstore/object.rb', line 21 def (bucket, filename, ={}) head(bucket, "/#{filename}", ) end |
#list_buckets(options = {}) ⇒ Object
4 5 6 |
# File 'lib/gstore/bucket.rb', line 4 def list_buckets(={}) get(nil, '/', ) end |
#put_object(bucket, filename, options = {}) ⇒ Object
3 4 5 |
# File 'lib/gstore/object.rb', line 3 def put_object(bucket, filename, ={}) put(bucket, "/#{filename}", ) end |
#signed_request(method, host, path, params = {}, headers = {}, options = {}) ⇒ Object
12 13 14 15 16 17 18 19 20 21 22 23 24 25 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 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 |
# File 'lib/gstore/request.rb', line 12 def signed_request(method, host, path, params={}, headers={}, ={}) if @debug puts puts "***** METHOD: #{method}" puts "***** HOST: #{host}" puts "***** PATH: #{path}" puts "***** PARAMS: #{params.inspect}" puts "***** HEADERS: #{headers.inspect}" puts "***** OPTIONS: #{.inspect}" puts end headers.merge!({ :Host => host, :Date => Time.now.utc.strftime('%a, %d %b %Y %H:%M:%S -0000') #:"Content-MD5" => '' }) if [:data] headers = headers.merge(:"Content-Length" => [:data].size) else headers = headers.merge(:"Content-Length" => 0) end headers[:"Content-Type"] ||= 'text/plain' bucket = nil if host =~ /(\S+).#{@host}/ bucket = $1 end canonical_headers = method.name.gsub('Net::HTTP::', '').upcase + "\n" + '' + "\n" + # Content-MD5 headers[:"Content-Type"] + "\n" + # Content-Type headers[:Date] + "\n" # Date headers.each do |key,value| if key.to_s =~ /^x-goog/ canonical_headers += "#{key}:#{value}\n" end end canonical_resource = "" canonical_resource += "/#{bucket}" if bucket canonical_resource += path canonical_resource += '?acl' if params[:acl] = 'GOOG1 ' + @access_key + ':' + sign((canonical_headers + canonical_resource).toutf8) if @debug puts puts "+++++ BUCKET: #{bucket}" puts "+++++ HEADERS: #{headers.inspect}" puts "+++++ CANONICAL_HEADERS: #{canonical_headers}" puts "+++++ CANONICAL_RESOURCE: #{canonical_resource}" puts "+++++ AUTHORIZATION: #{}" puts end _http_do(method, host, path, params_to_request_string(params), headers.merge(:Authorization => ), [:data]) end |