Skip to content

Commit

Permalink
BREAKING: Change api key to access token
Browse files Browse the repository at this point in the history
  • Loading branch information
Raphexion committed Jul 4, 2021
1 parent 1484302 commit 62ccb7e
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 11 deletions.
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,19 +12,19 @@

## Configure

Please create a personal api token in Noko (web page).
Please create a Personal Access Token in Noko (web page).

Either create an environmental variable

```
export NOKO_API_KEY="my-key-1234"
export NOKO_ACCESS_TOKEN="my-key-1234"
```

Or, create nina.yaml in your home folder:

```
# ~/nina.yaml
api_key: my-key-1234
access_token: my-key-1234
```

## Usage
Expand Down
16 changes: 8 additions & 8 deletions noko/noko.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,16 +17,16 @@ const (

type Client struct {
BaseURL string
apiKey string
accessToken string
HTTPClient *http.Client
}

func NewClient() *Client {
apiKey := fetchApiKey()
accessToken := fetchApiKey()

return &Client{
BaseURL: BaseURLV2,
apiKey: apiKey,
accessToken: accessToken,
HTTPClient: &http.Client{
Timeout: time.Minute,
},
Expand All @@ -38,7 +38,7 @@ func (c *Client) sendRequest(ctx context.Context, req *http.Request, v interface

req.Header.Set("Content-Type", "application/json")
req.Header.Set("Accept", "application/json")
req.Header.Set("X-NokoToken", c.apiKey)
req.Header.Set("X-NokoToken", c.accessToken)
req.Header.Set("User-Agent", "Nina/v0.1")

res, err := c.HTTPClient.Do(req)
Expand All @@ -65,7 +65,7 @@ func (c *Client) send(ctx context.Context, req *http.Request) error {

req.Header.Set("Content-Type", "application/json")
req.Header.Set("Accept", "application/json")
req.Header.Set("X-NokoToken", c.apiKey)
req.Header.Set("X-NokoToken", c.accessToken)
req.Header.Set("User-Agent", "Nina/v0.1")

res, err := c.HTTPClient.Do(req)
Expand All @@ -83,8 +83,8 @@ func (c *Client) send(ctx context.Context, req *http.Request) error {
}

func fetchApiKey() string {
env_key := viper.GetString("NOKO_API_KEY")
cnf_key := viper.GetString("api_key")
env_key := viper.GetString("NOKO_ACCESS_TOKEN")
cnf_key := viper.GetString("access_token")

if env_key != "" {
return env_key
Expand All @@ -95,7 +95,7 @@ func fetchApiKey() string {
}

log.Fatal(`
Please set enviromental variable NOKO_API_KEY or create ~/nina.yml with api_key
Please set enviromental variable NOKO_ACCESS_TOKEN or create ~/nina.yml with access_token
`)

return ""
Expand Down

0 comments on commit 62ccb7e

Please sign in to comment.