ann_wrapper 1.1.2 → 1.1.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +70 -1
- data/ann_wrapper.gemspec +1 -1
- data/lib/ann_wrapper.rb +33 -34
- data/lib/ann_wrapper/ann_objects.rb +4 -3
- data/lib/ann_wrapper/version.rb +1 -1
- data/spec/ann_wrapper_spec.rb +2 -2
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 5c633706a6c6f24e42f1f8bcb15df77b55438922
|
4
|
+
data.tar.gz: 59bc45c410c7ee4d5f7e438002d02d264ee4f6db
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b6388bdc6f50cb1058c36d02d5d4ae82fa50eea95bce3f7791839e15747b0e29c2ca31d68e5b0740ae07b930e6324e0d1acffbaf31dfa077939965a09aa74f2d
|
7
|
+
data.tar.gz: 83aebf0d4c30a3f97b3af180773e707d727685c40d6b03757eb6a0eacec80717ea1ecf62c665d2f60db723cb77c409002fd35f191321844b1baae85c878ae4cb
|
data/README.md
CHANGED
@@ -3,6 +3,7 @@
|
|
3
3
|
|
4
4
|
[![Gem Version](https://badge.fury.io/rb/ann_wrapper.png)](http://badge.fury.io/rb/ann_wrapper)
|
5
5
|
[![Build Status](https://travis-ci.org/Getkura/ann_wrapper.png?branch=dev)](https://travis-ci.org/Getkura/ann_wrapper)
|
6
|
+
[![Code Climate](https://codeclimate.com/github/Getkura/ann_wrapper.png)](https://codeclimate.com/github/Getkura/ann_wrapper)
|
6
7
|
|
7
8
|
|
8
9
|
A simple ruby wrapper/abstraction for the [Anime News Network API](http://www.animenewsnetwork.com/encyclopedia/api.php)
|
@@ -23,7 +24,75 @@ Or install it yourself as:
|
|
23
24
|
|
24
25
|
## Usage
|
25
26
|
|
26
|
-
|
27
|
+
Fetch an anime:
|
28
|
+
|
29
|
+
steins_gate = ANN_Wrapper.fetch_anime 11770
|
30
|
+
|
31
|
+
Info:
|
32
|
+
|
33
|
+
steins_gate.title
|
34
|
+
=> ["Steins;Gate"]
|
35
|
+
|
36
|
+
steins_gate.alt_titles
|
37
|
+
=> {"PT"=>["Steins-Gate e a Teoria do Caos"], "JA"=>["シュタインズ・ゲート"], "ZH-TW"=>["命運石之門"], "KO"=>["슈타인즈 게이트"]}
|
38
|
+
|
39
|
+
steins_gate.synopsis
|
40
|
+
=> ["Rintaro Okabe is a self-proclaimed "mad scientist" ... "]
|
41
|
+
|
42
|
+
steins_gate.num_episodes
|
43
|
+
=> ["24"]
|
44
|
+
|
45
|
+
steins_gate.vintage
|
46
|
+
=> ["2011-04-03 (Advanced screening)", "2011-04-05 to 2011-09-13"]
|
47
|
+
|
48
|
+
steins_gate.genres
|
49
|
+
=> ["adventure", "comedy", "drama", "mystery", "psychological", "romance", "science fiction", "thriller"]
|
50
|
+
|
51
|
+
steins_gate.themes
|
52
|
+
=> ["butterfly effect", "conspiracy", "technology", "Time travel"]
|
53
|
+
|
54
|
+
steins_gate.op_theme
|
55
|
+
=> ["\"Hacking to the Gate\" by Kanako Ito"]
|
56
|
+
|
57
|
+
steins_gate.ed_theme
|
58
|
+
=> ["\"Tokitsukasadoru Jūni no Meiyaku\" (刻司ル十二ノ盟約) by Yui Sakakibara", "#2: \"Sukai Kuraddo no Kansokusha\" (スカイクラッドの観測者) by Kanako Ito (ep 23)", "#3: \"Another Heaven\" by Kanako Itou (ep 24)"]
|
59
|
+
|
60
|
+
|
61
|
+
Cast and Staff:
|
62
|
+
|
63
|
+
steins_gate.cast.find_all {|c| c.name.include? "Hanazawa"}
|
64
|
+
=> [#<struct ANN_Cast id="53741", role="Mayuri Shiina", name="Kana Hanazawa", lang="JA">]
|
65
|
+
|
66
|
+
steins_gate.staff.find_all {|s| s.task.eql? "Director"}
|
67
|
+
=> [
|
68
|
+
#<struct ANN_Staff id="593", task="Director", name="Takuya Satō">,
|
69
|
+
#<struct ANN_Staff id="9693", task="Director", name="Hiroshi Hamasaki">,
|
70
|
+
#<struct ANN_Staff id="35713", task="Director", name="Tomoki Kobayashi">
|
71
|
+
]
|
72
|
+
|
73
|
+
|
74
|
+
Episodes:
|
75
|
+
|
76
|
+
steins_gate.episodes.first
|
77
|
+
=> #<struct ANN_Episode number="1", title="Prologue of the Beginning and End", lang="EN">
|
78
|
+
|
79
|
+
steins_gate.episodes.find_all {|e| e.title.include? "Prologue"}
|
80
|
+
=> [
|
81
|
+
#<struct ANN_Episode number="1", title="Prologue of the Beginning and End", lang="EN">,
|
82
|
+
#<struct ANN_Episode number="24", title="The Prologue Begins With the End", lang="EN">
|
83
|
+
]
|
84
|
+
|
85
|
+
Images:
|
86
|
+
|
87
|
+
steins_gate.images
|
88
|
+
=> [
|
89
|
+
#<struct ANN_Image src="http://cdn.animenewsnetwork.com/thumbnails/fit200x200/encyc/A11770-1864351140.1370764886.jpg", width="200", height="125">,
|
90
|
+
#<struct ANN_Image src="http://cdn.animenewsnetwork.com/thumbnails/fit200x200/encyc/A11770-8.jpg", width="200", height="200">
|
91
|
+
]
|
92
|
+
|
93
|
+
|
94
|
+
|
95
|
+
|
27
96
|
|
28
97
|
## Contributing
|
29
98
|
|
data/ann_wrapper.gemspec
CHANGED
@@ -10,7 +10,7 @@ Gem::Specification.new do |spec|
|
|
10
10
|
spec.email = ["getkura+ann_wrapper@gmail.com"]
|
11
11
|
spec.description = 'A simple wrapper for the Anime News Network API'
|
12
12
|
spec.summary = 'Anime News Network API wrapper'
|
13
|
-
spec.homepage = ""
|
13
|
+
spec.homepage = "http://documentup.com/Getkura/ann_wrapper"
|
14
14
|
spec.license = "MIT"
|
15
15
|
|
16
16
|
spec.files = `git ls-files`.split($/)
|
data/lib/ann_wrapper.rb
CHANGED
@@ -5,43 +5,20 @@
|
|
5
5
|
require "net/http"
|
6
6
|
require "nokogiri"
|
7
7
|
require 'ann_wrapper/ann_objects'
|
8
|
-
require 'singleton'
|
9
8
|
|
10
9
|
# wrapper class for ANN API
|
11
|
-
|
12
|
-
|
10
|
+
module ANN_Wrapper
|
11
|
+
extend ANN_Wrapper
|
12
|
+
|
13
13
|
# ANN API anime url
|
14
14
|
ANN_URL = "http://cdn.animenewsnetwork.com/encyclopedia"
|
15
15
|
ANN_API_URL = "#{ANN_URL}/api.xml"
|
16
16
|
ANN_REPORTS_URL = "#{ANN_URL}/reports.xml"
|
17
17
|
|
18
|
-
# fetch data from ANN API via http GET request
|
19
|
-
# returns Nokogiri or ANN_Error
|
20
|
-
def fetch(url)
|
21
|
-
begin
|
22
|
-
# send http GET request with uri parsed from url
|
23
|
-
resp = Net::HTTP.get_response(URI.parse(url))
|
24
|
-
|
25
|
-
# get the response body and try converting to Nokogiri object
|
26
|
-
Nokogiri.XML(resp.body)
|
27
|
-
rescue
|
28
|
-
ANN_Error.new("xml format error, API likely unavailable")
|
29
|
-
end
|
30
|
-
end
|
31
|
-
|
32
|
-
# attempt to grab error message from XMLObject
|
33
|
-
def get_xml_error(xobj)
|
34
|
-
begin
|
35
|
-
xobj.at_xpath('//ann/warning').content
|
36
|
-
rescue NameError
|
37
|
-
"bad response"
|
38
|
-
end
|
39
|
-
end
|
40
|
-
|
41
18
|
# fetch anime and convert to ANN_Anime
|
42
|
-
def
|
19
|
+
def fetch_anime(id, api_url=ANN_API_URL)
|
43
20
|
# append id to API url and send request
|
44
|
-
url = "#{
|
21
|
+
url = "#{api_url}?anime=#{id.to_s}"
|
45
22
|
|
46
23
|
ann = fetch(url)
|
47
24
|
|
@@ -54,8 +31,8 @@ class ANN_Wrapper
|
|
54
31
|
end
|
55
32
|
|
56
33
|
# fetch list of titles via reports
|
57
|
-
def fetch_titles(type="anime", nskip=0, nlist=50, name="")
|
58
|
-
url = "#{
|
34
|
+
def fetch_titles(type="anime", nskip=0, nlist=50, name="", api_url=ANN_REPORTS_URL)
|
35
|
+
url = "#{api_url}?id=155&type=#{type}&nskip=#{nskip}&nlist=#{nlist}"
|
59
36
|
report = fetch(url)
|
60
37
|
|
61
38
|
return report if report.is_a?(ANN_Error)
|
@@ -63,9 +40,31 @@ class ANN_Wrapper
|
|
63
40
|
reports = report.xpath('//report/item')
|
64
41
|
|
65
42
|
return ANN_Error.new(get_xml_error(report)) if reports.nil?
|
66
|
-
|
67
|
-
reports.map
|
68
|
-
|
43
|
+
|
44
|
+
reports.map { |item| ANN_Report.new(item) }
|
45
|
+
end
|
46
|
+
|
47
|
+
private
|
48
|
+
# fetch data from ANN API via http GET request
|
49
|
+
# returns Nokogiri or ANN_Error
|
50
|
+
def fetch(url)
|
51
|
+
begin
|
52
|
+
# send http GET request with uri parsed from url
|
53
|
+
resp = Net::HTTP.get_response(URI.parse(url))
|
54
|
+
|
55
|
+
# get the response body and try converting to Nokogiri object
|
56
|
+
Nokogiri.XML(resp.body)
|
57
|
+
rescue
|
58
|
+
ANN_Error.new("xml format error, API likely unavailable")
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
62
|
+
# attempt to grab error message from XMLObject
|
63
|
+
def get_xml_error(xobj)
|
64
|
+
begin
|
65
|
+
xobj.at_xpath('//ann/warning').content
|
66
|
+
rescue NameError
|
67
|
+
"bad response"
|
68
|
+
end
|
69
69
|
end
|
70
70
|
end
|
71
|
-
end
|
@@ -156,17 +156,18 @@ class ANN_Report < ANN
|
|
156
156
|
# initialize and build access methods
|
157
157
|
def initialize(ann_report)
|
158
158
|
@id, @type, @name, @precision, @vintage = ""
|
159
|
+
@ann_report = ann_report
|
159
160
|
|
160
161
|
self.instance_variables.each do |iv|
|
161
162
|
var_name = iv.to_s.partition("@").last
|
162
|
-
create_method(var_name) { get_info_on(
|
163
|
+
create_method(var_name) { get_info_on(var_name) }
|
163
164
|
end
|
164
165
|
end
|
165
166
|
|
166
167
|
# get info from xml
|
167
|
-
def get_info_on(
|
168
|
+
def get_info_on(var_name)
|
168
169
|
begin
|
169
|
-
ann_report.at_xpath(var_name).content
|
170
|
+
@ann_report.at_xpath(var_name).content
|
170
171
|
rescue NameError
|
171
172
|
nil
|
172
173
|
end
|
data/lib/ann_wrapper/version.rb
CHANGED
data/spec/ann_wrapper_spec.rb
CHANGED
@@ -4,7 +4,7 @@ describe "fetch_ann_anime" do
|
|
4
4
|
|
5
5
|
context "a valid id is provided" do
|
6
6
|
it "should return data for an ann anime" do
|
7
|
-
anime = ANN_Wrapper.
|
7
|
+
anime = ANN_Wrapper.fetch_anime(11770)
|
8
8
|
anime.should_not be_nil
|
9
9
|
anime.title.first.should eql "Steins;Gate"
|
10
10
|
end
|
@@ -12,7 +12,7 @@ describe "fetch_ann_anime" do
|
|
12
12
|
|
13
13
|
context "an invalid id is provided" do
|
14
14
|
it "should return an ANN_Error" do
|
15
|
-
anime = ANN_Wrapper.
|
15
|
+
anime = ANN_Wrapper.fetch_anime(117700)
|
16
16
|
anime.should_not be_nil
|
17
17
|
anime.should be_kind_of(ANN_Error)
|
18
18
|
anime.message.should_not be_nil
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ann_wrapper
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.1.
|
4
|
+
version: 1.1.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- shawntoffel
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-01-
|
11
|
+
date: 2014-01-12 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: nokogiri
|
@@ -85,7 +85,7 @@ files:
|
|
85
85
|
- lib/ann_wrapper/version.rb
|
86
86
|
- spec/ann_wrapper_spec.rb
|
87
87
|
- spec/spec_helper.rb
|
88
|
-
homepage:
|
88
|
+
homepage: http://documentup.com/Getkura/ann_wrapper
|
89
89
|
licenses:
|
90
90
|
- MIT
|
91
91
|
metadata: {}
|