migamake-api-cloudflare 0.2.0

A library to work with Cloudflare apis
Documentation
# Migamake Cloudflare API

This crate is a wrapper for the [Cloudflare API](https://api.cloudflare.com/). It includes support for 3 endpoints - 

* List Zone
* Create a DNS Record
* Delete a DNS Record

This crate uses API token for authentication. The token with appropriate permissions can be created on the [cloudflare dashboard](https://dash.cloudflare.com/profile/api-tokens). You can read more about [API Tokens](https://api.cloudflare.com/#getting-started-requests). From this document -

> API Tokens provide a new way to authenticate with the Cloudflare API. They allow for scoped and permissioned access to resources and use the RFC compliant Authorization Bearer Token Header.

# Installing

Add this library to an existing project -

```
cargo add migamake-api-cloudflare
```

# Building

Clone the repository and build the project - 

```
cargo build
```

# Documentation

To view the documentation locally run -

```
cargo doc --no-deps --open
```

# Running Tests

To run the unit tests -

```
cargo test --lib
```

To run all the tests including the integration tests - 
( expects enviornment variables CLOUDFLARE_API_KEY, CLOUDFLARE_DOMAIN and CLOUDFLARE_ZONE )

```
cargo test
```

# Usage

This example demonstrates the usage of the library. The example creates a TXT record.

    [dependencies]
    migamake-api-cloudflare = { version = "0.1"}

    use migamake_api_cloudflare::{Cloudflare, dns};

    fn main() {
        let domain = "example.com".into();
        let zoneid = "some id";

        // initializes the object using an environment variable CLOUDFLARE_API_KEY
        // or the api key could be passed to the default method
        // let cloudflare = Cloudflare::default(Some("api-key").into());
        let cloudflare = Cloudflare::default(None);

        let mut txt_dns_record = dns::TXTRecord::new();
        txt_dns_record.name = domain;
        txt_dns_record.content = "create a txt record".into();

        let response = cloudflare.create_dns_record(txt_dns_record, &zoneid);

        let res = response.unwrap();
        if res.success {
            println!("{}", "Record created");
        }
        else{
            println!("{:?}", res.errors);
        }

    }