Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
721899d
added postRequest method
Aras14HD Mar 3, 2021
63789aa
added postRequest method
Aras14HD Mar 3, 2021
1f3d157
Merge branch 'master' of https://github.com/Aras14HD/HabiticaMagic
Aras14HD Mar 3, 2021
7397ed1
fix commit issue
Aras14HD Mar 3, 2021
dd19eaa
Add .deepsource.toml
deepsourcebot Mar 11, 2021
8739f08
Update .deepsource.toml
Aras14HD Mar 11, 2021
eb3d7bc
Update .deepsource.toml
Aras14HD Mar 11, 2021
4aed4c8
Update .deepsource.toml
Aras14HD Mar 11, 2021
74c6d1d
Update .deepsource.toml
Aras14HD Mar 11, 2021
8b35aff
Update .deepsource.toml
Aras14HD Mar 11, 2021
d05669a
Update .deepsource.toml
Aras14HD Mar 11, 2021
a7d5bd4
bugfix
Aras14HD Mar 11, 2021
8d2cf96
bugfix: reject on sucess
Aras14HD Mar 12, 2021
9e0c934
Merge pull request #7 from Aras14HD/master
Aras14HD Mar 12, 2021
a496138
changed readme
Aras14HD Mar 12, 2021
cffe747
Merge pull request #8 from Aras14HD/dev
Aras14HD Mar 12, 2021
e6dc390
Delete .deepsource.toml
Aras14HD Mar 12, 2021
bed43fe
Merge pull request #9 from Aras14HD/dev
Aras14HD Mar 12, 2021
8ea87ae
Update README.md
Aras14HD Mar 12, 2021
7f3be3e
Merge pull request #10 from Aras14HD/dev
Aras14HD Mar 12, 2021
12bb9f0
removed "/docs" from gitignore
Aras14HD Mar 15, 2021
a5258c5
Merge pull request #11 from Aras14HD/dev
Aras14HD Mar 15, 2021
992b183
update readme
Aras14HD Mar 15, 2021
81f5a75
update changelog
Aras14HD Mar 18, 2021
92b1057
add putRequest method
Aras14HD Mar 30, 2021
425717c
Merge remote-tracking branch 'upstream/dev' into put
Aras14HD Mar 30, 2021
d394adf
docs and minify
Aras14HD Mar 30, 2021
7c12c66
Changelog
Aras14HD Mar 30, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
/node_modules
.DS_Store
/package-lock.json
/node_modules
.DS_Store
/package-lock.json
index.html
index.js
13 changes: 12 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,31 +1,42 @@
# Changelog

All notable changes to this project will be documented in this file.

The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [Unreleased]
- Nothing yet :)

- Added putRequest method

## 2.1.0 - 2021-3-23

### Added

