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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 7677573ec1279c4f8264add004da473f3a82b9c0
4
- data.tar.gz: c4c9a33631c29b4930a4b39015ff8fd6cddcb506
3
+ metadata.gz: 034af213e47a5f19347556b813096575e6e69339
4
+ data.tar.gz: 23998d9cbad1de89196cb626dceff4985211409b
5
5
  SHA512:
6
- metadata.gz: d4b4a92fb6f95ef1fa03ab7b939cac8524dbc1afe23e50bf8d09439eef8db0a5346f1cce05d53ce1dd522bcb9c746ecfb7c9505a6dbad84b8bbdcf9015acae42
7
- data.tar.gz: 3c6a6ede00bbdf0db98d23344e3932fc7471de927ca9651483ae7c0bde498dd4134c8a1ecd0483f05f5a69746013899613603784619db82a1fbb9a4fe31f1689
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
- OpenBD.get 9784309226712
35
- OpenBD.get '9784309226712'
36
- OpenBD.get '9784309226712,9784309226729'
37
- OpenBD.get [9784309226712,9784309226729]
38
- OpenBD.get ['9784309226712','9784309226729']
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
- OpenBD.bulk_get 9784309226712
42
- OpenBD.bulk_get '9784309226712'
43
- OpenBD.bulk_get '9784309226712,9784309226729'
44
- OpenBD.bulk_get [9784309226712,9784309226729]
45
- OpenBD.bulk_get ['9784309226712','9784309226729']
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
- OpenBD.coverage
51
+ client.coverage
49
52
 
50
53
  # schema
51
- OpenBD.schema
54
+ client.schema
52
55
  ```
53
56
 
54
57
  ### CLI
data/bin/openbd CHANGED
@@ -3,5 +3,5 @@ $LOAD_PATH.unshift File.expand_path("../../lib", __FILE__)
3
3
 
4
4
  require 'openbd_api'
5
5
 
6
- openbd_cli = OpenbdCLI.new(ARGV)
6
+ openbd_cli = ::OpenBD::OpenbdCLI.new(ARGV)
7
7
  openbd_cli.call
data/lib/openbd/client.rb CHANGED
@@ -1,43 +1,52 @@
1
- require 'faraday'
2
- require 'faraday_middleware'
3
- require 'json'
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
- response = get_request(PATH_TO_GET, { isbn: normalize_isbns(isbns) })
14
- response.body
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
- response = post_request(PATH_TO_GET, { isbn: isbns })
19
- response.body
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
- response = get_request(PATH_TO_COVERAGE)
24
- response.body
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
- response = get_request(PATH_TO_SCHEMA)
29
- response.body
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, params = nil)
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)
@@ -1,39 +1,43 @@
1
- class OpenbdCLI
2
- def initialize(argv)
3
- @argv = argv
4
- parse_option
5
- end
1
+ module OpenBD
2
+ class OpenbdCLI
3
+ def initialize(argv)
4
+ @argv = argv
5
+ parse_option
6
+ end
6
7
 
7
- def call
8
- if method_name.nil?
9
- puts @opts
10
- elsif params.empty?
11
- puts OpenBD.send(method_name).to_json
12
- else
13
- puts OpenBD.send(method_name, params).to_json
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
- private
20
+ private
18
21
 
19
- def method_name
20
- @argv[0]
21
- end
22
+ def method_name
23
+ @argv[0]
24
+ end
22
25
 
23
- def params
24
- @argv[1..-1]
25
- end
26
+ def params
27
+ @argv[1..-1]
28
+ end
26
29
 
27
- def parse_option
28
- @opts = Slop.parse do |o|
29
- o.banner = "Usage: openbd <method> [arguments] [options]"
30
- o.on '-v', '--version', 'print the version' do
31
- puts "openbd_api #{Openbd::VERSION}"
32
- exit
33
- end
34
- o.on '-h', '--help', 'print help' do
35
- puts o
36
- exit
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,11 @@
1
+ module OpenBD
2
+ module Resources
3
+ class BaseResource
4
+ attr_reader :source
5
+
6
+ def initialize(source)
7
+ @source = source
8
+ end
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,6 @@
1
+ module OpenBD
2
+ module Resources
3
+ class Hanmoto < BaseResource
4
+ end
5
+ end
6
+ end
@@ -0,0 +1,6 @@
1
+ module OpenBD
2
+ module Resources
3
+ class Onix < BaseResource
4
+ end
5
+ end
6
+ 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,13 @@
1
+ module OpenBD
2
+ module Responses
3
+ class BaseResponse
4
+ def initialize(faraday_response)
5
+ @faraday_response = faraday_response
6
+ end
7
+
8
+ def body
9
+ @faraday_response.body
10
+ end
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,11 @@
1
+ module OpenBD
2
+ module Responses
3
+ class Coverage < BaseResponse
4
+ include ::Enumerable
5
+
6
+ def each(&block)
7
+ body.each(&block)
8
+ end
9
+ end
10
+ end
11
+ 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
@@ -0,0 +1,6 @@
1
+ module OpenBD
2
+ module Responses
3
+ class Schema < BaseResponse
4
+ end
5
+ end
6
+ end
@@ -1,3 +1,3 @@
1
- module Openbd
2
- VERSION = "0.3.3"
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
@@ -5,7 +5,7 @@ require 'openbd/version'
5
5
 
6
6
  Gem::Specification.new do |spec|
7
7
  spec.name = "openbd_api"
8
- spec.version = Openbd::VERSION
8
+ spec.version = OpenBD::VERSION
9
9
  spec.authors = ["nasum"]
10
10
  spec.email = ["tomato.wonder.life@gmail.com"]
11
11
 
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.3.3
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 00:00:00.000000000 Z
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