-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add client.ListSites and site.Details functions (#5)
* Fix error message. * Add ListSites function. * Add get site function. * Add doc. * Finish up the PR --------- Co-authored-by: André Santos <andrerfcsantos@gmail.com>
- Loading branch information
1 parent
aabdf92
commit a3af610
Showing
8 changed files
with
234 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
package plausible | ||
|
||
import "github.com/andrerfcsantos/go-plausible/plausible/urlmaker/pagination" | ||
|
||
// SiteResult contains the details for a Site | ||
type SiteResult struct { | ||
// Domain of the site. | ||
Domain string `json:"domain"` | ||
// Timezone of the newly created site. | ||
Timezone string `json:"timezone"` | ||
} | ||
|
||
// ListSitesResult is the result of a request to list sites. | ||
type ListSitesResult struct { | ||
// Sites is the list of sites in a response | ||
Sites []SiteResult `json:"sites"` | ||
// Meta is the pagination meta information of a page | ||
Meta pagination.Meta `json:"meta"` | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
package pagination | ||
|
||
// Meta contains pagination information related with a response | ||
type Meta struct { | ||
// After is the domain id that appears before all the records in the current page | ||
After string `json:"after"` | ||
// Before is the domain id that appears after all the records in the current page | ||
Before string `json:"before"` | ||
// Limit limits the number of records in a page | ||
Limit int `json:"limit"` | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
package pagination | ||
|
||
// Option represents a pagination option. | ||
// It is not meant to be created directly - instead, you should get | ||
// an Option via the helper functions, like After, Before and Limit. | ||
type Option func(*Paginator) | ||
|
||
// After sets the 'after' pagination option | ||
func After(after string) Option { | ||
return func(p *Paginator) { | ||
p.After = after | ||
} | ||
} | ||
|
||
// Before sets the 'before' pagination option | ||
func Before(before string) Option { | ||
return func(p *Paginator) { | ||
p.Before = before | ||
} | ||
} | ||
|
||
// Limit sets the 'limit' pagination option | ||
func Limit(limit int) Option { | ||
return func(p *Paginator) { | ||
p.Limit = limit | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
package pagination | ||
|
||
// Paginator holds information to paginate requests | ||
type Paginator struct { | ||
// After is the domain id that appears before all the records in the desired page | ||
After string | ||
// Before is the domain id that appears after all the records in the desired page | ||
Before string | ||
// Limit sets the maximum records in the desired page | ||
Limit int | ||
} | ||
|
||
// NewPaginator creates a new paginator with the given options | ||
func NewPaginator(options ...Option) *Paginator { | ||
paginator := &Paginator{} | ||
for _, opt := range options { | ||
opt(paginator) | ||
} | ||
return paginator | ||
} |