ice_and_fire_api 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: f77fb7efd2311b54522eb2b3b6068e980ad0a840
4
+ data.tar.gz: e5dd492666eb7d2c024af3cf1ed1d9950d5fa676
5
+ SHA512:
6
+ metadata.gz: 55926bdf3919d6155fcecb8dc164edebe7619d973d6b99917e57b089f715af5fa3d6168a710fa4812b6becbebd952673ac5c7f2cdd829aedc751260744d59dc7
7
+ data.tar.gz: 3fd67214fcacb66db082277ae3258f04712f8775eecff5e2e44bad966d21ea4b2089b1b3ab11e4f26dc13e67a0f40db3cfb8ffe13e920095b55ada501d74fdf6
data/.gitignore ADDED
@@ -0,0 +1,9 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --format documentation
2
+ --color
data/.rubocop.yml ADDED
@@ -0,0 +1,14 @@
1
+ Documentation:
2
+ Enabled: false
3
+
4
+ MethodLength:
5
+ Max: 20
6
+
7
+ AbcSize:
8
+ Max: 25
9
+
10
+ LineLength:
11
+ Max: 90
12
+
13
+ Style/FrozenStringLiteralComment:
14
+ Enabled: false
data/.travis.yml ADDED
@@ -0,0 +1,5 @@
1
+ sudo: false
2
+ language: ruby
3
+ rvm:
4
+ - 2.3.0
5
+ before_install: gem install bundler -v 1.12.5
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in ice_and_fire_api.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2016 Dan Belling
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
13
+ all 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
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,86 @@
1
+ # IceAndFireApi
2
+
3
+ This gem provides an interface for the [Ice And Fire API](https://anapioficeandfire.com/). It was motivated by the current [lack of support](https://anapioficeandfire.com/Documentation#library-elixir) for a ruby library. More response fields and schema information for `House`, `Character`, and `Book` resources is available through the [documentation](https://anapioficeandfire.com/Documentation#root).
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ ```ruby
10
+ gem 'ice_and_fire_api'
11
+ ```
12
+
13
+ And then execute:
14
+
15
+ $ bundle
16
+
17
+ Or install it yourself as:
18
+
19
+ $ gem install ice_and_fire_api
20
+
21
+ ## Usage
22
+
23
+ The [Ice and Fire API](https://anapioficeandfire.com/) contains endpoints for the following resources:
24
+
25
+ * [`Root`](https://anapioficeandfire.com/Documentation#root)
26
+
27
+ **Fetch information about all resources available in the API.**
28
+
29
+ ```ruby
30
+ IceAndFireApi::Root.fetch
31
+ ```
32
+
33
+ * [`Books`](https://anapioficeandfire.com/Documentation#books)
34
+
35
+ **Find a book resource from its associated ID.**
36
+
37
+ ```ruby
38
+ IceAndFireApi::Book.find(5)
39
+ ```
40
+
41
+ or
42
+
43
+ **Find a book resource through a name filter.**
44
+
45
+ ```ruby
46
+ IceAndFireApi::Book.find_by_name('A Game of Thrones')
47
+ ```
48
+ * [`Characters`](https://anapioficeandfire.com/Documentation#characters)
49
+
50
+ **Find a character resource from its associated ID.**
51
+
52
+ ```ruby
53
+ IceAndFireApi::Character.find(88)
54
+ ```
55
+
56
+ or
57
+
58
+ **Find a character resource through a name filter.**
59
+
60
+ ```ruby
61
+ IceAndFireApi::Character.find('Eddard Stark')
62
+ ```
63
+
64
+ * [`Houses`](https://anapioficeandfire.com/Documentation#houses)
65
+
66
+ **Find a house resource from its associated ID.**
67
+
68
+ ```ruby
69
+ IceAndFireApi::House.find(42)
70
+ ```
71
+
72
+ or
73
+
74
+ **Find a house resource through its associated ID.**
75
+
76
+ ```ruby
77
+ IceAndFireApi::House.find('House Algood')
78
+ ```
79
+
80
+ ## Contributing
81
+
82
+ Bug reports and pull requests are welcome on GitHub at https://github.com/dbelling/ice_and_fire_api.
83
+
84
+ ## License
85
+
86
+ The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
data/Rakefile ADDED
@@ -0,0 +1,6 @@
1
+ require 'bundler/gem_tasks'
2
+ require 'rspec/core/rake_task'
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task default: :spec
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'bundler/setup'
4
+ require 'ice_and_fire_api'
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require 'irb'
14
+ IRB.start
data/bin/setup ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,31 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'ice_and_fire_api/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = 'ice_and_fire_api'
8
+ spec.version = IceAndFireApi::VERSION
9
+ spec.authors = ['Dan Belling']
10
+ spec.email = ['danhbelling@gmail.com']
11
+
12
+ spec.summary = "All the data from the universe \
13
+ of Ice And Fire you've ever wanted"
14
+ spec.description = 'A wrapper gem for http://www.anapioficeandfire.com/api'
15
+ spec.homepage = 'https://github.com/dbelling/ice_and_fire_api'
16
+ spec.license = 'MIT'
17
+
18
+ spec.add_development_dependency 'bundler', '~> 1.9'
19
+ spec.add_development_dependency 'rake', '~>10.0'
20
+ spec.add_development_dependency 'rspec', '~>3.0.0', '>=3.0.0'
21
+ spec.add_development_dependency 'vcr', '~>3.0.0', '>=3.0.0'
22
+
23
+ spec.add_dependency 'faraday', '~>0.9.2'
24
+ spec.add_dependency 'json', '~>1.8.2', '>=1.8.2'
25
+
26
+ spec.files = `git ls-files`.split("\n")
27
+ spec.bindir = 'bin'
28
+ spec.executables = `git ls-files -- bin/*`
29
+ .split("\n").map { |f| File.basename(f) }
30
+ spec.require_paths = ['lib']
31
+ end
@@ -0,0 +1,38 @@
1
+ module IceAndFireApi
2
+ class Book
3
+ attr_reader :url, :name, :isbn, :authors,
4
+ :numberOfPages, :publisher, :country,
5
+ :mediaType, :released, :characters, :povCharacters
6
+
7
+ def initialize(attributes)
8
+ @url = attributes['url']
9
+ @name = attributes['name']
10
+ @isbn = attributes['isbn']
11
+ @authors = attributes['authors']
12
+ @number_of_pages = attributes['numberOfPages']
13
+ @publisher = attributes['publisher']
14
+ @country = attributes['country']
15
+ @media_type = attributes['mediaType']
16
+ @released = attributes['released']
17
+ @characters = attributes['characters']
18
+ @pov_characters = attributes['povCharacters']
19
+ end
20
+
21
+ def self.find(id)
22
+ response = Faraday.get("#{IceAndFireApi::API_URL}/books/#{id}")
23
+ attributes = JSON.parse(response.body)
24
+ new(attributes)
25
+ end
26
+
27
+ def self.find_by_name(name)
28
+ name_query = URI.encode_www_form_component(name.to_s)
29
+ response = Faraday.get("#{IceAndFireApi::API_URL}/books?name=#{name_query}")
30
+ attributes_response = JSON.parse(response.body)
31
+ attributes_array = []
32
+ attributes_response.each do |attributes|
33
+ attributes_array << new(attributes)
34
+ end
35
+ attributes_array
36
+ end
37
+ end
38
+ end
@@ -0,0 +1,44 @@
1
+ module IceAndFireApi
2
+ class Character
3
+ attr_reader :url, :name, :gender, :culture,
4
+ :born, :died, :titles, :aliases,
5
+ :father, :mother, :spouse, :allegiances,
6
+ :books, :pov_books, :tv_series, :played_by
7
+
8
+ def initialize(attributes)
9
+ @url = attributes['url']
10
+ @name = attributes['name']
11
+ @gender = attributes['gender']
12
+ @culture = attributes['culture']
13
+ @born = attributes['born']
14
+ @died = attributes['died']
15
+ @titles = attributes['titles']
16
+ @aliases = attributes['aliases']
17
+ @father = attributes['father']
18
+ @mother = attributes['mother']
19
+ @spouse = attributes['spouse']
20
+ @allegiances = attributes['allegiances']
21
+ @books = attributes['books']
22
+ @pov_books = attributes['povBooks']
23
+ @tv_series = attributes['tvSeries']
24
+ @played_by = attributes['playedBy']
25
+ end
26
+
27
+ def self.find(id)
28
+ response = Faraday.get("#{IceAndFireApi::API_URL}/characters/#{id}")
29
+ attributes = JSON.parse(response.body)
30
+ new(attributes)
31
+ end
32
+
33
+ def self.find_by_name(name)
34
+ name_query = URI.encode_www_form_component(name.to_s)
35
+ response = Faraday.get("#{IceAndFireApi::API_URL}/characters?name=#{name_query}")
36
+ attributes_response = JSON.parse(response.body)
37
+ attributes_array = []
38
+ attributes_response.each do |attributes|
39
+ attributes_array << new(attributes)
40
+ end
41
+ attributes_array
42
+ end
43
+ end
44
+ end
@@ -0,0 +1,45 @@
1
+ module IceAndFireApi
2
+ class House
3
+ attr_reader :url, :name, :region, :coat_of_arms,
4
+ :words, :titles, :seats, :current_lord,
5
+ :heir, :overlord, :founded, :founder,
6
+ :died_out, :ancestral_weapons, :cadet_branches,
7
+ :sworn_members
8
+
9
+ def initialize(attributes)
10
+ @url = attributes['url']
11
+ @name = attributes['name']
12
+ @region = attributes['region']
13
+ @coat_of_arms = attributes['coatOfArms']
14
+ @words = attributes['words']
15
+ @titles = attributes['titles']
16
+ @seats = attributes['seats']
17
+ @current_lord = attributes['currentLord']
18
+ @heir = attributes['heir']
19
+ @overlord = attributes['overlord']
20
+ @founded = attributes['founded']
21
+ @founder = attributes['founder']
22
+ @died_out = attributes['diedOut']
23
+ @ancestral_weapons = attributes['ancestralWeapons']
24
+ @cadet_branches = attributes['cadetBranches']
25
+ @sworn_members = attributes['swornMembers']
26
+ end
27
+
28
+ def self.find(id)
29
+ response = Faraday.get("#{IceAndFireApi::API_URL}/houses/#{id}")
30
+ attributes = JSON.parse(response.body)
31
+ new(attributes)
32
+ end
33
+
34
+ def self.find_by_name(name)
35
+ name_query = URI.encode_www_form_component(name.to_s)
36
+ response = Faraday.get("#{IceAndFireApi::API_URL}/houses?name=#{name_query}")
37
+ attributes_response = JSON.parse(response.body)
38
+ attributes_array = []
39
+ attributes_response.each do |attributes|
40
+ attributes_array << new(attributes)
41
+ end
42
+ attributes_array
43
+ end
44
+ end
45
+ end
@@ -0,0 +1,17 @@
1
+ module IceAndFireApi
2
+ class Root
3
+ attr_reader :books, :characters, :houses
4
+
5
+ def initialize(attributes)
6
+ @books = attributes['books']
7
+ @characters = attributes['characters']
8
+ @houses = attributes['houses']
9
+ end
10
+
11
+ def self.fetch
12
+ response = Faraday.get(IceAndFireApi::API_URL.to_s)
13
+ attributes = JSON.parse(response.body)
14
+ new(attributes)
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,3 @@
1
+ module IceAndFireApi
2
+ VERSION = '1.0.0'.freeze
3
+ end
@@ -0,0 +1,12 @@
1
+ require 'ice_and_fire_api/version'
2
+ require 'ice_and_fire_api/book'
3
+ require 'ice_and_fire_api/character'
4
+ require 'ice_and_fire_api/house'
5
+ require 'ice_and_fire_api/root'
6
+ require 'json'
7
+ require 'faraday'
8
+ require 'uri'
9
+
10
+ module IceAndFireApi
11
+ API_URL = 'http://www.anapioficeandfire.com/api'.freeze
12
+ end