Skip to content

Commit

Permalink
Merge pull request #7 from calcit-lang/update
Browse files Browse the repository at this point in the history
upgrade calcit deps
  • Loading branch information
NoEgAm authored May 20, 2024
2 parents fbb87e9 + 21b9fe5 commit 2353d7e
Show file tree
Hide file tree
Showing 6 changed files with 60 additions and 33 deletions.
14 changes: 3 additions & 11 deletions .github/workflows/check.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,19 +12,11 @@ jobs:
name: Test
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4

- uses: supplypike/setup-bin@v3
- uses: calcit-lang/setup-[email protected]
with:
uri: "https://github.com/calcit-lang/calcit/releases/download/0.8.0/cr"
name: "cr"
version: "0.8.0"

- uses: supplypike/setup-bin@v3
with:
uri: "https://github.com/calcit-lang/calcit/releases/download/0.8.0/caps"
name: "caps"
version: "0.8.0"
version: "0.8.52"

- uses: dtolnay/rust-toolchain@stable
with:
Expand Down
39 changes: 34 additions & 5 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "calcit_http"
version = "0.0.5"
version = "0.0.8"
authors = ["jiyinyiyong <[email protected]>"]
edition = "2021"

Expand All @@ -13,6 +13,6 @@ crate-type = ["dylib"] # Creates dynamic lib
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
cirru_edn = "0.5.0"
cirru_parser = "0.1.25"
cirru_edn = "0.6.8"
cirru_parser = "0.1.29"
reqwest = { version = "0.11.20", features = ["blocking"] }
2 changes: 1 addition & 1 deletion calcit.cirru

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion compact.cirru
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@

{} (:package |fetch)
:configs $ {} (:init-fn |fetch.test/main!) (:reload-fn |fetch.test/reload!) (:version |0.0.5)
:configs $ {} (:init-fn |fetch.test/main!) (:reload-fn |fetch.test/reload!) (:version |0.0.8)
:modules $ []
:entries $ {}
:files $ {}
Expand Down
30 changes: 18 additions & 12 deletions src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use cirru_edn::Edn;
use cirru_edn::{Edn, EdnTupleView};
use reqwest::{
header::{HeaderMap, HeaderName, HeaderValue},
Method,
Expand All @@ -7,10 +7,16 @@ use std::sync::Arc;
use std::thread::spawn;

pub fn wrap_ok(x: Edn) -> Edn {
Edn::Tuple(Box::new(Edn::tag("ok")), vec![x])
Edn::Tuple(EdnTupleView {
tag: Arc::new(Edn::tag("ok")),
extra: vec![x],
})
}
pub fn wrap_err(x: Edn) -> Edn {
Edn::Tuple(Box::new(Edn::tag("err")), vec![x])
Edn::Tuple(EdnTupleView {
tag: Arc::new(Edn::tag("err")),
extra: vec![x],
})
}

struct RequestSkeleton {
Expand All @@ -22,7 +28,7 @@ struct RequestSkeleton {

#[no_mangle]
pub fn abi_version() -> String {
String::from("0.0.6")
String::from("0.0.9")
}

#[no_mangle]
Expand All @@ -47,11 +53,11 @@ pub fn fetch(
a => return Err(format!("unexpected method: {}", a)),
};

let b = builder.body(options.body).headers(options.headers).query(&options.query);
let b = builder.body(options.body).headers(options.headers).query(&*options.query);

let ret = match b.send() {
Ok(res) => match res.text() {
Ok(s) => handler(vec![wrap_ok(Edn::Str(s.to_string().into_boxed_str()))]),
Ok(s) => handler(vec![wrap_ok(Edn::Str(s.into()))]),
Err(e) => handler(vec![wrap_err(Edn::str(format!("failed to turn body into text: {}", e)))]),
},
Err(e) => return Err(format!("fetch failed: {}", e)),
Expand Down Expand Up @@ -80,7 +86,7 @@ fn parse_request_options(info: &Edn) -> Result<RequestSkeleton, String> {
match info {
Edn::Map(m) => {
req.method = match m.get(&Edn::tag("method")) {
Some(Edn::Tag(k)) => k.to_str().parse::<Method>().map_err(|x| x.to_string())?,
Some(Edn::Tag(k)) => k.ref_str().parse::<Method>().map_err(|x| x.to_string())?,
None => Method::GET,
Some(a) => return Err(format!("invalid method name: {}", a)),
};
Expand All @@ -91,7 +97,7 @@ fn parse_request_options(info: &Edn) -> Result<RequestSkeleton, String> {
};
match m.get(&Edn::tag("headers")) {
Some(Edn::Map(xs)) => {
for (k, v) in xs {
for (k, v) in &xs.0 {
match (k, v) {
(Edn::Str(k2), Edn::Str(v2)) => {
req
Expand All @@ -101,7 +107,7 @@ fn parse_request_options(info: &Edn) -> Result<RequestSkeleton, String> {
(Edn::Tag(k2), Edn::Str(v2)) => {
req
.headers
.insert(k2.to_str().parse::<HeaderName>().unwrap(), v2.parse::<HeaderValue>().unwrap());
.insert(k2.ref_str().parse::<HeaderName>().unwrap(), v2.parse::<HeaderValue>().unwrap());
}
_ => return Err(format!("expected strings for headers: {}, {}", k, v)),
}
Expand All @@ -118,14 +124,14 @@ fn parse_request_options(info: &Edn) -> Result<RequestSkeleton, String> {
for x in xs {
if let Edn::List(ys) = x {
if ys.len() == 2 {
match (&ys[0], &ys[1]) {
match (&ys.0[0], &ys.0[1]) {
(Edn::Str(k), Edn::Str(v)) => {
req.query.push((k.to_owned(), v.to_owned()));
req.query.push((Box::from(&**k), Box::from(&**v)));
// quit jump to next call
continue;
}
(Edn::Tag(k), Edn::Str(v)) => {
req.query.push((k.to_str().to_owned(), v.to_owned()));
req.query.push((k.ref_str().into(), Box::from(&**v)));
// quit jump to next call
continue;
}
Expand Down

0 comments on commit 2353d7e

Please sign in to comment.