vagrant_cloud 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/LICENSE +21 -0
- data/README.md +4 -0
- data/lib/vagrant_cloud/account.rb +56 -0
- data/lib/vagrant_cloud/box.rb +63 -0
- data/lib/vagrant_cloud/provider.rb +47 -0
- data/lib/vagrant_cloud/version.rb +76 -0
- data/lib/vagrant_cloud.rb +8 -0
- metadata +78 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: bdd043af5670ef6a78487763aeabe0f860bf23b6
|
4
|
+
data.tar.gz: 4776927f8b2d0fedf242cc026a57ec36ad4b9384
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 53dcd676d20dcbb30a3f16055c18a700c17b304c60f5b810f5305cdb7dfb1a0b16841c674c66e47ab50919dc3a62ecee03f593bce6c05846e6eaac754fb69666
|
7
|
+
data.tar.gz: d751eb2f840bfa329f7ef9550c7d8bdd79fd43c22b309414e577b3933b13b64ea1494a612dd97b035b859a577cf190412ae170be9b63c2b3ab1afc9db2ddcd0e
|
data/LICENSE
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2014 Cargo Media
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
13
|
+
copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
21
|
+
SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,56 @@
|
|
1
|
+
module VagrantCloud
|
2
|
+
|
3
|
+
class Account
|
4
|
+
|
5
|
+
attr_accessor :username
|
6
|
+
attr_accessor :access_token
|
7
|
+
|
8
|
+
def initialize(username, access_token)
|
9
|
+
@username = username
|
10
|
+
@access_token = access_token
|
11
|
+
end
|
12
|
+
|
13
|
+
def get_box(name, data = nil)
|
14
|
+
Box.new(self, name, data)
|
15
|
+
end
|
16
|
+
|
17
|
+
def create_box(name, description = nil)
|
18
|
+
params = {:name => name}
|
19
|
+
params[:description] = description if description
|
20
|
+
params[:short_description] = description if description
|
21
|
+
data = request('post', '/boxes', {:box => params})
|
22
|
+
get_box(name, data)
|
23
|
+
end
|
24
|
+
|
25
|
+
def ensure_box(name, description = nil)
|
26
|
+
begin
|
27
|
+
box = get_box(name)
|
28
|
+
box.data
|
29
|
+
rescue RestClient::ResourceNotFound => e
|
30
|
+
box = create_box(name, description)
|
31
|
+
end
|
32
|
+
if description and (description != box.description || description != box.description_short)
|
33
|
+
box.update(description)
|
34
|
+
end
|
35
|
+
box
|
36
|
+
end
|
37
|
+
|
38
|
+
def request(method, path, params = {})
|
39
|
+
params[:access_token] = access_token
|
40
|
+
arg = {:params => params}
|
41
|
+
arg = params if ['post', 'put'].include? method # Weird rest_client api
|
42
|
+
result = RestClient.send(method, url_base + path, arg)
|
43
|
+
result = JSON.parse(result)
|
44
|
+
errors = result['errors']
|
45
|
+
raise "Vagrant Cloud returned error: #{errors}" if errors
|
46
|
+
result
|
47
|
+
end
|
48
|
+
|
49
|
+
private
|
50
|
+
|
51
|
+
def url_base
|
52
|
+
'https://vagrantcloud.com/api/v1'
|
53
|
+
end
|
54
|
+
|
55
|
+
end
|
56
|
+
end
|
@@ -0,0 +1,63 @@
|
|
1
|
+
module VagrantCloud
|
2
|
+
|
3
|
+
class Box
|
4
|
+
|
5
|
+
attr_accessor :account
|
6
|
+
attr_accessor :name
|
7
|
+
attr_accessor :data
|
8
|
+
|
9
|
+
def initialize(account, name, data = nil)
|
10
|
+
@account = account
|
11
|
+
@name = name
|
12
|
+
@data = data
|
13
|
+
end
|
14
|
+
|
15
|
+
def description
|
16
|
+
data['description_markdown']
|
17
|
+
end
|
18
|
+
|
19
|
+
def description_short
|
20
|
+
data['short_description']
|
21
|
+
end
|
22
|
+
|
23
|
+
def versions
|
24
|
+
data['versions'].map { |data| Version.new(self, data['number'], data) }
|
25
|
+
end
|
26
|
+
|
27
|
+
def data
|
28
|
+
@data ||= account.request('get', "/box/#{account.username}/#{name}")
|
29
|
+
end
|
30
|
+
|
31
|
+
def update(description)
|
32
|
+
box = {:short_description => description, :description => description}
|
33
|
+
@data = account.request('put', "/box/#{account.username}/#{name}", {:box => box})
|
34
|
+
end
|
35
|
+
|
36
|
+
def delete
|
37
|
+
account.request('delete', "/box/#{account.username}/#{name}")
|
38
|
+
end
|
39
|
+
|
40
|
+
def get_version(number, data = nil)
|
41
|
+
Version.new(self, number, data)
|
42
|
+
end
|
43
|
+
|
44
|
+
def create_version(name, description = nil)
|
45
|
+
params = {:version => name}
|
46
|
+
params[:description] = description if description
|
47
|
+
data = account.request('post', "/box/#{account.username}/#{self.name}/versions", {:version => params})
|
48
|
+
get_version(data['number'], data)
|
49
|
+
end
|
50
|
+
|
51
|
+
def ensure_version(name, description = nil)
|
52
|
+
version = versions.select{ |version| version.version == name }.first
|
53
|
+
unless version
|
54
|
+
version = create_version(name, description)
|
55
|
+
end
|
56
|
+
if description and (description != version.description)
|
57
|
+
version.update(description)
|
58
|
+
end
|
59
|
+
version
|
60
|
+
end
|
61
|
+
|
62
|
+
end
|
63
|
+
end
|
@@ -0,0 +1,47 @@
|
|
1
|
+
module VagrantCloud
|
2
|
+
|
3
|
+
class Provider
|
4
|
+
|
5
|
+
attr_accessor :version
|
6
|
+
attr_accessor :name
|
7
|
+
attr_accessor :data
|
8
|
+
|
9
|
+
def initialize(version, name, data = nil)
|
10
|
+
@version = version
|
11
|
+
@name = name
|
12
|
+
@data = data
|
13
|
+
end
|
14
|
+
|
15
|
+
def url
|
16
|
+
data['original_url']
|
17
|
+
end
|
18
|
+
|
19
|
+
def download_url
|
20
|
+
data['download_url']
|
21
|
+
end
|
22
|
+
|
23
|
+
def data
|
24
|
+
@data ||= account.request('get', "/box/#{account.username}/#{box.name}/version/#{version.number}/provider/#{name}")
|
25
|
+
end
|
26
|
+
|
27
|
+
def update(url)
|
28
|
+
params = {:url => url}
|
29
|
+
@data = account.request('put', "/box/#{account.username}/#{box.name}/version/#{version.number}/provider/#{name}", {:provider => params})
|
30
|
+
end
|
31
|
+
|
32
|
+
def delete
|
33
|
+
account.request('delete', "/box/#{account.username}/#{box.name}/version/#{version.number}/provider/#{name}")
|
34
|
+
end
|
35
|
+
|
36
|
+
private
|
37
|
+
|
38
|
+
def box
|
39
|
+
version.box
|
40
|
+
end
|
41
|
+
|
42
|
+
def account
|
43
|
+
box.account
|
44
|
+
end
|
45
|
+
|
46
|
+
end
|
47
|
+
end
|
@@ -0,0 +1,76 @@
|
|
1
|
+
module VagrantCloud
|
2
|
+
|
3
|
+
class Version
|
4
|
+
|
5
|
+
attr_accessor :box
|
6
|
+
attr_accessor :number
|
7
|
+
attr_accessor :data
|
8
|
+
|
9
|
+
def initialize(box, number, data = nil)
|
10
|
+
@box = box
|
11
|
+
@number = number
|
12
|
+
@data = data
|
13
|
+
end
|
14
|
+
|
15
|
+
def version
|
16
|
+
data['version']
|
17
|
+
end
|
18
|
+
|
19
|
+
def description
|
20
|
+
data['description_markdown']
|
21
|
+
end
|
22
|
+
|
23
|
+
def providers
|
24
|
+
data['providers'].map { |data| Provider.new(self, data['name'], data) }
|
25
|
+
end
|
26
|
+
|
27
|
+
def data
|
28
|
+
@data ||= account.request('get', "/box/#{account.username}/#{box.name}/version/#{number}")
|
29
|
+
end
|
30
|
+
|
31
|
+
def update(description)
|
32
|
+
version = {:description => description}
|
33
|
+
@data = account.request('put', "/box/#{account.username}/#{box.name}/version/#{number}", {:version => version})
|
34
|
+
end
|
35
|
+
|
36
|
+
def delete
|
37
|
+
account.request('delete', "/box/#{account.username}/#{box.name}/version/#{number}")
|
38
|
+
end
|
39
|
+
|
40
|
+
def release
|
41
|
+
@data = account.request('put', "/box/#{account.username}/#{box.name}/version/#{number}/release")
|
42
|
+
end
|
43
|
+
|
44
|
+
def revoke
|
45
|
+
@data = account.request('put', "/box/#{account.username}/#{box.name}/version/#{number}/revoke")
|
46
|
+
end
|
47
|
+
|
48
|
+
def get_provider(name, data = nil)
|
49
|
+
Provider.new(self, name, data)
|
50
|
+
end
|
51
|
+
|
52
|
+
def create_provider(name, url)
|
53
|
+
params = {:name => name, :url => url}
|
54
|
+
data = account.request('post', "/box/#{account.username}/#{box.name}/version/#{self.number}/providers", {:provider => params})
|
55
|
+
get_provider(name, data)
|
56
|
+
end
|
57
|
+
|
58
|
+
def ensure_provider(name, url)
|
59
|
+
provider = providers.select{ |provider| provider.name == name }.first
|
60
|
+
unless provider
|
61
|
+
provider = create_provider(name, url)
|
62
|
+
end
|
63
|
+
if url != provider.url
|
64
|
+
provider.update(url)
|
65
|
+
end
|
66
|
+
provider
|
67
|
+
end
|
68
|
+
|
69
|
+
private
|
70
|
+
|
71
|
+
def account
|
72
|
+
box.account
|
73
|
+
end
|
74
|
+
|
75
|
+
end
|
76
|
+
end
|
metadata
ADDED
@@ -0,0 +1,78 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: vagrant_cloud
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Cargo Media
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2014-04-03 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: rest_client
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
description: Very minimalistic ruby wrapper for the Vagrant Cloud API
|
42
|
+
email: hello@cargomedia.ch
|
43
|
+
executables: []
|
44
|
+
extensions: []
|
45
|
+
extra_rdoc_files: []
|
46
|
+
files:
|
47
|
+
- LICENSE
|
48
|
+
- README.md
|
49
|
+
- lib/vagrant_cloud.rb
|
50
|
+
- lib/vagrant_cloud/account.rb
|
51
|
+
- lib/vagrant_cloud/box.rb
|
52
|
+
- lib/vagrant_cloud/provider.rb
|
53
|
+
- lib/vagrant_cloud/version.rb
|
54
|
+
homepage: https://github.com/cargomedia/vagrant_cloud
|
55
|
+
licenses:
|
56
|
+
- MIT
|
57
|
+
metadata: {}
|
58
|
+
post_install_message:
|
59
|
+
rdoc_options: []
|
60
|
+
require_paths:
|
61
|
+
- lib
|
62
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
63
|
+
requirements:
|
64
|
+
- - ">="
|
65
|
+
- !ruby/object:Gem::Version
|
66
|
+
version: '0'
|
67
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
68
|
+
requirements:
|
69
|
+
- - ">="
|
70
|
+
- !ruby/object:Gem::Version
|
71
|
+
version: '0'
|
72
|
+
requirements: []
|
73
|
+
rubyforge_project:
|
74
|
+
rubygems_version: 2.2.2
|
75
|
+
signing_key:
|
76
|
+
specification_version: 4
|
77
|
+
summary: Vagrant Cloud API wrapper
|
78
|
+
test_files: []
|