1
0
Fork 0
mirror of https://github.com/fog/fog.git synced 2022-11-09 13:51:43 -05:00
fog--fog/docs/about/getting_started.markdown

84 lines
2.8 KiB
Markdown
Raw Normal View History

---
layout: default
2011-04-01 09:24:50 -04:00
title: Getting Started
---
2011-04-01 14:20:47 -04:00
First off, install the gem:
$ gem install fog
2011-04-01 14:20:47 -04:00
## Setting Up Local Storage
2011-05-05 17:34:53 -04:00
We will be using Local storage in the example. Local storage provides the same api that cloud storage services in fog do, but without the bother of needing to signup for stuff or pay extra money.
First, make a local directory to hold your data.
$ mkdir ~/fog
2011-05-05 19:32:24 -04:00
Now we can start writing our script, first off we should require fog.
require 'rubygems'
require 'fog'
2011-05-05 17:34:53 -04:00
Now in order to play with our data we need to setup a storage connection.
2011-05-05 17:34:53 -04:00
storage = Fog::Storage.new(
2011-04-01 14:20:47 -04:00
:local_root => '~/fog',
:provider => 'Local',
)
2011-05-05 17:34:53 -04:00
`storage` will now contain our storage object, configured to use the Local provider from our specified directory.
## Storing Data
Now that you have cleared the preliminaries you are ready to start storing data. Storage providers in fog segregate files into `directories` to make it easier to organize things. So lets create a directory so we can see that in action.
directory = Fog::Storage.directories.create(
:key => 'data'
)
To make sure it was created you can always check in your filesystem, but we can also check from inside fog.
storage.directories
Progress! Now it is time to actually create a file inside our new directory.
file = directory.files.create(
:body => 'Hello World!',
:key => 'hello_world.txt'
)
We should now have our file, first we can open it up and make sure we are on the right track.
$ open ~/fog/hello_world.txt
It is much more likely that you will want to see what files you have from inside fog though.
directory.files
Now that we have run through all the basics, lets clean up our mess.
file.destroy
directory.destroy
After that you should be able to check your directory list in fog or your filesystem and see you are safely back to square one.
## Next Steps
Using the same interface you can also practice working against a real provider (such as Amazon S3). Rather than worrying about signing up for an account right away though, we can use mocks to simulate S3 while we practice.
This time we will turn on mocking and then, just like before, we will need to make a connection.
Fog.mock!
storage = Fog::Storage.new(
:aws_access_key_id => 'fake_access_key_id',
:aws_secret_access_key => 'fake_secret_access_key',
:provider => 'AWS'
)
You may notice that we used bogus credentials, this is fine since we are just simulating things. To use real S3 you can simply omit `Fog.mock!` and swap in your real credentials.
Once you have your connection you can go through all the steps you did before, only now you will be working against a real cloud service (or at least a simulated one).
Congratulations and welcome to the cloud! Continue your journey at [fog.io](http://fog.io)