Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 290d8a6
Showing
27 changed files
with
560 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
*.gem | ||
*.rbc | ||
.bundle | ||
.config | ||
.yardoc | ||
Gemfile.lock | ||
InstalledFiles | ||
_yardoc | ||
coverage | ||
doc/ | ||
lib/bundler/man | ||
pkg | ||
rdoc | ||
spec/reports | ||
test/tmp | ||
test/version_tmp | ||
tmp |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
--color | ||
--format documentation |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
source 'https://rubygems.org' | ||
|
||
gemspec |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
Copyright (c) 2012 Gosha Arinich | ||
|
||
MIT License | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining | ||
a copy of this software and associated documentation files (the | ||
"Software"), to deal in the Software without restriction, including | ||
without limitation the rights to use, copy, modify, merge, publish, | ||
distribute, sublicense, and/or sell copies of the Software, and to | ||
permit persons to whom the Software is furnished to do so, subject to | ||
the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be | ||
included in all copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, | ||
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF | ||
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND | ||
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE | ||
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION | ||
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION | ||
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,149 @@ | ||
# Ruroku | ||
|
||
The Ruby client for Heroku API, built on top of official `heroku.rb` | ||
gem. | ||
|
||
## Installation | ||
|
||
Add this line to your application's Gemfile: | ||
|
||
gem 'ruroku' | ||
|
||
And then execute: | ||
|
||
$ bundle | ||
|
||
Or install it yourself as: | ||
|
||
$ gem install ruroku | ||
|
||
## Usage | ||
|
||
Start by initiating a connection with Heroku API: | ||
|
||
heroku = Ruroku::API.new api_key: YOUR_HEROKU_API_KEY | ||
|
||
(You can leave out `:api_key` if `ENV['HEROKU_API_KEY']` is set | ||
instead.) | ||
|
||
Now you can interact with Heroku API using Ruroku. | ||
|
||
### Apps | ||
|
||
Each API object has apps associated with the Heroku account. You can | ||
access an Array of all the associated apps with `#apps`: | ||
|
||
heroku.apps | ||
# => [#<App>, #<App>, #<App>] | ||
|
||
app = heroku.apps.first | ||
|
||
You then can get additional app info: | ||
|
||
app.id | ||
app.name | ||
app.stack | ||
app.git_url | ||
app.slug_size | ||
app.repo_size | ||
app.dynos | ||
apps.workers | ||
# and a few less interesting ones | ||
|
||
Maintenance mode can be turned on and off: | ||
|
||
app.maintenance! | ||
app.no_maintenance! | ||
|
||
### Addons | ||
|
||
To get a list of addons used by a particular app: | ||
|
||
addons = app.addons | ||
# => [#<Addon>, #<Addon>, #<Addon>] | ||
|
||
addon = app.addons.first | ||
|
||
It's possible perform several actions on addon collections: | ||
|
||
#### Add an addon | ||
|
||
addons.add 'addon:plan' | ||
|
||
#### Remove an addon | ||
|
||
addons.delete 'addon-name' | ||
|
||
#### Upgrade an addon | ||
|
||
addons.upgrade 'addon:new-plan' | ||
|
||
Each addon object is associated with the application. You can delete | ||
addons from the app by calling `#delete` method on the addon object as | ||
well: | ||
|
||
addon.delete! | ||
|
||
### Collaborators | ||
|
||
List all app collaborators: | ||
|
||
collaborators = app.collaborators | ||
|
||
#### Add a collaborator | ||
|
||
collaborators.add 'email@me.com' | ||
|
||
#### Remove a collaborator | ||
|
||
collaborators.delete 'email@me.com' | ||
|
||
or | ||
|
||
collaborator.delete! | ||
|
||
### Config variables | ||
|
||
List all app config vars: | ||
|
||
app.config_vars | ||
|
||
### Domains | ||
|
||
Access domains used by the application: | ||
|
||
app.domains | ||
|
||
### Processes | ||
|
||
Get current application processes: | ||
|
||
app.collaborators | ||
|
||
### Releases | ||
|
||
List all app releases: | ||
|
||
app.releases | ||
|
||
## Mock | ||
|
||
For practice or testing you can also use a simulated Heroku: | ||
|
||
require 'ruroku' | ||
|
||
heroku = Ruroku::API.new api_key: API_KEY, mock: true | ||
|
||
After that commands should still behave the same, but they will only modify some local data instead of updating the state of things on Heroku. | ||
|
||
## Contributing | ||
|
||
1. Fork it | ||
2. Create your feature branch (`git checkout -b my-new-feature`) | ||
3. Commit your changes (`git commit -am 'Added some feature'`) | ||
4. Push to the branch (`git push origin my-new-feature`) | ||
5. Create new Pull Request | ||
|
||
## License | ||
|
||
Released under the MIT license. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
#!/usr/bin/env rake | ||
require "bundler/gem_tasks" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
* Logs | ||
* Stacks | ||
* Keys | ||
* User info | ||
* Collection finder methods | ||
* Specs |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
require "heroku-api" | ||
require "time" | ||
require "active_support/core_ext/numeric" | ||
require "active_support/core_ext/string" | ||
|
||
require "ruroku/base" | ||
require "ruroku/nested_base" | ||
require "ruroku/resource_set" | ||
|
||
require "ruroku/api" | ||
require "ruroku/app" | ||
require "ruroku/addon" | ||
require "ruroku/addon_set" | ||
require "ruroku/collaborator" | ||
require "ruroku/collaborator_set" | ||
require "ruroku/config_var" | ||
require "ruroku/config_var_set" | ||
require "ruroku/domain" | ||
require "ruroku/domain_set" | ||
require "ruroku/process" | ||
require "ruroku/process_set" | ||
require "ruroku/release" | ||
require "ruroku/release_set" | ||
require "ruroku/version" | ||
|
||
module Ruroku | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
module Ruroku | ||
class Addon < NestedBase | ||
attr_accessor :name, :description, :url, :state, :price, :beta | ||
deletable :name | ||
|
||
# Public: Check if the addon is in beta. | ||
def beta? | ||
!!beta | ||
end | ||
|
||
def price=(value) | ||
@price = value | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
module Ruroku | ||
class AddonSet < ResourceSet | ||
# Map API methods to collection methods. | ||
# | ||
# Examples | ||
# | ||
# addons.add 'addon-name' | ||
# addons.upgrade 'addon-name' | ||
# addon.delete 'addon-name' | ||
map_api add: :post_addon, | ||
upgrade: :put_addon, | ||
delete: :delete_addon | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
module Ruroku | ||
class API | ||
attr_accessor :heroku_api | ||
|
||
def initialize(options = {}) | ||
self.heroku_api = Heroku::API.new options | ||
end | ||
|
||
# Public: Get apps associated with current heroku account. | ||
# | ||
# Returns the Array[App]. | ||
def apps | ||
heroku_api.get_apps.body.map { |app| App.new heroku_api, app } | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
module Ruroku | ||
class App < Base | ||
attr_accessor :id, :name, :create_status, :created_at, :stack, :git_url, | ||
:requested_stack, :repo_migrate_status, :slug_size, :repo_size, | ||
:dynos, :workers | ||
|
||
# Public: Get addons associated with current app. | ||
def addons | ||
AddonSet.new self, *api.get_addons(name).body.map { |addon| Addon.new self, addon } | ||
end | ||
|
||
# Public: Get collaborators associated with current app. | ||
def collaborators | ||
CollaboratorSet.new self, *api.get_collaborators(name).body.map { |collaborator| Collaborator.new self, collaborator } | ||
end | ||
|
||
# Public: Get config vars associated with current app. | ||
def config_vars | ||
ConfigVarSet.new self, *api.get_config_vars(name).body.map { |key, value| ConfigVar.new self, key: key, value: value } | ||
end | ||
|
||
# Public: Get processes associated with current app. | ||
def processes | ||
ProcessSet.new self, *api.get_ps(name).body.map { |ps| Process.new self, ps } | ||
end | ||
|
||
# Public: Get releases associated with current app. | ||
def releases | ||
ReleaseSet.new self, *api.get_releases(name).body.map { |release| Release.new self, release } | ||
end | ||
|
||
# Public: Turn the maintenance mode on. | ||
def maintenance! | ||
api.post_app_maintenance name, '1' | ||
end | ||
|
||
# Public: Turn the maintenance mode off. | ||
def no_maintenance! | ||
api.post_app_maintenance name, '0' | ||
end | ||
|
||
def created_at=(value) | ||
@created_at = Time.parse value | ||
end | ||
|
||
def slug_size=(value) | ||
@slug_size = value.to_i.bytes | ||
end | ||
|
||
def repo_size=(value) | ||
@repo_size = value.to_i.bytes | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
module Ruroku | ||
class Base | ||
attr_accessor :api | ||
|
||
def initialize(api, attributes = {}) | ||
self.api = api | ||
|
||
attributes.each do |key, value| | ||
method = "#{key}=" | ||
send method, value if respond_to? method | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
module Ruroku | ||
class Collaborator < NestedBase | ||
attr_accessor :email, :access | ||
deletable :email | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
module Ruroku | ||
class CollaboratorSet < ResourceSet | ||
# Map API methods to collection methods. | ||
# | ||
# Examples | ||
# | ||
# collaborators.add 'collaborator-email' | ||
# collaborators.delete 'collaborator-email' | ||
map_api add: :post_collaborator, | ||
delete: :delete_collaborator | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
module Ruroku | ||
class ConfigVar < NestedBase | ||
attr_accessor :key, :value | ||
deletable :key | ||
|
||
def value=(new_value) | ||
if @value.nil? | ||
@value = new_value | ||
else | ||
api.put_config_vars app.name, key => new_value | ||
@value = new_value | ||
end | ||
end | ||
end | ||
end |
Oops, something went wrong.