Current section
Files
Jump to
Current section
Files
lib/fortnox_ex/api/default.ex
# NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
# https://openapi-generator.tech
# Do not edit the class manually.
defmodule FortnoxEx.Api.Default do
@moduledoc """
API calls for all endpoints tagged `Default`.
"""
alias FortnoxEx.Connection
import FortnoxEx.RequestBuilder
@doc """
Create customer
## Parameters
- connection (FortnoxEx.Connection): Connection to server
- single_customer_attrs (SingleCustomerAttrs):
- opts (KeywordList): [optional] Optional parameters
## Returns
{:ok, %FortnoxEx.Model.SingleCustomer{}} on success
{:error, info} on failure
"""
@spec create_customer(Tesla.Env.client, FortnoxEx.Model.SingleCustomerAttrs.t, keyword()) :: {:ok, FortnoxEx.Model.SingleCustomer.t} | {:error, Tesla.Env.t}
def create_customer(connection, single_customer_attrs, _opts \\ []) do
%{}
|> method(:post)
|> url("/customers")
|> add_param(:body, :body, single_customer_attrs)
|> Enum.into([])
|> (&Connection.request(connection, &1)).()
|> evaluate_response([
{ 201, %FortnoxEx.Model.SingleCustomer{}}
])
end
@doc """
Deletes a customer
## Parameters
- connection (FortnoxEx.Connection): Connection to server
- customer_number (String.t): The customer number
- opts (KeywordList): [optional] Optional parameters
## Returns
{:ok, %{}} on success
{:error, info} on failure
"""
@spec delete_customer(Tesla.Env.client, String.t, keyword()) :: {:ok, nil} | {:error, Tesla.Env.t}
def delete_customer(connection, customer_number, _opts \\ []) do
%{}
|> method(:delete)
|> url("/customers/#{customer_number}")
|> Enum.into([])
|> (&Connection.request(connection, &1)).()
|> evaluate_response([
{ 204, false}
])
end
@doc """
Get customer by customer number
## Parameters
- connection (FortnoxEx.Connection): Connection to server
- customer_number (String.t): The customer number
- opts (KeywordList): [optional] Optional parameters
## Returns
{:ok, %FortnoxEx.Model.SingleCustomer{}} on success
{:error, info} on failure
"""
@spec get_customer(Tesla.Env.client, String.t, keyword()) :: {:ok, FortnoxEx.Model.SingleCustomer.t} | {:error, Tesla.Env.t}
def get_customer(connection, customer_number, _opts \\ []) do
%{}
|> method(:get)
|> url("/customers/#{customer_number}")
|> Enum.into([])
|> (&Connection.request(connection, &1)).()
|> evaluate_response([
{ 200, %FortnoxEx.Model.SingleCustomer{}}
])
end
@doc """
List customers
## Parameters
- connection (FortnoxEx.Connection): Connection to server
- opts (KeywordList): [optional] Optional parameters
- :financialyeardate (String.t): Selects by date, what financial year that should be used
- :financialyear (String.t): Selects what financial year that should be used
- :fromdate (String.t): Defines a selection based on a start date. Only available for invoices, orders, offers and vouchers.
- :lastmodified (String.t): Retrieves all records since the provided timestamp.
- :limit (integer()): Limit per page. Default 100, from 1 to 500 are valid options.
- :offset (integer()): Offset
- :page (integer()): Page, with 1 beeing the first page
- :sortby (String.t): A result can be sorted, either ascending or descending, by specific fields. These fields are listed in the table under the section “Fields” in the documentation for each resource. This is made in the same way as the search and the filter, by adding GET parameters. Apart from the filters and the search, sorting uses two parameters. One named “sortby”, which specifies the field that the result should be sorted by and one named “sortorder”, which specifies the order in which the sorting should be made.
- :sortorder (String.t): Sorting order
- :todate (String.t): Defines a selection based on an end date. Only available for invoices, orders, offers and vouchers
- :filter (String.t): Filters on active and inactive customers
## Returns
{:ok, %FortnoxEx.Model.CustomerList{}} on success
{:error, info} on failure
"""
@spec list_customers(Tesla.Env.client, keyword()) :: {:ok, FortnoxEx.Model.CustomerList.t} | {:error, Tesla.Env.t}
def list_customers(connection, opts \\ []) do
optional_params = %{
:"financialyeardate" => :query,
:"financialyear" => :query,
:"fromdate" => :query,
:"lastmodified" => :query,
:"limit" => :query,
:"offset" => :query,
:"page" => :query,
:"sortby" => :query,
:"sortorder" => :query,
:"todate" => :query,
:"filter" => :query
}
%{}
|> method(:get)
|> url("/customers")
|> add_optional_params(optional_params, opts)
|> Enum.into([])
|> (&Connection.request(connection, &1)).()
|> evaluate_response([
{ 200, %FortnoxEx.Model.CustomerList{}}
])
end
@doc """
Updates a customer
## Parameters
- connection (FortnoxEx.Connection): Connection to server
- customer_number (String.t): The customer number
- single_customer_attrs (SingleCustomerAttrs):
- opts (KeywordList): [optional] Optional parameters
## Returns
{:ok, %FortnoxEx.Model.SingleCustomer{}} on success
{:error, info} on failure
"""
@spec update_customer(Tesla.Env.client, String.t, FortnoxEx.Model.SingleCustomerAttrs.t, keyword()) :: {:ok, FortnoxEx.Model.SingleCustomer.t} | {:error, Tesla.Env.t}
def update_customer(connection, customer_number, single_customer_attrs, _opts \\ []) do
%{}
|> method(:put)
|> url("/customers/#{customer_number}")
|> add_param(:body, :body, single_customer_attrs)
|> Enum.into([])
|> (&Connection.request(connection, &1)).()
|> evaluate_response([
{ 200, %FortnoxEx.Model.SingleCustomer{}}
])
end
end