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

refactor: removes /api, /api/platform and /api/v1 slugs #71

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
4 changes: 2 additions & 2 deletions src/config.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
const DEFAULT_ACCOUNT_URL = "https://accounts.platform.sh";
const DEFAULT_API_URL = "https://api.platform.sh/api";
const DEFAULT_API_URL = "https://api.platform.sh";

const getConfigDefault = (
baseUrl = DEFAULT_ACCOUNT_URL,
api_url = DEFAULT_API_URL
) => ({
provider: "cg",
client_id: "[email protected]",
account_url: `${baseUrl}/api`,
account_url: `${baseUrl}`,
api_url,
authentication_url: baseUrl,
scope: [],
Expand Down
20 changes: 9 additions & 11 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,11 +66,9 @@ export default class Client {
}
const { account_url } = getConfig();

return request(`${account_url}/platform/projects/${id}`, "GET").then(
result => {
return result.endpoint || false;
}
);
return request(`${account_url}/projects/${id}`, "GET").then(result => {
return result.endpoint || false;
});
});
}

Expand Down Expand Up @@ -463,7 +461,7 @@ export default class Client {
if (country_code) query.country_code = country_code;
const { api_url } = getConfig();

return request(`${api_url}/v1/subscriptions/estimate`, "GET", query);
return request(`${api_url}/subscriptions/estimate`, "GET", query);
}

/**
Expand Down Expand Up @@ -629,7 +627,7 @@ export default class Client {
*/
getCardOnFile() {
const { api_url } = getConfig();
const card = request(`${api_url}/platform/cardonfile`, "GET");
const card = request(`${api_url}/cardonfile`, "GET");
return card;
}

