openbd_api 0.4.3 → 0.4.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +7 -0
- data/lib/openbd/client.rb +7 -2
- data/lib/openbd/resources/openbd_item.rb +6 -6
- data/lib/openbd/version.rb +1 -1
- data/sample/fullget.rb +25 -0
- data/sample/fullget_para.rb +28 -0
- metadata +4 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a34d1689d167324f8ef010578c77eeb4c9a8c186
|
4
|
+
data.tar.gz: 167968f2ddd1d110a1ba56b1dd0349855a6094c4
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7d26b123a51ca26df09b6a3f0622a5591de7c60e0b184aff7478e20a2880544b7e2b0616e316eb9c135eb2821349ca2df18a0d64570c3b7228308dbb2accf8d1
|
7
|
+
data.tar.gz: 2280c86446436eb5a144a2c1ab246c91c3abea56adc706b589f6c304719666d8e7d501eda69e37a662bedabade2696e99762138daa9f0723d92a1a08604b7b9a
|
data/CHANGELOG.md
CHANGED
@@ -1,3 +1,10 @@
|
|
1
|
+
## 0.4.4
|
2
|
+
|
3
|
+
- OpenBD::Client.new: enable to define adapter and respnose parser
|
4
|
+
- add specs of OpenBD::Resources::OpenbdItem
|
5
|
+
- OpenBD::Resources::OpenbdItem.new: delay to generate objects
|
6
|
+
- add sample
|
7
|
+
|
1
8
|
## 0.4.3
|
2
9
|
|
3
10
|
- add OpenBD::Client specs for #get, #bulk_get, and #coverage
|
data/lib/openbd/client.rb
CHANGED
@@ -5,6 +5,11 @@ module OpenBD
|
|
5
5
|
PATH_TO_COVERAGE = 'v1/coverage'
|
6
6
|
PATH_TO_SCHEMA = 'v1/schema'
|
7
7
|
|
8
|
+
def initialize(adapter: :net_http, response_parser: :json)
|
9
|
+
@adapter = adapter
|
10
|
+
@response_parser = response_parser
|
11
|
+
end
|
12
|
+
|
8
13
|
def get(isbns)
|
9
14
|
get_request(
|
10
15
|
method: PATH_TO_GET,
|
@@ -39,8 +44,8 @@ module OpenBD
|
|
39
44
|
|
40
45
|
def connection
|
41
46
|
@connection ||= ::Faraday::Connection.new(url: API_BASE_URL) do |connection|
|
42
|
-
connection.adapter
|
43
|
-
connection.response
|
47
|
+
connection.adapter @adapter
|
48
|
+
connection.response @response_parser
|
44
49
|
end
|
45
50
|
end
|
46
51
|
|
@@ -3,21 +3,21 @@ module OpenBD
|
|
3
3
|
class OpenbdItem < BaseResource
|
4
4
|
def initialize(source)
|
5
5
|
@source = source
|
6
|
-
@hanmoto =
|
7
|
-
@onix =
|
8
|
-
@summary =
|
6
|
+
@hanmoto = nil
|
7
|
+
@onix = nil
|
8
|
+
@summary = nil
|
9
9
|
end
|
10
10
|
|
11
11
|
def onix
|
12
|
-
@onix
|
12
|
+
@onix ||= ::OpenBD::Resources::Onix.new(source['onix'])
|
13
13
|
end
|
14
14
|
|
15
15
|
def hanmoto
|
16
|
-
@hanmoto
|
16
|
+
@hanmoto ||= ::OpenBD::Resources::Hanmoto.new(source['hanmoto'])
|
17
17
|
end
|
18
18
|
|
19
19
|
def summary
|
20
|
-
@summary
|
20
|
+
@summary ||= ::OpenBD::Resources::Summary.new(source['summary'])
|
21
21
|
end
|
22
22
|
end
|
23
23
|
end
|
data/lib/openbd/version.rb
CHANGED
data/sample/fullget.rb
ADDED
@@ -0,0 +1,25 @@
|
|
1
|
+
require "openbd_api"
|
2
|
+
require "logger"
|
3
|
+
|
4
|
+
logger = Logger.new(STDERR)
|
5
|
+
logger.level = Logger::DEBUG
|
6
|
+
|
7
|
+
N = 10_000
|
8
|
+
MAX_REQ = 10 # if you want to get all data, use `nil`
|
9
|
+
|
10
|
+
client = OpenBD::Client.new()
|
11
|
+
coverage = client.coverage.body
|
12
|
+
|
13
|
+
coverage.each_slice(N).with_index do |list, i|
|
14
|
+
break if MAX_REQ && i >= MAX_REQ
|
15
|
+
logger.debug "req: #{i}..."
|
16
|
+
|
17
|
+
client.bulk_get(list).each do |item|
|
18
|
+
summary = item.summary
|
19
|
+
print "#{summary.isbn}: #{summary.title}\n"
|
20
|
+
|
21
|
+
## to reduce outputs, show only first title
|
22
|
+
break
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
@@ -0,0 +1,28 @@
|
|
1
|
+
require "openbd_api"
|
2
|
+
require "faraday_middleware/parse_oj"
|
3
|
+
require "parallel"
|
4
|
+
require "logger"
|
5
|
+
|
6
|
+
logger = Logger.new(STDERR)
|
7
|
+
logger.level = Logger::DEBUG
|
8
|
+
|
9
|
+
N = 10_000
|
10
|
+
MAX_PARA = 4
|
11
|
+
MAX_REQ = 10 # if you want to get all data, use `nil`
|
12
|
+
|
13
|
+
client = OpenBD::Client.new(response_parser: :oj)
|
14
|
+
coverage = client.coverage.body
|
15
|
+
|
16
|
+
Parallel.each_with_index(coverage.each_slice(N),
|
17
|
+
in_processes: MAX_PARA) do |list, i|
|
18
|
+
raise Parallel::Break if MAX_REQ && i >= MAX_REQ
|
19
|
+
logger.debug "req: #{i}..."
|
20
|
+
|
21
|
+
client.bulk_get(list).each do |item|
|
22
|
+
summary = item.summary
|
23
|
+
print "#{summary.isbn}: #{summary.title}\n"
|
24
|
+
|
25
|
+
## to reduce outputs, show only first title
|
26
|
+
break
|
27
|
+
end
|
28
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: openbd_api
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.4.
|
4
|
+
version: 0.4.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- nasum
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-02-
|
11
|
+
date: 2017-02-16 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -127,6 +127,8 @@ files:
|
|
127
127
|
- lib/openbd/version.rb
|
128
128
|
- lib/openbd_api.rb
|
129
129
|
- openbd_api.gemspec
|
130
|
+
- sample/fullget.rb
|
131
|
+
- sample/fullget_para.rb
|
130
132
|
homepage: https://github.com/nasum/openbd
|
131
133
|
licenses:
|
132
134
|
- MIT
|