animenewsnetwork 0.0.1 → 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- data/.travis.yml +5 -0
- data/README.md +2 -0
- data/animenewsnetwork.gemspec +2 -1
- data/lib/animenewsnetwork/encyclopedia.rb +23 -13
- data/lib/animenewsnetwork/version.rb +1 -1
- data/spec/unit/encyclopedia_spec.rb +18 -0
- metadata +56 -21
- checksums.yaml +0 -7
- data/.ruby-version +0 -1
data/.travis.yml
ADDED
data/README.md
CHANGED
data/animenewsnetwork.gemspec
CHANGED
@@ -18,10 +18,11 @@ Gem::Specification.new do |spec|
|
|
18
18
|
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
19
|
spec.require_paths = ["lib"]
|
20
20
|
|
21
|
-
spec.required_ruby_version = ">=
|
21
|
+
spec.required_ruby_version = ">= 1.9"
|
22
22
|
|
23
23
|
spec.add_dependency "nokogiri"
|
24
24
|
spec.add_dependency "addressable"
|
25
|
+
spec.add_dependency "data_validator"
|
25
26
|
|
26
27
|
spec.add_development_dependency "bundler", "~> 1.3"
|
27
28
|
spec.add_development_dependency "rake"
|
@@ -1,30 +1,40 @@
|
|
1
1
|
require 'open-uri'
|
2
2
|
require 'nokogiri'
|
3
3
|
require 'addressable/uri'
|
4
|
+
require 'data_validator'
|
4
5
|
|
5
6
|
class AnimeNewsNetwork::Encyclopedia
|
6
|
-
def initialize(
|
7
|
-
@url = url.
|
7
|
+
def initialize(args = {})
|
8
|
+
@url = args.has_key?(:url) ? args[:url] : 'http://cdn.animenewsnetwork.com/encyclopedia'
|
8
9
|
end
|
9
10
|
|
10
|
-
def get_reports(
|
11
|
-
|
12
|
-
|
11
|
+
def get_reports(args = {})
|
12
|
+
validator = DataValidator::Validator.new(
|
13
|
+
args, {
|
14
|
+
id: { presence: true, numericality: { only_integer: true } },
|
15
|
+
type: { presence: true, inclusion: { in: %w(anime manga) } },
|
16
|
+
nskip: { allow_nil: true, numericality: { only_integer: true } },
|
17
|
+
nlist: { allow_nil: true, format: { with: /^(\d+|all)$/ } },
|
18
|
+
}
|
19
|
+
)
|
20
|
+
raise ArgumentError, validator.errors unless validator.valid?
|
13
21
|
|
14
22
|
path = '/reports.xml';
|
15
|
-
query =
|
16
|
-
id: id,
|
17
|
-
type: type,
|
18
|
-
}
|
23
|
+
query = args
|
19
24
|
Nokogiri::XML(get(path, query))
|
20
25
|
end
|
21
26
|
|
22
|
-
def get_details(
|
23
|
-
|
24
|
-
|
27
|
+
def get_details(args = {})
|
28
|
+
validator = DataValidator::Validator.new(
|
29
|
+
args, {
|
30
|
+
id: { presence: true, numericality: { only_integer: true } },
|
31
|
+
type: { presence: true, inclusion: { in: %w(anime manga) } },
|
32
|
+
}
|
33
|
+
)
|
34
|
+
raise ArgumentError, validator.errors unless validator.valid?
|
25
35
|
|
26
36
|
path = '/api.xml';
|
27
|
-
query = { type => id }
|
37
|
+
query = { args[:type] => args[:id] }
|
28
38
|
Nokogiri::XML(get(path, query))
|
29
39
|
end
|
30
40
|
|
@@ -7,6 +7,16 @@ describe AnimeNewsNetwork::Encyclopedia do
|
|
7
7
|
.with(query: { id: 155, type: "anime" })
|
8
8
|
.to_return(body: reports_xml)
|
9
9
|
|
10
|
+
reports_xml = File.new(File.expand_path('../../resources/reports_xml_id_155_type_anime', __FILE__))
|
11
|
+
stub_http_request(:get, "cdn.animenewsnetwork.com/encyclopedia/reports.xml")
|
12
|
+
.with(query: { id: 155, type: "anime", nskip: 10, nlist: 10 })
|
13
|
+
.to_return(body: reports_xml)
|
14
|
+
|
15
|
+
reports_xml = File.new(File.expand_path('../../resources/reports_xml_id_155_type_anime', __FILE__))
|
16
|
+
stub_http_request(:get, "cdn.animenewsnetwork.com/encyclopedia/reports.xml")
|
17
|
+
.with(query: { id: 155, type: "anime", nlist: "all" })
|
18
|
+
.to_return(body: reports_xml)
|
19
|
+
|
10
20
|
api_xml = File.new(File.expand_path('../../resources/api_xml_anime_4658', __FILE__))
|
11
21
|
stub_http_request(:get, "cdn.animenewsnetwork.com/encyclopedia/api.xml")
|
12
22
|
.with(query: { anime: 4658 })
|
@@ -19,6 +29,14 @@ describe AnimeNewsNetwork::Encyclopedia do
|
|
19
29
|
subject { ann.get_reports(id: 155, type: 'anime') }
|
20
30
|
it { should be_a Nokogiri::XML::Document }
|
21
31
|
end
|
32
|
+
describe "GET reports nskip & nlist" do
|
33
|
+
subject { ann.get_reports(id: 155, type: 'anime', nskip: 10, nlist: 10) }
|
34
|
+
it { should be_a Nokogiri::XML::Document }
|
35
|
+
end
|
36
|
+
describe "GET reports nlist all" do
|
37
|
+
subject { ann.get_reports(id: 155, type: 'anime', nlist: 'all') }
|
38
|
+
it { should be_a Nokogiri::XML::Document }
|
39
|
+
end
|
22
40
|
|
23
41
|
describe "GET details" do
|
24
42
|
subject { ann.get_details(id: 4658, type: 'anime') }
|
metadata
CHANGED
@@ -1,46 +1,68 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: animenewsnetwork
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.2
|
5
|
+
prerelease:
|
5
6
|
platform: ruby
|
6
7
|
authors:
|
7
8
|
- Ryosuke IWANAGA
|
8
9
|
autorequire:
|
9
10
|
bindir: bin
|
10
11
|
cert_chain: []
|
11
|
-
date: 2013-05-
|
12
|
+
date: 2013-05-30 00:00:00.000000000 Z
|
12
13
|
dependencies:
|
13
14
|
- !ruby/object:Gem::Dependency
|
14
15
|
name: nokogiri
|
15
16
|
requirement: !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
16
18
|
requirements:
|
17
|
-
- - '>='
|
19
|
+
- - ! '>='
|
18
20
|
- !ruby/object:Gem::Version
|
19
21
|
version: '0'
|
20
22
|
type: :runtime
|
21
23
|
prerelease: false
|
22
24
|
version_requirements: !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
23
26
|
requirements:
|
24
|
-
- - '>='
|
27
|
+
- - ! '>='
|
25
28
|
- !ruby/object:Gem::Version
|
26
29
|
version: '0'
|
27
30
|
- !ruby/object:Gem::Dependency
|
28
31
|
name: addressable
|
29
32
|
requirement: !ruby/object:Gem::Requirement
|
33
|
+
none: false
|
30
34
|
requirements:
|
31
|
-
- - '>='
|
35
|
+
- - ! '>='
|
32
36
|
- !ruby/object:Gem::Version
|
33
37
|
version: '0'
|
34
38
|
type: :runtime
|
35
39
|
prerelease: false
|
36
40
|
version_requirements: !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
37
42
|
requirements:
|
38
|
-
- - '>='
|
43
|
+
- - ! '>='
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
version: '0'
|
46
|
+
- !ruby/object:Gem::Dependency
|
47
|
+
name: data_validator
|
48
|
+
requirement: !ruby/object:Gem::Requirement
|
49
|
+
none: false
|
50
|
+
requirements:
|
51
|
+
- - ! '>='
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
version: '0'
|
54
|
+
type: :runtime
|
55
|
+
prerelease: false
|
56
|
+
version_requirements: !ruby/object:Gem::Requirement
|
57
|
+
none: false
|
58
|
+
requirements:
|
59
|
+
- - ! '>='
|
39
60
|
- !ruby/object:Gem::Version
|
40
61
|
version: '0'
|
41
62
|
- !ruby/object:Gem::Dependency
|
42
63
|
name: bundler
|
43
64
|
requirement: !ruby/object:Gem::Requirement
|
65
|
+
none: false
|
44
66
|
requirements:
|
45
67
|
- - ~>
|
46
68
|
- !ruby/object:Gem::Version
|
@@ -48,6 +70,7 @@ dependencies:
|
|
48
70
|
type: :development
|
49
71
|
prerelease: false
|
50
72
|
version_requirements: !ruby/object:Gem::Requirement
|
73
|
+
none: false
|
51
74
|
requirements:
|
52
75
|
- - ~>
|
53
76
|
- !ruby/object:Gem::Version
|
@@ -55,57 +78,65 @@ dependencies:
|
|
55
78
|
- !ruby/object:Gem::Dependency
|
56
79
|
name: rake
|
57
80
|
requirement: !ruby/object:Gem::Requirement
|
81
|
+
none: false
|
58
82
|
requirements:
|
59
|
-
- - '>='
|
83
|
+
- - ! '>='
|
60
84
|
- !ruby/object:Gem::Version
|
61
85
|
version: '0'
|
62
86
|
type: :development
|
63
87
|
prerelease: false
|
64
88
|
version_requirements: !ruby/object:Gem::Requirement
|
89
|
+
none: false
|
65
90
|
requirements:
|
66
|
-
- - '>='
|
91
|
+
- - ! '>='
|
67
92
|
- !ruby/object:Gem::Version
|
68
93
|
version: '0'
|
69
94
|
- !ruby/object:Gem::Dependency
|
70
95
|
name: rspec
|
71
96
|
requirement: !ruby/object:Gem::Requirement
|
97
|
+
none: false
|
72
98
|
requirements:
|
73
|
-
- - '>='
|
99
|
+
- - ! '>='
|
74
100
|
- !ruby/object:Gem::Version
|
75
101
|
version: '0'
|
76
102
|
type: :development
|
77
103
|
prerelease: false
|
78
104
|
version_requirements: !ruby/object:Gem::Requirement
|
105
|
+
none: false
|
79
106
|
requirements:
|
80
|
-
- - '>='
|
107
|
+
- - ! '>='
|
81
108
|
- !ruby/object:Gem::Version
|
82
109
|
version: '0'
|
83
110
|
- !ruby/object:Gem::Dependency
|
84
111
|
name: webmock
|
85
112
|
requirement: !ruby/object:Gem::Requirement
|
113
|
+
none: false
|
86
114
|
requirements:
|
87
|
-
- - '>='
|
115
|
+
- - ! '>='
|
88
116
|
- !ruby/object:Gem::Version
|
89
117
|
version: '0'
|
90
118
|
type: :development
|
91
119
|
prerelease: false
|
92
120
|
version_requirements: !ruby/object:Gem::Requirement
|
121
|
+
none: false
|
93
122
|
requirements:
|
94
|
-
- - '>='
|
123
|
+
- - ! '>='
|
95
124
|
- !ruby/object:Gem::Version
|
96
125
|
version: '0'
|
97
126
|
- !ruby/object:Gem::Dependency
|
98
127
|
name: pry
|
99
128
|
requirement: !ruby/object:Gem::Requirement
|
129
|
+
none: false
|
100
130
|
requirements:
|
101
|
-
- - '>='
|
131
|
+
- - ! '>='
|
102
132
|
- !ruby/object:Gem::Version
|
103
133
|
version: '0'
|
104
134
|
type: :development
|
105
135
|
prerelease: false
|
106
136
|
version_requirements: !ruby/object:Gem::Requirement
|
137
|
+
none: false
|
107
138
|
requirements:
|
108
|
-
- - '>='
|
139
|
+
- - ! '>='
|
109
140
|
- !ruby/object:Gem::Version
|
110
141
|
version: '0'
|
111
142
|
description: AnimeNewsNetwork API
|
@@ -117,7 +148,7 @@ extra_rdoc_files: []
|
|
117
148
|
files:
|
118
149
|
- .gitignore
|
119
150
|
- .rspec
|
120
|
-
- .
|
151
|
+
- .travis.yml
|
121
152
|
- Gemfile
|
122
153
|
- LICENSE.txt
|
123
154
|
- README.md
|
@@ -134,26 +165,30 @@ files:
|
|
134
165
|
homepage: ''
|
135
166
|
licenses:
|
136
167
|
- MIT
|
137
|
-
metadata: {}
|
138
168
|
post_install_message:
|
139
169
|
rdoc_options: []
|
140
170
|
require_paths:
|
141
171
|
- lib
|
142
172
|
required_ruby_version: !ruby/object:Gem::Requirement
|
173
|
+
none: false
|
143
174
|
requirements:
|
144
|
-
- - '>='
|
175
|
+
- - ! '>='
|
145
176
|
- !ruby/object:Gem::Version
|
146
|
-
version:
|
177
|
+
version: '1.9'
|
147
178
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
179
|
+
none: false
|
148
180
|
requirements:
|
149
|
-
- - '>='
|
181
|
+
- - ! '>='
|
150
182
|
- !ruby/object:Gem::Version
|
151
183
|
version: '0'
|
184
|
+
segments:
|
185
|
+
- 0
|
186
|
+
hash: 3131183906614767275
|
152
187
|
requirements: []
|
153
188
|
rubyforge_project:
|
154
|
-
rubygems_version:
|
189
|
+
rubygems_version: 1.8.23
|
155
190
|
signing_key:
|
156
|
-
specification_version:
|
191
|
+
specification_version: 3
|
157
192
|
summary: AnimeNewsNetwork API
|
158
193
|
test_files:
|
159
194
|
- spec/animenewsnetwork_spec.rb
|
checksums.yaml
DELETED
@@ -1,7 +0,0 @@
|
|
1
|
-
---
|
2
|
-
SHA1:
|
3
|
-
metadata.gz: 485242bb38a628015fa70c792bf057490beaeb8b
|
4
|
-
data.tar.gz: c95fb34e388eca3cbf19c50ca04c716dd51130a8
|
5
|
-
SHA512:
|
6
|
-
metadata.gz: 5901394da31967f9223b752cf339da821c792742c4273a2f2fcd3ce151176cbef08f98c536a5b1a087e259a1cbae8aa352bc69c0e040d5c7c2d05be9aa2e7de7
|
7
|
-
data.tar.gz: 8f6ef18be8eed9b75f96793dd135a26f0bc8dd849c9d178ec3c2a1913074279100e0c3307d9dc636bbea9447e69773bc109f4c7c48c044d29a3836686bff997a
|
data/.ruby-version
DELETED
@@ -1 +0,0 @@
|
|
1
|
-
2.0.0-p195
|