atlas 1.1.0 → 1.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.codeclimate.yml +13 -0
- data/CHANGELOG.md +8 -2
- data/README.md +16 -3
- data/Rakefile +9 -0
- data/atlas.gemspec +2 -0
- data/lib/atlas.rb +1 -0
- data/lib/atlas/box.rb +4 -6
- data/lib/atlas/box_provider.rb +5 -7
- data/lib/atlas/box_version.rb +7 -9
- data/lib/atlas/client.rb +18 -4
- data/lib/atlas/errors.rb +25 -0
- data/lib/atlas/resource.rb +3 -5
- data/lib/atlas/user.rb +1 -1
- data/lib/atlas/version.rb +1 -1
- metadata +32 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: bfcc9c5fb98681ad07faaaf69d275418c22b1ea4
|
4
|
+
data.tar.gz: 55823eb3defae3a970ceb99b298e636fb90cd2b0
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b04a692cdba04c4b6f6bf5986acd7840eadd74493a696d777af8377ee57a3e3b20d2e558ce0e908653a6f74740ee60b11cb6ed9335210839e6dd183b3c898913
|
7
|
+
data.tar.gz: ae9887e9120916d97b94404523dbbb9c7db8340168a483afca4be1244f8a403c1253a78f8fa1659f323247f64039298f7a25fdee598d0c70951318d0dbf411ee
|
data/.codeclimate.yml
ADDED
data/CHANGELOG.md
CHANGED
@@ -1,12 +1,18 @@
|
|
1
1
|
# CHANGELOG
|
2
2
|
|
3
|
-
## 1.
|
3
|
+
## 1.2.0 (29/07/2015)
|
4
|
+
|
5
|
+
* Adds custom error classes and catching in the request.
|
6
|
+
* Moves the JSON response parsing into the request, removing from the
|
7
|
+
resources.
|
8
|
+
|
9
|
+
## 1.1.0 (27/07/2015)
|
4
10
|
|
5
11
|
* Adds support for uploading boxes to providers.
|
6
12
|
* Adds shorter methods to create versions from boxes, and providers from
|
7
13
|
versions.
|
8
14
|
|
9
|
-
## 1.0.0
|
15
|
+
## 1.0.0 (24/07/2015)
|
10
16
|
|
11
17
|
* Initial release; handles creating, updating, deleting boxes, versions and
|
12
18
|
providers.
|
data/README.md
CHANGED
@@ -35,13 +35,26 @@ end
|
|
35
35
|
# then you can load in users (creating, updating, etc isn't supported by Atlas)
|
36
36
|
user = Atlas::User.find('nickcharlton')
|
37
37
|
#=> <Atlas::User username=nickcharlton...>
|
38
|
+
```
|
39
|
+
|
40
|
+
More likely, you'll want to grab a box and work with it:
|
38
41
|
|
39
|
-
|
42
|
+
```ruby
|
40
43
|
box = Atlas::Box.find('nickcharlton/example-box')
|
41
44
|
#=> <Atlas::Box name=example-box'...>
|
42
45
|
|
43
|
-
#
|
44
|
-
version = box.
|
46
|
+
# creating a new version
|
47
|
+
version = box.create_version(version: '1.0.0')
|
48
|
+
#=> <Atlas::BoxVersion version: '1.0.0')
|
49
|
+
|
50
|
+
# add a provider to that version
|
51
|
+
provider = version.create_provider(name: 'virtualbox')
|
52
|
+
|
53
|
+
# upload a file for the version
|
54
|
+
provider.upload(File.open('box_name.box'))
|
55
|
+
|
56
|
+
# set the version to be released
|
57
|
+
version.release
|
45
58
|
```
|
46
59
|
|
47
60
|
It aims to support most of the functionality listed in the [Atlas API
|
data/Rakefile
CHANGED
@@ -16,6 +16,15 @@ require 'rspec/core/rake_task'
|
|
16
16
|
|
17
17
|
RSpec::Core::RakeTask.new
|
18
18
|
|
19
|
+
##
|
20
|
+
# RuboCop
|
21
|
+
##
|
22
|
+
require 'rubocop/rake_task'
|
23
|
+
|
24
|
+
RuboCop::RakeTask.new do |task|
|
25
|
+
task.requires << 'rubocop-rspec'
|
26
|
+
end
|
27
|
+
|
19
28
|
##
|
20
29
|
# By default, just run the tests.
|
21
30
|
##
|
data/atlas.gemspec
CHANGED
@@ -26,5 +26,7 @@ Gem::Specification.new do |spec|
|
|
26
26
|
spec.add_development_dependency 'rake', '~> 10.0'
|
27
27
|
spec.add_development_dependency 'vcr', '~> 2.9'
|
28
28
|
spec.add_development_dependency 'rspec', '~> 3.2'
|
29
|
+
spec.add_development_dependency 'rubocop', '~> 0.32'
|
30
|
+
spec.add_development_dependency 'rubocop-rspec', '~> 1.3'
|
29
31
|
spec.add_development_dependency 'pry'
|
30
32
|
end
|
data/lib/atlas.rb
CHANGED
data/lib/atlas/box.rb
CHANGED
@@ -22,7 +22,7 @@ module Atlas
|
|
22
22
|
url_builder = UrlBuilder.new tag
|
23
23
|
response = Atlas.client.get(url_builder.box_url)
|
24
24
|
|
25
|
-
new(tag,
|
25
|
+
new(tag, response)
|
26
26
|
end
|
27
27
|
|
28
28
|
# Create a new Box.
|
@@ -113,23 +113,21 @@ module Atlas
|
|
113
113
|
# update or create the box
|
114
114
|
begin
|
115
115
|
response = Atlas.client.put(url_builder.box_url, body: body)
|
116
|
-
rescue
|
116
|
+
rescue Atlas::Errors::NotFoundError
|
117
117
|
response = Atlas.client.post('/boxes', body: body)
|
118
118
|
end
|
119
119
|
|
120
120
|
# trigger the same on versions
|
121
121
|
versions.each(&:save) if versions
|
122
122
|
|
123
|
-
update_with_response(response
|
123
|
+
update_with_response(response, [:versions])
|
124
124
|
end
|
125
125
|
|
126
126
|
# Delete the box.
|
127
127
|
#
|
128
128
|
# @return [Hash] response body from Atlas.
|
129
129
|
def delete
|
130
|
-
|
131
|
-
|
132
|
-
JSON.parse(response.body)
|
130
|
+
Atlas.client.delete(url_builder.box_url)
|
133
131
|
end
|
134
132
|
end
|
135
133
|
end
|
data/lib/atlas/box_provider.rb
CHANGED
@@ -15,7 +15,7 @@ module Atlas
|
|
15
15
|
url_builder = UrlBuilder.new tag
|
16
16
|
response = Atlas.client.get(url_builder.box_provider_url)
|
17
17
|
|
18
|
-
new(tag,
|
18
|
+
new(tag, response)
|
19
19
|
end
|
20
20
|
|
21
21
|
# Create a new Provider.
|
@@ -55,12 +55,12 @@ module Atlas
|
|
55
55
|
|
56
56
|
begin
|
57
57
|
response = Atlas.client.put(url_builder.box_provider_url, body: body)
|
58
|
-
rescue
|
58
|
+
rescue Atlas::Errors::NotFoundError
|
59
59
|
response = Atlas.client.post("#{url_builder.box_version_url}/providers",
|
60
60
|
body: body)
|
61
61
|
end
|
62
62
|
|
63
|
-
update_with_response(response
|
63
|
+
update_with_response(response)
|
64
64
|
end
|
65
65
|
|
66
66
|
# Upload a .box file for this provider.
|
@@ -71,7 +71,7 @@ module Atlas
|
|
71
71
|
response = Atlas.client.get("#{url_builder.box_provider_url}/upload")
|
72
72
|
|
73
73
|
# upload the file
|
74
|
-
upload_url =
|
74
|
+
upload_url = response['upload_path']
|
75
75
|
Excon.put(upload_url, body: file)
|
76
76
|
end
|
77
77
|
|
@@ -79,9 +79,7 @@ module Atlas
|
|
79
79
|
#
|
80
80
|
# @return [Hash] Atlas response object.
|
81
81
|
def delete
|
82
|
-
|
83
|
-
|
84
|
-
JSON.parse(response.body)
|
82
|
+
Atlas.client.delete(url_builder.box_provider_url)
|
85
83
|
end
|
86
84
|
end
|
87
85
|
end
|
data/lib/atlas/box_version.rb
CHANGED
@@ -20,7 +20,7 @@ module Atlas
|
|
20
20
|
url_builder = UrlBuilder.new tag
|
21
21
|
response = Atlas.client.get(url_builder.box_version_url)
|
22
22
|
|
23
|
-
new(tag,
|
23
|
+
new(tag, response)
|
24
24
|
end
|
25
25
|
|
26
26
|
# Create a new version.
|
@@ -74,7 +74,7 @@ module Atlas
|
|
74
74
|
# Save the version.
|
75
75
|
#
|
76
76
|
# @return [Hash] Atlas response object.
|
77
|
-
def save # rubocop:disable Metrics/
|
77
|
+
def save # rubocop:disable Metrics/AbcSize
|
78
78
|
body = { version: to_hash }
|
79
79
|
|
80
80
|
# providers are saved seperately
|
@@ -82,7 +82,7 @@ module Atlas
|
|
82
82
|
|
83
83
|
begin
|
84
84
|
response = Atlas.client.put(url_builder.box_version_url, body: body)
|
85
|
-
rescue
|
85
|
+
rescue Atlas::Errors::NotFoundError
|
86
86
|
response = Atlas.client.post("#{url_builder.box_url}/versions",
|
87
87
|
body: body)
|
88
88
|
end
|
@@ -90,7 +90,7 @@ module Atlas
|
|
90
90
|
# trigger the same on the providers
|
91
91
|
providers.each(&:save) if providers
|
92
92
|
|
93
|
-
update_with_response(response
|
93
|
+
update_with_response(response, [:providers])
|
94
94
|
end
|
95
95
|
|
96
96
|
# Release the version.
|
@@ -99,7 +99,7 @@ module Atlas
|
|
99
99
|
def release
|
100
100
|
response = Atlas.client.put("#{url_builder.box_version_url}/release")
|
101
101
|
|
102
|
-
update_with_response(response
|
102
|
+
update_with_response(response)
|
103
103
|
end
|
104
104
|
|
105
105
|
# Revoke the version.
|
@@ -108,16 +108,14 @@ module Atlas
|
|
108
108
|
def revoke
|
109
109
|
response = Atlas.client.put("#{url_builder.box_version_url}/revoke")
|
110
110
|
|
111
|
-
update_with_response(response
|
111
|
+
update_with_response(response)
|
112
112
|
end
|
113
113
|
|
114
114
|
# Delete the version.
|
115
115
|
#
|
116
116
|
# @return [Hash] Atlas response object.
|
117
117
|
def delete
|
118
|
-
|
119
|
-
|
120
|
-
JSON.parse(response.body)
|
118
|
+
Atlas.client.delete(url_builder.box_version_url)
|
121
119
|
end
|
122
120
|
end
|
123
121
|
end
|
data/lib/atlas/client.rb
CHANGED
@@ -1,6 +1,8 @@
|
|
1
1
|
module Atlas
|
2
2
|
# Client for interacting with the Atlas API.
|
3
3
|
class Client
|
4
|
+
include Atlas::Errors
|
5
|
+
|
4
6
|
DEFAULT_HEADERS = { 'User-Agent' => "Atlas-Ruby/#{Atlas::VERSION}",
|
5
7
|
'Content-Type' => 'application/json' }
|
6
8
|
|
@@ -19,7 +21,7 @@ module Atlas
|
|
19
21
|
|
20
22
|
private
|
21
23
|
|
22
|
-
def request(method, path, opts = {})
|
24
|
+
def request(method, path, opts = {}) # rubocop:disable AbcSize, MethodLength
|
23
25
|
body, query, headers = parse_opts(opts)
|
24
26
|
|
25
27
|
# set the default headers
|
@@ -29,9 +31,21 @@ module Atlas
|
|
29
31
|
query.merge!(access_token: @access_token)
|
30
32
|
|
31
33
|
connection = Excon.new(@url)
|
32
|
-
connection.request(expects: [200, 201], method: method,
|
33
|
-
|
34
|
-
|
34
|
+
response = connection.request(expects: [200, 201], method: method,
|
35
|
+
path: "/api/v1#{path}", body: body,
|
36
|
+
query: query, headers: headers)
|
37
|
+
|
38
|
+
JSON.parse(response.body)
|
39
|
+
rescue Excon::Errors::BadRequest => e
|
40
|
+
raise ClientError, e.response.body
|
41
|
+
rescue Excon::Errors::Unauthorized => e
|
42
|
+
raise UnauthorizedError, e.response.body
|
43
|
+
rescue Excon::Errors::NotFound => e
|
44
|
+
raise NotFoundError, e.response.body
|
45
|
+
rescue Excon::Errors::InternalServerError => e
|
46
|
+
raise ServerError, e.response.body
|
47
|
+
rescue Excon::Errors::Timeout => e
|
48
|
+
raise TimeoutError, e.message
|
35
49
|
end
|
36
50
|
|
37
51
|
def parse_opts(opts)
|
data/lib/atlas/errors.rb
ADDED
@@ -0,0 +1,25 @@
|
|
1
|
+
module Atlas
|
2
|
+
# A collection of errors which can be raised by this gem.
|
3
|
+
module Errors
|
4
|
+
# Base error for all other gem errors.
|
5
|
+
class AtlasError < StandardError; end
|
6
|
+
|
7
|
+
# Raised when incorrect arguments are provided to a method.
|
8
|
+
class ArgumentError < AtlasError; end
|
9
|
+
|
10
|
+
# Raised when a request returns a 400 Bad Request.
|
11
|
+
class ClientError < AtlasError; end
|
12
|
+
|
13
|
+
# Raised when a request returns a 401 Unauthorized.
|
14
|
+
class UnauthorizedError < AtlasError; end
|
15
|
+
|
16
|
+
# Raised when a request returns a 404 Not Found.
|
17
|
+
class NotFoundError < AtlasError; end
|
18
|
+
|
19
|
+
# Raised when a request returns a 500 Server Error.
|
20
|
+
class ServerError < AtlasError; end
|
21
|
+
|
22
|
+
# Raised when a request times out.
|
23
|
+
class TimeoutError < AtlasError; end
|
24
|
+
end
|
25
|
+
end
|
data/lib/atlas/resource.rb
CHANGED
@@ -10,13 +10,11 @@ module Atlas
|
|
10
10
|
hash.each { |k, v| send("#{k}=", v) if respond_to?("#{k}=") }
|
11
11
|
end
|
12
12
|
|
13
|
-
def update_with_response(
|
14
|
-
hash = JSON.parse(o)
|
15
|
-
|
13
|
+
def update_with_response(response, except_keys = [])
|
16
14
|
# remove keys that shouldn't be included
|
17
|
-
except_keys.each { |k|
|
15
|
+
except_keys.each { |k| response.delete(k) }
|
18
16
|
|
19
|
-
|
17
|
+
response.each { |k, v| send("#{k}=", v) if respond_to?("#{k}=") }
|
20
18
|
end
|
21
19
|
|
22
20
|
def to_hash
|
data/lib/atlas/user.rb
CHANGED
data/lib/atlas/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: atlas
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Nick Charlton
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-07-
|
11
|
+
date: 2015-07-29 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: excon
|
@@ -94,6 +94,34 @@ dependencies:
|
|
94
94
|
- - "~>"
|
95
95
|
- !ruby/object:Gem::Version
|
96
96
|
version: '3.2'
|
97
|
+
- !ruby/object:Gem::Dependency
|
98
|
+
name: rubocop
|
99
|
+
requirement: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - "~>"
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: '0.32'
|
104
|
+
type: :development
|
105
|
+
prerelease: false
|
106
|
+
version_requirements: !ruby/object:Gem::Requirement
|
107
|
+
requirements:
|
108
|
+
- - "~>"
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: '0.32'
|
111
|
+
- !ruby/object:Gem::Dependency
|
112
|
+
name: rubocop-rspec
|
113
|
+
requirement: !ruby/object:Gem::Requirement
|
114
|
+
requirements:
|
115
|
+
- - "~>"
|
116
|
+
- !ruby/object:Gem::Version
|
117
|
+
version: '1.3'
|
118
|
+
type: :development
|
119
|
+
prerelease: false
|
120
|
+
version_requirements: !ruby/object:Gem::Requirement
|
121
|
+
requirements:
|
122
|
+
- - "~>"
|
123
|
+
- !ruby/object:Gem::Version
|
124
|
+
version: '1.3'
|
97
125
|
- !ruby/object:Gem::Dependency
|
98
126
|
name: pry
|
99
127
|
requirement: !ruby/object:Gem::Requirement
|
@@ -115,6 +143,7 @@ executables: []
|
|
115
143
|
extensions: []
|
116
144
|
extra_rdoc_files: []
|
117
145
|
files:
|
146
|
+
- ".codeclimate.yml"
|
118
147
|
- ".gitignore"
|
119
148
|
- ".travis.yml"
|
120
149
|
- CHANGELOG.md
|
@@ -132,6 +161,7 @@ files:
|
|
132
161
|
- lib/atlas/box_version.rb
|
133
162
|
- lib/atlas/client.rb
|
134
163
|
- lib/atlas/configuration.rb
|
164
|
+
- lib/atlas/errors.rb
|
135
165
|
- lib/atlas/resource.rb
|
136
166
|
- lib/atlas/url_builder.rb
|
137
167
|
- lib/atlas/user.rb
|