-
Notifications
You must be signed in to change notification settings - Fork 87
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[broken] add many new list and list with id endpoints to client
- Loading branch information
Showing
30 changed files
with
2,160 additions
and
470 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,40 @@ | ||
package golinode | ||
|
||
type Account struct { | ||
FirstName string `json:"first_name"` | ||
LastName string `json:"last_name"` | ||
Email string | ||
Company string | ||
Address1 string | ||
Address2 string | ||
Balance float32 | ||
City string | ||
State string | ||
Zip string | ||
Country string | ||
TaxID string `json:"tax_id"` | ||
CreditCard *CreditCard `json:"credit_card"` | ||
} | ||
|
||
type CreditCard struct { | ||
LastFour string `json:"last_four"` | ||
Expiry string | ||
} | ||
|
||
// fixDates converts JSON timestamps to Go time.Time values | ||
func (v *Account) fixDates() *Account { | ||
return v | ||
} | ||
|
||
// GetAccountEvents gets the template with the provided ID | ||
func (c *Client) GetAccount() (*Account, error) { | ||
e, err := c.Account.Endpoint() | ||
if err != nil { | ||
return nil, err | ||
} | ||
r, err := c.R().SetResult(&Account{}).Get(e) | ||
if err != nil { | ||
return nil, err | ||
} | ||
return r.Result().(*Account).fixDates(), nil | ||
} |
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,83 @@ | ||
package golinode | ||
|
||
import ( | ||
"time" | ||
|
||
"github.com/go-resty/resty" | ||
) | ||
|
||
// Events represent account events across all Linode things the | ||
// account is privy to (API endpoint /account/events) | ||
type Event struct { | ||
CreatedStr string `json:"created"` | ||
UpdatedStr string `json:"updated"` | ||
|
||
ID int | ||
Status string | ||
Action string | ||
PercentComplete int `json:"percent_complete"` | ||
Rate string | ||
Read bool | ||
Seen bool | ||
TimeRemaining int | ||
Username string | ||
Entity *EventEntity | ||
Created *time.Time `json:"-"` | ||
} | ||
|
||
type EventEntity struct { | ||
ID int | ||
Label string | ||
Type string | ||
URL string | ||
} | ||
|
||
// EventsPagedResponse represents a paginated Events API response | ||
type EventsPagedResponse struct { | ||
*PageOptions | ||
Data []*Event | ||
} | ||
|
||
// Endpoint gets the endpoint URL for Event | ||
func (EventsPagedResponse) Endpoint(c *Client) string { | ||
endpoint, err := c.Events.Endpoint() | ||
if err != nil { | ||
panic(err) | ||
} | ||
return endpoint | ||
} | ||
|
||
// Endpoint gets the endpoint URL for Event | ||
func (EventsPagedResponse) EndpointWithID(c *Client, id int) string { | ||
endpoint, err := c.Events.EndpointWithID(id) | ||
if err != nil { | ||
panic(err) | ||
} | ||
return endpoint | ||
} | ||
|
||
// AppendData appends Events when processing paginated Event responses | ||
func (resp *EventsPagedResponse) AppendData(r *EventsPagedResponse) { | ||
(*resp).Data = append(resp.Data, r.Data...) | ||
} | ||
|
||
// SetResult sets the Resty response type of Events | ||
func (EventsPagedResponse) SetResult(r *resty.Request) { | ||
r.SetResult(EventsPagedResponse{}) | ||
} | ||
|
||
// ListEvents lists Events | ||
func (c *Client) ListEvents(opts *ListOptions) ([]*Event, error) { | ||
response := EventsPagedResponse{} | ||
err := c.ListHelper(response, opts) | ||
for _, el := range response.Data { | ||
el.fixDates() | ||
} | ||
return response.Data, err | ||
} | ||
|
||
// fixDates converts JSON timestamps to Go time.Time values | ||
func (v *Event) fixDates() *Event { | ||
v.Created, _ = parseDates(v.CreatedStr) | ||
return v | ||
} |
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,129 @@ | ||
package golinode | ||
|
||
import ( | ||
"fmt" | ||
"time" | ||
|
||
"github.com/go-resty/resty" | ||
) | ||
|
||
// Invoice represents a Invoice object | ||
type Invoice struct { | ||
DateStr string `json:"date"` | ||
|
||
ID int | ||
Label string | ||
Total float32 | ||
Date *time.Time `json:"-"` | ||
} | ||
|
||
type InvoiceItem struct { | ||
FromStr string `json:"from"` | ||
ToStr string `json:"to"` | ||
|
||
Label string | ||
Type string | ||
UnitPrice int | ||
Quantity int | ||
Amount float32 | ||
From *time.Time `json:"-"` | ||
To *time.Time `json:"-"` | ||
} | ||
|
||
// InvoicesPagedResponse represents a paginated Invoice API response | ||
type InvoicesPagedResponse struct { | ||
*PageOptions | ||
Data []*Invoice | ||
} | ||
|
||
// Endpoint gets the endpoint URL for Invoice | ||
func (InvoicesPagedResponse) Endpoint(c *Client) string { | ||
endpoint, err := c.Invoices.Endpoint() | ||
if err != nil { | ||
panic(err) | ||
} | ||
return endpoint | ||
} | ||
|
||
// AppendData appends Invoices when processing paginated Invoice responses | ||
func (resp *InvoicesPagedResponse) AppendData(r *InvoicesPagedResponse) { | ||
(*resp).Data = append(resp.Data, r.Data...) | ||
} | ||
|
||
// SetResult sets the Resty response type of Invoice | ||
func (InvoicesPagedResponse) SetResult(r *resty.Request) { | ||
r.SetResult(InvoicesPagedResponse{}) | ||
} | ||
|
||
// ListInvoices lists Invoices | ||
func (c *Client) ListInvoices(opts *ListOptions) ([]*Invoice, error) { | ||
response := InvoicesPagedResponse{} | ||
err := c.ListHelper(response, opts) | ||
for _, el := range response.Data { | ||
el.fixDates() | ||
} | ||
return response.Data, err | ||
} | ||
|
||
// fixDates converts JSON timestamps to Go time.Time values | ||
func (v *Invoice) fixDates() *Invoice { | ||
v.Date, _ = parseDates(v.DateStr) | ||
return v | ||
} | ||
|
||
// fixDates converts JSON timestamps to Go time.Time values | ||
func (v *InvoiceItem) fixDates() *InvoiceItem { | ||
v.From, _ = parseDates(v.FromStr) | ||
v.To, _ = parseDates(v.ToStr) | ||
return v | ||
} | ||
|
||
// GetInvoice gets the template with the provided ID | ||
func (c *Client) GetInvoice(id string) (*Invoice, error) { | ||
e, err := c.Invoices.Endpoint() | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
e = fmt.Sprintf("%s/%s", e, id) | ||
r, err := c.R().SetResult(&Invoice{}).Get(e) | ||
if err != nil { | ||
return nil, err | ||
} | ||
return r.Result().(*Invoice).fixDates(), nil | ||
} | ||
|
||
// InvoiceItemsPagedResponse represents a paginated Invoice Item API response | ||
type InvoiceItemsPagedResponse struct { | ||
*PageOptions | ||
Data []*InvoiceItem | ||
} | ||
|
||
// Endpoint gets the endpoint URL for InvoiceItems | ||
func (InvoiceItemsPagedResponse) EndpointWithID(c *Client, id int) string { | ||
endpoint, err := c.InvoiceItems.EndpointWithID(id) | ||
if err != nil { | ||
panic(err) | ||
} | ||
return endpoint | ||
} | ||
|
||
// AppendData appends InvoiceItems when processing paginated Invoice Item responses | ||
func (resp *InvoiceItemsPagedResponse) AppendData(r *InvoiceItemsPagedResponse) { | ||
(*resp).Data = append(resp.Data, r.Data...) | ||
} | ||
|
||
// SetResult sets the Resty response type of InvoiceItems | ||
func (InvoiceItemsPagedResponse) SetResult(r *resty.Request) { | ||
r.SetResult(InvoiceItemsPagedResponse{}) | ||
} | ||
|
||
// ListInvoiceItems lists Invoice Items | ||
func (c *Client) ListInvoiceItems(id int, opts *ListOptions) ([]*InvoiceItem, error) { | ||
response := InvoiceItemsPagedResponse{} | ||
err := c.ListHelperWithID(response, id, opts) | ||
for _, el := range response.Data { | ||
el.fixDates() | ||
} | ||
return response.Data, err | ||
} |
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,80 @@ | ||
package golinode | ||
|
||
import ( | ||
"time" | ||
|
||
"github.com/go-resty/resty" | ||
) | ||
|
||
// Notifications represent account events across all Linode things the | ||
// account is privy to (API endpoint /account/events) | ||
type Notification struct { | ||
UntilStr string `json:"until"` | ||
WhenStr string `json:"when"` | ||
|
||
Label string | ||
Message string | ||
Type string | ||
Severity string | ||
Entity *NotificationEntity | ||
Until *time.Time `json:"-"` | ||
When *time.Time `json:"-"` | ||
} | ||
|
||
type NotificationEntity struct { | ||
ID int | ||
Label string | ||
Type string | ||
URL string | ||
} | ||
|
||
// NotificationsPagedResponse represents a paginated Notifications API response | ||
type NotificationsPagedResponse struct { | ||
*PageOptions | ||
Data []*Notification | ||
} | ||
|
||
// Endpoint gets the endpoint URL for Notification | ||
func (NotificationsPagedResponse) Endpoint(c *Client) string { | ||
endpoint, err := c.Notifications.Endpoint() | ||
if err != nil { | ||
panic(err) | ||
} | ||
return endpoint | ||
} | ||
|
||
// Endpoint gets the endpoint URL for Notification | ||
func (NotificationsPagedResponse) EndpointWithID(c *Client, id int) string { | ||
endpoint, err := c.Notifications.EndpointWithID(id) | ||
if err != nil { | ||
panic(err) | ||
} | ||
return endpoint | ||
} | ||
|
||
// AppendData appends Notifications when processing paginated Notification responses | ||
func (resp *NotificationsPagedResponse) AppendData(r *NotificationsPagedResponse) { | ||
(*resp).Data = append(resp.Data, r.Data...) | ||
} | ||
|
||
// SetResult sets the Resty response type of Notifications | ||
func (NotificationsPagedResponse) SetResult(r *resty.Request) { | ||
r.SetResult(NotificationsPagedResponse{}) | ||
} | ||
|
||
// ListNotifications lists Notifications | ||
func (c *Client) ListNotifications(opts *ListOptions) ([]*Notification, error) { | ||
response := NotificationsPagedResponse{} | ||
err := c.ListHelper(response, opts) | ||
for _, el := range response.Data { | ||
el.fixDates() | ||
} | ||
return response.Data, err | ||
} | ||
|
||
// fixDates converts JSON timestamps to Go time.Time values | ||
func (v *Notification) fixDates() *Notification { | ||
v.Until, _ = parseDates(v.UntilStr) | ||
v.When, _ = parseDates(v.WhenStr) | ||
return v | ||
} |
Oops, something went wrong.