-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
4a018fe
commit c013069
Showing
10 changed files
with
276 additions
and
6 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,44 @@ | ||
package app | ||
|
||
import ( | ||
"context" | ||
"encoding/json" | ||
"os" | ||
"time" | ||
|
||
"github.com/anothertobi/viseca-exporter/pkg/viseca" | ||
"github.com/urfave/cli/v2" | ||
) | ||
|
||
// NewCardsCommand creates a new cards CLI command | ||
func NewCardsCommand() *cli.Command { | ||
return &cli.Command{ | ||
Name: "cards", | ||
Usage: "list all cards", | ||
Action: func(cCtx *cli.Context) error { | ||
return cards(cCtx) | ||
}, | ||
} | ||
} | ||
|
||
func cards(cCtx *cli.Context) error { | ||
ctx, cancel := context.WithTimeout(context.Background(), 60*time.Second) | ||
defer cancel() | ||
|
||
visecaClient, err := loginCLI(ctx, cCtx) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
cardListOptions := viseca.NewDefaultCardListOptions() | ||
cards, err := visecaClient.ListCards(ctx, cardListOptions) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
encoder := json.NewEncoder(os.Stdout) | ||
|
||
encoder.Encode(cards) | ||
|
||
return 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
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,42 @@ | ||
package app | ||
|
||
import ( | ||
"context" | ||
"encoding/json" | ||
"os" | ||
"time" | ||
|
||
"github.com/urfave/cli/v2" | ||
) | ||
|
||
// NewUserCommand creates a new user CLI command | ||
func NewUserCommand() *cli.Command { | ||
return &cli.Command{ | ||
Name: "user", | ||
Usage: "get user", | ||
Action: func(cCtx *cli.Context) error { | ||
return user(cCtx) | ||
}, | ||
} | ||
} | ||
|
||
func user(cCtx *cli.Context) error { | ||
ctx, cancel := context.WithTimeout(context.Background(), 60*time.Second) | ||
defer cancel() | ||
|
||
visecaClient, err := loginCLI(ctx, cCtx) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
user, err := visecaClient.GetUser(ctx) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
encoder := json.NewEncoder(os.Stdout) | ||
|
||
encoder.Encode(user) | ||
|
||
return 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
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,22 @@ | ||
package viseca | ||
|
||
import ( | ||
"context" | ||
) | ||
|
||
// GetUser returns the user information. | ||
func (client *Client) GetUser(ctx context.Context) (*User, error) { | ||
request, err := client.NewRequest("user", "GET", nil) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
user := &User{} | ||
|
||
_, err = client.Do(ctx, request, user) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
return user, 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