-
-
Notifications
You must be signed in to change notification settings - Fork 155
feat: replace kadabra with mint #296
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
35f0ac2
feat: replace kadabra with mint
hpopp 19c101e
feat: remove kadabra from mix.exs
hpopp c22ebc3
feat: make ADM workers use mint
hpopp 8b49f36
refactor: various cleanup
hpopp 2ae1736
test: increase test coverage
hpopp 6e80350
refactor: more cleanup
hpopp 21249e4
refactor: ADM.Token and other refactoring
hpopp 9395ba3
Merge branch 'main' into feat/mint
hpopp 28e3e39
docs: update CHANGELOG
hpopp 8afebbb
fix: resolve comments
hpopp File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,43 @@ | ||
| defmodule Pigeon.ADM.Token do | ||
| @moduledoc false | ||
|
|
||
| # We expire the token slightly sooner than the actual expiration | ||
| # to account for network latency and other factors. | ||
| @token_refresh_early_seconds 5 | ||
|
hpopp marked this conversation as resolved.
|
||
|
|
||
| def expired?(_refreshed_datetime_erl, 0), do: true | ||
|
|
||
| def expired?(refreshed_datetime_erl, expiration_seconds) do | ||
| seconds_since(refreshed_datetime_erl) >= | ||
| expiration_seconds - @token_refresh_early_seconds | ||
| end | ||
|
|
||
| defp seconds_since(datetime_erl) do | ||
| gregorian_seconds = | ||
| datetime_erl | ||
| |> :calendar.datetime_to_gregorian_seconds() | ||
|
|
||
| now_gregorian_seconds = | ||
| :os.timestamp() | ||
| |> :calendar.now_to_universal_time() | ||
| |> :calendar.datetime_to_gregorian_seconds() | ||
|
|
||
| now_gregorian_seconds - gregorian_seconds | ||
| end | ||
|
|
||
| @spec refresh_body(String.t(), String.t()) :: String.t() | ||
| def refresh_body(client_id, client_secret) do | ||
| %{ | ||
| "grant_type" => "client_credentials", | ||
| "scope" => "messaging:push", | ||
| "client_id" => client_id, | ||
| "client_secret" => client_secret | ||
| } | ||
| |> URI.encode_query() | ||
| end | ||
|
|
||
| @spec refresh_headers :: [{String.t(), String.t()}] | ||
| def refresh_headers do | ||
| [{"Content-Type", "application/x-www-form-urlencoded;charset=UTF-8"}] | ||
| end | ||
| end | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.