issuesapp: github.com/shurcooL/issuesapp/httpclient Index | Examples | Files

package httpclient

import "github.com/shurcooL/issuesapp/httpclient"

Package httpclient contains issues.Service implementation over HTTP.

Index

Examples

Package Files

httpclient.go

func NewIssues Uses

func NewIssues(httpClient *http.Client, scheme, host string) issues.Service

NewIssues creates a client that implements issues.Service remotely over HTTP. If a nil httpClient is provided, http.DefaultClient will be used. scheme and host can be empty strings to target local service.

Code:

issuesClient := httpclient.NewIssues(nil, "http", "localhost:8080")

// Now you can use any of issuesClient methods.

Code:

// HTTP client with authentication.
src := oauth2.StaticTokenSource(
    &oauth2.Token{AccessToken: "... your access token ..."},
)
httpClient := oauth2.NewClient(context.Background(), src)

issuesClient := httpclient.NewIssues(httpClient, "http", "localhost:8080")

// Now you can use any of issuesClient methods.

type Issues Uses

type Issues struct {
    // contains filtered or unexported fields
}

Issues implements issues.Service remotely over HTTP. Use NewIssues for creation, zero value of Issues is unfit for use.

func (*Issues) Count Uses

func (i *Issues) Count(ctx context.Context, repo issues.RepoSpec, opt issues.IssueListOptions) (uint64, error)

Code:

count, err := issuesClient.Count(context.Background(), issues.RepoSpec{URI: "example.org/repo"}, issues.IssueListOptions{
    State: issues.AllStates,
})
if err != nil {
    log.Fatalln(err)
}

printJSON(count)

Output:

1

func (*Issues) Create Uses

func (*Issues) Create(_ context.Context, repo issues.RepoSpec, issue issues.Issue) (issues.Issue, error)

func (*Issues) CreateComment Uses

func (*Issues) CreateComment(_ context.Context, repo issues.RepoSpec, id uint64, comment issues.Comment) (issues.Comment, error)

func (*Issues) Edit Uses

func (*Issues) Edit(_ context.Context, repo issues.RepoSpec, id uint64, ir issues.IssueRequest) (issues.Issue, []issues.Event, error)

func (*Issues) EditComment Uses

func (i *Issues) EditComment(ctx context.Context, repo issues.RepoSpec, id uint64, cr issues.CommentRequest) (issues.Comment, error)

func (*Issues) Get Uses

func (*Issues) Get(_ context.Context, repo issues.RepoSpec, id uint64) (issues.Issue, error)

func (*Issues) List Uses

func (i *Issues) List(ctx context.Context, repo issues.RepoSpec, opt issues.IssueListOptions) ([]issues.Issue, error)

Code:

is, err := issuesClient.List(context.Background(), issues.RepoSpec{URI: "example.org/repo"}, issues.IssueListOptions{
    State: issues.StateFilter(issues.OpenState),
})
if err != nil {
    log.Fatalln(err)
}

printJSON(is)

Output:

[
	{
		"ID": 1,
		"State": "open",
		"Title": "Sample title",
		"Labels": null,
		"User": {
			"ID": 1,
			"Domain": "example.org",
			"Elsewhere": null,
			"Login": "gopher",
			"Name": "Sample Gopher",
			"Email": "gopher@example.org",
			"AvatarURL": "",
			"HTMLURL": "",
			"SiteAdmin": false
		},
		"CreatedAt": "2016-09-24T22:00:50.642521756Z",
		"Edited": null,
		"Body": "",
		"Reactions": null,
		"Editable": false,
		"Replies": 2
	}
]

func (*Issues) ListComments Uses

func (i *Issues) ListComments(ctx context.Context, repo issues.RepoSpec, id uint64, opt *issues.ListOptions) ([]issues.Comment, error)

Code:

is, err := issuesClient.ListComments(context.Background(), issues.RepoSpec{URI: "example.org/repo"}, 1, nil)
if err != nil {
    log.Fatalln(err)
}

printJSON(is)

Output:

