coreos-fleet-api 0.1.0
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/.travis.yml +5 -0
- data/Gemfile +5 -0
- data/Gemfile.lock +39 -0
- data/LICENSE +21 -0
- data/README.md +7 -0
- data/coreos-fleet-api.gemspec +24 -0
- data/lib/fleet_api.rb +22 -0
- data/lib/fleet_api/attributes.rb +28 -0
- data/lib/fleet_api/client.rb +123 -0
- data/lib/fleet_api/collection.rb +33 -0
- data/lib/fleet_api/mock.rb +23 -0
- data/lib/fleet_api/model.rb +7 -0
- data/lib/fleet_api/models/machine.rb +6 -0
- data/lib/fleet_api/models/machines.rb +11 -0
- data/lib/fleet_api/models/unit.rb +24 -0
- data/lib/fleet_api/models/units.rb +11 -0
- data/lib/fleet_api/paginated_collection.rb +36 -0
- data/lib/fleet_api/requests/create_unit.rb +26 -0
- data/lib/fleet_api/requests/destroy_unit.rb +12 -0
- data/lib/fleet_api/requests/get_machines.rb +26 -0
- data/lib/fleet_api/requests/get_unit.rb +31 -0
- data/lib/fleet_api/requests/get_units.rb +25 -0
- data/lib/fleet_api/requests/update_unit.rb +37 -0
- data/lib/fleet_api/response.rb +35 -0
- data/lib/fleet_api/version.rb +3 -0
- data/spec/spec_helper.rb +19 -0
- data/spec/support/client.rb +11 -0
- data/spec/support/unit.rb +10 -0
- data/spec/units_spec.rb +27 -0
- metadata +143 -0
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,39 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
coreos-fleet-api (0.1.0)
|
5
|
+
addressable (~> 2.2)
|
6
|
+
cistern (~> 0.11)
|
7
|
+
faraday (~> 0.9)
|
8
|
+
faraday_middleware (~> 0.9)
|
9
|
+
|
10
|
+
GEM
|
11
|
+
remote: https://rubygems.org/
|
12
|
+
specs:
|
13
|
+
addressable (2.3.6)
|
14
|
+
cistern (0.11.0)
|
15
|
+
diff-lcs (1.2.5)
|
16
|
+
faraday (0.9.0)
|
17
|
+
multipart-post (>= 1.2, < 3)
|
18
|
+
faraday_middleware (0.9.1)
|
19
|
+
faraday (>= 0.7.4, < 0.10)
|
20
|
+
multipart-post (2.0.0)
|
21
|
+
rspec (3.1.0)
|
22
|
+
rspec-core (~> 3.1.0)
|
23
|
+
rspec-expectations (~> 3.1.0)
|
24
|
+
rspec-mocks (~> 3.1.0)
|
25
|
+
rspec-core (3.1.3)
|
26
|
+
rspec-support (~> 3.1.0)
|
27
|
+
rspec-expectations (3.1.1)
|
28
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
29
|
+
rspec-support (~> 3.1.0)
|
30
|
+
rspec-mocks (3.1.0)
|
31
|
+
rspec-support (~> 3.1.0)
|
32
|
+
rspec-support (3.1.0)
|
33
|
+
|
34
|
+
PLATFORMS
|
35
|
+
ruby
|
36
|
+
|
37
|
+
DEPENDENCIES
|
38
|
+
coreos-fleet-api!
|
39
|
+
rspec
|
data/LICENSE
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2014 Ian Coffey
|
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
|
13
|
+
all 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
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,24 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'fleet_api/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |gem|
|
7
|
+
gem.name = "coreos-fleet-api"
|
8
|
+
gem.version = FleetAPI::VERSION
|
9
|
+
gem.authors = ["Ian Coffey"]
|
10
|
+
gem.email = ["ian.coffey@gmail.com"]
|
11
|
+
gem.description = %q{CoreOS Fleet Alpha API Client}
|
12
|
+
gem.summary = %q{Client library for communicating with the CoreOS Alpha API}
|
13
|
+
gem.homepage = ""
|
14
|
+
|
15
|
+
gem.files = `git ls-files`.split($/)
|
16
|
+
gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
|
17
|
+
gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
|
18
|
+
gem.require_paths = ["lib"]
|
19
|
+
|
20
|
+
gem.add_dependency "faraday", "~> 0.9"
|
21
|
+
gem.add_dependency "faraday_middleware", "~> 0.9"
|
22
|
+
gem.add_dependency "cistern", "~> 0.11"
|
23
|
+
gem.add_dependency "addressable", "~> 2.2"
|
24
|
+
end
|
data/lib/fleet_api.rb
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
require 'addressable/uri'
|
2
|
+
require 'cistern'
|
3
|
+
require 'json'
|
4
|
+
require 'faraday'
|
5
|
+
require 'faraday_middleware'
|
6
|
+
require 'logger'
|
7
|
+
require 'securerandom'
|
8
|
+
|
9
|
+
require 'fleet_api/version'
|
10
|
+
|
11
|
+
module FleetAPI
|
12
|
+
autoload :Client, 'fleet_api/client'
|
13
|
+
autoload :Collection, 'fleet_api/collection'
|
14
|
+
autoload :PaginatedCollection, 'fleet_api/paginated_collection'
|
15
|
+
autoload :Model, 'fleet_api/attributes'
|
16
|
+
autoload :Response, 'fleet_api/response'
|
17
|
+
autoload :Json, "fleet_api/json"
|
18
|
+
autoload :Mock, "fleet_api/mock"
|
19
|
+
autoload :Model, "fleet_api/model"
|
20
|
+
|
21
|
+
# TODO: handle the weirdo paging
|
22
|
+
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
module FleetAPI::Attributes
|
2
|
+
def assoc_reader(name, options={})
|
3
|
+
assoc_key = options[:key] || "#{name}_id"
|
4
|
+
collection = options[:collection] || "#{name}s"
|
5
|
+
define_method(name) do
|
6
|
+
if assoc_id = self.send(assoc_key)
|
7
|
+
self.connection.send(collection).get(assoc_id)
|
8
|
+
else self.instance_variable_get("@#{name}")
|
9
|
+
end
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
def assoc_writer(name, options={})
|
14
|
+
assoc_key = options[:key] || "#{name}_id"
|
15
|
+
define_method("#{name}=") do |assoc|
|
16
|
+
if assoc.is_a?(Cistern::Model)
|
17
|
+
self.send("#{assoc_key}=", assoc.identity)
|
18
|
+
else
|
19
|
+
self.instance_variable_set("@#{name}", assoc)
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
def assoc_accessor(name, options={})
|
25
|
+
assoc_reader(name, options)
|
26
|
+
assoc_writer(name, options)
|
27
|
+
end
|
28
|
+
end
|
@@ -0,0 +1,123 @@
|
|
1
|
+
class FleetAPI::Client < Cistern::Service
|
2
|
+
model_path "fleet_api/models"
|
3
|
+
request_path "fleet_api/requests"
|
4
|
+
|
5
|
+
model "unit"
|
6
|
+
request "get_unit"
|
7
|
+
request "get_units"
|
8
|
+
request "create_unit"
|
9
|
+
request "update_unit"
|
10
|
+
request "destroy_unit"
|
11
|
+
collection "units"
|
12
|
+
|
13
|
+
model "machine"
|
14
|
+
request "get_machines"
|
15
|
+
collection "machines"
|
16
|
+
|
17
|
+
recognizes :logger, :url
|
18
|
+
|
19
|
+
class Real
|
20
|
+
attr_reader :url, :path, :connection
|
21
|
+
|
22
|
+
def initialize(options={})
|
23
|
+
@url = URI.parse(options[:url])
|
24
|
+
@logger = Logger.new(nil)
|
25
|
+
adapter = Faraday.default_adapter
|
26
|
+
|
27
|
+
@connection = Faraday.new(:url => url) do |faraday|
|
28
|
+
faraday.response :logger
|
29
|
+
faraday.response :json
|
30
|
+
faraday.request :multipart
|
31
|
+
faraday.request :json
|
32
|
+
faraday.adapter(*adapter)
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
def request(options={})
|
37
|
+
method = (options[:method] || "get").to_s.downcase.to_sym
|
38
|
+
url = Addressable::URI.parse(options[:url] || File.join(@url.to_s, options[:path] || "/"))
|
39
|
+
url.query_values = (url.query_values || {}).merge(options[:query] || {})
|
40
|
+
params = options[:params] || {}
|
41
|
+
body = options[:body]
|
42
|
+
headers = options[:headers] || {"Accept" => "application/json"}
|
43
|
+
headers.merge!("Content-Type" => "application/x-www-form-urlencoded") if !body && !params.empty?
|
44
|
+
|
45
|
+
response = @connection.send(method) do |req|
|
46
|
+
req.url(url.to_s)
|
47
|
+
req.headers.merge!(headers)
|
48
|
+
req.params.merge!(params)
|
49
|
+
req.body = body
|
50
|
+
end
|
51
|
+
|
52
|
+
FleetAPI::Response.new(
|
53
|
+
:status => response.status,
|
54
|
+
:headers => response.headers,
|
55
|
+
:body => response.body,
|
56
|
+
:request => {
|
57
|
+
:method => method,
|
58
|
+
:url => url,
|
59
|
+
:body => body,
|
60
|
+
:headers => headers,
|
61
|
+
}
|
62
|
+
).raise!
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
66
|
+
class Mock
|
67
|
+
def initialize(options={})
|
68
|
+
@url = options[:url] || "http://fleet-api.localhost"
|
69
|
+
end
|
70
|
+
|
71
|
+
def self.data
|
72
|
+
@data ||= {
|
73
|
+
:units => {},
|
74
|
+
:machines => {},
|
75
|
+
}
|
76
|
+
end
|
77
|
+
|
78
|
+
def self.reset!
|
79
|
+
@data = nil
|
80
|
+
end
|
81
|
+
|
82
|
+
def data
|
83
|
+
self.class.data
|
84
|
+
end
|
85
|
+
|
86
|
+
def response(options={})
|
87
|
+
url = options[:url] || File.join(@url.to_s, options[:path] || "/")
|
88
|
+
method = (options[:method] || :get).to_s.to_sym
|
89
|
+
status = options[:status] || 200
|
90
|
+
body = options[:body]
|
91
|
+
headers = {
|
92
|
+
"Content-Type" => "application/json; charset=utf-8"
|
93
|
+
}.merge(options[:headers] || {})
|
94
|
+
|
95
|
+
FleetAPI::Response.new(
|
96
|
+
:status => status,
|
97
|
+
:headers => headers,
|
98
|
+
:body => body,
|
99
|
+
:request => {
|
100
|
+
:method => method,
|
101
|
+
:url => url,
|
102
|
+
:body => body,
|
103
|
+
:headers => headers,
|
104
|
+
}
|
105
|
+
).raise!
|
106
|
+
end
|
107
|
+
|
108
|
+
def page(params, collection, object_root, options={})
|
109
|
+
resources = options[:resources] || self.data[collection]
|
110
|
+
page_size = (params["per_page"] || 20).to_i
|
111
|
+
page_index = (params["page"] || 1).to_i
|
112
|
+
offset = (page_index - 1) * page_size
|
113
|
+
|
114
|
+
resource_page = resources.values.reverse.slice(offset, page_size)
|
115
|
+
|
116
|
+
resource_page
|
117
|
+
end
|
118
|
+
|
119
|
+
def url_for_page(collection, token)
|
120
|
+
"<#{File.join(@url, collection.to_s)}??nextPageToken=#{token}"
|
121
|
+
end
|
122
|
+
end
|
123
|
+
end
|
@@ -0,0 +1,33 @@
|
|
1
|
+
module FleetAPI::Collection
|
2
|
+
def self.included(klass)
|
3
|
+
klass.send(:extend, FleetAPI::Collection::Attributes)
|
4
|
+
end
|
5
|
+
|
6
|
+
module Attributes
|
7
|
+
def model_root(model_root)
|
8
|
+
@model_root = model_root
|
9
|
+
end
|
10
|
+
|
11
|
+
def model_request(model_request)
|
12
|
+
@model_request = model_request
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
def model_root
|
17
|
+
self.class.instance_variable_get(:@model_root)
|
18
|
+
end
|
19
|
+
|
20
|
+
def model_request
|
21
|
+
self.class.instance_variable_get(:@model_request)
|
22
|
+
end
|
23
|
+
|
24
|
+
def get(id)
|
25
|
+
if data = connection.send(self.model_request, {"name" => id}).body[self.model_root] # hax
|
26
|
+
new(data)
|
27
|
+
else
|
28
|
+
nil
|
29
|
+
end
|
30
|
+
rescue FleetAPI::Response::NotFound
|
31
|
+
nil
|
32
|
+
end
|
33
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
module FleetAPI
|
2
|
+
class Mock
|
3
|
+
def self.uuid
|
4
|
+
SecureRandom.uuid
|
5
|
+
end
|
6
|
+
|
7
|
+
def self.random_id
|
8
|
+
existing_ids = []
|
9
|
+
|
10
|
+
while true do
|
11
|
+
id = SecureRandom.random_number(1000)
|
12
|
+
unless existing_ids.include?(id)
|
13
|
+
existing_ids << id
|
14
|
+
return id
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
def self.random_name
|
20
|
+
SecureRandom.hex(6)
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
@@ -0,0 +1,11 @@
|
|
1
|
+
class FleetAPI::Client::Machines < Cistern::Collection
|
2
|
+
include FleetAPI::Collection
|
3
|
+
include FleetAPI::PaginatedCollection
|
4
|
+
|
5
|
+
model FleetAPI::Client::Machine
|
6
|
+
|
7
|
+
model_root "machine"
|
8
|
+
model_request :get_machine
|
9
|
+
collection_root "machines"
|
10
|
+
collection_request :get_machines
|
11
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
class FleetAPI::Client::Unit < FleetAPI::Model
|
2
|
+
identity :name
|
3
|
+
|
4
|
+
attribute :machineID
|
5
|
+
attribute :currentState
|
6
|
+
attribute :desiredState
|
7
|
+
attribute :options
|
8
|
+
|
9
|
+
def save
|
10
|
+
requires :name
|
11
|
+
params = {
|
12
|
+
"desiredState" => self.desiredState,
|
13
|
+
"options" => self.options,
|
14
|
+
"name" => self.name
|
15
|
+
}
|
16
|
+
|
17
|
+
unless self.machineID # hax
|
18
|
+
request_attributes = connection.create_unit(params).body
|
19
|
+
else
|
20
|
+
params["name"] = self.name
|
21
|
+
self.connection.update_unit(params)
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
@@ -0,0 +1,11 @@
|
|
1
|
+
class FleetAPI::Client::Units < Cistern::Collection
|
2
|
+
include FleetAPI::Collection
|
3
|
+
include FleetAPI::PaginatedCollection
|
4
|
+
|
5
|
+
model FleetAPI::Client::Unit
|
6
|
+
|
7
|
+
model_root "unit"
|
8
|
+
model_request :get_unit
|
9
|
+
collection_root "units"
|
10
|
+
collection_request :get_units
|
11
|
+
end
|
@@ -0,0 +1,36 @@
|
|
1
|
+
module FleetAPI::PaginatedCollection
|
2
|
+
def self.included(klass)
|
3
|
+
klass.attribute :nextPageToken
|
4
|
+
klass.send(:extend, FleetAPI::PaginatedCollection::Attributes)
|
5
|
+
end
|
6
|
+
|
7
|
+
module FleetAPI::PaginatedCollection::Attributes
|
8
|
+
def collection_root(collection_root)
|
9
|
+
@collection_root = collection_root
|
10
|
+
end
|
11
|
+
|
12
|
+
def collection_request(collection_request)
|
13
|
+
@collection_request = collection_request
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
def collection_root
|
18
|
+
self.class.instance_variable_get(:@collection_root)
|
19
|
+
end
|
20
|
+
|
21
|
+
def collection_request
|
22
|
+
self.class.instance_variable_get(:@collection_request)
|
23
|
+
end
|
24
|
+
|
25
|
+
def next_page
|
26
|
+
all("url" => self.next_link) if self.next_link
|
27
|
+
end
|
28
|
+
|
29
|
+
def all(params={})
|
30
|
+
response = connection.send(self.collection_request, params)
|
31
|
+
|
32
|
+
collection = self.clone.load(response.body[self.collection_root])
|
33
|
+
|
34
|
+
collection
|
35
|
+
end
|
36
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
class FleetAPI::Client
|
2
|
+
class Real
|
3
|
+
def create_unit(params={})
|
4
|
+
name = params["name"]
|
5
|
+
|
6
|
+
request(
|
7
|
+
:body => params,
|
8
|
+
:method => 'PUT',
|
9
|
+
:path => "v1-alpha/units/#{name}",
|
10
|
+
)
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
class Mock
|
15
|
+
def create_unit(params={})
|
16
|
+
params['machineID'] = FleetAPI::Mock.random_id
|
17
|
+
|
18
|
+
self.data[:units][params['name']] = params
|
19
|
+
|
20
|
+
response(
|
21
|
+
:body => {"unit" => self.data[:units][params['name']]},
|
22
|
+
:status => 200,
|
23
|
+
)
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
class FleetAPI::Client
|
2
|
+
class Real
|
3
|
+
def get_machines(params={})
|
4
|
+
request(
|
5
|
+
:query => query,
|
6
|
+
:method => 'GET',
|
7
|
+
:path => "v1-alpha/machines",
|
8
|
+
)
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
12
|
+
class Mock
|
13
|
+
def get_machines(params={})
|
14
|
+
units = self.data['machines']
|
15
|
+
|
16
|
+
response(
|
17
|
+
:body => {"machines" => machines},
|
18
|
+
:status => 200,
|
19
|
+
:headers => {
|
20
|
+
"Content-Type" => "application/json; charset=utf8",
|
21
|
+
}
|
22
|
+
)
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
@@ -0,0 +1,31 @@
|
|
1
|
+
class FleetAPI::Client
|
2
|
+
class Real
|
3
|
+
def get_unit(params={})
|
4
|
+
name = params["name"]
|
5
|
+
url = params["url"]
|
6
|
+
|
7
|
+
request(
|
8
|
+
:path => "v1-alpha/units/#{name}",
|
9
|
+
:url => url,
|
10
|
+
)
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
class Mock
|
15
|
+
def get_unit(params={})
|
16
|
+
name = params['name']
|
17
|
+
|
18
|
+
if unit = self.data[:units][name]
|
19
|
+
response(
|
20
|
+
:body => {'unit' => unit},
|
21
|
+
:status => 200,
|
22
|
+
)
|
23
|
+
else
|
24
|
+
response(
|
25
|
+
:body => {"error" => "Couldn't find unit with name #{name}"},
|
26
|
+
:status => 404,
|
27
|
+
)
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
class FleetAPI::Client
|
2
|
+
class Real
|
3
|
+
def get_units(params={})
|
4
|
+
request(
|
5
|
+
:method => 'GET',
|
6
|
+
:path => "v1-alpha/units",
|
7
|
+
)
|
8
|
+
end
|
9
|
+
end
|
10
|
+
|
11
|
+
class Mock
|
12
|
+
def get_units(params={})
|
13
|
+
units = page(params, :units, "unit")
|
14
|
+
|
15
|
+
response(
|
16
|
+
:body => {"units" => units},
|
17
|
+
:status => 200,
|
18
|
+
:headers => {
|
19
|
+
"Content-Type" => "application/json; charset=utf8",
|
20
|
+
}
|
21
|
+
)
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
@@ -0,0 +1,37 @@
|
|
1
|
+
class FleetAPI::Client
|
2
|
+
class Real
|
3
|
+
def update_unit(params={})
|
4
|
+
name = params["name"]
|
5
|
+
request(
|
6
|
+
:body => params,
|
7
|
+
:method => 'PUT',
|
8
|
+
:path => "v1-alpha/units/#{name}",
|
9
|
+
)
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
class Mock
|
14
|
+
def update_unit(params={})
|
15
|
+
name = params['name']
|
16
|
+
|
17
|
+
unit = self.data[:units][name]
|
18
|
+
unless unit
|
19
|
+
response(
|
20
|
+
:body => {"error" => "Couldn't find Unit with name #{name}"},
|
21
|
+
:status => 404,
|
22
|
+
)
|
23
|
+
end
|
24
|
+
|
25
|
+
update = params.delete("unit") || {}
|
26
|
+
|
27
|
+
updated_unit = unit.merge(update)
|
28
|
+
|
29
|
+
self.data[:units][unit['name']] = updated_unit
|
30
|
+
|
31
|
+
response(
|
32
|
+
:body => {"unit" => updated_unit},
|
33
|
+
:status => 204,
|
34
|
+
)
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
@@ -0,0 +1,35 @@
|
|
1
|
+
class FleetAPI::Response
|
2
|
+
attr_reader :headers, :status, :body, :request
|
3
|
+
|
4
|
+
def initialize(options={})
|
5
|
+
@status = options[:status]
|
6
|
+
@headers = options[:headers]
|
7
|
+
@body = options[:body]
|
8
|
+
@request = options[:request]
|
9
|
+
end
|
10
|
+
|
11
|
+
def successful?
|
12
|
+
self.status.to_s =~ /(2\d\d|304)/
|
13
|
+
end
|
14
|
+
|
15
|
+
def raise!
|
16
|
+
if !successful?
|
17
|
+
raise((ClientError).new(self))
|
18
|
+
else self
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
class ClientError < StandardError
|
23
|
+
attr_reader :response
|
24
|
+
|
25
|
+
def initialize(response)
|
26
|
+
@response = response
|
27
|
+
super({
|
28
|
+
:body => response.body,
|
29
|
+
:headers => response.headers,
|
30
|
+
:request => response.request,
|
31
|
+
:status => response.status,
|
32
|
+
}.inspect)
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
Bundler.require(:test)
|
2
|
+
Bundler.require(:darwin) if RUBY_PLATFORM.match(/darwin/)
|
3
|
+
require File.expand_path("../../lib/fleet_api", __FILE__)
|
4
|
+
Dir[File.expand_path("../{shared,support}/*.rb", __FILE__)].each{|f| require(f)}
|
5
|
+
|
6
|
+
FleetAPI::Client.mock!
|
7
|
+
|
8
|
+
FleetAPI::Client::Mock.timeout = 0
|
9
|
+
FleetAPI::Client::Mock.poll_interval = 0
|
10
|
+
FleetAPI::Client::Real.timeout = 10
|
11
|
+
|
12
|
+
RSpec.configure do |config|
|
13
|
+
config.order = :random
|
14
|
+
|
15
|
+
config.before(:each) do
|
16
|
+
FleetAPI::Client.mocking? ? FleetAPI::Client.reset! : client.reset!
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
data/spec/units_spec.rb
ADDED
@@ -0,0 +1,27 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe 'units' do
|
4
|
+
let!(:client) { create_client }
|
5
|
+
|
6
|
+
it 'can create a new unit' do
|
7
|
+
unit = create_unit('name' => 'dude')
|
8
|
+
expect(unit).to be
|
9
|
+
end
|
10
|
+
|
11
|
+
it 'can GET a list of units' do
|
12
|
+
create_unit(
|
13
|
+
'name' => 'faux_1',
|
14
|
+
)
|
15
|
+
create_unit(
|
16
|
+
'name' => 'faux_2',
|
17
|
+
)
|
18
|
+
|
19
|
+
expect(client.units.all.count).to eq(2)
|
20
|
+
end
|
21
|
+
|
22
|
+
it "can show a unit" do
|
23
|
+
unit = create_unit('name' => 'fred')
|
24
|
+
name = unit['name']
|
25
|
+
expect(client.units.get(name)).to be
|
26
|
+
end
|
27
|
+
end
|
metadata
ADDED
@@ -0,0 +1,143 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: coreos-fleet-api
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Ian Coffey
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2014-09-18 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: faraday
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ~>
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: '0.9'
|
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.9'
|
30
|
+
- !ruby/object:Gem::Dependency
|
31
|
+
name: faraday_middleware
|
32
|
+
requirement: !ruby/object:Gem::Requirement
|
33
|
+
none: false
|
34
|
+
requirements:
|
35
|
+
- - ~>
|
36
|
+
- !ruby/object:Gem::Version
|
37
|
+
version: '0.9'
|
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: '0.9'
|
46
|
+
- !ruby/object:Gem::Dependency
|
47
|
+
name: cistern
|
48
|
+
requirement: !ruby/object:Gem::Requirement
|
49
|
+
none: false
|
50
|
+
requirements:
|
51
|
+
- - ~>
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
version: '0.11'
|
54
|
+
type: :runtime
|
55
|
+
prerelease: false
|
56
|
+
version_requirements: !ruby/object:Gem::Requirement
|
57
|
+
none: false
|
58
|
+
requirements:
|
59
|
+
- - ~>
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0.11'
|
62
|
+
- !ruby/object:Gem::Dependency
|
63
|
+
name: addressable
|
64
|
+
requirement: !ruby/object:Gem::Requirement
|
65
|
+
none: false
|
66
|
+
requirements:
|
67
|
+
- - ~>
|
68
|
+
- !ruby/object:Gem::Version
|
69
|
+
version: '2.2'
|
70
|
+
type: :runtime
|
71
|
+
prerelease: false
|
72
|
+
version_requirements: !ruby/object:Gem::Requirement
|
73
|
+
none: false
|
74
|
+
requirements:
|
75
|
+
- - ~>
|
76
|
+
- !ruby/object:Gem::Version
|
77
|
+
version: '2.2'
|
78
|
+
description: CoreOS Fleet Alpha API Client
|
79
|
+
email:
|
80
|
+
- ian.coffey@gmail.com
|
81
|
+
executables: []
|
82
|
+
extensions: []
|
83
|
+
extra_rdoc_files: []
|
84
|
+
files:
|
85
|
+
- .travis.yml
|
86
|
+
- Gemfile
|
87
|
+
- Gemfile.lock
|
88
|
+
- LICENSE
|
89
|
+
- README.md
|
90
|
+
- coreos-fleet-api.gemspec
|
91
|
+
- lib/fleet_api.rb
|
92
|
+
- lib/fleet_api/attributes.rb
|
93
|
+
- lib/fleet_api/client.rb
|
94
|
+
- lib/fleet_api/collection.rb
|
95
|
+
- lib/fleet_api/mock.rb
|
96
|
+
- lib/fleet_api/model.rb
|
97
|
+
- lib/fleet_api/models/machine.rb
|
98
|
+
- lib/fleet_api/models/machines.rb
|
99
|
+
- lib/fleet_api/models/unit.rb
|
100
|
+
- lib/fleet_api/models/units.rb
|
101
|
+
- lib/fleet_api/paginated_collection.rb
|
102
|
+
- lib/fleet_api/requests/create_unit.rb
|
103
|
+
- lib/fleet_api/requests/destroy_unit.rb
|
104
|
+
- lib/fleet_api/requests/get_machines.rb
|
105
|
+
- lib/fleet_api/requests/get_unit.rb
|
106
|
+
- lib/fleet_api/requests/get_units.rb
|
107
|
+
- lib/fleet_api/requests/update_unit.rb
|
108
|
+
- lib/fleet_api/response.rb
|
109
|
+
- lib/fleet_api/version.rb
|
110
|
+
- spec/spec_helper.rb
|
111
|
+
- spec/support/client.rb
|
112
|
+
- spec/support/unit.rb
|
113
|
+
- spec/units_spec.rb
|
114
|
+
homepage: ''
|
115
|
+
licenses: []
|
116
|
+
post_install_message:
|
117
|
+
rdoc_options: []
|
118
|
+
require_paths:
|
119
|
+
- lib
|
120
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
121
|
+
none: false
|
122
|
+
requirements:
|
123
|
+
- - '>='
|
124
|
+
- !ruby/object:Gem::Version
|
125
|
+
version: '0'
|
126
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
127
|
+
none: false
|
128
|
+
requirements:
|
129
|
+
- - '>='
|
130
|
+
- !ruby/object:Gem::Version
|
131
|
+
version: '0'
|
132
|
+
requirements: []
|
133
|
+
rubyforge_project:
|
134
|
+
rubygems_version: 1.8.25
|
135
|
+
signing_key:
|
136
|
+
specification_version: 3
|
137
|
+
summary: Client library for communicating with the CoreOS Alpha API
|
138
|
+
test_files:
|
139
|
+
- spec/spec_helper.rb
|
140
|
+
- spec/support/client.rb
|
141
|
+
- spec/support/unit.rb
|
142
|
+
- spec/units_spec.rb
|
143
|
+
has_rdoc:
|