Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Method naming conventions #61

Merged
merged 5 commits into from
Feb 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions bin/lint
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
#!/usr/bin/env bash
bundle exec rubocop $@
27 changes: 21 additions & 6 deletions bin/setup
Original file line number Diff line number Diff line change
@@ -1,8 +1,23 @@
#!/usr/bin/env bash
set -euo pipefail
IFS=$'\n\t'
set -vx
#!/usr/bin/env ruby
require "fileutils"

bundle install
# path to your application root.
GEM_ROOT = File.expand_path("..", __dir__)

# Do any other automated setup that you need to do here
def system!(*args)
system(*args, exception: true)
end

FileUtils.chdir GEM_ROOT do
# This script is a way to set up or update your development environment automatically.
# This script is idempotent, so that you can run it at any time and get an expectable outcome.
# Add necessary setup steps to this file.

puts "== Installing dependencies =="
system! "gem install bundler --conservative"
system("bundle check") || system!("bundle install")

# Creating useful but unversioned env files
puts "\n== Creating .env.*.local files =="
FileUtils.touch(".env.local")
end
2 changes: 2 additions & 0 deletions bin/specs
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
#!/usr/bin/env bash
bundle exec rspec $@
6 changes: 3 additions & 3 deletions lib/scalingo/auth/keys.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@

module Scalingo
class Auth::Keys < API::Endpoint
get :all, "keys"
get :show, "keys/{id}"
get :list, "keys"
get :find, "keys/{id}"
post :create, "keys", root_key: :key
delete :destroy, "keys/{id}"
delete :delete, "keys/{id}"
end
end
6 changes: 3 additions & 3 deletions lib/scalingo/auth/scm_integrations.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@

module Scalingo
class Auth::ScmIntegrations < API::Endpoint
get :all, "scm_integrations"
get :show, "scm_integrations/{id}"
get :list, "scm_integrations"
get :find, "scm_integrations/{id}"
post :create, "scm_integrations", root_key: :scm_integration
delete :destroy, "scm_integrations/{id}"
delete :delete, "scm_integrations/{id}"
end
end
8 changes: 4 additions & 4 deletions lib/scalingo/auth/tokens.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@

module Scalingo
class Auth::Tokens < API::Endpoint
post :exchange, "tokens/exchange", connected: false
get :all, "tokens"
get :list, "tokens"
post :create, "tokens", root_key: :token
patch :renew, "tokens/{id}/renew"
delete :destroy, "tokens/{id}"
delete :delete, "tokens/{id}"
post :exchange, "tokens/exchange", connected: false
put :renew, "tokens/{id}/renew"
end
end
2 changes: 1 addition & 1 deletion lib/scalingo/auth/user.rb
ksol marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

module Scalingo
class Auth::User < API::Endpoint
get :self, "users/self"
get :find, "users/self"
put :update, "users/account", root_key: :user
post :stop_free_trial, "users/stop_free_trial"
end
Expand Down
4 changes: 1 addition & 3 deletions lib/scalingo/billing/profile.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,8 @@

module Scalingo
class Billing::Profile < API::Endpoint
get :show, "profile"
get :find, "profile"
post :create, "profiles", root_key: :profile
put :update, "profiles/{id}", root_key: :profile

alias_method :self, :show
end
end
5 changes: 5 additions & 0 deletions lib/scalingo/client.rb
Original file line number Diff line number Diff line change
Expand Up @@ -50,5 +50,10 @@ def db_api_osc_secnum_fr1
scalingo: self
)
end

## Helpers
def self
auth.user.find
end
end
end
8 changes: 4 additions & 4 deletions lib/scalingo/regional/addons.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@

