Skip to content
This repository was archived by the owner on Mar 17, 2022. It is now read-only.
This repository was archived by the owner on Mar 17, 2022. It is now read-only.

Library Interface Brainstorming #1

@kespinola

Description

@kespinola

What do you all think of an interface like this?

defmodule Procore.Endpoint do
  def construct(%Procore.Company{id :id}), do: "/vapid/companies/#{id}"
  def construct(%Procore.Company{}), do: "/vapid/companies"
  def construct(%Procore.Inspection{project_id: project_id, id :id}), do: "/vapid/projects/#{project_id}/inspections/#{id}"
end

defmodule Procore.Api do
  def get(struct), do: struct |> Procore.Endpoint.construct() |> OauthClient.get()
  def post(struct, params), do: struct |> Procore.Endpoint.construct() |> OauthClient.post(params)
end

%Procore.ApiResponse{body: body} = Procore.Api.get(%Procore.Company{id: 1})
%Procore.ApiResponse{body: body} = Procore.Api.post(
  %Procore.Inspection{project_id: 2, id: 1},
  %{title: "example title"}
)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions