Skip to content

Commit

Permalink
cli: implement history, init, order
Browse files Browse the repository at this point in the history
Fixes #44

Implements CLI with multiple commands:
* history
* init
* order

Firstly to install the CLI:
```shell
$ go get -u -v github.com/orijtech/uber/cmd/uber
```

Exhibits:
* history: List your last 3 trips
```shell
$ uber history --limit-per-page 3 --max-page 1

Page: #1
+--------+---------------+-------------------------+----------+-------+--------------------------------------+
| TRIP # |  CITY         |          DATE           | DURATION | MILES |              REQUESTID               |
+--------+---------------+-------------------------+----------+-------+--------------------------------------+
|      1 | Denver        | 2017/07/15 21:47:44 MDT | 7m31s    | 3.211 | 8e7f479c-63e2-4ccc-babd-8671771485c3 |
+--------+---------------+-------------------------+----------+-------+--------------------------------------+
|      2 | San Francisco | 2017/07/13 18:11:06 MDT | 14m16s   | 3.694 | d521aed9-e9bc-4673-9109-25d9ce5c434c |
+--------+---------------+-------------------------+----------+-------+--------------------------------------+
|      3 | London        | 2017/06/25 16:17:43 MDT | 13m35s   | 3.318 | 1ce3cccb-2e09-4920-ad80-d00a4645f9ce |
+--------+---------------+-------------------------+----------+-------+--------------------------------------+
```

* init
init initializes the context and authorization for your Uber app in the current working directory

```shell
$ go get -u -v github.com/orijtech/uber/cmd/uber
$ uber init
Please visit this URL for the auth dialog: https://login.uber.com/oauth/v2/authorize?access_type=offline&client_id=a_client_id&redirect_uri=https%3A%2F%2Fexample.org/uber&response_type=code&scope=profile+request+history+places+request_receipt+delivery&state=15004223370.604660
```
which after successful authorization will give you a notice in your browser, to return to
your terminal and will save the token to a file on disk, for example:
```shell
Successfully saved your OAuth2.0 token to "/Users/orijtech/uber-account/.uber/credentials.json"
```

