-
Notifications
You must be signed in to change notification settings - Fork 154
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Add one click resource * Fix readme * Update .rubocop_todo.yml
- Loading branch information
1 parent
37a3b1d
commit 85a4f47
Showing
12 changed files
with
159 additions
and
5 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
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
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
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
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 @@ | ||
# frozen_string_literal: true | ||
|
||
module DropletKit | ||
class OneClickKubernetesMapping | ||
include Kartograph::DSL | ||
|
||
kartograph do | ||
mapping OneClickKubernetes | ||
|
||
scoped :create do | ||
property :addon_slugs | ||
property :cluster_uuid | ||
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,17 @@ | ||
# frozen_string_literal: true | ||
|
||
module DropletKit | ||
class OneClickMapping | ||
include Kartograph::DSL | ||
|
||
kartograph do | ||
mapping OneClick | ||
root_key plural: '1_clicks', scopes: [:read] | ||
|
||
scoped :read do | ||
property :slug | ||
property :type | ||
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,8 @@ | ||
# frozen_string_literal: true | ||
|
||
module DropletKit | ||
class OneClick < BaseModel | ||
attribute :slug | ||
attribute :type | ||
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,8 @@ | ||
# frozen_string_literal: true | ||
|
||
module DropletKit | ||
class OneClickKubernetes < BaseModel | ||
attribute :addon_slugs | ||
attribute :cluster_uuid | ||
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,23 @@ | ||
# frozen_string_literal: true | ||
|
||
module DropletKit | ||
class OneClickResource < ResourceKit::Resource | ||
include ErrorHandlingResourcable | ||
|
||
resources do | ||
action :all, 'GET /v2/1-clicks' do | ||
query_keys :type | ||
|
||
handler(200) do |response| | ||
OneClickMapping.extract_collection(response.body, :read) | ||
end | ||
end | ||
|
||
action :create_kubernetes, 'POST /v2/1-clicks/kubernetes' do | ||
body { |object| OneClickKubernetesMapping.representation_for(:create, object) } | ||
|
||
handler(200) { |response| response.body } | ||
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,12 @@ | ||
{ | ||
"1_clicks": [ | ||
{ | ||
"slug": "monitoring", | ||
"type": "kubernetes" | ||
}, | ||
{ | ||
"slug": "wordpress-18-04", | ||
"type": "droplet" | ||
} | ||
] | ||
} |
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 @@ | ||
{ "message": "Successfully kicked off addon job." } |
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,52 @@ | ||
# frozen_string_literal: true | ||
|
||
require 'spec_helper' | ||
|
||
RSpec.describe DropletKit::OneClickResource do | ||
subject(:resource) { described_class.new(connection: connection) } | ||
|
||
include_context 'resources' | ||
|
||
describe '#all' do | ||
it 'returns kubernetes 1-click apps' do | ||
stub_do_api('/v2/1-clicks?type=kubernetes', :get).to_return(body: api_fixture('one_clicks/all')) | ||
one_clicks = resource.all(type: 'kubernetes') | ||
expect(one_clicks).to all(be_a(DropletKit::OneClick)) | ||
|
||
expect(one_clicks.first.slug).to eq('monitoring') | ||
expect(one_clicks.first.type).to eq('kubernetes') | ||
end | ||
|
||
it 'returns droplet 1-click apps' do | ||
stub_do_api('/v2/1-clicks?type=droplet', :get).to_return(body: api_fixture('one_clicks/all')) | ||
one_clicks = resource.all(type: 'droplet') | ||
expect(one_clicks).to all(be_a(DropletKit::OneClick)) | ||
|
||
expect(one_clicks.last.slug).to eq('wordpress-18-04') | ||
expect(one_clicks.last.type).to eq('droplet') | ||
end | ||
|
||
it_behaves_like 'resource that handles common errors' do | ||
let(:path) { '/v2/1-clicks' } | ||
let(:method) { :get } | ||
let(:action) { :all } | ||
let(:arguments) { { type: 'kubernetes' } } | ||
end | ||
end | ||
|
||
describe '#create_kubernetes' do | ||
context 'with a successful create' do | ||
it 'returns a message' do | ||
one_click_kubernetes = DropletKit::OneClickKubernetes.new( | ||
addon_slugs: %w[slug1 slug2], | ||
cluster_uuid: '177dc8c-12c1-4483-af1c-877eed0f14cb' | ||
) | ||
|
||
json = DropletKit::OneClickKubernetesMapping.representation_for(:create, one_click_kubernetes) | ||
stub_do_api('/v2/1-clicks/kubernetes', :post).with(body: json).to_return(body: api_fixture('one_clicks/create_kubernetes'), status: 200) | ||
response = resource.create_kubernetes(one_click_kubernetes) | ||
expect(response).to eq('{ "message": "Successfully kicked off addon job." }') | ||
end | ||
end | ||
end | ||
end |