ruroku 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/.gitignore ADDED
@@ -0,0 +1,17 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --color
2
+ --format documentation
data/Gemfile ADDED
@@ -0,0 +1,3 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gemspec
data/LICENSE ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2012 Gosha Arinich
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,149 @@
1
+ # Ruroku
2
+
3
+ The Ruby client for Heroku API, built on top of official `heroku.rb`
4
+ gem.
5
+
6
+ ## Installation
7
+
8
+ Add this line to your application's Gemfile:
9
+
10
+ gem 'ruroku'
11
+
12
+ And then execute:
13
+
14
+ $ bundle
15
+
16
+ Or install it yourself as:
17
+
18
+ $ gem install ruroku
19
+
20
+ ## Usage
21
+
22
+ Start by initiating a connection with Heroku API:
23
+
24
+ heroku = Ruroku::API.new api_key: YOUR_HEROKU_API_KEY
25
+
26
+ (You can leave out `:api_key` if `ENV['HEROKU_API_KEY']` is set
27
+ instead.)
28
+
29
+ Now you can interact with Heroku API using Ruroku.
30
+
31
+ ### Apps
32
+
33
+ Each API object has apps associated with the Heroku account. You can
34
+ access an Array of all the associated apps with `#apps`:
35
+
36
+ heroku.apps
37
+ # => [#<App>, #<App>, #<App>]
38
+
39
+ app = heroku.apps.first
40
+
41
+ You then can get additional app info:
42
+
43
+ app.id
44
+ app.name
45
+ app.stack
46
+ app.git_url
47
+ app.slug_size
48
+ app.repo_size
49
+ app.dynos
50
+ apps.workers
51
+ # and a few less interesting ones
52
+
53
+ Maintenance mode can be turned on and off:
54
+
55
+ app.maintenance!
56
+ app.no_maintenance!
57
+
58
+ ### Addons
59
+
60
+ To get a list of addons used by a particular app:
61
+
62
+ addons = app.addons
63
+ # => [#<Addon>, #<Addon>, #<Addon>]
64
+
65
+ addon = app.addons.first
66
+
67
+ It's possible perform several actions on addon collections:
68
+
69
+ #### Add an addon
70
+
71
+ addons.add 'addon:plan'
72
+
73
+ #### Remove an addon
74
+
75
+ addons.delete 'addon-name'
76
+
77
+ #### Upgrade an addon
78
+
79
+ addons.upgrade 'addon:new-plan'
80
+
81
+ Each addon object is associated with the application. You can delete
82
+ addons from the app by calling `#delete` method on the addon object as
83
+ well:
84
+
85
+ addon.delete!
86
+
87
+ ### Collaborators
88
+
89
+ List all app collaborators:
90
+
91
+ collaborators = app.collaborators
92
+
93
+ #### Add a collaborator
94
+
95
+ collaborators.add 'email@me.com'
96
+
97
+ #### Remove a collaborator
98
+
99
+ collaborators.delete 'email@me.com'
100
+
101
+ or
102
+
103
+ collaborator.delete!
104
+
105
+ ### Config variables
106
+
107
+ List all app config vars:
108
+
109
+ app.config_vars
110
+
111
+ ### Domains
112
+
113
+ Access domains used by the application:
114
+
115
+ app.domains
116
+
117
+ ### Processes
118
+
119
+ Get current application processes:
120
+
121
+ app.collaborators
122
+
123
+ ### Releases
124
+
125
+ List all app releases:
126
+
127
+ app.releases
128
+
129
+ ## Mock
130
+
131
+ For practice or testing you can also use a simulated Heroku:
132
+
133
+ require 'ruroku'
134
+
135
+ heroku = Ruroku::API.new api_key: API_KEY, mock: true
136
+
137
+ 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.
138
+
139
+ ## Contributing
140
+
141
+ 1. Fork it
142
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
143
+ 3. Commit your changes (`git commit -am 'Added some feature'`)
144
+ 4. Push to the branch (`git push origin my-new-feature`)
145
+ 5. Create new Pull Request
146
+
147
+ ## License
148
+
149
+ Released under the MIT license.
data/Rakefile ADDED
@@ -0,0 +1,2 @@
1
+ #!/usr/bin/env rake
2
+ require "bundler/gem_tasks"
data/TODO.md ADDED
@@ -0,0 +1,6 @@
1
+ * Logs
2
+ * Stacks
3
+ * Keys
4
+ * User info
5
+ * Collection finder methods
6
+ * Specs
@@ -0,0 +1,15 @@
1
+ module Ruroku
2
+ class Addon < NestedBase
3
+ attr_accessor :name, :description, :url, :state, :price, :beta
4
+ deletable :name
5
+
6
+ # Public: Check if the addon is in beta.
7
+ def beta?
8
+ !!beta
9
+ end
10
+
11
+ def price=(value)
12
+ @price = value
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,14 @@
1
+ module Ruroku
2
+ class AddonSet < ResourceSet
3
+ # Map API methods to collection methods.
4
+ #
5
+ # Examples
6
+ #
7
+ # addons.add 'addon-name'
8
+ # addons.upgrade 'addon-name'
9
+ # addon.delete 'addon-name'
10
+ map_api add: :post_addon,
11
+ upgrade: :put_addon,
12
+ delete: :delete_addon
13
+ end
14
+ end
data/lib/ruroku/api.rb ADDED
@@ -0,0 +1,16 @@
1
+ module Ruroku
2
+ class API
3
+ attr_accessor :heroku_api
4
+
5
+ def initialize(options = {})
6
+ self.heroku_api = Heroku::API.new options
7
+ end
8
+
9
+ # Public: Get apps associated with current heroku account.
10
+ #
11
+ # Returns the Array[App].
12
+ def apps
13
+ heroku_api.get_apps.body.map { |app| App.new heroku_api, app }
14
+ end
15
+ end
16
+ end
data/lib/ruroku/app.rb ADDED
@@ -0,0 +1,54 @@
1
+ module Ruroku
2
+ class App < Base
3
+ attr_accessor :id, :name, :create_status, :created_at, :stack, :git_url,
4
+ :requested_stack, :repo_migrate_status, :slug_size, :repo_size,
5
+ :dynos, :workers
6
+
7
+ # Public: Get addons associated with current app.
8
+ def addons
9
+ AddonSet.new self, *api.get_addons(name).body.map { |addon| Addon.new self, addon }
10
+ end
11
+
12
+ # Public: Get collaborators associated with current app.
13
+ def collaborators
14
+ CollaboratorSet.new self, *api.get_collaborators(name).body.map { |collaborator| Collaborator.new self, collaborator }
15
+ end
16
+
17
+ # Public: Get config vars associated with current app.
18
+ def config_vars
19
+ ConfigVarSet.new self, *api.get_config_vars(name).body.map { |key, value| ConfigVar.new self, key: key, value: value }
20
+ end
21
+
22
+ # Public: Get processes associated with current app.
23
+ def processes
24
+ ProcessSet.new self, *api.get_ps(name).body.map { |ps| Process.new self, ps }
25
+ end
26
+
27
+ # Public: Get releases associated with current app.
28
+ def releases
29
+ ReleaseSet.new self, *api.get_releases(name).body.map { |release| Release.new self, release }
30
+ end
31
+
32
+ # Public: Turn the maintenance mode on.
33
+ def maintenance!
34
+ api.post_app_maintenance name, '1'
35
+ end
36
+
37
+ # Public: Turn the maintenance mode off.
38
+ def no_maintenance!
39
+ api.post_app_maintenance name, '0'
40
+ end
41
+
42
+ def created_at=(value)
43
+ @created_at = Time.parse value
44
+ end
45
+
46
+ def slug_size=(value)
47
+ @slug_size = value.to_i.bytes
48
+ end
49
+
50
+ def repo_size=(value)
51
+ @repo_size = value.to_i.bytes
52
+ end
53
+ end
54
+ end
@@ -0,0 +1,14 @@
1
+ module Ruroku
2
+ class Base
3
+ attr_accessor :api
4
+
5
+ def initialize(api, attributes = {})
6
+ self.api = api
7
+
8
+ attributes.each do |key, value|
9
+ method = "#{key}="
10
+ send method, value if respond_to? method
11
+ end
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,6 @@
1
+ module Ruroku
2
+ class Collaborator < NestedBase
3
+ attr_accessor :email, :access
4
+ deletable :email
5
+ end
6
+ end
@@ -0,0 +1,12 @@
1
+ module Ruroku
2
+ class CollaboratorSet < ResourceSet
3
+ # Map API methods to collection methods.
4
+ #
5
+ # Examples
6
+ #
7
+ # collaborators.add 'collaborator-email'
8
+ # collaborators.delete 'collaborator-email'
9
+ map_api add: :post_collaborator,
10
+ delete: :delete_collaborator
11
+ end
12
+ end
@@ -0,0 +1,15 @@
1
+ module Ruroku
2
+ class ConfigVar < NestedBase
3
+ attr_accessor :key, :value
4
+ deletable :key
5
+
6
+ def value=(new_value)
7
+ if @value.nil?
8
+ @value = new_value
9
+ else
10
+ api.put_config_vars app.name, key => new_value
11
+ @value = new_value
12
+ end
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,12 @@
1
+ module Ruroku
2
+ class ConfigVarSet < ResourceSet
3
+ # Map API methods to collection methods.
4
+ #
5
+ # Examples
6
+ #
7
+ # config_vars.add 'KEY' => 'value'
8
+ # config_vars.delete 'KEY' => 'value'
9
+ map_api add: :post_config_vars,
10
+ delete: :delete_config_var
11
+ end
12
+ end
@@ -0,0 +1,14 @@
1
+ module Ruroku
2
+ class Domain < NestedBase
3
+ attr_accessor :id, :domain, :base_domain, :default, :created_at, :updated_at
4
+ deletable :domain
5
+
6
+ def created_at=(value)
7
+ @created_at = Time.parse value
8
+ end
9
+
10
+ def updated_at=(value)
11
+ @updated_at = Time.parse value
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,12 @@
1
+ module Ruroku
2
+ class DomainSet < ResourceSet
3
+ # Map API methods to collection methods.
4
+ #
5
+ # Examples
6
+ #
7
+ # domains.add 'domain.com'
8
+ # domains.delete 'domain.com'
9
+ map_api add: :post_domains,
10
+ delete: :delete_domain
11
+ end
12
+ end
@@ -0,0 +1,21 @@
1
+ module Ruroku
2
+ class NestedBase < Base
3
+ attr_accessor :app, :api
4
+
5
+ def initialize(app, attributes = {})
6
+ self.app = app
7
+
8
+ super app.api, attributes
9
+ end
10
+
11
+ def self.deletable(resource_id)
12
+ resource_name = name.demodulize.underscore
13
+
14
+ define_method :delete! do
15
+ api_method = "delete_#{resource_name}"
16
+ resource_id = send resource_id
17
+ api.send api_method, app.name, resource_id
18
+ end
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,25 @@
1
+ module Ruroku
2
+ class Process < NestedBase
3
+ attr_accessor :process, :type, :command, :upid, :slug, :action,
4
+ :pretty_state, :elapsed, :rendezvous_url, :attached, :transitioned_at
5
+
6
+ # Public: Restart the process.
7
+ def restart
8
+ api.post_ps_restart app.name, 'ps' => process
9
+ end
10
+
11
+ # Public: Stop the process.
12
+ def stop
13
+ api.post_ps_stop app.name, 'ps' => process
14
+ end
15
+
16
+ # Public: Check if the process is attached.
17
+ def attached?
18
+ !!attached
19
+ end
20
+
21
+ def transitioned_at=(value)
22
+ @transitioned_at = Time.parse value
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,37 @@
1
+ module Ruroku
2
+ class ProcessSet < ResourceSet
3
+ # Publc: Run the command.
4
+ #
5
+ # command - The String command.
6
+ def run(command)
7
+ api.post_ps app.name, command
8
+ end
9
+
10
+ # Public: Restart all the processes.
11
+ def restart
12
+ api.post_ps_restart app.name
13
+ end
14
+
15
+ # Public: Scale processes.
16
+ #
17
+ # type - The String process type.
18
+ # qty - The Integer process quantity.
19
+ def scale(type, qty)
20
+ api.ps_scale app.name, type, qty
21
+ end
22
+
23
+ # Public: Stop the process(es).
24
+ #
25
+ # options - The Hash
26
+ # either :ps - The String process name
27
+ # or :type - The String process type
28
+ #
29
+ # Examples
30
+ #
31
+ # processes.stop 'ps' => 'web.1'
32
+ # processes.stop 'type' => 'web'
33
+ def stop(options)
34
+ api.post_ps_stop app.name, options
35
+ end
36
+ end
37
+ end
@@ -0,0 +1,10 @@
1
+ module Ruroku
2
+ class Release < NestedBase
3
+ attr_accessor :name, :descr, :user, :commit, :env, :addons, :pstable,
4
+ :created_at
5
+
6
+ def created_at=(value)
7
+ @created_at = Time.parse value
8
+ end
9
+ end
10
+ end
@@ -0,0 +1,10 @@
1
+ module Ruroku
2
+ class ReleaseSet < ResourceSet
3
+ # Map API methods to collection methods.
4
+ #
5
+ # Examples
6
+ #
7
+ # releases.rollback 'v1'
8
+ map_api rollback: :post_release
9
+ end
10
+ end
@@ -0,0 +1,20 @@
1
+ module Ruroku
2
+ class ResourceSet < Array
3
+ attr_accessor :app, :api
4
+
5
+ def initialize(app, *args)
6
+ self.app = app
7
+ self.api = app.api
8
+
9
+ super args
10
+ end
11
+
12
+ def self.map_api(methods)
13
+ methods.each do |method_name, api_mapping|
14
+ define_method method_name do |resource_name|
15
+ api.send api_mapping, app.name, resource_name
16
+ end
17
+ end
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,3 @@
1
+ module Ruroku
2
+ VERSION = "0.0.1"
3
+ end
data/lib/ruroku.rb ADDED
@@ -0,0 +1,27 @@
1
+ require "heroku-api"
2
+ require "time"
3
+ require "active_support/core_ext/numeric"
4
+ require "active_support/core_ext/string"
5
+
6
+ require "ruroku/base"
7
+ require "ruroku/nested_base"
8
+ require "ruroku/resource_set"
9
+
10
+ require "ruroku/api"
11
+ require "ruroku/app"
12
+ require "ruroku/addon"
13
+ require "ruroku/addon_set"
14
+ require "ruroku/collaborator"
15
+ require "ruroku/collaborator_set"
16
+ require "ruroku/config_var"
17
+ require "ruroku/config_var_set"
18
+ require "ruroku/domain"
19
+ require "ruroku/domain_set"
20
+ require "ruroku/process"
21
+ require "ruroku/process_set"
22
+ require "ruroku/release"
23
+ require "ruroku/release_set"
24
+ require "ruroku/version"
25
+
26
+ module Ruroku
27
+ end
data/ruroku.gemspec ADDED
@@ -0,0 +1,22 @@
1
+ # -*- encoding: utf-8 -*-
2
+ require File.expand_path('../lib/ruroku/version', __FILE__)
3
+
4
+ Gem::Specification.new do |gem|
5
+ gem.authors = ["Gosha Arinich"]
6
+ gem.email = ["me@goshakkk.name"]
7
+ gem.description = %q{Ruby client for the Heroku API}
8
+ gem.summary = %q{Ruby client for the Heroku API}
9
+ gem.homepage = ""
10
+
11
+ gem.files = `git ls-files`.split($\)
12
+ gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
13
+ gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
14
+ gem.name = "ruroku"
15
+ gem.require_paths = ["lib"]
16
+ gem.version = Ruroku::VERSION
17
+
18
+ gem.add_runtime_dependency 'heroku-api', '~> 0.2.4'
19
+ gem.add_runtime_dependency 'activesupport', '~> 3.2.5'
20
+
21
+ gem.add_development_dependency 'rspec'
22
+ end
metadata ADDED
@@ -0,0 +1,126 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: ruroku
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Gosha Arinich
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-06-09 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: heroku-api
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ~>
20
+ - !ruby/object:Gem::Version
21
+ version: 0.2.4
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ~>
28
+ - !ruby/object:Gem::Version
29
+ version: 0.2.4
30
+ - !ruby/object:Gem::Dependency
31
+ name: activesupport
32
+ requirement: !ruby/object:Gem::Requirement
33
+ none: false
34
+ requirements:
35
+ - - ~>
36
+ - !ruby/object:Gem::Version
37
+ version: 3.2.5
38
+ type: :runtime
39
+ prerelease: false
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ~>
44
+ - !ruby/object:Gem::Version
45
+ version: 3.2.5
46
+ - !ruby/object:Gem::Dependency
47
+ name: rspec
48
+ requirement: !ruby/object:Gem::Requirement
49
+ none: false
50
+ requirements:
51
+ - - ! '>='
52
+ - !ruby/object:Gem::Version
53
+ version: '0'
54
+ type: :development
55
+ prerelease: false
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ! '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ description: Ruby client for the Heroku API
63
+ email:
64
+ - me@goshakkk.name
65
+ executables: []
66
+ extensions: []
67
+ extra_rdoc_files: []
68
+ files:
69
+ - .gitignore
70
+ - .rspec
71
+ - Gemfile
72
+ - LICENSE
73
+ - README.md
74
+ - Rakefile
75
+ - TODO.md
76
+ - lib/ruroku.rb
77
+ - lib/ruroku/addon.rb
78
+ - lib/ruroku/addon_set.rb
79
+ - lib/ruroku/api.rb
80
+ - lib/ruroku/app.rb
81
+ - lib/ruroku/base.rb
82
+ - lib/ruroku/collaborator.rb
83
+ - lib/ruroku/collaborator_set.rb
84
+ - lib/ruroku/config_var.rb
85
+ - lib/ruroku/config_var_set.rb
86
+ - lib/ruroku/domain.rb
87
+ - lib/ruroku/domain_set.rb
88
+ - lib/ruroku/nested_base.rb
89
+ - lib/ruroku/process.rb
90
+ - lib/ruroku/process_set.rb
91
+ - lib/ruroku/release.rb
92
+ - lib/ruroku/release_set.rb
93
+ - lib/ruroku/resource_set.rb
94
+ - lib/ruroku/version.rb
95
+ - ruroku.gemspec
96
+ homepage: ''
97
+ licenses: []
98
+ post_install_message:
99
+ rdoc_options: []
100
+ require_paths:
101
+ - lib
102
+ required_ruby_version: !ruby/object:Gem::Requirement
103
+ none: false
104
+ requirements:
105
+ - - ! '>='
106
+ - !ruby/object:Gem::Version
107
+ version: '0'
108
+ segments:
109
+ - 0
110
+ hash: 2659213015072619677
111
+ required_rubygems_version: !ruby/object:Gem::Requirement
112
+ none: false
113
+ requirements:
114
+ - - ! '>='
115
+ - !ruby/object:Gem::Version
116
+ version: '0'
117
+ segments:
118
+ - 0
119
+ hash: 2659213015072619677
120
+ requirements: []
121
+ rubyforge_project:
122
+ rubygems_version: 1.8.23
123
+ signing_key:
124
+ specification_version: 3
125
+ summary: Ruby client for the Heroku API
126
+ test_files: []