* order
```shell
$ uber order
Start Point: Redwood City Cinemark
+--------+--------------------------------+-----------+-----------+-------------+
| CHOICE |              NAME              | RELEVANCE | LATITUDE  |  LONGITUDE  |
+--------+--------------------------------+-----------+-----------+-------------+
|      0 | Cinemark 20 Redwood City,      | 98.70%    | 37.485912 | -122.228752 |
|        | 825 Middlefield Rd, Redwood    |           |           |             |
|        | City, California 94063, United |           |           |             |
|        | States                         |           |           |             |
+--------+--------------------------------+-----------+-----------+-------------+
|      1 | Redwood City, California,      | 49.00%    | 37.485199 | -122.236397 |
|        | United States                  |           |           |             |
+--------+--------------------------------+-----------+-----------+-------------+
|      2 | Redwood City Station, 805      | 39.00%    | 37.485439 | -122.231796 |
|        | Veterans Blvd, Redwood City,   |           |           |             |
|        | California 94063, United       |           |           |             |
|        | States                         |           |           |             |
+--------+--------------------------------+-----------+-----------+-------------+
|      3 | Cinemark Ave, Markham, Ontario | 39.00%    | 43.887989 |  -79.225441 |
|        | L6B 1E3, Canada                |           |           |             |
+--------+--------------------------------+-----------+-----------+-------------+
|      4 | Cinemark Ct, Mulberry, Florida | 39.00%    | 27.934687 |  -81.996933 |
|        | 33860, United States           |           |           |             |
+--------+--------------------------------+-----------+-----------+-------------+
Please enter your choice by numeric key or (n) to search again: 0
End Point: Palo Alto
+--------+--------------------------------+-----------+-----------+-------------+
| CHOICE |              NAME              | RELEVANCE | LATITUDE  |  LONGITUDE  |
+--------+--------------------------------+-----------+-----------+-------------+
|      0 | Palo Alto, California, United  | 99.00%    | 37.442200 | -122.163399 |
|        | States                         |           |           |             |
+--------+--------------------------------+-----------+-----------+-------------+
|      1 | Palo Alto Battlefield National | 99.00%    | 26.021400 |  -97.480598 |
|        | Historical Park, 7200 PAREDES  |           |           |             |
|        | LINE Rd, Los Fresnos, Texas    |           |           |             |
|        | 78566, United States           |           |           |             |
+--------+--------------------------------+-----------+-----------+-------------+
|      2 | Palo Alto Baylands Nature      | 99.00%    | 37.459599 | -122.106003 |
|        | Preserve, 2500 Embarcadero     |           |           |             |
|        | Way, East Palo Alto,           |           |           |             |
|        | California 94303, United       |           |           |             |
|        | States                         |           |           |             |
+--------+--------------------------------+-----------+-----------+-------------+
|      3 | Palo Alto University, 1791     | 99.00%    | 37.382301 | -122.188004 |
|        | Arastradero Rd, Palo Alto,     |           |           |             |
|        | California 94304, United       |           |           |             |
|        | States                         |           |           |             |
+--------+--------------------------------+-----------+-----------+-------------+
|      4 | Palo Alto High School, 50      | 99.00%    | 37.437000 | -122.156998 |
|        | Embarcadero Rd, Palo Alto,     |           |           |             |
|        | California 94306, United       |           |           |             |
|        | States                         |           |           |             |
+--------+--------------------------------+-----------+-----------+-------------+
Please enter your choice by numeric key or (n) to search again: 0
Seat count: 1 or 2 (default 2) 1
+--------+--------+----------+----------+----------------------+--------------------+
| CHOICE |  NAME  | ESTIMATE | CURRENCY | PICKUP ETA (MINUTES) | DURATION (MINUTES) |
+--------+--------+----------+----------+----------------------+--------------------+
|      0 | SELECT | $31-39   | USD      |                  3.0 |               22.0 |
+--------+--------+----------+----------+----------------------+--------------------+
|      1 | ASSIST | $15-19   | USD      |                 10.0 |               22.0 |
+--------+--------+----------+----------+----------------------+--------------------+
|      2 | uberXL | $19-24   | USD      |                 12.0 |               22.0 |
+--------+--------+----------+----------+----------------------+--------------------+
|      3 | BLACK  | $40-50   | USD      |                  5.0 |               22.0 |
+--------+--------+----------+----------+----------------------+--------------------+
|      4 | SUV    | $53-65   | USD      |                  5.0 |               22.0 |
+--------+--------+----------+----------+----------------------+--------------------+
|      5 | WAV    | $13-16   | USD      |                  0.0 |               22.0 |
+--------+--------+----------+----------+----------------------+--------------------+
|      6 | POOL   | $6-8     | USD      |                  9.0 |               22.0 |
+--------+--------+----------+----------+----------------------+--------------------+
|      7 | uberX  | $15-19   | USD      |                  8.0 |               22.0 |
+--------+--------+----------+----------+----------------------+--------------------+
Please enter the choice of your item or n to cancel
```
  • Loading branch information
odeke-em committed Jul 19, 2017
1 parent 45b2deb commit db0194e
Show file tree
Hide file tree
Showing 4 changed files with 471 additions and 193 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -26,3 +26,6 @@ _testmain.go
# Text editor and miscellaneous files
*.sw[op]
*.DS_Store

# Binary directories
bin/
144 changes: 137 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,16 +1,19 @@
# uber
Uber API client in Go

