Giter VIP home page Giter VIP logo

elixir-cloudflare-api-client's Introduction

Cloudflare

hex.pm hex.pm github.com

Cloudflare API Client. Written for the Elixir community, based on :restlax.

Installation

If available in Hex, the package can be installed by adding cloudflare to your list of dependencies in mix.exs:

def deps do
  [
    {:cloudflare, "~> 0.2"}
  ]
end

Configuration

Authentication

config :cloudflare,
  auth_token: "my-auth-token"

Or

config :cloudflare,
  auth_email: "[email protected]",
  auth_key: "my-auth-key"

Or both ¯\(°_o)/¯.

Or passed in

Cloudflare.Zone.index(opts: [auth_token: "my-auth-token"])
Cloudflare.Zone.index(opts: [auth_email: "[email protected]", auth_key: "my-auth-key"])

Or directly as header

Cloudflare.Zone.index(headers: [{"Authorization", "Bearer my-auth-token"}])
Cloudflare.Zone.index(headers: [{"X-Auth-Email", "[email protected]"}, {"X-Auth-Key", "my-auth-key"}])

Register client

Normally it's teadius to explicitly pass the client module in.

Cloudflare.Zone.index(client: CloudFlare.Client)

It can be registered on application start, e.g. in YourApp.Application.start

defmodule YourApp.Application do
  use Application

  def start(_type, _args) do
    Cloudflare.Client.init() # <- You can add this line
    children = [
      {Phoenix.PubSub, name: App.PubSub},
      App.Repo,
      AppWeb.Endpoint
    ]

    opts = [strategy: :one_for_one, name: App.Supervisor]
    Supervisor.start_link(children, opts)
  end

  def config_change(changed, _new, removed) do
    AppWeb.Endpoint.config_change(changed, removed)
    :ok
  end
end

Usage

Cloudflare.Zone.index()
Cloudflare.DnsRecord.index(params: [zone_id: "my-zone-id"])
Cloudflare.DnsRecord.create(
  %{type: "A", name: "my.domain", content: "127.0.0.1", ttl: 120},
  params: [zone_id: "my-zone-id"]
)

Documentation can be generated with ExDoc and published on HexDocs. Once published, the docs can be found at https://hexdocs.pm/cloudflare.

Contribution

Half manually scraped Cloudflare docs are located in priv/docs. Pick an entity and write module for it.

Simple entities can be as easy as Cloudflare.Account and Cloudflare.User

Some need a little customization like Cloudflare.DnsRecord

Some need more Cloudflare.ZoneSetting

elixir-cloudflare-api-client's People

Contributors

princemaple avatar renovate[bot] avatar

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.