Skip to content

Commit

Permalink
improve examples
Browse files Browse the repository at this point in the history
  • Loading branch information
thewh1teagle committed May 6, 2024
1 parent 8d04eaf commit fda07d0
Show file tree
Hide file tree
Showing 24 changed files with 69 additions and 13 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
target/
Cargo.lock
__pycache__
*.pyc
*.pyc
node_modules/
4 changes: 2 additions & 2 deletions BUILDING.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,5 +25,5 @@ python3 -m venv venv
source venv/bin/activate
# Install dependencies + build + install
# May take sometime on first use
pip3 install .
```
pip3 install .
```
8 changes: 1 addition & 7 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,10 +1,4 @@
[workspace]
members = [
"rookie-rs",
"bindings/python",
"bindings/node",
"cli",
"rookie-rs/examples/*",
]
members = ["rookie-rs", "bindings/python", "bindings/node", "cli"]
default-members = ["rookie-rs", "bindings/python"]
resolver = "2"
10 changes: 8 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -63,16 +63,22 @@ for (const cookie of cookies) {

## Examples 📋

`Python` [examples](https://github.com/thewh1teagle/rookie/tree/main/examples)
`Python` [examples/python](examples/python)

`Rust` [rookie-rs/examples](https://github.com/thewh1teagle/rookie/tree/main/rookie-rs/examples)
`JavaScript` [examples/javascript](examples/python)

`Rust` [examples/rust](examples/rust)

## Docs 📘

`Python`

- [docs/Python.md](docs/Python.md)

`JavaScript`

- [docs/JavaScript.md][docs/JavaScript.md]

`Rust`

- [docs/Rust.md](docs/Rust.md)
Expand Down
2 changes: 1 addition & 1 deletion bindings/node/.yarn/releases/yarn-4.2.1.cjs

Large diffs are not rendered by default.

14 changes: 14 additions & 0 deletions docs/JavaScript.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# Rookie JavaScript Docs

## Install

```typescript
npm install @rookie/api
```

## Basic Usage

```js
import { brave } from "@rookie/api";
const cookies = brave();
```
25 changes: 25 additions & 0 deletions examples/javascript/fetch.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import rookie from "@rookie-rs/api";

function createHeaders() {
// Get all Github cookies from Brave browser
const cookies = rookie.brave(["github.com"]);
// Create cookie header
const cookie = cookies
.map((c) => decodeURIComponent(`${c.name}=${c.value}`))
.join(";");
const userAgent =
"Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/124.0.0.0 Safari/537.36";
return {
"User-Agent": userAgent,
Cookie: cookie,
};
}

const headers = createHeaders();
const res = await fetch("https://github.com/settings/profile", { headers });
const html = await res.text();
// Parse username from HTML
const username =
html.match(/<a href="\/(.+)" class="btn.+>/)?.[1] ??
`Not Logged In. Response URL: ${res.url}`;
console.log(`Github username: ${username}`);
6 changes: 6 additions & 0 deletions examples/javascript/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"type": "module",
"dependencies": {
"@rookie-rs/api": "^0.0.1-beta.4"
}
}
5 changes: 5 additions & 0 deletions examples/javascript/simple.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import rookie from "@rookie-rs/api";

for (const cookie of rookie.brave()) {
console.log(cookie);
}
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
1 change: 1 addition & 0 deletions examples/python/requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
rookiepy
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
4 changes: 4 additions & 0 deletions rookie-rs/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -59,3 +59,7 @@ windows = { version = "0.51", features = [
"Win32_System",
"Win32_System_RestartManager",
] }

[[example]]
name = "simple"
path = "../examples/rust/simple.rs"

0 comments on commit fda07d0

Please sign in to comment.