module Scalingo
class Regional::Addons < API::Endpoint
get :for, "apps/{app_id}/addons"
get :list, "apps/{app_id}/addons"
get :find, "apps/{app_id}/addons/{id}"
post :provision, "apps/{app_id}/addons", root_key: :addon
patch :update, "apps/{app_id}/addons/{id}", root_key: :addon
delete :destroy, "apps/{app_id}/addons/{id}"
post :create, "apps/{app_id}/addons", root_key: :addon
put :update, "apps/{app_id}/addons/{id}", root_key: :addon
delete :delete, "apps/{app_id}/addons/{id}"
get :sso, "apps/{app_id}/addons/{id}/sso"
post :token, "apps/{app_id}/addons/{id}/token"
get :categories, "addon_categories", connected: false
Expand Down
13 changes: 6 additions & 7 deletions lib/scalingo/regional/apps.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,15 @@

module Scalingo
class Regional::Apps < API::Endpoint
get :all, "apps"
get :list, "apps"
get :find, "apps/{id}"
get :logs_url, "apps/{id}/logs"
post :rename, "apps/{id}/rename"
patch :update, "apps/{id}", root_key: :app
patch :transfer, "apps/{id}"
delete :destroy, "apps/{id}"

post :create, "apps", root_key: :app do |req, params|
req.headers["X-Dry-Run"] = "true" if params[:dry_run]
end
put :update, "apps/{id}", root_key: :app
delete :delete, "apps/{id}"
get :logs_url, "apps/{id}/logs"
post :rename, "apps/{id}/rename"
put :transfer, "apps/{id}"
end
end
6 changes: 3 additions & 3 deletions lib/scalingo/regional/autoscalers.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@

module Scalingo
class Regional::Autoscalers < API::Endpoint
get :for, "apps/{app_id}/autoscalers"
get :list, "apps/{app_id}/autoscalers"
get :find, "apps/{app_id}/autoscalers/{id}"
post :create, "apps/{app_id}/autoscalers", root_key: :autoscaler
patch :update, "apps/{app_id}/autoscalers/{id}", root_key: :autoscaler
delete :destroy, "apps/{app_id}/autoscalers/{id}"
put :update, "apps/{app_id}/autoscalers/{id}", root_key: :autoscaler
delete :delete, "apps/{app_id}/autoscalers/{id}"
end
end
6 changes: 3 additions & 3 deletions lib/scalingo/regional/collaborators.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@

module Scalingo
class Regional::Collaborators < API::Endpoint
get :for, "apps/{app_id}/collaborators"
get :list, "apps/{app_id}/collaborators"
post :create, "apps/{app_id}/collaborators", root_key: "collaborator"
delete :delete, "apps/{app_id}/collaborators/{id}"
get :accept, "apps/collaboration?token={token}"
post :invite, "apps/{app_id}/collaborators", root_key: "collaborator"
delete :destroy, "apps/{app_id}/collaborators/{id}"
end
end
2 changes: 1 addition & 1 deletion lib/scalingo/regional/containers.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

module Scalingo
class Regional::Containers < API::Endpoint
get :for, "apps/{app_id}/containers"
get :list, "apps/{app_id}/containers"
post :scale, "apps/{app_id}/scale", root_key: :containers
post :restart, "apps/{app_id}/restart", root_key: :scope
get :sizes, "features/container_sizes"
Expand Down
2 changes: 1 addition & 1 deletion lib/scalingo/regional/deployments.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

module Scalingo
class Regional::Deployments < API::Endpoint
get :for, "apps/{app_id}/deployments{?query*}", optional: [:query]
get :list, "apps/{app_id}/deployments{?query*}", optional: [:query]
get :find, "apps/{app_id}/deployments/{id}"
get :logs, "apps/{app_id}/deployments/{id}/output"
end
Expand Down
6 changes: 3 additions & 3 deletions lib/scalingo/regional/domains.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@

