├── package.json ├── .gitignore ├── LICENSE ├── asoiaf.js └── README.md /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "asoiaf-api", 3 | "version": "1.0.0", 4 | "description": "Javascript wrapper for the A song of ice and fire API ", 5 | "main": "asoiaf.js", 6 | "scripts": { 7 | "test": "echo \"Error: no test specified\" && exit 1" 8 | }, 9 | "repository": { 10 | "type": "git", 11 | "url": "git+https://github.com/arbazsiddiqui/A-song-of-ice-and-fire-API.git" 12 | }, 13 | "author": "arbaz siddiqui", 14 | "license": "MIT", 15 | "bugs": { 16 | "url": "https://github.com/arbazsiddiqui/A-song-of-ice-and-fire-API/issues" 17 | }, 18 | "homepage": "https://github.com/arbazsiddiqui/A-song-of-ice-and-fire-API#readme", 19 | "dependencies": { 20 | "xmlhttprequest": "^1.8.0" 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | ### Node template 2 | # Logs 3 | logs 4 | *.log 5 | npm-debug.log* 6 | .idea 7 | # Runtime data 8 | pids 9 | *.pid 10 | *.seed 11 | 12 | # Directory for instrumented libs generated by jscoverage/JSCover 13 | lib-cov 14 | 15 | # Coverage directory used by tools like istanbul 16 | coverage 17 | 18 | # Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files) 19 | .grunt 20 | 21 | # node-waf configuration 22 | .lock-wscript 23 | 24 | # Compiled binary addons (http://nodejs.org/api/addons.html) 25 | build/Release 26 | 27 | # Dependency directory 28 | # https://docs.npmjs.com/misc/faq#should-i-check-my-node-modules-folder-into-git 29 | node_modules 30 | 31 | # Created by .ignore support plugin (hsz.mobi) 32 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2016 Arbaz Siddiqui 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /asoiaf.js: -------------------------------------------------------------------------------- 1 | var asoiaf = function() { 2 | if (typeof require == 'function') { 3 | var XMLHttpRequest = require("xmlhttprequest").XMLHttpRequest; 4 | var exports = module.exports = {}; 5 | var httpGet = function(url) 6 | { 7 | var xmlHttp = new XMLHttpRequest(); 8 | xmlHttp.open("GET", url, false); 9 | xmlHttp.send(null); 10 | return JSON.parse(xmlHttp.responseText); 11 | } 12 | } else { 13 | var exports = {}; 14 | var httpGet = $.get; 15 | } 16 | 17 | //Getters for book 18 | 19 | exports.getBookByID = function(book_id) { 20 | book_id = book_id.toString(); 21 | var url = 'http://www.anapioficeandfire.com/api/books/' + book_id; 22 | return httpGet(url); 23 | } 24 | 25 | exports.getBookByName = function(book_name) { 26 | var url = 'http://www.anapioficeandfire.com/api/books/?name=' + book_name; 27 | return httpGet(url); 28 | } 29 | 30 | exports.getAllBooks = function() { 31 | var url = 'http://www.anapioficeandfire.com/api/books'; 32 | return httpGet(url); 33 | } 34 | 35 | //Getters for Character 36 | 37 | exports.getCharacterByID = function(char_id) { 38 | char_id = char_id.toString(); 39 | var url = 'http://www.anapioficeandfire.com/api/characters/' + char_id; 40 | return httpGet(url); 41 | } 42 | 43 | exports.getCharacterByName = function(char_name) { 44 | var url = 'http://www.anapioficeandfire.com/api/characters/?name=' + char_name; 45 | return httpGet(url); 46 | } 47 | 48 | exports.getAllCharacters = function() { 49 | var url = 'http://www.anapioficeandfire.com/api/characters'; 50 | return httpGet(url); 51 | } 52 | 53 | exports.getCharactersByCulture = function(culture_name) { 54 | var url = 'http://www.anapioficeandfire.com/api/characters/?culture=' + culture_name; 55 | return httpGet(url); 56 | } 57 | 58 | exports.getCharactersByGender = function(gender) { 59 | var url = 'http://www.anapioficeandfire.com/api/characters/?gender=' + gender; 60 | return httpGet(url); 61 | } 62 | 63 | //Getters for House 64 | 65 | exports.getAllHouses = function() { 66 | var url = 'http://www.anapioficeandfire.com/api/houses'; 67 | return httpGet(url); 68 | } 69 | 70 | exports.getHouseByID = function(house_id) { 71 | house_id = house_id.toString(); 72 | var url = 'http://www.anapioficeandfire.com/api/houses/' + house_id; 73 | return httpGet(url); 74 | } 75 | 76 | exports.getHouseByName = function(house_name) { 77 | var url = 'http://www.anapioficeandfire.com/api/houses/?name=' + house_name; 78 | return httpGet(url); 79 | } 80 | 81 | exports.getHouseByRegion = function(region) { 82 | var url = 'http://www.anapioficeandfire.com/api/houses/?region=' + region; 83 | return httpGet(url); 84 | } 85 | 86 | exports.getHouseByWords = function(words) { 87 | var url = 'http://www.anapioficeandfire.com/api/houses/?words=' + words; 88 | return httpGet(url); 89 | } 90 | 91 | }(); 92 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # A-song-of-ice-and-fire-API # 2 | 3 | ## Overview ## 4 | A-song-of-ice-and-fire-API is a Node.js wrapper for accessing [AnApiOfIceAndFire](https://github.com/joakimskoog/AnApiOfIceAndFire). 5 | 6 | ## Installation ## 7 | 8 | The current production release of A-song-of-ice-and-fire-API is available through [npm](https://www.npmjs.com/package/asoiaf-api): 9 | 10 | ``` 11 | npm install asoiaf-api 12 | ``` 13 | 14 | ## Usage ## 15 | 16 | ```javascript 17 | > var asoaif = require('asoiaf-api'); 18 | > asoaif.getCharacterByName("Jon Snow"); 19 | 20 | 21 | [ { url: 'http://www.anapioficeandfire.com/api/characters/583', 22 | name: 'Jon Snow', 23 | gender: 'Male', 24 | culture: 'Northmen', 25 | born: 'In 283 AC', 26 | died: '', 27 | titles: [ 'Lord Commander of the Night\'s Watch' ], 28 | aliases: 29 | [ 'Lord Snow', 30 | 'Ned Stark\'s Bastard', 31 | 'The Snow of Winterfell', 32 | 'The Crow-Come-Over', 33 | 'The 998th Lord Commander of the Night\'s Watch', 34 | 'The Bastard of Winterfell', 35 | 'The Black Bastard of the Wall', 36 | 'Lord Crow' ], 37 | father: '', 38 | mother: '', 39 | spouse: '', 40 | allegiances: [ 'http://www.anapioficeandfire.com/api/houses/362' ], 41 | books: [ 'http://www.anapioficeandfire.com/api/books/5' ], 42 | povBooks: 43 | [ 'http://www.anapioficeandfire.com/api/books/1', 44 | 'http://www.anapioficeandfire.com/api/books/2', 45 | 'http://www.anapioficeandfire.com/api/books/3', 46 | 'http://www.anapioficeandfire.com/api/books/8' ], 47 | tvSeries: [ 'Season 1', 'Season 2', 'Season 3', 'Season 4', 'Season 5' ], 48 | playedBy: [ 'Kit Harington' ] } ] 49 | ``` 50 | 51 | ## API ## 52 | 53 | ### Characters ### 54 | 55 | **getCharacterByID** 56 | 57 | * Accepts: A string or number representing a character ID. 58 | * Returns: An object containing the character's properties if the character exists. 59 | 60 | **getCharacterByName** 61 | 62 | * Accepts: A string representing full name of the character. 63 | * Returns: An array of objects containing all the characters with given name. 64 | 65 | **getCharactersByCulture** 66 | 67 | * Accepts: A string representing the culture of Character. 68 | * Returns: An array of objects containing all the characters with given culture. 69 | 70 | **getCharactersByGender** 71 | 72 | * Accepts: A string representing the gender of Character. 73 | * Returns: An array of objects containing all the characters with given gender. 74 | 75 | **getAllCharacters** 76 | 77 | * Returns: An array of objects containing all the characters. 78 | 79 | ### Houses ### 80 | 81 | **getHouseByID** 82 | 83 | * Accepts: A string or number representing a house ID. 84 | * Returns: An object containing the house's properties if the house exists. 85 | 86 | **getHouseByName** 87 | 88 | * Accepts: A string representing full name of the house. 89 | * Returns: An array of objects containing all the houses with given name. 90 | 91 | **getHouseByRegion** 92 | 93 | * Accepts: A string representing the region of the house. 94 | * Returns: An array of objects containing all the houses with given region. 95 | 96 | **getHouseByWords** 97 | 98 | * Accepts: A string representing the words/saying of the house. 99 | * Returns: An array of objects containing all the houses with given words/saying. 100 | 101 | **getAllHouses** 102 | 103 | * Returns: An array of objects containing all the houses. 104 | 105 | ### Books ### 106 | 107 | **getBookByID** 108 | 109 | * Accepts: A string or number representing a book ID. 110 | * Returns: An object containing the book's properties if the book exists. 111 | 112 | **getBookByName** 113 | 114 | * Accepts: A string representing full name of the book. 115 | * Returns: An array of objects containing all the books with given name. 116 | 117 | **getAllBooks** 118 | 119 | * Returns: An array of objects containing all the books. 120 | 121 | ### FUN ### 122 | 123 | **getRandomCharacter** 124 | 125 | * Returns: An object containing the properties of a random character. 126 | 127 | **getRandomHouse** 128 | 129 | * Returns: An object containing the properties of a random house. 130 | 131 | **getRandomCharacterOfHouse** 132 | 133 | * Accepts: A string representing full name of the house. 134 | * Returns: An object containing the properties of a random character from the given house 135 | 136 | ```javascript 137 | > var asoaif = require('asoiaf-api'); 138 | > asoaif.getRandomCharacterOfHouse("House Stark of Winterfell"); 139 | 140 | { url: 'http://www.anapioficeandfire.com/api/characters/170', 141 | name: 'Barthogan Stark', 142 | gender: 'Male', 143 | culture: 'Northmen', 144 | born: '', 145 | died: '', 146 | titles: [ 'Lord of Winterfell', 'Warden of the North' ], 147 | aliases: [ 'Barth Blacksword' ], 148 | father: '', 149 | mother: '', 150 | spouse: '', 151 | allegiances: [ 'http://www.anapioficeandfire.com/api/houses/362' ], 152 | books: 153 | [ 'http://www.anapioficeandfire.com/api/books/2', 154 | 'http://www.anapioficeandfire.com/api/books/11' ], 155 | povBooks: [], 156 | tvSeries: [], 157 | playedBy: [] } 158 | 159 | ``` 160 | --------------------------------------------------------------------------------