README.md in nightcrawler_swift-0.4.0 vs README.md in nightcrawler_swift-0.5.0

- old
+ new

@@ -4,22 +4,32 @@ ## Installation Add this line to your application's Gemfile: - gem 'nightcrawler_swift' +```ruby +gem 'nightcrawler_swift' +``` And then execute: - $ bundle +```sh +$ bundle +``` Or install it yourself as: - $ gem install nightcrawler_swift +```sh +$ gem install nightcrawler_swift +``` ## Usage +* [With Rails](https://github.com/tulios/nightcrawler_swift#with-rails) +* [Programatically](https://github.com/tulios/nightcrawler_swift#programatically) +* [Command Line](https://github.com/tulios/nightcrawler_swift#command-line) + ### With Rails #### 1) Configure your swift credentials and options _In config/application.rb_ or _config/environments/*.rb_ @@ -35,24 +45,40 @@ ```ruby config.nightcrawler_swift.max_age = 3600 # default: nil config.nightcrawler_swift.verify_ssl = true # default: false config.nightcrawler_swift.timeout = 10 # in seconds, default: nil +config.nightcrawler_swift.admin_url = "https://api.host.com/v1/AUTH_1234" # default: uses the admin_url returned by authentication +config.nightcrawler_swift.public_url = "http://asset.host.com/v1/AUTH_1234" # default: uses the public_url returned by authentication +config.nightcrawler_swift.retries = 3 # default: 5, to disable set it to false +config.nightcrawler_swift.max_retry_time = 64 # in seconds, default: 30 ``` -_max_age_ will be used to define *Cache-Control:max-age=<value>* header. - By default it will use ```Rails.logger``` as logger, to change that use a different logger in configurations, like: ```ruby config.nightcrawler_swift.logger = Logger.new(STDOUT) ``` +##### further explanation of configurations + +> max_age + +It will be used to define *Cache-Control:max-age=<value>* header. + +> retries + +The number of times to retry the request before failing. To disable this feature set it to __false__. + +> max_retry_time + +Maximum delay in seconds between each retry. The delay will start with 1s and will double for each retry until this value. + #### 2) Profit! ```sh -rake nightcrawler_swift:rails:asset_sync +$ rake nightcrawler_swift:rails:asset_sync ``` It will invoke ```rake assets:precompile``` and will copy your public directory to swift bucket/container. To sync the public directory without the asset precompilation use the task: ```nightcrawler_swift:rails:sync``` ### Programatically @@ -72,11 +98,15 @@ __Optional configurations:__ ```ruby max_age: 3600, verify_ssl: true, -timeout: 10 +timeout: 10, # in seconds +admin_url: "https://api.host.com/v1/AUTH_1234", # default: uses the admin_url returned by authentication +public_url: "http://asset.host.com/v1/AUTH_1234", # default: uses the public_url returned by authentication +retries: 3, # default: 5, to disable set it to false +max_retry_time: 64 # in seconds, default: 30 ``` By default it will use ```Logger.new(STDOUT)``` as logger, to change that use: ```ruby @@ -87,10 +117,62 @@ ```ruby NightcrawlerSwift.sync File.expand_path("./my-dir") ``` +### Command Line + +The NightcrawlerSwift shell command (CLI) allows you to interact with your buckets/containers easily, it has the same commands of the gem. To see the help, use the cli without arguments or use the _-h_/_--help_ switch. + +```sh +$ nswift # or nswift -h +``` + +```nswift``` will use the configurations stored at the file __.nswiftrc__ located at your home directory. If you try to use any command without the file, it will create a sample configuration for you, but you can create your own. + +The configuration is a __json__ file, named __.nswiftrc__. You can include any configuration available to the gem (see the other usages example to know each option available). Follow the format: + +```json +{ + "bucket": "<bucket/container name>", + "tenant_name": "<tenant name>", + "username": "<username>", + "password": "<password>", + "auth_url": "<auth url, ex: https://auth.url.com:123/v2.0/tokens>" +} +``` + +The following commands are available through the cli: + +```sh +$ nswift list +``` +```sh +$ nswift upload <real_path> <swift_path> # nswift upload robots.txt assets/robots.txt +``` +```sh +$ nswift download <swift_path> # nswift download assets/robots.txt > my-robots.txt +``` +```sh +$ nswift delete <swift_path> # nswift delete assets/robots.txt +``` +```sh +$ nswift url-for <swift_path> # nswift url-for assets/robots.txt +``` + +For any commands you could provide a different configuration file through the _-c_/_--config_ switch, as: + +```sh +$ nswift list -c /dir/my-nswift-rc +``` + +and a different bucket/container name through the _-b_/_--bucket_ switch, as: + +```sh +$ nwift list -b rogue +``` + ## Commands NightcrawlerSwift has some useful built-in commands. All commands require the configuration and will __automatically__ connect/reconnect to keystone when necessary. ### Upload @@ -127,10 +209,17 @@ delete = NightcrawlerSwift::Delete.new delete.execute "my_file_path.txt" # true / false ``` +### Sync + +```ruby +sync = NightcrawlerSwift::Sync.new +sync.execute "/dir/to/synchronize" +``` + ## Connection To manually establish the connection with keystone, use: ```ruby @@ -143,9 +232,25 @@ NightcrawlerSwift.connection.connected? ``` To reconnect just use ```NightcrawlerSwift.connection.connect!``` again. +## Options + +After configure the NightcrawlerSwift you can access your configurations through the __options__ method, like: + +```ruby +NightcrawlerSwift.options +``` + +The only difference is that you will access each configuration as a method instead of a hash style, like: + +```ruby +NightcrawlerSwift.configure tenant_name: "rogue" + +# Can be used as: +NightcrawlerSwift.options.tenant_name # "rogue" +``` ## Contributing 1. Fork it ( https://github.com/tulios/nightcrawler_swift/fork ) 2. Create your feature branch (`git checkout -b my-new-feature`)