module Scalingo
class Regional::Domains < API::Endpoint
get :for, "apps/{app_id}/domains"
get :list, "apps/{app_id}/domains"
get :find, "apps/{app_id}/domains/{id}"
post :create, "apps/{app_id}/domains", root_key: :domain
patch :update, "apps/{app_id}/domains/{id}", root_key: :domain
delete :destroy, "apps/{app_id}/domains/{id}"
put :update, "apps/{app_id}/domains/{id}", root_key: :domain
delete :delete, "apps/{app_id}/domains/{id}"
end
end
6 changes: 3 additions & 3 deletions lib/scalingo/regional/environment.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@

module Scalingo
class Regional::Environment < API::Endpoint
get :for, "apps/{app_id}/variables"
get :list, "apps/{app_id}/variables"
post :create, "apps/{app_id}/variables", root_key: :variable
patch :update, "apps/{app_id}/variables/{id}", root_key: :variable
put :update, "apps/{app_id}/variables/{id}", root_key: :variable
delete :delete, "apps/{app_id}/variables/{id}"
put :bulk_update, "apps/{app_id}/variables", root_key: :variables
delete :destroy, "apps/{app_id}/variables/{id}"
delete :bulk_destroy, "apps/{app_id}/variables", root_key: :variable_ids, params_as_body: true
end
end
6 changes: 4 additions & 2 deletions lib/scalingo/regional/events.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
module Scalingo
class Regional::Events < API::Endpoint
get :all, "events{?query*}", optional: [:query]
get :for, "apps/{app_id}/events{?query*}", optional: [:query]
get :list, "events{?query*}", optional: [:app_id, :query] do |req, params|
# Can't rely on URI templates if we need a static part depending on a dynamic one
req.path = "apps/#{params[:app_id]}/#{req.path}" if params[:app_id]
end
get :types, "event_types"
get :categories, "event_categories"
end
Expand Down
6 changes: 3 additions & 3 deletions lib/scalingo/regional/logs.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,21 @@ module Scalingo
class Regional::Logs < API::Endpoint
get :archives, "apps/{app_id}/logs_archives"

def get(url, **params, &block)
def fetch(url, **params, &block)
request(:get, url, **params) do |req|
block&.call(req, params)
req.params[:n] = params[:n] if params[:n].present?
end
end

## Helper method to avoid having to manually chain two operations
def for(**params, &block)
def find(**params, &block)
params[:id] = params.delete(:app_id) if params[:app_id].present?
logs_response = client.apps.logs_url(**params)

return logs_response unless logs_response.success?

get(logs_response.body, **params, &block)
fetch(logs_response.body, **params, &block)
end
end
end
2 changes: 1 addition & 1 deletion lib/scalingo/regional/metrics.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

module Scalingo
class Regional::Metrics < API::Endpoint
get :list, "/apps/{app_id}/stats/{metric}{/container_type}{/container_index}", optional: [:container_type, :container_index]
get :types, "/features/metrics"
get :for, "/apps/{app_id}/stats/{metric}{/container_type}{/container_index}", optional: [:container_type, :container_index]
end
end
8 changes: 4 additions & 4 deletions lib/scalingo/regional/notifiers.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@

module Scalingo
class Regional::Notifiers < API::Endpoint
get :platforms, "/notification_platforms"
get :for, "/apps/{app_id}/notifiers"
get :list, "/apps/{app_id}/notifiers"
get :find, "/apps/{app_id}/notifiers/{id}"
post :create, "/apps/{app_id}/notifiers", root_key: :notifier
put :update, "/apps/{app_id}/notifiers/{id}", root_key: :notifier
delete :delete, "/apps/{app_id}/notifiers/{id}"
get :platforms, "/notification_platforms"
post :test, "/apps/{app_id}/notifiers/{id}/test"
patch :update, "/apps/{app_id}/notifiers/{id}", root_key: :notifier
delete :destroy, "/apps/{app_id}/notifiers/{id}"
end
end
2 changes: 1 addition & 1 deletion lib/scalingo/regional/operations.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ module Scalingo
class Regional::Operations < API::Endpoint
get :find, "/apps/{app_id}/operations/{id}"

