This repository has been archived by the owner on Feb 5, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 10
/
email_subscriptions.go
91 lines (76 loc) · 2.84 KB
/
email_subscriptions.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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
// Copyright (c) 2015 Ableton AG, Berlin. All rights reserved.
//
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package travis
import (
"context"
"fmt"
"net/http"
"net/url"
)
// EmailSubscriptionService handles communication with the
// email subscription related methods of the Travis CI API.
type EmailSubscriptionsService struct {
client *Client
}
// SubscribeByRepoId enables an email subscription of the repository based on the provided repository id
//
// Travis CI API docs: https://developer.travis-ci.com/resource/email_subscription#resubscribe
func (es *EmailSubscriptionsService) SubscribeByRepoId(ctx context.Context, repoId uint) (*http.Response, error) {
u, err := urlWithOptions(fmt.Sprintf("repo/%d/email_subscription", repoId), nil)
if err != nil {
return nil, err
}
req, err := es.client.NewRequest(http.MethodPost, u, nil, nil)
if err != nil {
return nil, err
}
resp, err := es.client.Do(ctx, req, nil)
return resp, err
}
// SubscribeByRepoSlug enables an email subscription of the repository based on the provided repository slug
//
// Travis CI API docs: https://developer.travis-ci.com/resource/email_subscription#resubscribe
func (es *EmailSubscriptionsService) SubscribeByRepoSlug(ctx context.Context, repoSlug string) (*http.Response, error) {
u, err := urlWithOptions(fmt.Sprintf("repo/%s/email_subscription", url.QueryEscape(repoSlug)), nil)
if err != nil {
return nil, err
}
req, err := es.client.NewRequest(http.MethodPost, u, nil, nil)
if err != nil {
return nil, err
}
resp, err := es.client.Do(ctx, req, nil)
return resp, err
}
// UnsubscribeByRepoId disables an email subscription of the repository based on the provided repository id
//
// Travis CI API docs: https://developer.travis-ci.com/resource/email_subscription#unsubscribe
func (es *EmailSubscriptionsService) UnsubscribeByRepoId(ctx context.Context, repoId uint) (*http.Response, error) {
u, err := urlWithOptions(fmt.Sprintf("repo/%d/email_subscription", repoId), nil)
if err != nil {
return nil, err
}
req, err := es.client.NewRequest(http.MethodDelete, u, nil, nil)
if err != nil {
return nil, err
}
resp, err := es.client.Do(ctx, req, nil)
return resp, err
}
// UnsubscribeByRepoSlug disables an email subscription of the repository based on the provided repository slug
//
// Travis CI API docs: https://developer.travis-ci.com/resource/email_subscription#unsubscribe
func (es *EmailSubscriptionsService) UnsubscribeByRepoSlug(ctx context.Context, repoSlug string) (*http.Response, error) {
u, err := urlWithOptions(fmt.Sprintf("repo/%s/email_subscription", url.QueryEscape(repoSlug)), nil)
if err != nil {
return nil, err
}
req, err := es.client.NewRequest(http.MethodDelete, u, nil, nil)
if err != nil {
return nil, err
}
resp, err := es.client.Do(ctx, req, nil)
return resp, err
}