Skip to content

Commit

Permalink
Improved README examples
Browse files Browse the repository at this point in the history
  • Loading branch information
Richard Wooding committed Sep 3, 2022
1 parent 30b3ea9 commit 653645c
Show file tree
Hide file tree
Showing 5 changed files with 61 additions and 10 deletions.
46 changes: 44 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,51 @@ Flags:
Use "powerdown [command] --help" for more information about a command.
```

## Install with go install
```
go install github.com/richardwooding/powerdown@latest
```

## Run with docker
```
docker run --volume $HOME/.powerdown.yaml:/.powerdown.yaml ghcr.io/richardwooding/powerdown allowance
docker run --volume $HOME/.powerdown.yaml:/.powerdown.yaml ghcr.io/richardwooding/powerdown
```
## Usage examples

### Check your API allowance

```
$ powerdown allowance
Using config file: /Users/richardwooding/.powerdown.yaml
Count Limit Type
20 50 daily
```
### Check your allowance

### Search areas by text

```
$ powerdown search text --query plett
Using config file: /Users/richardwooding/.powerdown.yaml
Search area matching: plett
Id Name Region
eskme-7-plettenbergbaybitouwesterncape Plettenberg Bay (7) Eskom Municipal, Bitou, Western Cape
westerncape-7-plettenbergbay Plettenberg Bay (7) Western Cape
eskde-7-plettenbergbaybitouwesterncape Plettenberg Bay (7) Eskom Direct, Bitou, Western Cape
eskde-7-plettenbergbayoutlyingbitouwesterncape Plettenberg Bay Outlying (7) Eskom Direct, Bitou, Western Cape
```
### Search area by latitude and longitude

```
$ powerdown search nearby --lat -33.6007 --lon 22.2026
Using config file: /Users/richardwooding/.powerdown.yaml
Count Id
344 westerncape-3-oudtshoorn
116 eskde-3-oudtshoornoudtshoornwesterncape
54 westerncape-12-george
20 westerncape-7-mosselbay
8 westerncape-7-knysna
```
2 changes: 1 addition & 1 deletion api/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,6 @@ import "github.com/richardwooding/powerdown/model"
type Client interface {
Allowance() (*model.AllowanceResponse, error)
SearchAreasByText(text string) (*model.AreasResponse, error)
SearchAreasByLatLong(lat, lon float64) (*model.AreasResponse, error)
SearchAreasByLatLong(lat, lon float64) (*model.NearbyResponse, error)
SearchArea(id string) (*model.AreaResponse, error)
}
8 changes: 4 additions & 4 deletions api/restclient.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,14 +73,14 @@ func (c *RestClient) SearchAreasByText(text string) (*model.AreasResponse, error
return &areasResponse, err
}

func (c *RestClient) SearchAreasByLatLong(lat float64, lon float64) (*model.AreasResponse, error) {
func (c *RestClient) SearchAreasByLatLong(lat float64, lon float64) (*model.NearbyResponse, error) {
req, err := c.newRequestWithParams(http.MethodGet, "./areas_nearby", nil, map[string]string{"lat": fmt.Sprintf("%f", lat), "lon": fmt.Sprintf("%f", lon)})
if err != nil {
return nil, err
}
var areasResponse model.AreasResponse
_, err = c.do(req, &areasResponse)
return &areasResponse, err
var nearbyResponse model.NearbyResponse
_, err = c.do(req, &nearbyResponse)
return &nearbyResponse, err
}

func (c *RestClient) SearchArea(id string) (*model.AreaResponse, error) {
Expand Down
7 changes: 4 additions & 3 deletions cmd/nearby.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ THE SOFTWARE.
package cmd

import (
"fmt"
"github.com/rodaine/table"

"github.com/spf13/cobra"
Expand All @@ -40,15 +41,15 @@ to quickly create a Cobra application.`,
RunE: func(cmd *cobra.Command, args []string) error {
lat, _ := cmd.Flags().GetFloat64("lat")
lon, _ := cmd.Flags().GetFloat64("lon")
println("Search area nearby:", lat, lon)
fmt.Sprintf("Search area nearby: %f %f\n", lat, lon)
println()
areasResponse, err := client.SearchAreasByLatLong(lat, lon)
if err == nil {
areas := areasResponse.Areas
tbl := table.New("Id", "Name", "Region")
tbl := table.New("Count", "Id")
tbl.WithHeaderFormatter(headerFmt).WithFirstColumnFormatter(columnFmt)
for _, area := range areas {
tbl.AddRow(area.Id, area.Name, area.Region)
tbl.AddRow(area.Count, area.Id)
}
tbl.Print()
}
Expand Down
8 changes: 8 additions & 0 deletions model/nearby.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package model

type NearbyResponse struct {
Areas []struct {
Count int `json:"count"`
Id string `json:"id"`
} `json:"areas"`
}

0 comments on commit 653645c

Please sign in to comment.