Skip to content

Commit f652976

Browse files
authored
[DEVREL-116] Remove unnecessary env switching to determine base URL #58
2 parents 40f1f86 + 295b537 commit f652976

File tree

4 files changed

+7
-42
lines changed

4 files changed

+7
-42
lines changed

README.md

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ const trolley = require('trolley');
2222
const client = trolley.connect({
2323
key: "YOUR-API-KEY",
2424
secret: "YOUR-API-SECRET",
25-
environment: "production",
2625
});
2726

2827
// Async/Await version
@@ -67,7 +66,6 @@ If you're working on the library itself, here's easy way to run the tests.
6766
$ cp .env.test .env
6867
6968
// Set access key and secret in the env file
70-
TROLLEY_ENVIRONMENT="production"
7169
TROLLEY_ACCESS_KEY="ACCESS_KEY"
7270
TROLLEY_SECRET_KEY="SECRET_KEY"
7371

docs/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@
4343

4444
Create a client for the Trolley (Payment Rails) JavasScript API
4545

46-
const client = paymentrails.connect({
46+
const client = trolley.connect({
4747
key: "MY_PUBLIC_KEY",
4848
secret: "MY_PRIVATE_KEY",
4949
});

lib/Configuration.ts

Lines changed: 6 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,17 @@ import { Gateway } from "./Gateway";
22

33
export interface ConfigurationParams {
44
/**
5-
* The Trolley public key
5+
* The Trolley access key
66
*/
77
key: string;
88
/**
9-
* The Trolley private key
9+
* The Trolley secret key
1010
*/
1111
secret: string;
1212
/**
13-
* The environment that you're using, most likely one of "production" or "sandbox"
13+
* Optional. The base URL to use to connect to the API gateway. Useful while running from source.
1414
*/
15-
environment?: "production" | "sandbox" | "integration" | "development";
15+
apiBase?: string;
1616
}
1717

1818
// tslint:disable:function-name
@@ -40,13 +40,8 @@ export class Configuration {
4040
*/
4141
constructor(config?: ConfigurationParams) {
4242
this.apiKey = (config && config.key) || Configuration.apiKeyDefault;
43-
this.apiSecret =
44-
(config && config.secret) || Configuration.apiSecretDefault;
45-
if (config && config.environment) {
46-
this.apiBase = Configuration.environmentToUrl(config.environment);
47-
} else {
48-
this.apiBase = Configuration.apiBaseDefault;
49-
}
43+
this.apiSecret = (config && config.secret) || Configuration.apiSecretDefault;
44+
this.apiBase = (config && config.apiBase) || Configuration.apiBaseDefault;
5045
}
5146

5247
/**
@@ -83,31 +78,4 @@ export class Configuration {
8378
static setApiBase(baseUrl: string) {
8479
Configuration.apiBaseDefault = baseUrl;
8580
}
86-
87-
/**
88-
* Set the Trolley API environment that your using
89-
* @param environment one of "production" or "sandbox"
90-
*/
91-
static setEnvironment(environment: "production" | "sandbox" | "integration") {
92-
Configuration.apiBaseDefault = Configuration.environmentToUrl(environment);
93-
}
94-
95-
/**
96-
* Private method that converts an environment to a specific URL
97-
* @param environment "production" | "sandbox"
98-
* @hidden
99-
*/
100-
private static environmentToUrl(environment: string) {
101-
switch (environment) {
102-
case "integration":
103-
// tslint:disable-next-line:no-http-string
104-
return "http://api.local.dev:3000";
105-
case "sandbox":
106-
return "https://api.trolley.com";
107-
case "production":
108-
return "https://api.trolley.com";
109-
default:
110-
return "https://api.trolley.com";
111-
}
112-
}
11381
}

test/integration/helpers/integrationTestsHelpers.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ import * as nock from "nock";
44
export const testingApiClient = trolley.connect({
55
key: process.env.TROLLEY_ACCESS_KEY,
66
secret: process.env.TROLLEY_SECRET_KEY,
7-
environment: process.env.TROLLEY_ENVIRONMENT as any,
87
} as any);
98

109
export let nockBack = nock.back

0 commit comments

Comments
 (0)