Skip to content
This repository has been archived by the owner on Jun 26, 2023. It is now read-only.

Commit

Permalink
Basic Crux Client for Crux/state
Browse files Browse the repository at this point in the history
Co-authored-by: Otávio Pace <otaviopp8@gmail.com>
  • Loading branch information
naomijub and evaporei committed Jul 10, 2020
1 parent 682b86c commit 5d801e6
Show file tree
Hide file tree
Showing 7 changed files with 68 additions and 9 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
/target
Cargo.lock
datomic-pro-*.jar
5 changes: 4 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,13 @@ authors = ["Julia Naomi <jnboeira@outlook.com>"]
description = "Crate to parse and emit EDN"
documentation = "https://docs.rs/transistor/"
repository = "https://github.com/naomijub/transistor"
keywords = ["DATOMIC", "Client", "database"]
keywords = ["CRUX", "Client", "database"]
license = "GPL-3.0-or-later"
edition = "2018"


# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
reqwest = { version = "0.10.6", features = ["blocking"] }
edn-rs = "0.5.3"
2 changes: 2 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
crux:
docker run -d -p 3000:3000 juxt/crux-standalone:20.02-1.7.0-alpha
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# Transistor

A Datomic Client crate.
A Crux Client crate.
* Gave up on datomic already.
49 changes: 49 additions & 0 deletions src/http/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
use reqwest::{
header::{HeaderMap,AUTHORIZATION},
blocking::{Client},
Result
};

pub struct Crux {
host: String,
port: String,
headers: HeaderMap
}

impl Crux{
pub fn new(host: &str, port: &str) -> Self {
Self{host: host.to_string(), port: port.to_string(), headers: HeaderMap::new()}
}

pub fn with_authorization(mut self, authorization: &str) -> Self {
self.headers.insert(AUTHORIZATION, authorization.parse().unwrap());
self
}

fn uri(&self) -> String {
format!("http://{}:{}", self.host, self.port)
}

pub fn client(&self) -> CruxClient {
CruxClient {
client: reqwest::blocking::Client::new(),
uri: self.uri().clone(),
headers: self.headers.clone()
}
}
}

pub struct CruxClient {
client: Client,
uri: String,
headers: HeaderMap,
}

impl CruxClient {
pub fn state(&self) -> Result<String> {
self.client.get(&self.uri)
.headers(self.headers.clone())
.send()?
.text()
}
}
8 changes: 1 addition & 7 deletions src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1 @@
#[cfg(test)]
mod tests {
#[test]
fn it_works() {
assert_eq!(2 + 2, 4);
}
}
pub mod http;
9 changes: 9 additions & 0 deletions src/main.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
mod http;

use http::Crux;

fn main() {
let body = Crux::new("localhost", "3000").client().state().unwrap();

println!("body = {:?}", body);
}

0 comments on commit 5d801e6

Please sign in to comment.