Skip to content

Commit

Permalink
Merge pull request #14 from Boulevard/lnikkila/v0.6.0
Browse files Browse the repository at this point in the history
Release v0.6.0
  • Loading branch information
lnikkila authored Mar 22, 2017
2 parents 620ffac + bc4806b commit 469c5a6
Show file tree
Hide file tree
Showing 6 changed files with 598 additions and 6 deletions.
11 changes: 7 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,14 @@

**QuickBooks Online API client for Elixir.**

Everything is still a work in progress. Currently only these APIs are supported:
## Features

Everything is still a work in progress.

- Item
- OAuth
- Preferences
- Data queries
- Item API
- Preferences API

## Installation

Expand All @@ -17,7 +20,7 @@ dependencies in `mix.exs`:

```elixir
def deps do
[{:exquickbooks, "~> 0.5.0"}]
[{:exquickbooks, "~> 0.6.0"}]
end
```

Expand Down
30 changes: 30 additions & 0 deletions lib/exquickbooks/api.ex
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
defmodule ExQuickBooks.API do
@moduledoc """
Functions for interacting with the API.
This module directly implements operations from the official API:
<https://developer.intuit.com/v2/docs/api/accounting>
"""

use ExQuickBooks.Endpoint, base_url: ExQuickBooks.accounting_api
use ExQuickBooks.Endpoint.JSON

alias ExQuickBooks.OAuth.AccessToken

@doc """
Retrieves multiple entities using a SQL-like query.
See the [query documentation][0] for more details.
[0]: https://developer.intuit.com/docs/0100_quickbooks_online/0300_references/0000_programming_guide/0050_data_queries
"""
@spec query(AccessToken.t, String.t) :: {:ok, json_map} | {:error, any}
def query(token, query) do
headers = [{"Content-Type", "text/plain"}]
options = [params: [{"query", query}]]

request(:get, "company/#{token.realm_id}/query", nil, headers, options)
|> sign_request(token)
|> send_json_request
end
end
4 changes: 2 additions & 2 deletions mix.exs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ defmodule ExQuickBooks.Mixfile do

def project do
[app: :exquickbooks,
version: "0.5.0",
version: "0.6.0",
elixir: "~> 1.4",

# Compilation
Expand Down Expand Up @@ -32,7 +32,7 @@ defmodule ExQuickBooks.Mixfile do
end

defp env do
[backend: ExQuickBooks.HTTPoisonBackend]
[backend: ExQuickBooks.Backend.HTTPoison]
end

defp description do
Expand Down
44 changes: 44 additions & 0 deletions test/exquickbooks/api_test.exs
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
defmodule ExQuickBooks.APITest do
use ExUnit.Case, async: false
use ExQuickBooks.APICase

alias ExQuickBooks.API
alias ExQuickBooks.OAuth.AccessToken

doctest API

@token %AccessToken{
token: "token",
token_secret: "secret",
realm_id: "realm_id"
}

test "query/2 retrieves a query response" do
load_response("api/query.json") |> send_response

assert {:ok, %{"QueryResponse" => _}} =
API.query(@token, "SELECT * FROM Item")

assert %{
url: url,
headers: headers,
options: [params: params]
} = take_request()

assert String.contains?(url, "/query")

assert {"Accept", "application/json"} in headers
assert {"Content-Type", "text/plain"} in headers

assert {"query", "SELECT * FROM Item"} in params
end

test "query/2 recovers from an error" do
load_response("api/query_error.json")
|> Map.put(:status_code, 400)
|> send_response

assert {:error, %{"Fault" => _}} =
API.query(@token, "SELECT * FROM NULL")
end
end
Loading

0 comments on commit 469c5a6

Please sign in to comment.