- Added postRequest method (by [@Aras14HD](https://github.com/delightedCrow/HabiticaMagic/pull/4))

## 2.0.1 - 2019-11-15

### Changed

- Updating HabiticaUser.class to return "mage" instead of "wizard" for users with a mage class.

## 2.0.0 - 2019-11-2

### Added

- So. Much. Documentation.
- This CHANGELOG!
- The Demo.
- The Docs.
- Just... everything good.

### Changed

- Pretty much everything about HabiticaAPIManager. Nothing is compatible with the last version. sorry :(

## 1.0.0 - 2019-10-31

### Added

- EVERYTHING (this was the initial HabiticaMagicJS release)
42 changes: 21 additions & 21 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
MIT License

Copyright (c) 2019 Jess Coulter

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
MIT License
Copyright (c) 2019 Jess Coulter
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
156 changes: 82 additions & 74 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,12 @@ For the most comprehensive and up-to-date documentation on HabiticaMagicJS funct

### HabiticaAPIManager

````javascript
```javascript
var apiManager = new HabiticaAPIManager("Your x-client ID", "en@pirate");
````
```

The `HabiticaAPIManager` class is the primary way you'll interact with HabiticaMagicJS. Its constructor takes two parameters:

- **x-client-id**: REQUIRED. Your x-client-id. [See Habitica's documentation here for what your x-client should be](https://habitica.fandom.com/wiki/Guidance_for_Comrades#X-Client_Header).
- **language**: OPTIONAL. The language you want Habitica's content in. [See possible values here](https://habitica.com/apidoc/#api-Content-ContentGet). The default is `"en"` for english.

Expand All @@ -37,24 +38,25 @@ Check out this example of making multiple API requests and chaining them togethe
let manager = new HabiticaAPIManager(xclient);

// first we're going to do an API call to fetch the Habitica content data
manager.fetchContentData()
// once our content data fetch succeeds we can add the fetchUser()
// API call to the promise chain.
.then(() => {
return manager.fetchUser(userID);
})
// Now that our fetchUser call has finished we're done with API calls
// (for now!) and we can send the resulting HabiticaUser object to our
// renderUserTemplate function to display.
.then((user) => {
this.renderUserTemplate(user);
})
// The nice thing about promise chains like this is that if an error
// happens AT ANY POINT in the chain here we'll automatically skip
// to this catch block, which will render our error template
.catch((error) => {
this.renderErrorTemplate(error);
});
manager
.fetchContentData()
// once our content data fetch succeeds we can add the fetchUser()
// API call to the promise chain.
.then(() => {
return manager.fetchUser(userID);
})
// Now that our fetchUser call has finished we're done with API calls
// (for now!) and we can send the resulting HabiticaUser object to our
// renderUserTemplate function to display.
.then((user) => {
this.renderUserTemplate(user);
})
// The nice thing about promise chains like this is that if an error
// happens AT ANY POINT in the chain here we'll automatically skip
// to this catch block, which will render our error template
.catch((error) => {
this.renderErrorTemplate(error);
});
```

#### Generic Get Requests
Expand All @@ -70,12 +72,11 @@ HabiticaMagicJS provides several fetch functions for getting specific API data (
var apiManager = new HabiticaAPIManager("Your x-client ID");

let apiURL = "https://habitica.com/api/v3/status";
apiManager.getRequest(apiURL)
.then((rawData) => {
// process the raw string of data into a JSON object
let statusData = JSON.parse(rawData).data;
// Now you know the API status!
console.log(statusData);
apiManager.getRequest(apiURL).then((rawData) => {
// process the raw string of data into a JSON object
let statusData = JSON.parse(rawData).data;
// Now you know the API status!
console.log(statusData);
});
```

Expand All @@ -85,13 +86,14 @@ apiManager.getRequest(apiURL)
var apiManager = new HabiticaAPIManager("Your x-client ID");

let apiURL = "https://habitica.com/api/v3/groups/party";
apiManager.authGetRequest(apiURL, "USER ID", "USER API TOKEN")
.then((rawData) => {
// process the raw string of data into a JSON object
let partyData = JSON.parse(rawData).data;
// now you can party!
console.log(partyData);
});
apiManager
.authGetRequest(apiURL, "USER ID", "USER API TOKEN")
.then((rawData) => {
// process the raw string of data into a JSON object
let partyData = JSON.parse(rawData).data;
// now you can party!
console.log(partyData);
});
```

#### Generic Post Request
Expand All @@ -105,10 +107,10 @@ var apiManager = new HabiticaAPIManager("Your x-client ID");

let apiURL = "https://habitica.com/api/v3/tasks/user";
let task = {
type: "TASK TYPE",
text: "TASK NAME",
}
apiManager.postRequest(apiURL, "USER ID", "USER API TOKEN", task)
type: "TASK TYPE",
text: "TASK NAME",
};
apiManager.postRequest(apiURL, "USER ID", "USER API TOKEN", task);
```

#### Before Fetching HabiticaUsers: Getting the Habitica Content
Expand All @@ -135,7 +137,9 @@ apiManager.fetchUser("USER-ID")
shield: "shield_base_0"
}
```

#### Example: fetchUser() After Content Fetch: details filled in!

```javascript
// fetching the content first
apiManager.fetchContentData()
Expand Down Expand Up @@ -178,23 +182,23 @@ These classes store the API returned by Habitica in a property (`.apiData`) and
- There is often a lot of complexity in the way the Habitica API returns data, which `HabiticaUser` smoothes over - just look at the following example for getting a user's gems.

##### Example: getting a user's gems

```javascript
// Assuming you've already created an apiManager and fetched
// Habitica the content data
apiManager.fetchUserWithTasks("USER ID", "API TOKEN")
.then((user) => {
// you can always get to the raw API object data from
// the .apiData property
console.log(user.apiData);

// If you were to use the old-fashioned way of finding out how
// many gems a user had you'd have to know the Habitica API
// returns gems in a data property called "balance", and that
// you had to multiply that value by 4.
console.log(user.apiData.balance * 4); // gives you # of gems...

// But really you should just call:
console.log(user.gems); // what it does is obvious!
apiManager.fetchUserWithTasks("USER ID", "API TOKEN").then((user) => {
// you can always get to the raw API object data from
// the .apiData property
console.log(user.apiData);

// If you were to use the old-fashioned way of finding out how
// many gems a user had you'd have to know the Habitica API
// returns gems in a data property called "balance", and that
// you had to multiply that value by 4.
console.log(user.apiData.balance * 4); // gives you # of gems...

// But really you should just call:
console.log(user.gems); // what it does is obvious!
});
```

Expand All @@ -204,29 +208,28 @@ apiManager.fetchUserWithTasks("USER ID", "API TOKEN")
// Assuming you've already created an apiManager and fetched
// Habitica the content data

apiManager.fetchUserWithTasks("USER ID", "API TOKEN")
.then((user) => {
// you can always get to the raw API object data from
// the .apiData property
console.log(user.apiData);

// user.tasks is actually a HabiticaUserTasksManager object that
// lets you do neat things like see the amount of damage your
// undone dailies will to!
console.log(user.tasks.dailyStats.dailyDamageToSelf);

// want a list of this user's todos, due today?
console.log(user.tasks.todosDueToday);

// user stats will be computed for you! Yay!
console.log(user.stats)
// output of console.log(user.stats):
// {
// totals: {str: 0, con: 0, int: 0, per: 0},
// armor: {str: 0, con: 0, int: 0, per: 0},
// buffs: {str: 0, con: 0, int: 0, per: 0},
// points: {str: 0, con: 0, int: 0, per: 0}
// }
apiManager.fetchUserWithTasks("USER ID", "API TOKEN").then((user) => {
// you can always get to the raw API object data from
// the .apiData property
console.log(user.apiData);

// user.tasks is actually a HabiticaUserTasksManager object that
// lets you do neat things like see the amount of damage your
// undone dailies will to!
console.log(user.tasks.dailyStats.dailyDamageToSelf);

// want a list of this user's todos, due today?
console.log(user.tasks.todosDueToday);

// user stats will be computed for you! Yay!
console.log(user.stats);
// output of console.log(user.stats):
// {
// totals: {str: 0, con: 0, int: 0, per: 0},
// armor: {str: 0, con: 0, int: 0, per: 0},
// buffs: {str: 0, con: 0, int: 0, per: 0},
// points: {str: 0, con: 0, int: 0, per: 0}
// }
});
```

Expand All @@ -237,6 +240,7 @@ apiManager.fetchUserWithTasks("USER ID", "API TOKEN")
### Build Scripts

To run all the build scripts:

```bash
npm run build
```
Expand All @@ -252,17 +256,21 @@ npm run build:minify
Compiled files will be output in the `/dist` directory. To modify the build process, edit `minify.js`.

### Generating the Developer Docs

The Developer documentation is generated from [JSDoc](https://jsdoc.app/index.html) formatted comments in the code, and created using [documentation.js](https://documentation.js.org/). To rebuild the documentation file after updating comments:

First, install dependencies locally.

```bash
npm install
```

Then run the following command to build the html docs:

```bash
npm run build:docs
```

---

## Contributing
Expand Down
Loading