-
Notifications
You must be signed in to change notification settings - Fork 0
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
7ab98f9
commit 51543f4
Showing
15 changed files
with
159 additions
and
134 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,4 +1,5 @@ | ||
geocodio | ||
app | ||
.idea | ||
|
||
dist/ | ||
geocodio |
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,4 +1,4 @@ | ||
project_name: geocodio-cli | ||
project_name: geocodio | ||
before: | ||
hooks: | ||
- go mod tidy | ||
|
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
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,15 @@ | ||
package api | ||
|
||
import ( | ||
"github.com/geocodio/geocodio-cli/output" | ||
"github.com/urfave/cli/v2" | ||
"strconv" | ||
) | ||
|
||
func ValidateSpreadsheetJobId(c *cli.Context) (int, error) { | ||
spreadsheetJobId, err := strconv.Atoi(c.Args().First()) | ||
if err != nil || spreadsheetJobId <= 0 { | ||
return 0, output.ErrorStringAndExit("Invalid spreadsheet job id specified") | ||
} | ||
return spreadsheetJobId, 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
package download | ||
|
||
import ( | ||
"fmt" | ||
"github.com/geocodio/geocodio-cli/api" | ||
"github.com/geocodio/geocodio-cli/output" | ||
"github.com/urfave/cli/v2" | ||
"net/http" | ||
) | ||
|
||
type downloadResponse struct { | ||
Message string `json:"message"` | ||
Success bool `json:"success"` | ||
} | ||
|
||
func RegisterCommand() *cli.Command { | ||
var command *cli.Command | ||
command = new(cli.Command) | ||
command.Name = "download" | ||
command.Usage = "Download output data for a specific geocoding job" | ||
command.Action = download | ||
command.ArgsUsage = "id" | ||
|
||
return command | ||
} | ||
|
||
func download(c *cli.Context) error { | ||
spreadsheetJobId, err := api.ValidateSpreadsheetJobId(c) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
body, isJson, err := api.Request(http.MethodGet, fmt.Sprintf("lists/%d/download", spreadsheetJobId), c) | ||
if err != nil { | ||
return output.ErrorAndExit(err) | ||
} | ||
|
||
if isJson { | ||
job := downloadResponse{} | ||
if err = api.ParseJson(body, &job); err != nil { | ||
return err | ||
} | ||
|
||
return output.ErrorStringAndExit(job.Message) | ||
} else { | ||
fmt.Fprintf(c.App.Writer, string(body)) | ||
} | ||
|
||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,48 +1,17 @@ | ||
package main | ||
|
||
import ( | ||
"github.com/geocodio/geocodio-cli/create" | ||
"github.com/geocodio/geocodio-cli/list" | ||
"github.com/geocodio/geocodio-cli/release" | ||
"github.com/geocodio/geocodio-cli/remove" | ||
"github.com/geocodio/geocodio-cli/status" | ||
"github.com/urfave/cli/v2" | ||
"log" | ||
cli "github.com/geocodio/geocodio-cli/app" | ||
"github.com/geocodio/geocodio-cli/output" | ||
"os" | ||
) | ||
|
||
func main() { | ||
app := cli.NewApp() | ||
app.Name = "Geocodio" | ||
app.Usage = "Geocode lists using the Geocodio API" | ||
app.Version = release.Version() | ||
app.EnableBashCompletion = true | ||
app.Flags = []cli.Flag{ | ||
&cli.StringFlag{ | ||
Name: "hostname", | ||
Aliases: []string{"n"}, | ||
Value: "api.geocod.io", | ||
Usage: "Geocodio hostname to use, change this for Geocodio+HIPAA or on-premise environments", | ||
EnvVars: []string{"GEOCODIO_HOSTNAME"}, | ||
}, | ||
&cli.StringFlag{ | ||
Name: "apikey", | ||
Aliases: []string{"k"}, | ||
Value: "", | ||
Usage: "Geocodio API Key to use. Generate a new one in the Geocodio Dashboard", | ||
EnvVars: []string{"GEOCODIO_API_KEY"}, | ||
Required: true, | ||
}, | ||
} | ||
app.Commands = []*cli.Command{ | ||
create.RegisterCommand(), | ||
list.RegisterCommand(), | ||
status.RegisterCommand(), | ||
remove.RegisterCommand(), | ||
} | ||
app := cli.BuildApp() | ||
|
||
err := app.Run(os.Args) | ||
if err != nil { | ||
log.Fatal(err) | ||
output.ErrorAndExit(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
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
Oops, something went wrong.