interpark-book 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +18 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +60 -0
- data/Rakefile +1 -0
- data/interpark-book.gemspec +23 -0
- data/lib/interpark/book.rb +40 -0
- data/lib/interpark/book/client.rb +97 -0
- data/lib/interpark/book/requirement.rb +9 -0
- data/lib/interpark/book/search.rb +84 -0
- data/lib/interpark/book/version.rb +5 -0
- data/test.rb +13 -0
- metadata +84 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: d2456a47f65f7a21054b54bf2b42a5abec973fe7
|
4
|
+
data.tar.gz: 8e25905f878eb962c3109086f24dac435a34c10e
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: fd4286d576f171d6d31f469730e6bd398b33e383b51ab10cb1bb9a5203f93c95c0bac38403bec6891c5072c76335ce833252f36549c5e557d4c0f5b108be7509
|
7
|
+
data.tar.gz: 2e502282443101c25751627ba1e45d4a19ff1a79ab2dd66fc480b90f88383b9eb289afeff6825047e219bedb8cadffc160cb9730f2209469532581f30a79ac95
|
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2014 Taekmin Kim
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,60 @@
|
|
1
|
+
# Interpark::Book
|
2
|
+
|
3
|
+
Interpark에서 제공하는 도서 API를 루비 버전으로 묶은 gem입니다.
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
gem 'interpark-book'
|
10
|
+
|
11
|
+
And then execute:
|
12
|
+
|
13
|
+
$ bundle
|
14
|
+
|
15
|
+
Or install it yourself as:
|
16
|
+
|
17
|
+
$ gem install interpark-book
|
18
|
+
|
19
|
+
## Usage
|
20
|
+
|
21
|
+
### Setup
|
22
|
+
|
23
|
+
# config/initialize/interpark-book.rb
|
24
|
+
|
25
|
+
require 'interpark-book'
|
26
|
+
|
27
|
+
Interpark::Book.configure do |config|
|
28
|
+
config.key = "인터파크 API 콘솔에서 발급 받은 키"
|
29
|
+
end
|
30
|
+
|
31
|
+
### 기본 검색
|
32
|
+
|
33
|
+
content = "삼국지"
|
34
|
+
Interpark::Book::Search.content(query)
|
35
|
+
|
36
|
+
### 상세 검색
|
37
|
+
content = "삼국지"
|
38
|
+
options = {:query_type => "all"}
|
39
|
+
Interpark::Book::Search.query(content, options)
|
40
|
+
|
41
|
+
### 다른 예제
|
42
|
+
test.rb 참고
|
43
|
+
|
44
|
+
## Rails Example
|
45
|
+
|
46
|
+
[https://github.com/tantara/interpark-book-rails](https://github.com/tantara/interpark-book-rails)
|
47
|
+
|
48
|
+
|
49
|
+
## Contributing
|
50
|
+
|
51
|
+
1. Fork it ( http://github.com/<my-github-username>/interpark-book/fork )
|
52
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
53
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
54
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
55
|
+
5. Create new Pull Request
|
56
|
+
|
57
|
+
|
58
|
+
## Contact
|
59
|
+
|
60
|
+
1. Taekmin Kim (tantara.tm@gmail.com)
|
data/Rakefile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require "bundler/gem_tasks"
|
@@ -0,0 +1,23 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'interpark/book/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "interpark-book"
|
8
|
+
spec.version = Interpark::Book::VERSION
|
9
|
+
spec.authors = ["Taekmin Kim"]
|
10
|
+
spec.email = ["tantara.tm@gmail.com"]
|
11
|
+
spec.description = %q{인터파크 도서 API}
|
12
|
+
spec.summary = %q{인터파크 도서 API}
|
13
|
+
spec.homepage = "https://github.com/wafflestudio/interpark-book"
|
14
|
+
spec.license = "MIT"
|
15
|
+
|
16
|
+
spec.files = `git ls-files`.split($/)
|
17
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
18
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
|
+
spec.require_paths = ["lib"]
|
20
|
+
|
21
|
+
spec.add_development_dependency "bundler", "~> 1.3"
|
22
|
+
spec.add_development_dependency "rake"
|
23
|
+
end
|
@@ -0,0 +1,40 @@
|
|
1
|
+
#require "interpark/book/version"
|
2
|
+
require "logger"
|
3
|
+
|
4
|
+
module Interpark
|
5
|
+
module Book
|
6
|
+
autoload :Client, 'interpark/book/client'
|
7
|
+
autoload :Search, 'interpark/book/search'
|
8
|
+
autoload :Requirement, 'interpark/book/requirement'
|
9
|
+
|
10
|
+
# Raise this when we hit a Trello error.
|
11
|
+
Error = Class.new(StandardError)
|
12
|
+
|
13
|
+
# This specific error is thrown when your key is invalid. You should get a new one.
|
14
|
+
InvalidKey = Class.new(Error)
|
15
|
+
|
16
|
+
# This error is thrown when your client has not been configured
|
17
|
+
ConfigurationError = Class.new(Error)
|
18
|
+
|
19
|
+
def self.logger
|
20
|
+
@logger ||= Logger.new(STDOUT)
|
21
|
+
end
|
22
|
+
|
23
|
+
def self.logger=(logger)
|
24
|
+
@logger = logger
|
25
|
+
end
|
26
|
+
|
27
|
+
def self.client
|
28
|
+
@client ||= Client.new
|
29
|
+
end
|
30
|
+
|
31
|
+
def self.configure(&block)
|
32
|
+
reset!
|
33
|
+
client.configure(&block)
|
34
|
+
end
|
35
|
+
|
36
|
+
def self.reset!
|
37
|
+
@client = nil
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
@@ -0,0 +1,97 @@
|
|
1
|
+
require 'net/http'
|
2
|
+
require 'forwardable'
|
3
|
+
#require 'openssl'
|
4
|
+
require 'json'
|
5
|
+
|
6
|
+
module Interpark::Book
|
7
|
+
class Configuration
|
8
|
+
API_HOST="http://book.interpark.com"
|
9
|
+
CONFIGURABLE_ATTRIBUTES=[
|
10
|
+
:key
|
11
|
+
]
|
12
|
+
|
13
|
+
attr_accessor *CONFIGURABLE_ATTRIBUTES
|
14
|
+
|
15
|
+
def self.configurable_attributes
|
16
|
+
CONFIGURABLE_ATTRIBUTES
|
17
|
+
end
|
18
|
+
|
19
|
+
def initialize(attrs = {})
|
20
|
+
self.attributes = attrs
|
21
|
+
end
|
22
|
+
|
23
|
+
def attributes=(attrs = {})
|
24
|
+
attrs.each { |key, value| instance_variable_set("@#{key}", value) }
|
25
|
+
end
|
26
|
+
|
27
|
+
def http
|
28
|
+
uri = URI.parse(API_HOST)
|
29
|
+
@http ||= Net::HTTP.new(uri.host, uri.port)
|
30
|
+
#@http.use_ssl = true
|
31
|
+
#@http.verify_mode = OpenSSL::SSL::VERIFY_NONE
|
32
|
+
@http
|
33
|
+
end
|
34
|
+
|
35
|
+
def data
|
36
|
+
@data = {"key" => @key}
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
class Client
|
41
|
+
extend Forwardable
|
42
|
+
|
43
|
+
APIS = {
|
44
|
+
:search => {:method => "GET", :path => "/api/search.api"}
|
45
|
+
}
|
46
|
+
|
47
|
+
def_delegators :configuration, :credentials, *Configuration.configurable_attributes
|
48
|
+
|
49
|
+
def initialize(attrs = {})
|
50
|
+
self.configuration.attributes = attrs
|
51
|
+
end
|
52
|
+
|
53
|
+
def configure
|
54
|
+
yield configuration if block_given?
|
55
|
+
end
|
56
|
+
|
57
|
+
def configuration
|
58
|
+
@configuration ||= Configuration.new
|
59
|
+
end
|
60
|
+
|
61
|
+
def request(method, path, data)
|
62
|
+
http = configuration.http
|
63
|
+
data = configuration.data.merge(data)
|
64
|
+
|
65
|
+
case method
|
66
|
+
when "GET"
|
67
|
+
get(http, path, data)
|
68
|
+
when "POST"
|
69
|
+
post(http, path, data)
|
70
|
+
end
|
71
|
+
end
|
72
|
+
|
73
|
+
def get(http, path, data)
|
74
|
+
data = URI.encode_www_form(data)
|
75
|
+
resp, body = http.send_request("GET", "#{path}?#{data}")
|
76
|
+
|
77
|
+
JSON.parse(resp.body)
|
78
|
+
end
|
79
|
+
|
80
|
+
def post(http, path, data)
|
81
|
+
data = URI.encode_www_form(data)
|
82
|
+
resp, body = http.send_request("POST", path, data)
|
83
|
+
|
84
|
+
JSON.parse(resp.body)
|
85
|
+
end
|
86
|
+
|
87
|
+
def search(content, options)
|
88
|
+
method = APIS[:search][:method]
|
89
|
+
path = APIS[:search][:path]
|
90
|
+
|
91
|
+
data = {"query" => content}
|
92
|
+
data = data.merge(options)
|
93
|
+
|
94
|
+
request(method, path, data)
|
95
|
+
end
|
96
|
+
end
|
97
|
+
end
|
@@ -0,0 +1,84 @@
|
|
1
|
+
module Interpark::Book
|
2
|
+
class Search < Requirement
|
3
|
+
class << self
|
4
|
+
### reference
|
5
|
+
# http://book.interpark.com/bookPark/html/bookpinion/api_booksearch.html
|
6
|
+
|
7
|
+
### queryType
|
8
|
+
# title(기본값) : 제목검색
|
9
|
+
# author : 저자검색
|
10
|
+
# publisher : 출판사검색
|
11
|
+
# isbn : Isbn검색
|
12
|
+
# productNumber : 상품번호
|
13
|
+
# all : 제목, 저자, 출판사,ISBN 검색 대상
|
14
|
+
|
15
|
+
### searchTarget
|
16
|
+
# book(기본값) : 국내도서
|
17
|
+
# foreign : 외국도서
|
18
|
+
# cd : 음반
|
19
|
+
# dvd : DVD
|
20
|
+
|
21
|
+
### start
|
22
|
+
# 1이상, 양의 정수(기본값:1)
|
23
|
+
|
24
|
+
### maxResults
|
25
|
+
# 1이상 100이하, 양의 정수(기본값:10)
|
26
|
+
|
27
|
+
### sort
|
28
|
+
# accuracy(기본값) : 정확도순
|
29
|
+
# publishTime : 출간일
|
30
|
+
# title : 제목
|
31
|
+
# salesPoint : 판매량
|
32
|
+
# customerRating : 고객평점
|
33
|
+
# reviewCount : 리뷰갯수
|
34
|
+
# price : 가격오름순
|
35
|
+
# priceDesc : 가격내림순
|
36
|
+
|
37
|
+
### categoryId
|
38
|
+
# 분야의 고유 번호(기본값:100 )
|
39
|
+
|
40
|
+
### output
|
41
|
+
# xml(기본값) : REST XML형식
|
42
|
+
# json : JSON방식
|
43
|
+
|
44
|
+
### inputEncoding
|
45
|
+
# utf-8(기본값)
|
46
|
+
# euc-kr
|
47
|
+
|
48
|
+
### adultImageExposure
|
49
|
+
# n(기본값) : 노출안함
|
50
|
+
# y : 노출함
|
51
|
+
|
52
|
+
### soldOut
|
53
|
+
# y(기본값) : 품절/절판함께보기
|
54
|
+
# n : 품절/절판빼고보기
|
55
|
+
|
56
|
+
def query(content, options = {})
|
57
|
+
query_type = options[:query_type].nil? ? "title" : options[:query_type]
|
58
|
+
search_target = options[:search_target].nil? ? "book" : options[:search_target]
|
59
|
+
start = options[:start].nil? ? 1 : options[:start]
|
60
|
+
max_results = options[:max_results].nil? ? 10 : options[:max_results]
|
61
|
+
sort = options[:sort].nil? ? "accuracy" : options[:sort]
|
62
|
+
category_id = options[:category_id].nil? ? 100 : options[:category_id]
|
63
|
+
output = options[:output].nil? ? "xml" : options[:output]
|
64
|
+
input_encoding = options[:input_encoding].nil? ? "utf-8" : options[:input_encoding]
|
65
|
+
adult_image_exposure = options[:adult_image_exposure].nil? ? "n" : options[:adult_image_exposure]
|
66
|
+
sold_out = options[:sold_out].nil? ? "y" : options[:sold_out]
|
67
|
+
|
68
|
+
res = client.search(content, {
|
69
|
+
"queryType" => query_type,
|
70
|
+
"searchTarget" => search_target,
|
71
|
+
"start" => start,
|
72
|
+
"maxResults" => max_results,
|
73
|
+
"sort" => sort,
|
74
|
+
"categoryId" => category_id,
|
75
|
+
# "output" => output,
|
76
|
+
"output" => "json",
|
77
|
+
"inputEncoding" => input_encoding,
|
78
|
+
"adultImageExposure" => adult_image_exposure,
|
79
|
+
"soldOut" => sold_out,
|
80
|
+
})
|
81
|
+
end
|
82
|
+
end
|
83
|
+
end
|
84
|
+
end
|
data/test.rb
ADDED
@@ -0,0 +1,13 @@
|
|
1
|
+
$LOAD_PATH.unshift 'lib'
|
2
|
+
require 'interpark/book'
|
3
|
+
|
4
|
+
Interpark::Book.configure do |config|
|
5
|
+
config.key = File.exists?("api_key") ? File.read("api_key").strip : "API_KEY"
|
6
|
+
end
|
7
|
+
|
8
|
+
title = "삼국지"
|
9
|
+
|
10
|
+
res = Interpark::Book::Search.query(title)
|
11
|
+
|
12
|
+
puts res["link"]
|
13
|
+
puts res["item"].count
|
metadata
ADDED
@@ -0,0 +1,84 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: interpark-book
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Taekmin Kim
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2014-07-26 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ~>
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.3'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ~>
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.3'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - '>='
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - '>='
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
description: 인터파크 도서 API
|
42
|
+
email:
|
43
|
+
- tantara.tm@gmail.com
|
44
|
+
executables: []
|
45
|
+
extensions: []
|
46
|
+
extra_rdoc_files: []
|
47
|
+
files:
|
48
|
+
- .gitignore
|
49
|
+
- Gemfile
|
50
|
+
- LICENSE.txt
|
51
|
+
- README.md
|
52
|
+
- Rakefile
|
53
|
+
- interpark-book.gemspec
|
54
|
+
- lib/interpark/book.rb
|
55
|
+
- lib/interpark/book/client.rb
|
56
|
+
- lib/interpark/book/requirement.rb
|
57
|
+
- lib/interpark/book/search.rb
|
58
|
+
- lib/interpark/book/version.rb
|
59
|
+
- test.rb
|
60
|
+
homepage: https://github.com/wafflestudio/interpark-book
|
61
|
+
licenses:
|
62
|
+
- MIT
|
63
|
+
metadata: {}
|
64
|
+
post_install_message:
|
65
|
+
rdoc_options: []
|
66
|
+
require_paths:
|
67
|
+
- lib
|
68
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
69
|
+
requirements:
|
70
|
+
- - '>='
|
71
|
+
- !ruby/object:Gem::Version
|
72
|
+
version: '0'
|
73
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
74
|
+
requirements:
|
75
|
+
- - '>='
|
76
|
+
- !ruby/object:Gem::Version
|
77
|
+
version: '0'
|
78
|
+
requirements: []
|
79
|
+
rubyforge_project:
|
80
|
+
rubygems_version: 2.1.11
|
81
|
+
signing_key:
|
82
|
+
specification_version: 4
|
83
|
+
summary: 인터파크 도서 API
|
84
|
+
test_files: []
|