openbd_api 0.3.2 → 0.3.3

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: 5d7dbb8431a3263434f2803c4d6ddfe812b45638
4
- data.tar.gz: c8418e54012fef1faaed816df101b5d51d22633e
3
+ metadata.gz: 7677573ec1279c4f8264add004da473f3a82b9c0
4
+ data.tar.gz: c4c9a33631c29b4930a4b39015ff8fd6cddcb506
5
5
  SHA512:
6
- metadata.gz: cdb36dd3ebb4a0fb33daa50781a3b7199906740af32c60e7c24cb2dd700b8181139b9434cf298a521bd72366397ddca5b041bf2fdcd28afc1630b392cccef03b
7
- data.tar.gz: 768c10f9b655a6f8c33b370979c14f54ba240751f7a8c8ff800834e09cf31165acddf785508c7d0065f3d788095709006ee31f66c76e4059d0ecbd16d232e5e5
6
+ metadata.gz: d4b4a92fb6f95ef1fa03ab7b939cac8524dbc1afe23e50bf8d09439eef8db0a5346f1cce05d53ce1dd522bcb9c746ecfb7c9505a6dbad84b8bbdcf9015acae42
7
+ data.tar.gz: 3c6a6ede00bbdf0db98d23344e3932fc7471de927ca9651483ae7c0bde498dd4134c8a1ecd0483f05f5a69746013899613603784619db82a1fbb9a4fe31f1689
data/.travis.yml CHANGED
@@ -1,6 +1,7 @@
1
1
  sudo: false
2
2
  language: ruby
3
3
  rvm:
4
- - 2.3.0
4
+ - 2.2.6
5
+ - 2.3.3
5
6
  - 2.4.0
6
7
  before_install: gem install bundler -v 1.14.3
data/lib/openbd/client.rb CHANGED
@@ -1,51 +1,49 @@
1
- require 'net/http'
1
+ require 'faraday'
2
+ require 'faraday_middleware'
2
3
  require 'json'
3
4
 
4
5
  class OpenBD
5
- API_BASE_URL = 'http://api.openbd.jp/v1/'.freeze
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'
6
10
 
7
11
  class << self
8
12
  def get(isbns)
9
- request_url = prepare_url('get', isbns)
10
- response = Net::HTTP.get_response(URI::parse(request_url))
11
- create_body(response).select { |item| item != nil }
13
+ response = get_request(PATH_TO_GET, { isbn: normalize_isbns(isbns) })
14
+ response.body
12
15
  end
13
16
 
14
17
  def bulk_get(isbns)
15
- request_url = prepare_url('get')
16
- response = Net::HTTP.post_form(URI::parse(request_url), isbn: normalize_isbns(isbns))
17
- create_body(response).select { |item| item != nil }
18
+ response = post_request(PATH_TO_GET, { isbn: isbns })
19
+ response.body
18
20
  end
19
21
 
20
22
  def coverage
21
- request_url = prepare_url('coverage')
22
- response = Net::HTTP.get_response(URI::parse(request_url))
23
- create_body(response)
23
+ response = get_request(PATH_TO_COVERAGE)
24
+ response.body
24
25
  end
25
26
 
26
27
  def schema
27
- request_url = prepare_url('schema')
28
- response = Net::HTTP.get_response(URI::parse(request_url))
29
- create_body(response)
28
+ response = get_request(PATH_TO_SCHEMA)
29
+ response.body
30
30
  end
31
31
 
32
- def create_body(response)
33
- JSON.parse response.body
32
+ def connection
33
+ Faraday::Connection.new(url: API_BASE_URL) do |connection|
34
+ connection.adapter :net_http
35
+ connection.response :json
36
+ end
34
37
  end
35
38
 
36
- def prepare_url(method, isbns = nil)
37
- case isbns
38
- when String
39
- params = normalize_isbns(isbns)
40
- "#{API_BASE_URL}#{method}?isbn=#{params}"
41
- when Numeric
42
- params = normalize_isbns(isbns)
43
- "#{API_BASE_URL}#{method}?isbn=#{params}"
44
- when Array
45
- params = normalize_isbns(isbns)
46
- "#{API_BASE_URL}#{method}?isbn=#{params}"
47
- else
48
- "#{API_BASE_URL}#{method}"
39
+ def get_request(method, params = nil)
40
+ faraday_response = connection.get(method, params)
41
+ end
42
+
43
+ def post_request(method, params)
44
+ faraday_response = connection.post do |req|
45
+ req.url method
46
+ req.body = "isbn=#{normalize_isbns(params[:isbn])}"
49
47
  end
50
48
  end
51
49
 
@@ -1,3 +1,3 @@
1
1
  module Openbd
2
- VERSION = "0.3.2"
2
+ VERSION = "0.3.3"
3
3
  end
data/openbd_api.gemspec CHANGED
@@ -14,6 +14,8 @@ Gem::Specification.new do |spec|
14
14
  spec.homepage = "https://github.com/nasum/openbd"
15
15
  spec.license = "MIT"
16
16
 
17
+ spec.required_ruby_version = '~> 2.2'
18
+
17
19
  spec.files = `git ls-files -z`.split("\x0").reject do |f|
18
20
  f.match(%r{^(test|spec|features)/})
19
21
  end
@@ -25,4 +27,6 @@ Gem::Specification.new do |spec|
25
27
  spec.add_development_dependency "rake", "~> 10.0"
26
28
  spec.add_development_dependency "rspec", "~> 3.0"
27
29
  spec.add_runtime_dependency "slop", "~> 4.4"
30
+ spec.add_runtime_dependency "faraday", "~> 0.11"
31
+ spec.add_runtime_dependency "faraday_middleware", "~> 0.11"
28
32
  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.3.2
4
+ version: 0.3.3
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-08 00:00:00.000000000 Z
11
+ date: 2017-02-11 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -66,6 +66,34 @@ dependencies:
66
66
  - - "~>"
67
67
  - !ruby/object:Gem::Version
68
68
  version: '4.4'
69
+ - !ruby/object:Gem::Dependency
70
+ name: faraday
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '0.11'
76
+ type: :runtime
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '0.11'
83
+ - !ruby/object:Gem::Dependency
84
+ name: faraday_middleware
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - "~>"
88
+ - !ruby/object:Gem::Version
89
+ version: '0.11'
90
+ type: :runtime
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - "~>"
95
+ - !ruby/object:Gem::Version
96
+ version: '0.11'
69
97
  description: This gem wraps openBD Web API.
70
98
  email:
71
99
  - tomato.wonder.life@gmail.com
@@ -99,9 +127,9 @@ require_paths:
99
127
  - lib
100
128
  required_ruby_version: !ruby/object:Gem::Requirement
101
129
  requirements:
102
- - - ">="
130
+ - - "~>"
103
131
  - !ruby/object:Gem::Version
104
- version: '0'
132
+ version: '2.2'
105
133
  required_rubygems_version: !ruby/object:Gem::Requirement
106
134
  requirements:
107
135
  - - ">="