def get(url, **params, &block)
def fetch(url, **params, &block)
request(:get, url, **params) do |req|
block&.call(req, params)
end
Expand Down
8 changes: 4 additions & 4 deletions lib/scalingo/regional/scm_repo_links.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@

module Scalingo
class Regional::ScmRepoLinks < API::Endpoint
get :show, "/apps/{app_id}/scm_repo_link"
get :find, "/apps/{app_id}/scm_repo_link"
post :create, "/apps/{app_id}/scm_repo_link", root_key: :scm_repo_link
put :update, "/apps/{app_id}/scm_repo_link", root_key: :scm_repo_link
delete :delete, "/apps/{app_id}/scm_repo_link"
get :branches, "/apps/{app_id}/scm_repo_link/branches"
get :pulls, "/apps/{app_id}/scm_repo_link/pulls"
post :create, "/apps/{app_id}/scm_repo_link", root_key: :scm_repo_link
post :deploy, "/apps/{app_id}/scm_repo_link/manual_deploy"
post :review_app, "/apps/{app_id}/scm_repo_link/manual_review_app"
patch :update, "/apps/{app_id}/scm_repo_link", root_key: :scm_repo_link
delete :destroy, "/apps/{app_id}/scm_repo_link"
end
end
4 changes: 2 additions & 2 deletions lib/scalingo/regional_database/backups.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

module Scalingo
class RegionalDatabase::Backups < API::Endpoint
get :for, "databases/{addon_id}/backups"
get :archive, "databases/{addon_id}/backups/{id}/archive"
get :list, "databases/{addon_id}/backups"
post :create, "databases/{addon_id}/backups"
get :archive, "databases/{addon_id}/backups/{id}/archive"
end
end
12 changes: 6 additions & 6 deletions spec/scalingo/auth/keys_spec.rb
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
require "spec_helper"

RSpec.describe Scalingo::Auth::Keys, type: :endpoint do
describe "all" do
subject(:response) { instance.all(**arguments) }
describe "list" do
subject(:response) { instance.list(**arguments) }

include_examples "requires authentication"

Expand All @@ -19,8 +19,8 @@
it { is_expected.to have_requested(:post, api_path.merge("/keys")).with(body: {key: body}) }
end

describe "show" do
subject(:response) { instance.show(**arguments) }
describe "find" do
subject(:response) { instance.find(**arguments) }

let(:params) { {id: "key-id"} }

Expand All @@ -30,8 +30,8 @@
it { is_expected.to have_requested(:get, api_path.merge("/keys/key-id")) }
end

describe "destroy" do
subject(:response) { instance.destroy(**arguments) }
describe "delete" do
subject(:response) { instance.delete(**arguments) }

let(:params) { {id: "key-id"} }

Expand Down
12 changes: 6 additions & 6 deletions spec/scalingo/auth/scm_integrations_spec.rb
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
require "spec_helper"

RSpec.describe Scalingo::Auth::ScmIntegrations, type: :endpoint do
describe "all" do
subject(:response) { instance.all(**arguments) }
describe "list" do
subject(:response) { instance.list(**arguments) }

include_examples "requires authentication"

Expand All @@ -19,8 +19,8 @@
it { is_expected.to have_requested(:post, api_path.merge("/scm_integrations")).with(body: {scm_integration: body}) }
end

describe "show" do
subject(:response) { instance.show(**arguments) }
describe "find" do
subject(:response) { instance.find(**arguments) }

let(:params) { {id: "scm-integration-id"} }

Expand All @@ -30,8 +30,8 @@
it { is_expected.to have_requested(:get, api_path.merge("/scm_integrations/scm-integration-id")) }
end

describe "destroy" do
subject(:response) { instance.destroy(**arguments) }
describe "delete" do
subject(:response) { instance.delete(**arguments) }

let(:params) { {id: "scm-integration-id"} }

Expand Down
Loading