-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathpackage_details.go
70 lines (56 loc) · 1.42 KB
/
package_details.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
package playstore
import (
"errors"
"net/url"
)
type AppDetails struct {
Title string
Id string
Creator string
Mature bool
Images []AppImage
VersionCode int
VersionString string
Developer *Developer
}
type AppImage struct {
Url string
Type int
}
type Developer struct {
Name string
Email string
Website string
}
func (p *Playstore) PackageDetails(pkg string) (*AppDetails, error) {
query := url.Values{}
query.Add("doc", pkg)
d("Will fetch data for package %s", pkg)
resp, err := p.makeApiRequest("/details", query, nil)
if err != nil {
return nil, err
}
doc := resp.GetPayload().GetDetailsResponse().GetDocV2()
appDetails := doc.GetDetails().GetAppDetails()
if appDetails == nil {
return nil, errors.New("Could not extract app details from package")
}
images := make([]AppImage, len(doc.Image))
for j, i := range doc.Image {
images[j] = AppImage{Url: i.GetImageUrl(), Type: int(i.GetImageType())}
}
return &AppDetails{
Title: doc.GetTitle(),
Id: doc.GetDocid(),
Creator: doc.GetCreator(),
Mature: doc.GetMature(),
Images: images,
VersionCode: int(appDetails.GetVersionCode()),
VersionString: appDetails.GetVersionString(),
Developer: &Developer{
Name: appDetails.GetDeveloperName(),
Email: appDetails.GetDeveloperEmail(),
Website: appDetails.GetDeveloperWebsite(),
},
}, nil
}