OpenStates v0.1.2 OpenStates View Source

An Elixir client for the OpenStates GraphQL API.

Link to this section Summary

Functions

Returns the API key

Returns the request headers

Fetches the jurisdiction objects from the API

Fetches legislators from a particular jurisdiction and organization

Constructs a GraphQL query to the OpenStates API

Calls query/1 passing the string as the argument

Returns the API endpoint URL

Link to this section Types

Link to this type

response() View Source
response() :: {:ok, Neuron.Response.t()} | {:error, response :: term()}

Link to this section Functions

Returns the API key.

Examples

iex> OpenStates.api_key()
System.get_env("OPENSTATES_API_KEY")

Returns the request headers.

Examples

iex> OpenStates.headers()
["X-API-KEY": OpenStates.api_key()]
Link to this function

jurisdictions() View Source
jurisdictions() :: response()

Fetches the jurisdiction objects from the API.

Link to this function

jurisdictions(list) View Source
jurisdictions([{:attrs, args()}]) :: response()

Fetches legislators from a particular jurisdiction and organization.

Link to this function

query(query_string) View Source
query(query_string :: String.t()) :: response()

Constructs a GraphQL query to the OpenStates API.

Example

{:ok, response} =
  OpenStates.query("""
  {
    jurisdictions {
      edges {
        node {
          id
        }
      }
    }
  }
  """)
#=> {:ok, %Neuron.Response{body: %{ ... }, headers: [ ... ], status_code: 200}}
Link to this function

sigil_q(query_string, list) View Source
sigil_q(query_string :: String.t(), list()) :: response()

Calls query/1 passing the string as the argument.

Example

~q"""
{
  jurisdictions {
    edges {
      node {
        id
      }
    }
  }
}
"""
#=> {:ok, %Neuron.Response{body: %{ ... }, headers: [ ... ], status_code: 200}}

Returns the API endpoint URL.

Examples

iex> OpenStates.url()
"https://openstates.org/graphql"