A RubyMotion library for version 2 of the DigitalOcean API.
Switch branches/tags
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Failed to load latest commit information.
app
lib
spec
.gitignore
Gemfile
LICENSE.txt
README.md
Rakefile
motion_ocean.gemspec

README.md

MotionOcean

Gem Version

RubyMotion library for version 2 of DigitalOcean's API

Please note that version 2 of DigitalOcean's API is in beta, and is still being developed. Everything is subject to change.

Installation

Add this line to your application's Gemfile:

gem 'motion_ocean'

And then execute:

$ bundle

Or install it yourself as:

$ gem install motion_ocean

Initialization

client = MotionOcean::Client.new(access_token: 'token')

or

client = MotionOcean::Client.new do |config|
  config.access_token = 'token'
end

Usage

The API client is based on NSURLSession and every request is executed asynchronously. Every MotionOcean method call therefore requires a block, which yields a MotionOcean::API::Response.

MotionOcean pretty much implements the DO API 1:1, so please check their documentation for the available functions and options.

The response object

success?

You can use success? to check if a successful HTTP status code was returned:

client.droplet.create(options) do |result|
  result.success? # => true
end

data

The response data is assigned to the data-property of the response object. This is a Hash which corresponds with the returned JSON by DigitalOcean.

client.droplet.create(options) do |result|
  result.data # => Hash with the JSON response
end

response

MotionOcean uses NSURLSession. You can use response to get to the original response object:

client.droplet.create(options) do |result|
  result.response # => NSHTTPURLResponse
end

error

When there is an error you can check this for the specific error. If you think it is a bug in MotionOcean, please open an issue or even better: submit a Pull Request with the fix!

Aknowledgements

This library is an adaptation for RubyMotion of barge by Ørjan Blom.

The brilliant MotionInMotion screencasts helped me with implementing the API client using NSURLSession (specifically episode #33) and iOS development using RubyMotion in general.

Contributing

  1. Fork it ( https://github.com/datarift/motion_ocean/fork )
  2. Create your feature branch (git checkout -b my-new-feature)
  3. Commit your changes (git commit -am 'Add some feature')
  4. Push to the branch (git push origin my-new-feature)
  5. Create a new Pull Request