[
	{
		"ID": 0,
		"User": {
			"ID": 1,
			"Domain": "example.org",
			"Elsewhere": null,
			"Login": "gopher",
			"Name": "Sample Gopher",
			"Email": "gopher@example.org",
			"AvatarURL": "",
			"HTMLURL": "",
			"SiteAdmin": false
		},
		"CreatedAt": "2016-09-24T22:00:50.642521756Z",
		"Edited": null,
		"Body": "Sample body.",
		"Reactions": [
			{
				"Reaction": "grinning",
				"Users": [
					{
						"ID": 1,
						"Domain": "example.org",
						"Elsewhere": null,
						"Login": "gopher",
						"Name": "Sample Gopher",
						"Email": "gopher@example.org",
						"AvatarURL": "",
						"HTMLURL": "",
						"SiteAdmin": false
					}
				]
			},
			{
				"Reaction": "+1",
				"Users": [
					{
						"ID": 2,
						"Domain": "example.org",
						"Elsewhere": null,
						"Login": "2@example.org",
						"Name": "",
						"Email": "",
						"AvatarURL": "https://secure.gravatar.com/avatar?d=mm\u0026f=y\u0026s=96",
						"HTMLURL": "",
						"SiteAdmin": false
					},
					{
						"ID": 1,
						"Domain": "example.org",
						"Elsewhere": null,
						"Login": "gopher",
						"Name": "Sample Gopher",
						"Email": "gopher@example.org",
						"AvatarURL": "",
						"HTMLURL": "",
						"SiteAdmin": false
					},
					{
						"ID": 3,
						"Domain": "example.org",
						"Elsewhere": null,
						"Login": "3@example.org",
						"Name": "",
						"Email": "",
						"AvatarURL": "https://secure.gravatar.com/avatar?d=mm\u0026f=y\u0026s=96",
						"HTMLURL": "",
						"SiteAdmin": false
					}
				]
			},
			{
				"Reaction": "mushroom",
				"Users": [
					{
						"ID": 3,
						"Domain": "example.org",
						"Elsewhere": null,
						"Login": "3@example.org",
						"Name": "",
						"Email": "",
						"AvatarURL": "https://secure.gravatar.com/avatar?d=mm\u0026f=y\u0026s=96",
						"HTMLURL": "",
						"SiteAdmin": false
					}
				]
			}
		],
		"Editable": true
	},
	{
		"ID": 1,
		"User": {
			"ID": 2,
			"Domain": "example.org",
			"Elsewhere": null,
			"Login": "2@example.org",
			"Name": "",
			"Email": "",
			"AvatarURL": "https://secure.gravatar.com/avatar?d=mm\u0026f=y\u0026s=96",
			"HTMLURL": "",
			"SiteAdmin": false
		},
		"CreatedAt": "2016-10-02T12:31:50.813167602Z",
		"Edited": null,
		"Body": "Sample reply.",
		"Reactions": null,
		"Editable": false
	},
	{
		"ID": 2,
		"User": {
			"ID": 1,
			"Domain": "example.org",
			"Elsewhere": null,
			"Login": "gopher",
			"Name": "Sample Gopher",
			"Email": "gopher@example.org",
			"AvatarURL": "",
			"HTMLURL": "",
			"SiteAdmin": false
		},
		"CreatedAt": "2016-10-02T18:51:14.250725508Z",
		"Edited": {
			"By": {
				"ID": 1,
				"Domain": "example.org",
				"Elsewhere": null,
				"Login": "gopher",
				"Name": "Sample Gopher",
				"Email": "gopher@example.org",
				"AvatarURL": "",
				"HTMLURL": "",
				"SiteAdmin": false
			},
			"At": "2016-10-02T18:57:47.938813179Z"
		},
		"Body": "Sample another reply.",
		"Reactions": null,
		"Editable": true
	}
]

func (*Issues) ListEvents Uses

func (i *Issues) ListEvents(ctx context.Context, repo issues.RepoSpec, id uint64, opt *issues.ListOptions) ([]issues.Event, error)

Package httpclient imports 9 packages (graph) and is imported by 3 packages. Updated 2018-12-31. Refresh now. Tools for package owners.