Skip to content
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

feat: add ID getter methods #103

Merged
merged 1 commit into from
Jul 12, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
5 changes: 5 additions & 0 deletions appsTransport.go
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,11 @@ func (t *AppsTransport) RoundTrip(req *http.Request) (*http.Response, error) {
return resp, err
}

// AppID returns the appID of the transport
func (t *AppsTransport) AppID() int64 {
return t.appID
}

type AppsTransportOption func(*AppsTransport)

// WithSigner configures the AppsTransport to use the given Signer for generating JWT tokens.
Expand Down
4 changes: 4 additions & 0 deletions appsTransport_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,10 @@ func TestAppsTransport(t *testing.T) {
t.Fatalf("error creating transport: %v", err)
}

if tr.appID != appID {
t.Errorf("appID want->got: %d->%d", appID, tr.appID)
}

req := httptest.NewRequest(http.MethodGet, "http://example.com", new(bytes.Buffer))
req.Header.Add("Accept", customHeader)
if _, err := tr.RoundTrip(req); err != nil {
Expand Down
10 changes: 10 additions & 0 deletions transport.go
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,16 @@ func (t *Transport) Expiry() (expiresAt time.Time, refreshAt time.Time, err erro
return t.token.ExpiresAt, t.token.getRefreshTime(), nil
}

// AppID returns the app ID associated with the transport
func (t *Transport) AppID() int64 {
return t.appID
}

// InstallationID returns the installation ID associated with the transport
func (t *Transport) InstallationID() int64 {
return t.installationID
}

func (t *Transport) refreshToken(ctx context.Context) error {
// Convert InstallationTokenOptions into a ReadWriter to pass as an argument to http.NewRequest.
body, err := GetReadWriter(t.InstallationTokenOptions)
Expand Down
9 changes: 9 additions & 0 deletions transport_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,15 @@ func TestNew(t *testing.T) {
}
tr.BaseURL = ts.URL

// test id getter methods
if tr.AppID() != appID {
t.Fatalf("appID got: %q want: %q", tr.AppID(), appID)
}

if tr.InstallationID() != installationID {
t.Fatalf("installationID got: %q want: %q", tr.InstallationID(), installationID)
}

client := http.Client{Transport: tr}
_, err = client.Get(ts.URL + "/auth/with/installation/token/endpoint")
if err != nil {
Expand Down