GithubHelp home page GithubHelp logo

kamui-fin / adzuna-rs Goto Github PK

View Code? Open in Web Editor NEW
1.0 1.0 0.0 55 KB

A simple & async Rust API wrapper for Adzuna

Home Page: https://docs.rs/adzuna

License: GNU General Public License v3.0

Rust 100.00%
adzuna-api api-wrapper job-api rust-crate

adzuna-rs's Introduction

Adzuna API Wrapper

An easy to use, asynchronous, and complete Rust crate for interacting with the Adzuna API.

Documentation Crate GPLv3 License

Installation

Via cargo, add this to your project's Cargo.toml:

[dependencies]
adzuna-rs = "1.0.2"

Usage

First, obtain an api_id and api_key by registering for the API. Then, you can instantiate a Client:

use adzuna::{Client, RequestBuilder};

let client = Client::new("API_ID".into(), "API_KEY".into());

We also have to import the RequestBuilder trait to invoke .fetch() on the built requests.

You can access all the endpoints from this client. Calling an endpoint will return a request builder, which allows you to chain calls for idiomatic query parameter configuration.

After customizing the query, you have to call .fetch(), which asynchronously sends the request and returns the data in a Result<T, AdzunaError>. AdzunaError optionally contains more information about the error returned by the API as such:

AdzunaError {
    api_error: Some(
        ApiException {
            exception: "AUTH_FAIL",
            doc: "https://api.adzuna.com/v1/doc",
            display: "Authorisation failed",
        },
    ),
    http_status: 401,
}

Examples

Getting the top companies for SWE in Texas:

let companies = client
    .top_companies()
    .what("software engineering")
    .location("US")
    .location("Texas")
    .fetch()
    .await;

Search for UI Design jobs 5km away from Boston:

let jobs = client
    .search()
    .what("ui design")
    .where("boston")
    .distance(5)
    .fetch()
    .await;

Search for part time sales jobs sorted by salary in descending order:

use adzuna::models::{SortBy, SortDirection};

let jobs = client
    .search()
    .what("sales")
    .sort_by(SortBy::Salary)
    .sort_dir(SortDirection::Down)
    .fetch()
    .await;

Generate a histogram of salary data for data analyst jobs:

let jobs = client
    .histogram()
    .what("data analyst")
    .fetch()
    .await;

Running Tests

Tests need to be ran sequentially to avoid getting rate limited. You also need to provide environmental variables for authentication:

API_ID=123 API_KEY=abc cargo test -- --test-threads 1

Contributing

Contributions are always welcome! This crate currently covers all the endpoints mentioned in the official documentation, but if you see something missing or encounter a bug, feel free to open an issue or create a pull request.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.