Giter Site home page Giter Site logo

gstore's Introduction

Ruby client library for the Google Storage API

This is the first release and supports all the basic operations. Advanced support for ACLs etc.. coming soon

Install the gem

sudo gem install gstore

Using the gem

Visit The Google Storage Key Manager to get your access and secret keys.

In your code just: require 'gstore'

Basic Examples

Create an instance of the client with your credentials:

client = GStore::Client.new(
   :access_key => 'YOUR_ACCESS_KEY',
   :secret_key => 'YOUR_SECRET_KEY'
)

# List all of your existing Buckets
client.list_buckets

Here are some example bucket operations:

# Create a Bucket
client.create_bucket('my_unique_bucket')

# Retrieve a Bucket
client.get_bucket('my_unique_bucket')

# Delete a [empty] Bucket
client.delete_bucket('my_unique_bucket')

Once you have a bucket you can manipulate objects in the following way:

# Store a file in a bucket
client.put_object('my_unique_bucket', 'my_first_object', :data => File.read('mytext.txt'))

# Retrieve the contents of the object in the specified bucket
puts client.get_object('my_unique_bucket', 'my_first_object')

# Alternatively specify an outfile and the contents will be saved to there
client.get_object('my_unique_bucket', 'my_first_object', :outfile => 'retrieved_mytext.txt')

# Delete an object from the bucket
client.delete_object('my_unique_bucket', 'my_first_object')

Advanced Examples

Query parameters

For certain requests like get_bucket('my_unique_bucket') you can specify query parameters like max-keys, prefix, delimiter and marker (see The Google Developer Guide) for more information.

Here’s an example with gstore:

client.get_bucket('my_unique_bucket', :params => {:max_keys => 2, :prefix => 'backup'})
  • max_keys is converted to max-keys so you can use the ruby symbol without quotes. :"max-keys" and "max-keys" also work

Access Control

Here is how you retrieve the ACL for a bucket or object:

client.get_bucket('my_unique_bucket', :params => {:acl => ''})
client.get_bucket('my_unique_bucket', 'my_first_object', :params => {:acl => ''})

To create a bucket or object with one of the pre-defined ACL’s:

client.create_bucket('my_public_bucket', :headers => {:x_goog_acl => 'public-read'})
client.create_object('my_public_bucket', 'my_public_object', :headers => {:x_goog_acl => 'public-read-write'})
  • x_goog_acl is converted to x-goog-acl so you can use the ruby symbol without quotes. :"x-goog-acl" and "x-goog-acl" also work

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.