2024-02-27 22:26:57 -05:00
|
|
|
|
package charity
|
|
|
|
|
|
|
|
|
|
import (
|
2024-02-27 23:03:40 -05:00
|
|
|
|
"context"
|
2024-02-27 22:26:57 -05:00
|
|
|
|
"encoding/json"
|
2024-02-27 23:03:40 -05:00
|
|
|
|
"net/http"
|
2024-02-27 22:26:57 -05:00
|
|
|
|
"net/url"
|
|
|
|
|
|
|
|
|
|
"go.fifitido.net/twitch/api/types"
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
type GetCharityCampaignResponse struct {
|
|
|
|
|
// A list that contains the charity campaign that the broadcaster is currently running.
|
|
|
|
|
// The list is empty if the broadcaster is not running a charity campaign; the campaign information is not available after the campaign ends.
|
|
|
|
|
Data []CharityCampaign `json:"data"`
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
type CharityCampaign struct {
|
|
|
|
|
// An ID that identifies the charity campaign.
|
|
|
|
|
ID string `json:"id"`
|
|
|
|
|
|
|
|
|
|
// An ID that identifies the broadcaster that’s running the campaign.
|
|
|
|
|
BroadcasterID string `json:"broadcaster_id"`
|
|
|
|
|
|
|
|
|
|
// The broadcaster’s login name.
|
|
|
|
|
BroadcasterLogin string `json:"broadcaster_login"`
|
|
|
|
|
|
|
|
|
|
// The broadcaster’s display name.
|
|
|
|
|
BroadcasterName string `json:"broadcaster_name"`
|
|
|
|
|
|
|
|
|
|
// The charity’s name.
|
|
|
|
|
CharityName string `json:"charity_name"`
|
|
|
|
|
|
|
|
|
|
// A description of the charity.
|
|
|
|
|
CharityDescription string `json:"charity_description"`
|
|
|
|
|
|
|
|
|
|
// A URL to an image of the charity’s logo. The image’s type is PNG and its size is 100px X 100px.
|
|
|
|
|
CharityLogo string `json:"charity_logo"`
|
|
|
|
|
|
|
|
|
|
// A URL to the charity’s website.
|
|
|
|
|
CharityWebsite string `json:"charity_website"`
|
|
|
|
|
|
|
|
|
|
// The current amount of donations that the campaign has received.
|
|
|
|
|
CurrentAmount types.CurrencyAmount `json:"current_amount"`
|
|
|
|
|
|
|
|
|
|
// The campaign’s fundraising goal. This field is null if the broadcaster has not defined a fundraising goal.
|
|
|
|
|
TargetAmount *types.CurrencyAmount `json:"target_amount"`
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Gets information about the charity campaign that a broadcaster is running.
|
|
|
|
|
// For example, the campaign’s fundraising goal and the current amount of donations.
|
|
|
|
|
//
|
|
|
|
|
// To receive events when progress is made towards the campaign’s goal or the broadcaster changes the fundraising goal,
|
|
|
|
|
// subscribe to the channel.charity_campaign.progress subscription type.
|
|
|
|
|
//
|
|
|
|
|
// Requires a user access token that includes the channel:read:charity scope.
|
2024-02-27 23:03:40 -05:00
|
|
|
|
func (c *Charity) GetCharityCampaign(ctx context.Context, broadcasterID string) (*GetCharityCampaignResponse, error) {
|
2024-02-27 22:26:57 -05:00
|
|
|
|
endpoint := c.baseUrl.ResolveReference(&url.URL{Path: "charity/campaigns", RawQuery: "broadcaster_id=" + broadcasterID})
|
|
|
|
|
|
2024-02-27 23:03:40 -05:00
|
|
|
|
req, err := http.NewRequestWithContext(ctx, http.MethodGet, endpoint.String(), nil)
|
2024-02-27 22:26:57 -05:00
|
|
|
|
if err != nil {
|
|
|
|
|
return nil, err
|
|
|
|
|
}
|
|
|
|
|
|
2024-02-27 23:03:40 -05:00
|
|
|
|
res, err := c.client.Do(req)
|
|
|
|
|
if err != nil {
|
|
|
|
|
return nil, err
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
defer res.Body.Close()
|
2024-02-27 22:26:57 -05:00
|
|
|
|
|
|
|
|
|
var data GetCharityCampaignResponse
|
2024-02-27 23:03:40 -05:00
|
|
|
|
if err := json.NewDecoder(res.Body).Decode(&data); err != nil {
|
2024-02-27 22:26:57 -05:00
|
|
|
|
return nil, err
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return &data, nil
|
|
|
|
|
}
|