Skip to content
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: 1 addition & 1 deletion examples/simpleDELETE/simpleDELETE.jule
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,6 @@ fn main() {

fn handleStatus(code: status::StatusCode)! {
if !status::IsSuccess(code) {
error(code)
throw code
}
}
2 changes: 1 addition & 1 deletion examples/simpleDownload/simpleDownload.jule
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
use "example/snapbox"

fn main() {
snapbox::Download("https://httpbin.org/get", "examples/bin/output.txt") else {
snapbox::Download("https://httpbin.org/get", "examples/output.txt") else {
println(error)
}
}
2 changes: 1 addition & 1 deletion examples/simpleGET/simpleGET.jule
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,6 @@ fn main() {

fn handleStatus(code: status::StatusCode)! {
if !status::IsSuccess(code) {
error(code)
throw code
}
}
4 changes: 2 additions & 2 deletions examples/simplePOST/simplePOST.jule
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ const DATA = "Hello, World!"

fn main() {
let headerMap: header::HeaderMap = {
header::ACCEPT: "application/json",
header::ACCEPT: "application/json",
header::CONTENT_TYPE: "text/plain",
}

Expand All @@ -26,6 +26,6 @@ fn main() {

fn handleStatus(code: status::StatusCode)! {
if !status::IsSuccess(code) {
error(code)
throw code
}
}
4 changes: 2 additions & 2 deletions examples/simplePUT/simplePUT.jule
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ const DATA = "Puttin' on the Ritz..."

fn main() {
let headerMap: header::HeaderMap = {
header::ACCEPT: "application/json",
header::ACCEPT: "application/json",
header::CONTENT_TYPE: "text/plain",
}

Expand All @@ -26,6 +26,6 @@ fn main() {

fn handleStatus(code: status::StatusCode)! {
if !status::IsSuccess(code) {
error(code)
throw code
}
}
2 changes: 1 addition & 1 deletion header/_test.jule
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ use "std/testing"
#test
fn slicing(t: &testing::T) {
let headerMap: HeaderMap = {
ACCEPT: "application/json",
ACCEPT: "application/json",
USER_AGENT: "snapbox",
}

Expand Down
30 changes: 15 additions & 15 deletions snapbox.jule
Original file line number Diff line number Diff line change
Expand Up @@ -11,22 +11,22 @@ BSD 3-Clause License
use "snapbox/header"
use "snapbox/status"

cpp use "snapbox/internal/curlwrapper.hpp"
extern use "snapbox/internal/curlwrapper.hpp"

#typedef
cpp struct Response {
extern struct Response {
body: str
status: status::StatusCode
}

/* args: url, headers, method */
cpp fn request(str, []str, int): cpp.Response
extern fn request(str, []str, int): extern.Response

/* args: url, data, headers, method */
cpp fn post(str, str, []str, int): cpp.Response
extern fn post(str, str, []str, int): extern.Response

/* args: url, path */
cpp fn download(str, str): bool
extern fn download(str, str): bool

// Request structure for non-data requests.
struct Request {
Expand All @@ -37,9 +37,9 @@ struct Request {

impl Request {
// Executes the request and returns the response.
fn Send(*self): cpp.Response {
fn Send(*self): extern.Response {
headers := header::Slice(self.headers)
ret cpp.request(self.url, headers, self.method)
ret extern.request(self.url, headers, self.method)
}

// Sets headers for the request.
Expand All @@ -59,9 +59,9 @@ struct DataRequest {

impl DataRequest {
// Executes the request and returns the response.
fn Send(*self): cpp.Response {
fn Send(*self): extern.Response {
headers := header::Slice(self.headers)
ret cpp.post(self.url, self.data, headers, self.method)
ret extern.post(self.url, self.data, headers, self.method)
}

// Sets headers for the request.
Expand All @@ -80,46 +80,46 @@ impl DataRequest {
// Builds a GET request object.
fn GET(url: str): Request {
ret Request{
url: url,
url: url,
method: 0,
}
}

// Builds a HEAD request object.
fn HEAD(url: str): Request {
ret Request{
url: url,
url: url,
method: 1,
}
}

// Builds a POST request object.
fn POST(url: str): DataRequest {
ret DataRequest{
url: url,
url: url,
method: 0,
}
}

// Builds a PUT request object.
fn PUT(url: str): DataRequest {
ret DataRequest{
url: url,
url: url,
method: 1,
}
}

// Builds a DELETE request object.
fn DELETE(url: str): DataRequest {
ret DataRequest{
url: url,
url: url,
method: 2,
}
}

// Uses the internal C++ function to download a file from the given URL and save it to the given path.
fn Download(url: str, path: str)! {
response := cpp.download(url, path)
response := extern.download(url, path)
if !response {
panic("Download failed")
}
Expand Down
Loading