Skip to content

Commit

Permalink
refactor: use types from Apple.Types.AppleDeveloper
Browse files Browse the repository at this point in the history
  • Loading branch information
c4710n committed Oct 13, 2024
1 parent d528506 commit b60850b
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 55 deletions.
32 changes: 7 additions & 25 deletions lib/apple/maps_server_api.ex
Original file line number Diff line number Diff line change
Expand Up @@ -4,37 +4,19 @@ defmodule Apple.MapsServerAPI do
"""

alias JOSE.{JWK, JWS, JWT}

@typedoc """
The team ID, like `"6MPDV0UYYX"`.
"""
@type team_id :: String.t()

@typedoc """
The private key ID, like `"2Y9R5HMY68"`.
"""
@type key_id :: String.t()

@typedoc """
The private key associated with the `key_id`.
It's in PEM format, like:
```text
-----BEGIN PRIVATE KEY-----
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
...
-----END PRIVATE KEY-----
```
"""
@type private_key :: String.t()
alias Apple.Types.AppleDeveloper

@typedoc """
Something like `"*.example.com"`.
"""
@type origin :: String.t()

@spec build_auth_token!(team_id(), key_id(), private_key(), origin() | nil) :: String.t()
@spec build_auth_token!(
AppleDeveloper.team_id(),
AppleDeveloper.key_id(),
AppleDeveloper.private_key(),
origin() | nil
) :: String.t()
def build_auth_token!(team_id, key_id, private_key, origin \\ nil)
when is_binary(team_id) and
is_binary(key_id) and
Expand Down
37 changes: 7 additions & 30 deletions lib/apple/weather_kit_rest_api.ex
Original file line number Diff line number Diff line change
Expand Up @@ -4,35 +4,7 @@ defmodule Apple.WeatherKitRestAPI do
"""

alias JOSE.{JWK, JWS, JWT}

@typedoc """
The team ID, like `"6MPDV0UYYX"`.
"""
@type team_id :: String.t()

@typedoc """
The private key ID, like `"2Y9R5HMY68"`.
"""
@type key_id :: String.t()

@typedoc """
The private key associated with the `key_id`.
It's in PEM format, like:
```text
-----BEGIN PRIVATE KEY-----
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
...
-----END PRIVATE KEY-----
```
"""
@type private_key :: String.t()

@typedoc """
The registered service ID, like `"com.example.weatherkit-client"`.
"""
@type service_id :: String.t()
alias Apple.Types.AppleDeveloper

@doc """
Builds a token to authorize HTTP requests.
Expand All @@ -46,7 +18,12 @@ defmodule Apple.WeatherKitRestAPI do
Authorization: Bearer <JWT>
```
"""
@spec build_auth_token!(team_id(), key_id(), private_key(), service_id()) :: String.t()
@spec build_auth_token!(
AppleDeveloper.team_id(),
AppleDeveloper.key_id(),
AppleDeveloper.private_key(),
AppleDeveloper.service_id()
) :: String.t()
def build_auth_token!(team_id, key_id, private_key, service_id)
when is_binary(team_id) and
is_binary(key_id) and
Expand Down
14 changes: 14 additions & 0 deletions lib/types/apple_developer.ex
Original file line number Diff line number Diff line change
Expand Up @@ -40,4 +40,18 @@ defmodule Apple.Types.AppleDeveloper do
```
"""
@type private_key :: String.t()

@typedoc """
The registered service ID, like `"com.example.weatherkit"`.
It can be obtained from your Apple Developer account by following this path:
1. Sign into your Apple Developer account.
2. Navigate to "Certificates, IDs & Profiles".
3. Navigate to "Identifiers".
4. Click the plus button to add a new identifier.
5. Select "Service IDs", and register a service ID.
"""
@type service_id :: String.t()
end

0 comments on commit b60850b

Please sign in to comment.