# Open Planet Node

Node.js client for the Open Planet API.

### Create a client
Define a few ENV variables...

```
AUTH_CLIENT_ID=your-client-id
AUTH_HOST=http://connect.qa.lonelyplanet.com
OPENID_HOST=http://connect.qa.lonelyplanet.com
OPEN_PLANET_HOST=http://stable.web.op-api-gateway.qa.lonelyplanet.com
```

Create a client with...

```js
import createClient from "@lonelyplanet/open-planet-node"

const client = createClient();
```

### Docs
Generate docs with...

```js
npm run docs
```

### Endpoint Examples

#### User
```js
client.user.find({
  username: "foo.user",
});
client.user.findById("1234");
```

#### Bookmark List
```js
client.bookmarkList.findById(":listId");
client.bookmarkList.createList(":userId", { /** list attributes */ });
```

### Filtering
Most endpoints support the following types of filtering...

```ts
client.user.find({
  key: "some value",
});
// ?filter[user][key][equals]=some%20value

client.poi.find({
  place_id: {
    has_ancestor: "362228",
  },
});
// ?filter[poi][place_id][has_ancestor]=362228

client.place.find({
  name: {
    like: "nashv",
  },
});
// ?filter[place][name][like]=nashv
```

### Pagination
You can paginate by passing in the following...

```ts
client.user.find({
  limit: 10,
  offset: 2
});
// ?page[limit]=10&page[offset]=2
```

### Disable include service caching
If you find yourself getting back cached things via `?include`...

```ts
client.user.find({
  nocache: true,
});
// ?nocache=true
```

### Pass extra query string arguments
To pass additional non-filter query string arguments, use `extras`...

```ts
client.user.find({
  name: "someusername",
  extras: {
    foo: "bar"
  }
});
// ?filter[user][name][equals]=someusername&foo=bar
```


### Building
```shell
npm run build

npm run build -- --watch
```

### Testing
```shell
npm run test
```

### Dependency Injection with Inversify and Reflect-Metadata
Make sure to have the following code in the main entrypoint for an application, or included via CDN in the appliaction consuming this library.

```js
import "reflect-metadata";
```

Open Planet Node uses https://github.com/inversify/InversifyJS for dependency injection whish is depednent upon Reflect.
