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

Add Fetch.UploadBuilds #222

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
80 changes: 80 additions & 0 deletions butlerd/generous/docs/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -1948,6 +1948,86 @@ afterwards with &lsquo;Fresh&rsquo; set</p>

</div>

### Fetch.UploadBuilds (client request)


<p>
<p>Fetches builds for an itch.io game</p>

</p>

<p>
<span class="header">Parameters</span>
</p>


<table class="field-table">
<tr>
<td><code>game</code></td>
<td><code class="typename"><span class="type" data-tip-selector="#Game__TypeHint">Game</span></code></td>
<td><p>Game whose builds we should look for</p>
</td>
</tr>
<tr>
<td><code>upload</code></td>
<td><code class="typename"><span class="type" data-tip-selector="#Upload__TypeHint">Upload</span></code></td>
<td><p>Upload whose builds we should look for</p>
</td>
</tr>
</table>



<p>
<span class="header">Result</span>
</p>


<table class="field-table">
<tr>
<td><code>builds</code></td>
<td><code class="typename"><span class="type" data-tip-selector="#Build__TypeHint">Build</span>[]</code></td>
<td><p>List of builds</p>
</td>
</tr>
</table>


<div id="FetchUploadBuildsParams__TypeHint" class="tip-content">
<p>Fetch.UploadBuilds (client request) <a href="#/?id=fetchuploadbuilds-client-request">(Go to definition)</a></p>

<p>
<p>Fetches builds for an itch.io game</p>

</p>

<table class="field-table">
<tr>
<td><code>game</code></td>
<td><code class="typename"><span class="type">Game</span></code></td>
</tr>
<tr>
<td><code>upload</code></td>
<td><code class="typename"><span class="type">Upload</span></code></td>
</tr>
</table>

</div>


<div id="FetchUploadBuildsResult__TypeHint" class="tip-content">
<p>FetchUploadBuilds <a href="#/?id=fetchuploadbuilds-">(Go to definition)</a></p>


<table class="field-table">
<tr>
<td><code>builds</code></td>
<td><code class="typename"><span class="type">Build</span>[]</code></td>
</tr>
</table>

</div>

### Fetch.User (client request)


Expand Down
28 changes: 28 additions & 0 deletions butlerd/generous/spec/butlerd.json
Original file line number Diff line number Diff line change
Expand Up @@ -616,6 +616,34 @@
]
}
},
{
"method": "Fetch.UploadBuilds",
"doc": "Fetches builds for an itch.io game",
"caller": "client",
"params": {
"fields": [
{
"name": "game",
"doc": "Game whose builds we should look for",
"type": "Game"
},
{
"name": "upload",
"doc": "Upload whose builds we should look for",
"type": "Upload"
}
]
},
"result": {
"fields": [
{
"name": "builds",
"doc": "List of builds",
"type": "Build[]"
}
]
}
},
{
"method": "Fetch.User",
"doc": "Fetches information for an itch.io user.",
Expand Down
41 changes: 41 additions & 0 deletions butlerd/messages/messages.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

25 changes: 25 additions & 0 deletions butlerd/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -715,6 +715,31 @@ func (r *FetchGameUploadsResult) SetStale(stale bool) {
r.Stale = stale
}

// Fetches builds for an itch.io game
//
// @name Fetch.UploadBuilds
// @category Fetch
// @caller client
type FetchUploadBuildsParams struct {
// Game whose builds we should look for
Game *itchio.Game `json:"game"`

// Upload whose builds we should look for
Upload *itchio.Upload `json:"upload"`
}

func (p FetchUploadBuildsParams) Validate() error {
return validation.ValidateStruct(&p,
validation.Field(&p.Game, validation.Required),
validation.Field(&p.Upload, validation.Required),
)
}

type FetchUploadBuildsResult struct {
// List of builds
Builds []*itchio.Build `json:"builds"`
}

// Fetches information for an itch.io user.
//
// @name Fetch.User
Expand Down
1 change: 1 addition & 0 deletions endpoints/fetch/fetch.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
func Register(router *butlerd.Router) {
messages.FetchGame.Register(router, FetchGame)
messages.FetchGameUploads.Register(router, FetchGameUploads)
messages.FetchUploadBuilds.Register(router, FetchUploadBuilds)
messages.FetchUser.Register(router, FetchUser)
messages.FetchSale.Register(router, FetchSale)
messages.FetchCollection.Register(router, FetchCollection)
Expand Down
31 changes: 31 additions & 0 deletions endpoints/fetch/fetch_upload_builds.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package fetch

import (
"crawshaw.io/sqlite"
"github.com/itchio/butler/butlerd"
"github.com/itchio/butler/cmd/operate"
"github.com/itchio/go-itchio"
"github.com/pkg/errors"
)

func FetchUploadBuilds(rc *butlerd.RequestContext, params butlerd.FetchUploadBuildsParams) (*butlerd.FetchUploadBuildsResult, error) {
res := &butlerd.FetchUploadBuildsResult{}

var access *operate.GameAccess
rc.WithConn(func(conn *sqlite.Conn) {
access = operate.AccessForGameID(conn, params.Game.ID)
})
client := rc.Client(access.APIKey)

buildsRes, err := client.ListUploadBuilds(rc.Ctx, itchio.ListUploadBuildsParams{
UploadID: params.Upload.ID,
Credentials: access.Credentials,
})
if err != nil {
return nil, errors.WithStack(err)
}

res.Builds = buildsRes.Builds

return res, nil
}