From 5abc5d1777ce2bdc32d99767683ae88248ff1dfd Mon Sep 17 00:00:00 2001 From: Majd Alfhaily Date: Sun, 9 Apr 2023 20:34:46 +0200 Subject: [PATCH] Expose Lookup API (#172) --- pkg/appstore/appstore.go | 1 + pkg/appstore/appstore_lookup.go | 25 +++++++++++++++++++++++++ 2 files changed, 26 insertions(+) diff --git a/pkg/appstore/appstore.go b/pkg/appstore/appstore.go index df1869c..27f1900 100644 --- a/pkg/appstore/appstore.go +++ b/pkg/appstore/appstore.go @@ -13,6 +13,7 @@ type AppStore interface { Login(email, password, authCode string) (LoginOutput, error) Info() (InfoOutput, error) Revoke() error + Lookup(bundleID string) (LookupOutput, error) Search(term string, limit int64) (SearchOutput, error) Purchase(bundleID string) error Download(bundleID string, outputPath string, acquireLicense bool) (DownloadOutput, error) diff --git a/pkg/appstore/appstore_lookup.go b/pkg/appstore/appstore_lookup.go index 4cf509a..37273a1 100644 --- a/pkg/appstore/appstore_lookup.go +++ b/pkg/appstore/appstore_lookup.go @@ -7,6 +7,31 @@ import ( "net/url" ) +type LookupOutput struct { + App App +} + +func (a *appstore) Lookup(bundleID string) (LookupOutput, error) { + acc, err := a.account() + if err != nil { + return LookupOutput{}, errors.Wrap(err, ErrGetAccount.Error()) + } + + countryCode, err := a.countryCodeFromStoreFront(acc.StoreFront) + if err != nil { + return LookupOutput{}, errors.Wrap(err, ErrInvalidCountryCode.Error()) + } + + app, err := a.lookup(bundleID, countryCode) + if err != nil { + return LookupOutput{}, err + } + + return LookupOutput{ + App: app, + }, nil +} + func (a *appstore) lookup(bundleID, countryCode string) (App, error) { if StoreFronts[countryCode] == "" { return App{}, ErrInvalidCountryCode