Skip to content

Commit

Permalink
Allow to specify the API token separately from the URL
Browse files Browse the repository at this point in the history
  • Loading branch information
shesek committed Dec 9, 2017
1 parent 5ad6308 commit 38d47f4
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 4 deletions.
7 changes: 5 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,10 @@ $ composer require elementsproject/lightning-strike-client-php

```php
<?php
$strike = new LightingStrikeClient('http://localhost:8009');
// Initialize client
$strike = new LightingStrikeClient('http://localhost:8009', '[TOKEN]');
// alternatively, the token can be provided as part of URL:
$strike = new LightingStrikeClient('http://api-token:[TOKEN]@localhost:8009');

// Create invoice
$invoice = $strike->invoice([ 'msatoshi' => 50, 'metadata' => [ 'customer' => 'Satoshi', 'products' => [ 'potato', 'chips' ] ] ]);
Expand All @@ -31,7 +34,7 @@ TODO: document missing methods
## Test

```bash
$ STRIKE_URL=http://localhost:8009 phpunit test
$ STRIKE_URL=http://api-token:[TOKEN]@localhost:8009 phpunit test
```

## License
Expand Down
9 changes: 7 additions & 2 deletions client.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,13 @@
class LightningStrikeClient {
protected $api;

public function __construct($url) {
$this->api = new RestClient([ 'base_url' => rtrim($url, '/') ]);
public function __construct($url, $api_token=null) {
$this->api = new RestClient([
'base_url' => rtrim($url, '/'),
'curl_options' => $api_token ? [
CURLOPT_USERPWD => 'api-token:' . $api_token
] : []
]);
}

/**
Expand Down

0 comments on commit 38d47f4

Please sign in to comment.