Fork of daniellemaywood.uk/gleam — Wasm codegen work
2

Configure Feed

Select the types of activity you want to include in your feed.

gleam / hexpm / CONTRIBUTING.md
2.6 kB 65 lines
1<!-- 2 SPDX-License-Identifier: Apache-2.0 3 SPDX-FileCopyrightText: 2026 The Gleam contributors 4--> 5 6# How to Contribute 7 8## Adding a New API Function 9 101. Figure out what you want to do 11 - Go to https://hex.hexdocs.pm/Mix.Tasks.Hex.html and find what you want to do 122. Once you find the page, click on the code icon on the top-right to go to the corresponding source code like so: https://github.com/hexpm/hex/blob/main/lib/mix/tasks/hex.owner.ex#L125 13```elixir 14 defp transfer_owner(organization, package, owner) do 15 auth = Mix.Tasks.Hex.auth_info(:write) 16 Hex.Shell.info("Transferring ownership to #{owner} for #{package}") 17 18 case Hex.API.Package.Owner.add(organization, package, owner, "full", true, auth) do 19 {:ok, {code, _body, _headers}} when code in 200..299 -> 20 :ok 21 22 other -> 23 Hex.Shell.error("Transferring ownership failed") 24 Hex.Utils.print_error_result(other) 25 end 26 end 27``` 28 293. The API function this is calling is `Hex.API.Package.Owner.add` so we go to https://github.com/hexpm/hex/blob/main/lib/hex/api/package.ex, scroll down to the defmodule for Owner and then find the `add` function: 30```elixir 31 def add(repo, package, owner, level, transfer, auth) when package != "" do 32 Hex.API.check_write_api() 33 34 owner = URI.encode_www_form(owner) 35 path = "packages/#{URI.encode(package)}/owners/#{URI.encode(owner)}" 36 params = %{level: level, transfer: transfer} 37 API.erlang_put_request(repo, path, params, auth) 38 end 39``` 40`path` tells us what path and variables we will be using while `params` tells us what the body of the request should contain. The `API.erlang_put_request` at the bottom of this tells us the method of our request needs to be `PUT`. Now we have all of the information we need to create our request function like so: 41```elixir 42pub fn transfer_owner_request( 43 package_name: &str, 44 owner: &str, 45 api_key: &str, 46 config: &Config, 47) -> http::Request<Vec<u8>> { 48 let body = json!({ 49 "level": OwnerLevel::Full.to_string(), 50 "transfer": true, 51 }); 52 53 config 54 .api_request( 55 Method::PUT, 56 &format!("packages/{}/owners/{}", package_name, owner), 57 Some(api_key), 58 ) 59 .body(body.to_string().into_bytes()) 60 .expect("transfer_owner_request request") 61} 62``` 63Note that the `api_key` and `config` fields will always be present in these request functions while the other fields are tailored to the specific request we want to make. 64 654. TODO: How to figure out what to write for the response function?