* Requirement:
## Table of contents
- [Requirements](#requirements)
- [CLI](#cli)
- [Installation](#installation)
- [init](#init)
- [history](#history)
- [order](#order)
- [SDK Usage](#sdk-usage)

## Requirements:
To use client v1, you'll need to set
+ `UBER_TOKEN_KEY`

## CLI installation
```go
$ go get -u -v github.com/orijtech/uber/cmd/uber
$ uber --order
```

## SDK usage
Sample usage: You can see file
[example_test.go](./example_test.go)
Expand Down Expand Up @@ -420,3 +423,130 @@ func cancelDelivery() {
}
}
```

## CLI
### Installation
```go
$ go get -u -v github.com/orijtech/uber/cmd/uber
```

### init
init initializes the context and authorization for your Uber app in the current working directory

```shell
$ go get -u -v github.com/orijtech/uber/cmd/uber
$ uber init
Please visit this URL for the auth dialog: https://login.uber.com/oauth/v2/authorize?access_type=offline&client_id=a_client_id&redirect_uri=https%3A%2F%2Fexample.org/uber&response_type=code&scope=profile+request+history+places+request_receipt+delivery&state=15004223370.604660
```
which after successful authorization will give you a notice in your browser, to return to
your terminal and will save the token to a file on disk, for example:
```shell
Successfully saved your OAuth2.0 token to "/Users/orijtech/uber-account/.uber/credentials.json"
```

From then on, for that Uber account, please go into that directory "/Users/orijtech/uber-account/"
in order to use that account

### history
history allows you to retrieve and examine your previous trips in a tabular form

```shell
$ uber history -h
```
for all available options.

* List your last 3 trips
```shell
$ uber history --limit-per-page 3 --max-page 1

Page: #1
+--------+---------------+-------------------------+----------+-------+--------------------------------------+
| TRIP # | CITY | DATE | DURATION | MILES | REQUESTID |
+--------+---------------+-------------------------+----------+-------+--------------------------------------+
| 1 | Denver | 2017/07/15 21:47:44 MDT | 7m31s | 3.211 | 8e7f479c-63e2-4ccc-babd-8671771485c3 |
+--------+---------------+-------------------------+----------+-------+--------------------------------------+
| 2 | San Francisco | 2017/07/13 18:11:06 MDT | 14m16s | 3.694 | d521aed9-e9bc-4673-9109-25d9ce5c434c |
+--------+---------------+-------------------------+----------+-------+--------------------------------------+
| 3 | London | 2017/06/25 16:17:43 MDT | 13m35s | 3.318 | 1ce3cccb-2e09-4920-ad80-d00a4645f9ce |
+--------+---------------+-------------------------+----------+-------+--------------------------------------+
```

### order
order allows you to order an Uber to any location and destination
```shell
$ uber order
Start Point: Redwood City Cinemark
+--------+--------------------------------+-----------+-----------+-------------+
| CHOICE | NAME | RELEVANCE | LATITUDE | LONGITUDE |
+--------+--------------------------------+-----------+-----------+-------------+
| 0 | Cinemark 20 Redwood City, | 98.70% | 37.485912 | -122.228752 |
| | 825 Middlefield Rd, Redwood | | | |
| | City, California 94063, United | | | |
| | States | | | |
+--------+--------------------------------+-----------+-----------+-------------+
| 1 | Redwood City, California, | 49.00% | 37.485199 | -122.236397 |
| | United States | | | |
+--------+--------------------------------+-----------+-----------+-------------+
| 2 | Redwood City Station, 805 | 39.00% | 37.485439 | -122.231796 |
| | Veterans Blvd, Redwood City, | | | |
| | California 94063, United | | | |
| | States | | | |
+--------+--------------------------------+-----------+-----------+-------------+
| 3 | Cinemark Ave, Markham, Ontario | 39.00% | 43.887989 | -79.225441 |
| | L6B 1E3, Canada | | | |
+--------+--------------------------------+-----------+-----------+-------------+
| 4 | Cinemark Ct, Mulberry, Florida | 39.00% | 27.934687 | -81.996933 |
| | 33860, United States | | | |
+--------+--------------------------------+-----------+-----------+-------------+
Please enter your choice by numeric key or (n) to search again: 0
End Point: Palo Alto
+--------+--------------------------------+-----------+-----------+-------------+
| CHOICE | NAME | RELEVANCE | LATITUDE | LONGITUDE |
+--------+--------------------------------+-----------+-----------+-------------+
| 0 | Palo Alto, California, United | 99.00% | 37.442200 | -122.163399 |
| | States | | | |
+--------+--------------------------------+-----------+-----------+-------------+
| 1 | Palo Alto Battlefield National | 99.00% | 26.021400 | -97.480598 |
| | Historical Park, 7200 PAREDES | | | |
| | LINE Rd, Los Fresnos, Texas | | | |
| | 78566, United States | | | |
+--------+--------------------------------+-----------+-----------+-------------+
| 2 | Palo Alto Baylands Nature | 99.00% | 37.459599 | -122.106003 |
| | Preserve, 2500 Embarcadero | | | |
| | Way, East Palo Alto, | | | |
| | California 94303, United | | | |
| | States | | | |
+--------+--------------------------------+-----------+-----------+-------------+
| 3 | Palo Alto University, 1791 | 99.00% | 37.382301 | -122.188004 |
| | Arastradero Rd, Palo Alto, | | | |
| | California 94304, United | | | |
| | States | | | |
+--------+--------------------------------+-----------+-----------+-------------+
| 4 | Palo Alto High School, 50 | 99.00% | 37.437000 | -122.156998 |
| | Embarcadero Rd, Palo Alto, | | | |
| | California 94306, United | | | |
| | States | | | |
+--------+--------------------------------+-----------+-----------+-------------+
Please enter your choice by numeric key or (n) to search again: 0
Seat count: 1 or 2 (default 2) 1
+--------+--------+----------+----------+----------------------+--------------------+
| CHOICE | NAME | ESTIMATE | CURRENCY | PICKUP ETA (MINUTES) | DURATION (MINUTES) |
+--------+--------+----------+----------+----------------------+--------------------+
| 0 | SELECT | $31-39 | USD | 3.0 | 22.0 |
+--------+--------+----------+----------+----------------------+--------------------+
| 1 | ASSIST | $15-19 | USD | 10.0 | 22.0 |
+--------+--------+----------+----------+----------------------+--------------------+
| 2 | uberXL | $19-24 | USD | 12.0 | 22.0 |
+--------+--------+----------+----------+----------------------+--------------------+
| 3 | BLACK | $40-50 | USD | 5.0 | 22.0 |
+--------+--------+----------+----------+----------------------+--------------------+
| 4 | SUV | $53-65 | USD | 5.0 | 22.0 |
+--------+--------+----------+----------+----------------------+--------------------+
| 5 | WAV | $13-16 | USD | 0.0 | 22.0 |
+--------+--------+----------+----------+----------------------+--------------------+
| 6 | POOL | $6-8 | USD | 9.0 | 22.0 |
+--------+--------+----------+----------+----------------------+--------------------+
| 7 | uberX | $15-19 | USD | 8.0 | 22.0 |
+--------+--------+----------+----------+----------------------+--------------------+
Please enter the choice of your item or n to cancel
```
35 changes: 35 additions & 0 deletions cmd/uber/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
# Makefile for cross-compilation
#
OS := $(shell uname)
BINDIR := ./bin
MD5_TEXTFILE := $(BINDIR)/md5Sums.txt

MAIN_FILE_DIR := ./

ifeq ($(OS), Darwin)
MD5_UTIL = md5
else
MD5_UTIL = md5sum
endif

all: compileThemAll md5SumThemAll

compileThemAll: armv5 armv6 armv7 armv8 darwin linux

md5SumThemAll:
rm -f $(MD5_TEXTFILE)
find $(BINDIR) -type f -name "uber_*" -exec $(MD5_UTIL) {} >> $(MD5_TEXTFILE) \;
cat $(MD5_TEXTFILE)

armv5:
CGO_ENABLED=0 GOOS=linux GOARM=5 GOARCH=arm go build -o $(BINDIR)/uber_armv5 $(MAIN_FILE_DIR)
armv6:
CGO_ENABLED=0 GOOS=linux GOARM=6 GOARCH=arm go build -o $(BINDIR)/uber_armv6 $(MAIN_FILE_DIR)
armv7:
CGO_ENABLED=0 GOOS=linux GOARM=7 GOARCH=arm go build -o $(BINDIR)/uber_armv7 $(MAIN_FILE_DIR)
armv8:
CGO_ENABLED=0 GOOS=linux GOARCH=arm64 go build -o $(BINDIR)/uber_armv8 $(MAIN_FILE_DIR)
darwin:
CGO_ENABLED=0 GOOS=darwin go build -o $(BINDIR)/uber_darwin $(MAIN_FILE_DIR)
linux:
CGO_ENABLED=0 GOOS=linux go build -o $(BINDIR)/uber_linux $(MAIN_FILE_DIR)
Loading

0 comments on commit db0194e

Please sign in to comment.