Skip to content

Commit

Permalink
chore: update examples remove dollar sign from str
Browse files Browse the repository at this point in the history
  • Loading branch information
staycoolcall911 committed Jan 6, 2024
1 parent 14dda3b commit d8f17c1
Show file tree
Hide file tree
Showing 7 changed files with 21 additions and 21 deletions.
4 changes: 2 additions & 2 deletions examples/api-basic-auth-middleware/basic-auth.w
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,9 @@ pub class BasicAuth {
}

// force cast to str from str?
return "${authHeader}";
return "{authHeader}";
} else {
log("headers: ${Json.stringify(headers)}");
log("headers: {Json.stringify(headers)}");
log("no auth header");
throw("no auth header");
}
Expand Down
4 changes: 2 additions & 2 deletions examples/api-basic-auth-middleware/main.w
Original file line number Diff line number Diff line change
Expand Up @@ -46,12 +46,12 @@ api.get("/hello-middleware", authenticatedMiddleware(inflight (request) => {
let apiUrl = api.url;

test "not authenticated" {
let response = http.get("${apiUrl}/hello-middleware");
let response = http.get("{apiUrl}/hello-middleware");
expect.equal(response.status, 401);
}

test "authenticated" {
let response = http.get("${apiUrl}/hello-middleware", {
let response = http.get("{apiUrl}/hello-middleware", {
headers: {
Accept: "application/json",
Authorization: "Basic " + auth.Utils.base64encode("admin:admin")
Expand Down
10 changes: 5 additions & 5 deletions examples/api-basic-auth/main.w
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ class BasicAuth {
let password = credentials.password;
return username == this.user && password == this.password;
} catch e {
log("exception caught ${e}");
log("exception caught {e}");
return false;
}
}
Expand All @@ -52,9 +52,9 @@ class BasicAuth {
}

// force cast to str from str?
return "${authHeader}";
return "{authHeader}";
} else {
log("headers: ${Json.stringify(headers)}");
log("headers: {Json.stringify(headers)}");
log("no auth header");
throw("no auth header");
}
Expand Down Expand Up @@ -100,12 +100,12 @@ api.get("/hello", inflight (req) => {
let apiUrl = api.url;

test "not authenticated" {
let response = http.get("${apiUrl}/hello");
let response = http.get("{apiUrl}/hello");
expect.equal(response.status, 401);
}

test "authenticated" {
let response = http.get("${apiUrl}/hello", {
let response = http.get("{apiUrl}/hello", {
headers: {
Accept: "application/json",
Authorization: "Basic " + util.base64Encode("admin:admin")
Expand Down
2 changes: 1 addition & 1 deletion examples/hello-wing/main.w
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ let bucket = new cloud.Bucket();
let queue = new cloud.Queue();

queue.setConsumer(inflight (message) => {
bucket.put("wing.txt", "Hello, ${message}");
bucket.put("wing.txt", "Hello, {message}");
}, timeout: 30s);

test "Hello, world!" {
Expand Down
2 changes: 1 addition & 1 deletion examples/provider-specific/awscdk-hello-wing/main.w
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ let bucket = new cloud.Bucket();
let queue = new cloud.Queue();

queue.setConsumer(inflight (message) => {
bucket.put("wing.txt", "Hello, ${message}");
bucket.put("wing.txt", "Hello, {message}");
}, timeout: 1s);

// tests
Expand Down
10 changes: 5 additions & 5 deletions examples/static-website/main.w
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,12 @@ api.post("/hello-static", inflight (request) => {
"Content-Type" => "text/html",
"Access-Control-Allow-Origin" => "*",
},
body: "<div id=\"hello\" class=\"mt-4\">Hello ${counter.inc()}</div>",
body: "<div id=\"hello\" class=\"mt-4\">Hello {counter.inc()}</div>",
};
});

let invokeAndAssert = inflight(response: http.Response, expected: str) => {
log("response: ${response.status} ");
log("response: {response.status} ");
expect.equal(response.status, 200);
assert(response.body?.contains(expected) == true);
};
Expand All @@ -40,19 +40,19 @@ test "renders the index page" {
}

test "api returns the correct response" {
invokeAndAssert(http.post("${api.url}/hello-static"), "Hello 0");
invokeAndAssert(http.post("{api.url}/hello-static"), "Hello 0");
}

test "api handles cors" {
let response = http.fetch("${api.url}/hello-static", {
let response = http.fetch("{api.url}/hello-static", {
method: http.HttpMethod.OPTIONS,
headers: {
"Origin" => "https://example.com",
"hx-target" => "hello",
},
});
expect.equal(response.status, 204);
log("headers: ${Json.stringify(response.headers)}");
log("headers: {Json.stringify(response.headers)}");

expect.equal(response.headers.get("access-control-allow-headers"), "*");
expect.equal(response.headers.get("access-control-allow-origin"), "*");
Expand Down
10 changes: 5 additions & 5 deletions examples/stock-poller/main.w
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ class TwelveDataApi {
}

pub inflight stockUpdates(tickerSymbol: str): http.Response {
return http.get("https://api.twelvedata.com/time_series?symbol=${tickerSymbol}&interval=1min&outputsize=1&apikey=${this.key.value()}");
return http.get("https://api.twelvedata.com/time_series?symbol={tickerSymbol}&interval=1min&outputsize=1&apikey={this.key.value()}");
}
}

Expand All @@ -28,19 +28,19 @@ let stockUpdatesFetchSchedule = new cloud.Schedule(rate: 2m); // Twelve Da
let stockUpdatesPoller = stockUpdatesFetchSchedule.onTick(inflight () => {
let stockUpdates = twelveDataApi.stockUpdates(tickerSymbol);

log("Status: ${stockUpdates.status}");
log("Body: ${stockUpdates.body}");
log("Status: {stockUpdates.status}");
log("Body: {stockUpdates.body}");

let stockUpdatesBody = stockUpdates.body;

log("Received this stock updates: ${stockUpdatesBody}");
log("Received this stock updates: {stockUpdatesBody}");

let stockUpdatesBodyJson = Json.parse(stockUpdatesBody);
let latestStockPriceStr = stockUpdatesBodyJson.get("values").getAt(0).get("close").asStr();
let latestStockPrice = num.fromStr(latestStockPriceStr);

let previousStockPrice = recentStockPriceCache.peek(tickerSymbol);
log("Stock price for ${tickerSymbol} changed from ${previousStockPrice} to ${latestStockPrice} with a difference of: ${latestStockPrice - previousStockPrice}");
log("Stock price for {tickerSymbol} changed from {previousStockPrice} to {latestStockPrice} with a difference of: {latestStockPrice - previousStockPrice}");

recentStockPriceCache.set(latestStockPrice, tickerSymbol);
stockUpdatesQueue.push(stockUpdatesBody);
Expand Down

0 comments on commit d8f17c1

Please sign in to comment.