Glific v0.3.1 Glific.Partners View Source

The Partners context. This is the gateway for the application to access/update all the organization and Provider information.

Link to this section Summary

Functions

List of organizations that are active within the system

Returns an %Ecto.Changeset{} for tracking organization changes.

Returns an %Ecto.Changeset{} for tracking provider changes.

Return the count of organizations, using the same filter as list_organizations

Return the count of providers, using the same filter as list_providers

Creates a organization.

Creates a provider.

Deletes an Organization.

Deletes a provider.

Gets a single organization.

Gets a single provider.

Returns the list of organizations.

Returns the list of providers.

Cache the entire organization structure.

This contact id is special since it is the sender for all outbound messages and the receiver for all inbound messages

Temorary hack to get the organization id while we get tests to pass

Get the default language id

Return the days of week and the hours for each day for this organization. At some point we will unify the structures, so each day can have a different set of hours

Execute a function across all active organizations. This function is typically called by a cron job worker process

Updates an organization.

Updates a provider.

Link to this section Functions

Specs

active_organizations() :: map()

List of organizations that are active within the system

Link to this function

change_organization(organization, attrs \\ %{})

View Source

Specs

change_organization(Glific.Partners.Organization.t(), map()) ::
  Ecto.Changeset.t()

Returns an %Ecto.Changeset{} for tracking organization changes.

Examples

iex> Glific.Partners.change_organization(organization)
%Ecto.Changeset{data: %Glific.Partners.Organization{}}
Link to this function

change_provider(provider, attrs \\ %{})

View Source

Specs

change_provider(
  %Glific.Partners.Provider{
    __meta__: term(),
    api_end_point: term(),
    id: term(),
    inserted_at: term(),
    name: term(),
    organizations: term(),
    updated_at: term(),
    url: term()
  },
  map()
) :: Ecto.Changeset.t()

Returns an %Ecto.Changeset{} for tracking provider changes.

Examples

iex> change_provider(provider)
%Ecto.Changeset{data: %Provider{}}
Link to this function

count_organizations(args \\ %{})

View Source

Specs

count_organizations(map()) :: integer()

Return the count of organizations, using the same filter as list_organizations

Link to this function

count_providers(args \\ %{})

View Source

Specs

count_providers(map()) :: integer()

Return the count of providers, using the same filter as list_providers

Link to this function

create_organization(attrs \\ %{})

View Source

Specs

create_organization(map()) ::
  {:ok, Glific.Partners.Organization.t()} | {:error, Ecto.Changeset.t()}

Creates a organization.

Examples

iex> Glific.Partners.create_organization(%{name: value})
{:ok, %Glific.Partners.Organization{}}

iex> Glific.Partners.create_organization(%{bad_field: bad_value})
{:error, %Ecto.Changeset{}}
Link to this function

create_provider(attrs \\ %{})

View Source

Specs

create_provider(map()) ::
  {:ok,
   %Glific.Partners.Provider{
     __meta__: term(),
     api_end_point: term(),
     id: term(),
     inserted_at: term(),
     name: term(),
     organizations: term(),
     updated_at: term(),
     url: term()
   }}
  | {:error, Ecto.Changeset.t()}

Creates a provider.

Examples

iex> create_provider(%{field: value})
{:ok, %Provider{}}

iex> create_provider(%{field: bad_value})
{:error, %Ecto.Changeset{}}
Link to this function

delete_organization(organization)

View Source

Specs

delete_organization(Glific.Partners.Organization.t()) ::
  {:ok, Glific.Partners.Organization.t()} | {:error, Ecto.Changeset.t()}

Deletes an Organization.

Examples

iex> Glific.Partners.delete_organization(organization)
{:ok, %Glific.Partners.Organization{}}

iex> delete_organization(organization)
{:error, %Ecto.Changeset{}}
Link to this function

delete_provider(provider)

View Source

Specs

delete_provider(%Glific.Partners.Provider{
  __meta__: term(),
  api_end_point: term(),
  id: term(),
  inserted_at: term(),
  name: term(),
  organizations: term(),
  updated_at: term(),
  url: term()
}) ::
  {:ok,
   %Glific.Partners.Provider{
     __meta__: term(),
     api_end_point: term(),
     id: term(),
     inserted_at: term(),
     name: term(),
     organizations: term(),
     updated_at: term(),
     url: term()
   }}
  | {:error, Ecto.Changeset.t()}

Deletes a provider.

Examples

