Socrata v0.1.0 Socrata.Client View Source

The Client is the main interface of the library. Using a Client, you can get the records and metadata for a data set.

The Client accepts optional paramaters domain and app_token. These values can either be configured when you call new/3 or in your application’s config/config.exs file:

config :socrata,
  domain: "example.com",
  app_token: "blah blah blah"

For more information about tokens and their use, see the Socrata App Tokens docs.

Link to this section Summary

Functions

Gets the view information (metadata) for a data set

Creates a new Client struct

Link to this section Types

Link to this type t() View Source
t() :: %Socrata.Client{
  app_token: String.t(),
  domain: String.t(),
  fourby: String.t()
}

Link to this section Functions

Link to this function get_records(r, query \\ nil, fmt \\ "json", opts \\ []) View Source

Gets the records for a data set.

Options

The opts parameter of the function is passed directly to HTTPoison.get!/3 so you can control the request/response life cycle.

Note: the params key of the options is overwritten by the query struct.

Example

  alias Socrata.{Client, Query}

  query =
    Query.new()
    |> Query.limit(5)

  Client.new("6zsd-86xi", "data.cityofchicago.org")
  |> Client.get_records(query)

  # %HTTPoison.Response{
  #   body: "[{\"arrest\":false,\"beat\":\"0412\",\"block\":\"016XX E 86TH PL\", ...}, ... ]",
  #   headers: [ {"X-Socrata-RequestId", "blahblahblah"}, ... ],
  #   request_url: "https://data.cityofchicago.org/resource/6zsd-86xi.json?%24limit=5",
  #   status_code: 200
  # }

Gets the view information (metadata) for a data set.

Options

The opts parameter of the function is passed directly to HTTPoison.get!/3 so you can control the request/response life cycle.

Example

alias Socrata.Client

Rader.new("6zsd-86xi", "data.cityofchicago.org")
|> Client.get_view()

# %HTTPoison.Response{
#   body: "{\"name\": \"Crimes - 2001 to present\", ... }",
#   headers: [ {"X-Socrata-RequestId", "blahblahblah"}, ... ],
#   request_url: "https://data.cityofchicago.org/views/6zsd-86xi.json",
#   status_code: 200
# }
Link to this function new(fourby, domain \\ nil, app_token \\ nil) View Source

Creates a new Client struct.