openbd_api 0.3.3 → 0.4.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +13 -0
- data/README.md +15 -12
- data/bin/openbd +1 -1
- data/lib/openbd/client.rb +29 -20
- data/lib/openbd/openbd_cli.rb +34 -30
- data/lib/openbd/resources/base_resource.rb +11 -0
- data/lib/openbd/resources/hanmoto.rb +6 -0
- data/lib/openbd/resources/onix.rb +6 -0
- data/lib/openbd/resources/openbd_item.rb +24 -0
- data/lib/openbd/resources/summary.rb +37 -0
- data/lib/openbd/responses/base_response.rb +13 -0
- data/lib/openbd/responses/coverage.rb +11 -0
- data/lib/openbd/responses/get.rb +17 -0
- data/lib/openbd/responses/schema.rb +6 -0
- data/lib/openbd/version.rb +2 -2
- data/lib/openbd_api.rb +11 -0
- data/openbd_api.gemspec +1 -1
- metadata +12 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 034af213e47a5f19347556b813096575e6e69339
|
4
|
+
data.tar.gz: 23998d9cbad1de89196cb626dceff4985211409b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ace39f05080e63c642efb4a37cac91c55c367f26ea5de17b4d681b0d93d0e40ae533b42334ce54dde4d8440291e456480b89cd0d9a91675c36418c0b8c68f6d2
|
7
|
+
data.tar.gz: cd1bdcbb170b009a1c9a2ec86e2abd239a309146f0551859c1ebec09dc07a261481aa10a030dcc5bbec5d2986b37378b2d14817edbecf5fa2dbbf73df417f3a0
|
data/CHANGELOG.md
ADDED
@@ -0,0 +1,13 @@
|
|
1
|
+
## 0.4.0
|
2
|
+
|
3
|
+
- Change Architecture. need to create `Client` instance.
|
4
|
+
- Add `OpenBD::Client`
|
5
|
+
- Add `OpenBD::Responses::BaseResoponse`
|
6
|
+
- Add `OpenBD::Responses::Coverage`
|
7
|
+
- Add `OpenBD::Responses::Get`
|
8
|
+
- Add `OpenBD::Responses::Schema`
|
9
|
+
- Add `OpenBD::Resources::BaseResource`
|
10
|
+
- Add `OpenBD::Resources::Hanmoto`
|
11
|
+
- Add `OpenBD::Resources::Onix`
|
12
|
+
- Add `OpenBD::Resources::OpenbdItem`
|
13
|
+
- Add `OpenBD::Resources::Summary`
|
data/README.md
CHANGED
@@ -30,25 +30,28 @@ Like this.
|
|
30
30
|
```rb
|
31
31
|
require 'openbd_api'
|
32
32
|
|
33
|
+
# create instance
|
34
|
+
client = OpenBD::Client.new
|
35
|
+
|
33
36
|
# get
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
37
|
+
client.get 9784309226712
|
38
|
+
client.get '9784309226712'
|
39
|
+
client.get '9784309226712,9784309226729'
|
40
|
+
client.get [9784309226712,9784309226729]
|
41
|
+
client.get ['9784309226712','9784309226729']
|
39
42
|
|
40
43
|
# bulk_get
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
44
|
+
client.bulk_get 9784309226712
|
45
|
+
client.bulk_get '9784309226712'
|
46
|
+
client.bulk_get '9784309226712,9784309226729'
|
47
|
+
client.bulk_get [9784309226712,9784309226729]
|
48
|
+
client.bulk_get ['9784309226712','9784309226729']
|
46
49
|
|
47
50
|
# coverage
|
48
|
-
|
51
|
+
client.coverage
|
49
52
|
|
50
53
|
# schema
|
51
|
-
|
54
|
+
client.schema
|
52
55
|
```
|
53
56
|
|
54
57
|
### CLI
|
data/bin/openbd
CHANGED
data/lib/openbd/client.rb
CHANGED
@@ -1,43 +1,52 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
1
|
+
module OpenBD
|
2
|
+
class Client
|
3
|
+
API_BASE_URL = 'http://api.openbd.jp/'.freeze
|
4
|
+
PATH_TO_GET = 'v1/get'
|
5
|
+
PATH_TO_COVERAGE = 'v1/coverage'
|
6
|
+
PATH_TO_SCHEMA = 'v1/schema'
|
4
7
|
|
5
|
-
class OpenBD
|
6
|
-
API_BASE_URL = 'http://api.openbd.jp/'.freeze
|
7
|
-
PATH_TO_GET = 'v1/get'
|
8
|
-
PATH_TO_COVERAGE = 'v1/coverage'
|
9
|
-
PATH_TO_SCHEMA = 'v1/schema'
|
10
|
-
|
11
|
-
class << self
|
12
8
|
def get(isbns)
|
13
|
-
|
14
|
-
|
9
|
+
get_request(
|
10
|
+
method: PATH_TO_GET,
|
11
|
+
params: { isbn: normalize_isbns(isbns) },
|
12
|
+
response_class: ::OpenBD::Responses::Get
|
13
|
+
)
|
15
14
|
end
|
16
15
|
|
17
16
|
def bulk_get(isbns)
|
18
|
-
|
19
|
-
|
17
|
+
get_request(
|
18
|
+
method: PATH_TO_GET,
|
19
|
+
params: { isbn: normalize_isbns(isbns) },
|
20
|
+
response_class: ::OpenBD::Responses::Get
|
21
|
+
)
|
20
22
|
end
|
21
23
|
|
22
24
|
def coverage
|
23
|
-
|
24
|
-
|
25
|
+
get_request(
|
26
|
+
method: PATH_TO_COVERAGE,
|
27
|
+
params: nil,
|
28
|
+
response_class: ::OpenBD::Responses::Coverage
|
29
|
+
)
|
25
30
|
end
|
26
31
|
|
27
32
|
def schema
|
28
|
-
|
29
|
-
|
33
|
+
get_request(
|
34
|
+
method: PATH_TO_SCHEMA,
|
35
|
+
params: nil,
|
36
|
+
response_class: ::OpenBD::Responses::Schema
|
37
|
+
)
|
30
38
|
end
|
31
39
|
|
32
40
|
def connection
|
33
|
-
Faraday::Connection.new(url: API_BASE_URL) do |connection|
|
41
|
+
@connection ||= ::Faraday::Connection.new(url: API_BASE_URL) do |connection|
|
34
42
|
connection.adapter :net_http
|
35
43
|
connection.response :json
|
36
44
|
end
|
37
45
|
end
|
38
46
|
|
39
|
-
def get_request(method
|
47
|
+
def get_request(method:, params:, response_class:)
|
40
48
|
faraday_response = connection.get(method, params)
|
49
|
+
response_class.new(faraday_response)
|
41
50
|
end
|
42
51
|
|
43
52
|
def post_request(method, params)
|
data/lib/openbd/openbd_cli.rb
CHANGED
@@ -1,39 +1,43 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
1
|
+
module OpenBD
|
2
|
+
class OpenbdCLI
|
3
|
+
def initialize(argv)
|
4
|
+
@argv = argv
|
5
|
+
parse_option
|
6
|
+
end
|
6
7
|
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
8
|
+
def call
|
9
|
+
if method_name.nil?
|
10
|
+
puts @opts
|
11
|
+
elsif params.empty?
|
12
|
+
client = ::OpenBD::Client.new
|
13
|
+
puts client.send(method_name).body.to_json
|
14
|
+
else
|
15
|
+
client = ::OpenBD::Client.new
|
16
|
+
puts client.send(method_name, params).body.to_json
|
17
|
+
end
|
14
18
|
end
|
15
|
-
end
|
16
19
|
|
17
|
-
|
20
|
+
private
|
18
21
|
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
+
def method_name
|
23
|
+
@argv[0]
|
24
|
+
end
|
22
25
|
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
+
def params
|
27
|
+
@argv[1..-1]
|
28
|
+
end
|
26
29
|
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
30
|
+
def parse_option
|
31
|
+
@opts = ::Slop.parse do |o|
|
32
|
+
o.banner = "Usage: openbd <method> [arguments] [options]"
|
33
|
+
o.on '-v', '--version', 'print the version' do
|
34
|
+
puts "openbd_api #{OpenBD::VERSION}"
|
35
|
+
exit
|
36
|
+
end
|
37
|
+
o.on '-h', '--help', 'print help' do
|
38
|
+
puts o
|
39
|
+
exit
|
40
|
+
end
|
37
41
|
end
|
38
42
|
end
|
39
43
|
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
module OpenBD
|
2
|
+
module Resources
|
3
|
+
class OpenbdItem < BaseResource
|
4
|
+
def initialize(source)
|
5
|
+
@source = source
|
6
|
+
@hanmoto = ::OpenBD::Resources::Hanmoto.new(source['hanmoto'])
|
7
|
+
@onix = ::OpenBD::Resources::Onix.new(source['onix'])
|
8
|
+
@summary = ::OpenBD::Resources::Summary.new(source['summary'])
|
9
|
+
end
|
10
|
+
|
11
|
+
def onix
|
12
|
+
@onix
|
13
|
+
end
|
14
|
+
|
15
|
+
def hanmoto
|
16
|
+
@hanmoto
|
17
|
+
end
|
18
|
+
|
19
|
+
def summary
|
20
|
+
@summary
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
@@ -0,0 +1,37 @@
|
|
1
|
+
module OpenBD
|
2
|
+
module Resources
|
3
|
+
class Summary < BaseResource
|
4
|
+
def isbn
|
5
|
+
source['isbn']
|
6
|
+
end
|
7
|
+
|
8
|
+
def title
|
9
|
+
source['title']
|
10
|
+
end
|
11
|
+
|
12
|
+
def volume
|
13
|
+
source['volume']
|
14
|
+
end
|
15
|
+
|
16
|
+
def series
|
17
|
+
source['series']
|
18
|
+
end
|
19
|
+
|
20
|
+
def publisher
|
21
|
+
source['publisher']
|
22
|
+
end
|
23
|
+
|
24
|
+
def pubdate
|
25
|
+
source['pubdate']
|
26
|
+
end
|
27
|
+
|
28
|
+
def cover
|
29
|
+
source['cover']
|
30
|
+
end
|
31
|
+
|
32
|
+
def author
|
33
|
+
source['author']
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
module OpenBD
|
2
|
+
module Responses
|
3
|
+
class Get < BaseResponse
|
4
|
+
include ::Enumerable
|
5
|
+
|
6
|
+
def each(&block)
|
7
|
+
resources.each(&block)
|
8
|
+
end
|
9
|
+
|
10
|
+
def resources
|
11
|
+
body.map do |source|
|
12
|
+
::OpenBD::Resources::OpenbdItem.new(source)
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
data/lib/openbd/version.rb
CHANGED
@@ -1,3 +1,3 @@
|
|
1
|
-
module
|
2
|
-
VERSION = "0.
|
1
|
+
module OpenBD
|
2
|
+
VERSION = "0.4.0"
|
3
3
|
end
|
data/lib/openbd_api.rb
CHANGED
@@ -1,5 +1,16 @@
|
|
1
|
+
require 'faraday'
|
2
|
+
require 'faraday_middleware'
|
1
3
|
require 'slop'
|
2
4
|
|
5
|
+
require 'openbd/resources/base_resource'
|
6
|
+
require 'openbd/resources/hanmoto'
|
7
|
+
require 'openbd/resources/onix'
|
8
|
+
require 'openbd/resources/summary'
|
9
|
+
require 'openbd/resources/openbd_item'
|
10
|
+
require 'openbd/responses/base_response'
|
11
|
+
require 'openbd/responses/coverage'
|
12
|
+
require 'openbd/responses/Get'
|
13
|
+
require 'openbd/responses/schema'
|
3
14
|
require 'openbd/version'
|
4
15
|
require 'openbd/client'
|
5
16
|
require 'openbd/openbd_cli'
|
data/openbd_api.gemspec
CHANGED
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
|
+
version: 0.4.0
|
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-12 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -106,6 +106,7 @@ files:
|
|
106
106
|
- ".rspec"
|
107
107
|
- ".ruby-version"
|
108
108
|
- ".travis.yml"
|
109
|
+
- CHANGELOG.md
|
109
110
|
- CODE_OF_CONDUCT.md
|
110
111
|
- Gemfile
|
111
112
|
- LICENSE.txt
|
@@ -114,6 +115,15 @@ files:
|
|
114
115
|
- bin/openbd
|
115
116
|
- lib/openbd/client.rb
|
116
117
|
- lib/openbd/openbd_cli.rb
|
118
|
+
- lib/openbd/resources/base_resource.rb
|
119
|
+
- lib/openbd/resources/hanmoto.rb
|
120
|
+
- lib/openbd/resources/onix.rb
|
121
|
+
- lib/openbd/resources/openbd_item.rb
|
122
|
+
- lib/openbd/resources/summary.rb
|
123
|
+
- lib/openbd/responses/base_response.rb
|
124
|
+
- lib/openbd/responses/coverage.rb
|
125
|
+
- lib/openbd/responses/get.rb
|
126
|
+
- lib/openbd/responses/schema.rb
|
117
127
|
- lib/openbd/version.rb
|
118
128
|
- lib/openbd_api.rb
|
119
129
|
- openbd_api.gemspec
|