File: package.ex

package info (click to toggle)
erlang-hex 2.0.6-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 2,204 kB
  • sloc: erlang: 2,950; sh: 203; makefile: 10
file content (40 lines) | stat: -rw-r--r-- 1,095 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
defmodule Hex.API.Package do
  @moduledoc false

  alias Hex.API

  def get(repo, name, auth \\ []) do
    path = "packages/#{URI.encode(name)}"
    API.request(:get, repo, path, auth)
  end

  def search(repo, search, auth \\ []) do
    path = "packages?search=#{URI.encode(search)}&sort=downloads"
    API.request(:get, repo, path, auth)
  end

  defmodule Owner do
    @moduledoc false

    def add(repo, package, owner, level, transfer, auth) do
      Hex.API.check_write_api()

      owner = URI.encode_www_form(owner)
      path = "packages/#{URI.encode(package)}/owners/#{URI.encode(owner)}"
      params = %{level: level, transfer: transfer}
      API.erlang_put_request(repo, path, params, auth)
    end

    def delete(repo, package, owner, auth) do
      Hex.API.check_write_api()

      owner = URI.encode_www_form(owner)
      path = "packages/#{URI.encode(package)}/owners/#{URI.encode(owner)}"
      API.request(:delete, repo, path, auth)
    end

    def get(repo, package, auth) do
      API.request(:get, repo, "packages/#{URI.encode(package)}/owners", auth)
    end
  end
end