Expand Down Expand Up @@ -731,7 +729,7 @@ export default class Client {
async updateUserProfile(id, data) {
const { api_url } = getConfig();
const updatedProfile = await request(
`${api_url}/platform/profiles/${id}`,
`${api_url}/profiles/${id}`,
"PATCH",
data
);
Expand All @@ -746,7 +744,7 @@ export default class Client {
*/
getSetupRegistry() {
const { api_url } = getConfig();
return request(`${api_url}/platform/setup/registry`, "POST").then(data => {
return request(`${api_url}/setup/registry`, "POST").then(data => {
return typeof data === "undefined"
? undefined
: Object.entries(data).reduce((items, [key, value]) => {
Expand Down Expand Up @@ -783,7 +781,7 @@ export default class Client {
*/
getSetupRegistry() {
const { api_url } = getConfig();
return request(`${api_url}/platform/setup/registry`, "POST").then(data => {
return request(`${api_url}/setup/registry`, "POST").then(data => {
return typeof data === "undefined"
? undefined
: Object.entries(data).reduce((items, [key, value]) => {
Expand Down Expand Up @@ -834,7 +832,7 @@ export default class Client {
const { api_url } = getConfig();

const user = await request(
`${api_url}/v1/profiles?filter[username]=${username}`
`${api_url}/profiles?filter[username]=${username}`
);

return new entities.AccountsProfile(user.profiles[0]);
Expand Down
2 changes: 1 addition & 1 deletion src/model/Account.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import Ressource from "./Ressource";
import { getConfig } from "../config";

const url = "/platform/users/:id";
const url = "/users/:id";
const paramDefaults = {};

export default class Account extends Ressource {
Expand Down
8 changes: 4 additions & 4 deletions src/model/AccountsProfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { getConfig } from "../config";
import request from "../api";
import _urlParser from "../urlParser";

const url = "/platform/profiles/:id";
const url = "/profiles/:id";
const paramDefaults = {};
const createableField = [
"id",
Expand Down Expand Up @@ -90,19 +90,19 @@ export default class AccountsProfile extends Ressource {
const { api_url } = getConfig();

const user = await request(
`${api_url}/v1/profiles?filter[username]=${username}`
`${api_url}/profiles?filter[username]=${username}`
);

return new AccountsProfile(user.profiles[0]);
}

static updateProfilePicture(userId, picture) {
const { api_url } = getConfig();
return request(`${api_url}/v1/profile/${userId}/picture`, "POST", picture);
return request(`${api_url}/profile/${userId}/picture`, "POST", picture);
}

static async deleteProfilePicture(userId) {
const { api_url } = getConfig();
return request(`${api_url}/v1/profile/${userId}/picture`, "DELETE");
return request(`${api_url}/profile/${userId}/picture`, "DELETE");
}
}
2 changes: 1 addition & 1 deletion src/model/Address.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import Ressource from "./Ressource";
import { getConfig } from "../config";
import _urlParser from "../urlParser";

const url = "/v1/profiles/:id/address";
const url = "/profiles/:id/address";
const paramDefaults = {};

export default class Address extends Ressource {
Expand Down
2 changes: 1 addition & 1 deletion src/model/Comment.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import Ressource from "./Ressource";
import { getConfig } from "../config";
import request from "../api";

const url = "/v1/comments";
const url = "/comments";
const paramDefaults = {};

export default class Comment extends Ressource {
Expand Down
4 changes: 2 additions & 2 deletions src/model/Me.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import User from "./User";
import Ressource from "./Ressource";
import { getConfig } from "../config";

const url = "/platform/me";
const url = "/me";
const paramDefaults = {};
const modifiableField = [
"picture",
Expand Down Expand Up @@ -46,7 +46,7 @@ export default class Me extends User {
async update(data) {
const { api_url } = getConfig();

const result = await super.update(data, `${api_url}/platform/profiles/:id`);
const result = await super.update(data, `${api_url}/profiles/:id`);

return new Me(result.data); // Account API does not return a Result
}
Expand Down
2 changes: 1 addition & 1 deletion src/model/Order.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import Ressource from "./Ressource";
import { getConfig } from "../config";

const url = "/v1/orders/:id";
const url = "/orders/:id";
const paramDefaults = {};

export default class Order extends Ressource {
Expand Down
2 changes: 1 addition & 1 deletion src/model/PaymentSource.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import Result from "./Result";
import _urlParser from "../urlParser";
import request from "../api";

const url = "/platform/payment_source";
const url = "/payment_source";
const paramDefaults = {};
const creatableField = ["type", "token", "email"];

Expand Down
2 changes: 1 addition & 1 deletion src/model/Region.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import Ressource from "./Ressource";
import { getConfig } from "../config";

const url = "/platform/regions";
const url = "/regions";
const paramDefaults = {};

export default class Region extends Ressource {
Expand Down
2 changes: 1 addition & 1 deletion src/model/SetupConfig.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { getConfig } from "../config";
import _urlParser from "../urlParser";
import request from "../api";

const _url = "/platform/setup/config";
const _url = "/setup/config";
const paramDefaults = {};

export default class SetupConfig extends Ressource {
Expand Down
4 changes: 2 additions & 2 deletions src/model/SetupRegistry.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ import { getConfig } from "../config";
import _urlParser from "../urlParser";
import request from "../api";

const _url = "/platform/setup/registry";
const _url = "/setup/registry";
const paramDefaults = {};
// /api/platform/setup/registry\?service\=redis-persistent
// /setup/registry\?service\=redis-persistent

export default class SetupRegistry extends Ressource {
constructor(registry, url = `${_url}?service=:name`, modifiableField = []) {
Expand Down
2 changes: 1 addition & 1 deletion src/model/SshKey.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import _urlParser from "../urlParser";
import { getConfig } from "../config";

const paramDefaults = {};
const url = "/v1/ssh_keys/:id";
const url = "/ssh_keys/:id";

export default class SshKey extends Ressource {
constructor(sshKey) {
Expand Down
4 changes: 2 additions & 2 deletions src/model/Subscription.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ const creatableField = [

const modifiableField = ["plan", "environments", "storage", "big_dev"];

const url = "/v1/subscriptions/:id";
const url = "/subscriptions/:id";
const STATUS_ACTIVE = "active";
const STATUS_REQUESTED = "requested";
const STATUS_PROVISIONING = "provisioning";
Expand Down Expand Up @@ -177,7 +177,7 @@ export default class Subscription extends Ressource {
*/
getOwner() {
const id = this.owner;
const url = this.makeAbsoluteUrl("/api/users", this.getLink("project"));
const url = this.makeAbsoluteUrl("/users", this.getLink("project"));

return Account.get({ id }, url);
}
Expand Down
2 changes: 1 addition & 1 deletion src/model/Team.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { getConfig } from "../config";
import TeamMember from "./TeamMember";

const paramDefaults = {};
const _url = "/platform/teams";
const _url = "/teams";

const creatableField = ["name", "parent", "id"];
const modifiableField = ["name"];
Expand Down
2 changes: 1 addition & 1 deletion src/model/TeamMember.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import Ressource from "./Ressource";
import { getConfig } from "../config";

const paramDefaults = {};
const _url = "/platform/teams/:teamId/members";
const _url = "/teams/:teamId/members";

const creatableField = ["role"];

Expand Down
6 changes: 3 additions & 3 deletions src/model/Ticket.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import Ressource from "./Ressource";
import { getConfig } from "../config";
import request from "../api";

const url = "/v1/tickets";
const url = "/tickets";
const paramDefaults = {};

export default class Ticket extends Ressource {
Expand All @@ -23,14 +23,14 @@ export default class Ticket extends Ressource {

static getAttachments(ticketId) {
const { api_url } = getConfig();
const url = `/v1/comments/${ticketId}/description`;
const url = `/comments/${ticketId}/description`;

return super.get(`${api_url}${url}`, {}, paramDefaults, {});
}

static getAllAttachments(ticketId) {
const { api_url } = getConfig();
const url = `/v1/comments/${ticketId}/attachments`;
const url = `/comments/${ticketId}/attachments`;

return request(`${api_url}${url}`, "GET");
}
Expand Down
2 changes: 1 addition & 1 deletion src/model/TicketPriority.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import Ressource from "./Ressource";
import { getConfig } from "../config";

const url = "/v1/tickets/priority";
const url = "/tickets/priority";
const paramDefaults = {};

export default class TicketPriority extends Ressource {
Expand Down
2 changes: 1 addition & 1 deletion src/model/User.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import Ressource from "./Ressource";
import { getConfig } from "../config";

const _url = "/api/users";
const _url = "/users";
const paramDefaults = {};

export default class User extends Ressource {
Expand Down
2 changes: 1 addition & 1 deletion src/model/Voucher.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import Ressource from "./Ressource";
import { getConfig } from "../config";

const url = "/v1/vouchers";
const url = "/vouchers";
const paramDefaults = {};

export default class Voucher extends Ressource {
Expand Down
7 changes: 2 additions & 5 deletions test/Account.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ describe("Account", () => {
});

it("Get account", done => {
fetchMock.mock(`${account_url}/platform/users/1`, {
fetchMock.mock(`${account_url}/users/1`, {
id: 1,
email: "[email protected]"
});
Expand All @@ -40,10 +40,7 @@ describe("Account", () => {
{ id: 4, email: "test4" }
];

fetchMock.mock(
`${account_url}/platform/users?id=1&id=2&id=3&id=4`,
accounts
);
fetchMock.mock(`${account_url}/users?id=1&id=2&id=3&id=4`, accounts);

Account.query({ id: [1, 2, 3, 4] }).then(accounts => {
assert.equal(accounts.length, 4);
Expand Down
6 changes: 3 additions & 3 deletions test/AccountsProfile.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ describe("AccountsProfile", () => {
});

it("Get AccountsProfile", done => {
fetchMock.mock(`${api_url}/platform/profiles/1`, {
fetchMock.mock(`${api_url}/profiles/1`, {
id: 1,
display_name: "test",
email: "[email protected]",
Expand All @@ -38,7 +38,7 @@ describe("AccountsProfile", () => {
});

it("GetUserIdFromUsername AccountsProfile", done => {
fetchMock.mock(`${api_url}/v1/profiles?filter[username]=alice`, {
fetchMock.mock(`${api_url}/profiles?filter[username]=alice`, {
profiles: [
{
id: 1,
Expand All @@ -62,7 +62,7 @@ describe("AccountsProfile", () => {

it("Update AccountsProfile", done => {
fetchMock.mock(
`${api_url}/platform/profiles/1`,
`${api_url}/profiles/1`,
{
display_name: "test",
username: "alice"
Expand Down
Loading