iex> delete_provider(provider)
{:ok, %Provider{}}

iex> delete_provider(provider)
{:error, %Ecto.Changeset{}}

Specs

get_organization!(integer()) :: Glific.Partners.Organization.t()

Gets a single organization.

Raises Ecto.NoResultsError if the organization does not exist.

Examples

iex> Glific.Partners.get_organization!(1)
%Glific.Partners.Organization{}

iex> Glific.Partners.get_organization!(-1)
** (Ecto.NoResultsError)

Specs

get_provider!(id :: integer()) :: %Glific.Partners.Provider{
  __meta__: term(),
  api_end_point: term(),
  id: term(),
  inserted_at: term(),
  name: term(),
  organizations: term(),
  updated_at: term(),
  url: term()
}

Gets a single provider.

Raises Ecto.NoResultsError if the Provider does not exist.

Examples

iex> get_provider!(123)
%Provider{}

iex> get_provider!(456)
** (Ecto.NoResultsError)
Link to this function

list_organizations(args \\ %{})

View Source

Specs

list_organizations(map()) :: [Glific.Partners.Organization.t()]

Returns the list of organizations.

Examples

iex> Glific.Partners.list_organizations()
[%Glific.Partners.Organization{}, ...]
Link to this function

list_providers(args \\ %{})

View Source

Specs

list_providers(map()) :: [
  %Glific.Partners.Provider{
    __meta__: term(),
    api_end_point: term(),
    id: term(),
    inserted_at: term(),
    name: term(),
    organizations: term(),
    updated_at: term(),
    url: term()
  },
  ...
]

Returns the list of providers.

Examples

iex> list_providers()
[%Provider{}, ...]
Link to this function

organization(organization_id)

View Source

Specs

Cache the entire organization structure.

In v0.4, we should cache it based on organization id, and that should be a parameter

Link to this function

organization_contact_id(organization_id)

View Source

Specs

organization_contact_id(non_neg_integer()) :: integer()

This contact id is special since it is the sender for all outbound messages and the receiver for all inbound messages

Link to this function

organization_id(organization_id)

View Source

Specs

organization_id(non_neg_integer()) :: integer()

Temorary hack to get the organization id while we get tests to pass

Link to this function

organization_language_id(organization_id)

View Source

Specs

organization_language_id(non_neg_integer()) :: integer()

Get the default language id

Link to this function

organization_out_of_office_summary(organization_id)

View Source

Specs

organization_out_of_office_summary(non_neg_integer()) ::
  {[Time.t()], [integer()]}

Return the days of week and the hours for each day for this organization. At some point we will unify the structures, so each day can have a different set of hours

Link to this function

organization_timezone(organization_id)

View Source

Specs

organization_timezone(non_neg_integer()) :: String.t()

Get the timezone

Link to this function

perform_all(handler, handler_args \\ %{})

View Source

Specs

perform_all((non_neg_integer(), map() -> nil), map()) :: :ok

Execute a function across all active organizations. This function is typically called by a cron job worker process

The handler is expected to take the organization id as its first argument. The second argument is expected to be a map of arguments passed in by the cron job, and can be ignored if not used

Link to this function

update_organization(organization, attrs)

View Source

Specs

update_organization(Glific.Partners.Organization.t(), map()) ::
  {:ok, Glific.Partners.Organization.t()} | {:error, Ecto.Changeset.t()}

Updates an organization.

Examples

iex> Glific.Partners.update_organization(Organization, %{name: new_name})
{:ok, %Glific.Partners.Organization{}}

iex> Glific.Partners.update_organization(Organization, %{abc: bad_value})
{:error, %Ecto.Changeset{}}
Link to this function

update_provider(provider, attrs)

View Source

Specs

update_provider(
  %Glific.Partners.Provider{
    __meta__: term(),
    api_end_point: term(),
    id: term(),
    inserted_at: term(),
    name: term(),
    organizations: term(),
    updated_at: term(),
    url: term()
  },
  map()
) ::
  {:ok,
   %Glific.Partners.Provider{
     __meta__: term(),
     api_end_point: term(),
     id: term(),
     inserted_at: term(),
     name: term(),
     organizations: term(),
     updated_at: term(),
     url: term()
   }}
  | {:error, Ecto.Changeset.t()}

Updates a provider.

Examples

iex> update_provider(provider, %{field: new_value})
{:ok, %Provider{}}

iex> update_provider(provider, %{field: bad_value})
{:error, %Ecto.Changeset{}}