hondana 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
File without changes
@@ -0,0 +1,4 @@
1
+ === 0.0.1 2013-01-05
2
+
3
+ * 1 major enhancement:
4
+ * Initial release
@@ -0,0 +1,11 @@
1
+ History.txt
2
+ Manifest.txt
3
+ PostInstall.txt
4
+ README.rdoc
5
+ Rakefile
6
+ lib/hondana.rb
7
+ script/console
8
+ script/destroy
9
+ script/generate
10
+ test/test_helper.rb
11
+ test/test_hondana.rb
@@ -0,0 +1,7 @@
1
+
2
+ For more information on hondana, see http://hondana.rubyforge.org
3
+
4
+ NOTE: Change this information in PostInstall.txt
5
+ You can also delete it if you don't want it.
6
+
7
+
@@ -0,0 +1,48 @@
1
+ = hondana
2
+
3
+ * http://github.com/masui/ruby-hondana
4
+
5
+ == DESCRIPTION:
6
+
7
+ API for hondana.org
8
+
9
+ == FEATURES/PROBLEMS:
10
+
11
+ Access hondana.org DB from Ruby
12
+
13
+ == SYNOPSIS:
14
+
15
+ require "hondana"
16
+
17
+ == REQUIREMENTS:
18
+
19
+ * FIX (list of requirements)
20
+
21
+ == INSTALL:
22
+
23
+ * sudo gem install hondana
24
+
25
+ == LICENSE:
26
+
27
+ (The MIT License)
28
+
29
+ Copyright (c) 2013 Toshiyuki Masui @ pitecan.com
30
+
31
+ Permission is hereby granted, free of charge, to any person obtaining
32
+ a copy of this software and associated documentation files (the
33
+ 'Software'), to deal in the Software without restriction, including
34
+ without limitation the rights to use, copy, modify, merge, publish,
35
+ distribute, sublicense, and/or sell copies of the Software, and to
36
+ permit persons to whom the Software is furnished to do so, subject to
37
+ the following conditions:
38
+
39
+ The above copyright notice and this permission notice shall be
40
+ included in all copies or substantial portions of the Software.
41
+
42
+ THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
43
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
44
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
45
+ IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
46
+ CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
47
+ TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
48
+ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,26 @@
1
+ require 'rubygems'
2
+ gem 'hoe', '>= 2.1.0'
3
+ require 'hoe'
4
+ require 'fileutils'
5
+ require './lib/hondana'
6
+
7
+ Hoe.plugin :newgem
8
+ # Hoe.plugin :website
9
+ # Hoe.plugin :cucumberfeatures
10
+
11
+ # Generate all the Rake tasks
12
+ # Run 'rake -T' to see list of generated tasks (from gem root directory)
13
+ $hoe = Hoe.spec 'hondana' do
14
+ self.developer 'Toshiyuki Masui', 'masui@pitecan.com'
15
+ self.post_install_message = 'PostInstall.txt' # TODO remove if post-install message not required
16
+ self.rubyforge_name = self.name # TODO this is default value
17
+ # self.extra_deps = [['activesupport','>= 2.0.2']]
18
+
19
+ end
20
+
21
+ require 'newgem/tasks'
22
+ Dir['tasks/**/*.rake'].each { |t| load t }
23
+
24
+ # TODO - want other tests/tasks run by default? Add them to the list
25
+ # remove_task :default
26
+ # task :default => [:spec, :features]
@@ -0,0 +1,93 @@
1
+ # -*- coding: utf-8 -*-
2
+ #
3
+ # 本棚.org API
4
+ #
5
+ require 'net/http'
6
+ require 'json'
7
+
8
+ $:.unshift(File.dirname(__FILE__)) unless
9
+ $:.include?(File.dirname(__FILE__)) || $:.include?(File.expand_path(File.dirname(__FILE__)))
10
+
11
+ class Hondana
12
+ VERSION = '0.0.1'
13
+
14
+ def Hondana.http_get(addr)
15
+ ret = nil
16
+ begin
17
+ Net::HTTP.start('api.hondana.org', 80) {|http|
18
+ req = Net::HTTP::Get.new(addr)
19
+ response = http.request(req)
20
+ raise "status code error (#{response.code})" if response.code != "200"
21
+ ret = response.body
22
+ }
23
+ rescue
24
+ end
25
+ raise "http_get failed" if ret == nil
26
+ ret.chomp
27
+ end
28
+
29
+ class Book
30
+ def initialize(isbn)
31
+ data = JSON.parse(Hondana.http_get("/bookinfo?isbn=#{isbn}"))
32
+ @isbn = isbn
33
+ @title = data['title']
34
+ @authors = data['authors']
35
+ @publisher = data['publisher']
36
+ end
37
+ attr_reader :title
38
+ attr_reader :isbn
39
+ attr_reader :authors
40
+ attr_reader :publisher
41
+ end
42
+
43
+ class Shelf
44
+ def initialize(name)
45
+ data = JSON.parse(Hondana.http_get("/shelfinfo?shelf=#{name}"))
46
+ @name = name
47
+ @url = data['url']
48
+ @description = data['description']
49
+ end
50
+ attr_reader :name
51
+ attr_reader :description
52
+ attr_reader :url
53
+ end
54
+
55
+ def initialize
56
+ end
57
+
58
+ def isbns(shelf='',pattern='')
59
+ if shelf == '' && pattern == ''
60
+ JSON.parse(Hondana.http_get("/books"))
61
+ elsif pattern == ''
62
+ JSON.parse(Hondana.http_get("/books?shelf=#{shelf}"))
63
+ elsif shelf == ''
64
+ JSON.parse(Hondana.http_get("/books?pattern=#{pattern}"))
65
+ else
66
+ JSON.parse(Hondana.http_get("/books?pattern=#{shelf},#{pattern}"))
67
+ end
68
+ end
69
+
70
+ def books(shelf='',pattern='')
71
+ isbns(shelf,pattern).collect { |isbn|
72
+ Book.new(isbn)
73
+ }
74
+ end
75
+
76
+ def shelfnames(isbn='',pattern='')
77
+ if isbn == '' && pattern == ''
78
+ JSON.parse(Hondana.http_get("/shelves"))
79
+ elsif pattern == ''
80
+ JSON.parse(Hondana.http_get("/shelves?isbn=#{isbn}"))
81
+ elsif isbn == ''
82
+ JSON.parse(Hondana.http_get("/shelves?pattern=#{pattern}"))
83
+ else
84
+ JSON.parse(Hondana.http_get("/shelves?pattern=#{isbn},#{pattern}"))
85
+ end
86
+ end
87
+
88
+ def shelves(isbn='',pattern='')
89
+ shelfnames(isbn,pattern).collect { |name|
90
+ Shelf.new(name)
91
+ }
92
+ end
93
+ end
@@ -0,0 +1,10 @@
1
+ #!/usr/bin/env ruby
2
+ # File: script/console
3
+ irb = RUBY_PLATFORM =~ /(:?mswin|mingw)/ ? 'irb.bat' : 'irb'
4
+
5
+ libs = " -r irb/completion"
6
+ # Perhaps use a console_lib to store any extra methods I may want available in the cosole
7
+ # libs << " -r #{File.dirname(__FILE__) + '/../lib/console_lib/console_logger.rb'}"
8
+ libs << " -r #{File.dirname(__FILE__) + '/../lib/hondana.rb'}"
9
+ puts "Loading hondana gem"
10
+ exec "#{irb} #{libs} --simple-prompt"
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+ APP_ROOT = File.expand_path(File.join(File.dirname(__FILE__), '..'))
3
+
4
+ begin
5
+ require 'rubigen'
6
+ rescue LoadError
7
+ require 'rubygems'
8
+ require 'rubigen'
9
+ end
10
+ require 'rubigen/scripts/destroy'
11
+
12
+ ARGV.shift if ['--help', '-h'].include?(ARGV[0])
13
+ RubiGen::Base.use_component_sources! [:rubygems, :newgem, :newgem_theme, :test_unit]
14
+ RubiGen::Scripts::Destroy.new.run(ARGV)
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+ APP_ROOT = File.expand_path(File.join(File.dirname(__FILE__), '..'))
3
+
4
+ begin
5
+ require 'rubigen'
6
+ rescue LoadError
7
+ require 'rubygems'
8
+ require 'rubigen'
9
+ end
10
+ require 'rubigen/scripts/generate'
11
+
12
+ ARGV.shift if ['--help', '-h'].include?(ARGV[0])
13
+ RubiGen::Base.use_component_sources! [:rubygems, :newgem, :newgem_theme, :test_unit]
14
+ RubiGen::Scripts::Generate.new.run(ARGV)
@@ -0,0 +1,3 @@
1
+ require 'stringio'
2
+ require 'test/unit'
3
+ require File.dirname(__FILE__) + '/../lib/hondana'
@@ -0,0 +1,13 @@
1
+ require File.dirname(__FILE__) + '/test_helper.rb'
2
+
3
+ class TestHondana < Test::Unit::TestCase
4
+
5
+ def setup
6
+ end
7
+
8
+ def test_books
9
+ h = Hondana.new
10
+ assert h.isbns('yuco').member?('4102113010')
11
+ # assert h.isbns(nil,'yuco').member?('4102113010')
12
+ end
13
+ end
metadata ADDED
@@ -0,0 +1,126 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: hondana
3
+ version: !ruby/object:Gem::Version
4
+ hash: 29
5
+ prerelease:
6
+ segments:
7
+ - 0
8
+ - 0
9
+ - 1
10
+ version: 0.0.1
11
+ platform: ruby
12
+ authors:
13
+ - Toshiyuki Masui
14
+ autorequire:
15
+ bindir: bin
16
+ cert_chain: []
17
+
18
+ date: 2013-01-06 00:00:00 Z
19
+ dependencies:
20
+ - !ruby/object:Gem::Dependency
21
+ name: rdoc
22
+ prerelease: false
23
+ requirement: &id001 !ruby/object:Gem::Requirement
24
+ none: false
25
+ requirements:
26
+ - - ~>
27
+ - !ruby/object:Gem::Version
28
+ hash: 19
29
+ segments:
30
+ - 3
31
+ - 10
32
+ version: "3.10"
33
+ type: :development
34
+ version_requirements: *id001
35
+ - !ruby/object:Gem::Dependency
36
+ name: newgem
37
+ prerelease: false
38
+ requirement: &id002 !ruby/object:Gem::Requirement
39
+ none: false
40
+ requirements:
41
+ - - ">="
42
+ - !ruby/object:Gem::Version
43
+ hash: 5
44
+ segments:
45
+ - 1
46
+ - 5
47
+ - 3
48
+ version: 1.5.3
49
+ type: :development
50
+ version_requirements: *id002
51
+ - !ruby/object:Gem::Dependency
52
+ name: hoe
53
+ prerelease: false
54
+ requirement: &id003 !ruby/object:Gem::Requirement
55
+ none: false
56
+ requirements:
57
+ - - ~>
58
+ - !ruby/object:Gem::Version
59
+ hash: 27
60
+ segments:
61
+ - 2
62
+ - 12
63
+ version: "2.12"
64
+ type: :development
65
+ version_requirements: *id003
66
+ description: API for hondana.org
67
+ email:
68
+ - masui@pitecan.com
69
+ executables: []
70
+
71
+ extensions: []
72
+
73
+ extra_rdoc_files:
74
+ - History.txt
75
+ - Manifest.txt
76
+ - PostInstall.txt
77
+ files:
78
+ - History.txt
79
+ - Manifest.txt
80
+ - PostInstall.txt
81
+ - README.rdoc
82
+ - Rakefile
83
+ - lib/hondana.rb
84
+ - script/console
85
+ - script/destroy
86
+ - script/generate
87
+ - test/test_helper.rb
88
+ - test/test_hondana.rb
89
+ - .gemtest
90
+ homepage: http://github.com/masui/ruby-hondana
91
+ licenses: []
92
+
93
+ post_install_message: PostInstall.txt
94
+ rdoc_options:
95
+ - --main
96
+ - README.rdoc
97
+ require_paths:
98
+ - lib
99
+ required_ruby_version: !ruby/object:Gem::Requirement
100
+ none: false
101
+ requirements:
102
+ - - ">="
103
+ - !ruby/object:Gem::Version
104
+ hash: 3
105
+ segments:
106
+ - 0
107
+ version: "0"
108
+ required_rubygems_version: !ruby/object:Gem::Requirement
109
+ none: false
110
+ requirements:
111
+ - - ">="
112
+ - !ruby/object:Gem::Version
113
+ hash: 3
114
+ segments:
115
+ - 0
116
+ version: "0"
117
+ requirements: []
118
+
119
+ rubyforge_project: hondana
120
+ rubygems_version: 1.8.23
121
+ signing_key:
122
+ specification_version: 3
123
+ summary: API for hondana.org
124
+ test_files:
125
+ - test/test_helper.rb
126
+ - test/test_hondana.rb