Skip to content

Commit 343f19f

Browse files
authored
Update documentation and typespecs (#6)
1 parent 3497cfc commit 343f19f

27 files changed

Lines changed: 1986 additions & 375 deletions

.github/workflows/ci.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ on:
44
push:
55
branches: ["main"]
66
pull_request:
7+
branches: ["main"]
78

89
jobs:
910
# https://docs.github.com/en/actions/managing-workflow-runs/skipping-workflow-runs

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,12 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
77

88
## major.minor.patch (yyyy.mm.dd)
99

10+
## 0.4.0 (2024.12.17)
11+
12+
### Changed
13+
14+
* Typespecs for each functions
15+
1016
## 0.3.0 (2024.12.15)
1117

1218
### Changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ by adding `open_api_typesense` to your list of dependencies in `mix.exs`:
2121
```elixir
2222
def deps do
2323
[
24-
{:open_api_typesense, "~> 0.3"}
24+
{:open_api_typesense, "~> 0.4"}
2525

2626
# Or from GitHub repository, if you want the latest greatest from main branch
2727
{:open_api_typesense, git: "https://github.com/jaeyson/open_api_typesense.git"}

lib/open_api_typesense/client.ex

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,10 +111,18 @@ defmodule OpenApiTypesense.Client do
111111
query: URI.encode_query(opts[:opts] || [])
112112
}
113113

114+
encoded_body =
115+
if opts[:request] do
116+
[content_type] = opts[:request]
117+
parse_content_type(content_type, opts[:body])
118+
else
119+
Jason.encode_to_iodata!(opts[:body])
120+
end
121+
114122
{_req, resp} =
115123
[
116124
method: opts[:method] || :get,
117-
body: opts[:body],
125+
body: encoded_body,
118126
url: url,
119127
retry: retry,
120128
max_retries: max_retries,
@@ -130,6 +138,23 @@ defmodule OpenApiTypesense.Client do
130138
parse_resp(resp, opts[:response])
131139
end
132140

141+
defp parse_content_type({"application/octet-stream", {:string, :generic}}, body) do
142+
Enum.map_join(body, "\n", &Jason.encode_to_iodata!/1)
143+
end
144+
145+
defp parse_content_type({"application/json", _}, body) do
146+
Jason.encode_to_iodata!(body)
147+
end
148+
149+
# defp parse_content_type({"application/json", {mod, :t}}, body) do
150+
# # Checks if map keys are atom or string
151+
# if Enum.all?(Map.keys(body), &is_atom/1) do
152+
# Jason.encode_to_iodata!(struct(mod, body))
153+
# else
154+
# Jason.encode_to_iodata!(body)
155+
# end
156+
# end
157+
133158
defp parse_resp(%Req.TransportError{} = error, _opts_resp) do
134159
{:error, Exception.message(error)}
135160
end

lib/open_api_typesense/connection.ex

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ defmodule OpenApiTypesense.Connection do
4343
@doc since: "0.2.0"
4444
@spec new(connection :: t() | map()) :: %__MODULE__{}
4545

46-
def new(connection \\ defaults())
46+
def new, do: new(defaults())
4747

4848
def new(connection) when is_map(connection) do
4949
missing_fields = Enum.sort(required_fields() -- Map.keys(connection))

0 commit comments

Comments
 (0)