find-a-book 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 24e9d748f80661631d6007104eedf53d267621e9
4
+ data.tar.gz: 772db90ff6ff3ec556f2c848830478f98993bb39
5
+ SHA512:
6
+ metadata.gz: a45c726fd78eb781836327e6e0a932f44942361de7620ca8598029d98acb81206dae9568ebd6bff6aaa85523f7cb38d62244aab239a3e1607e68116fac11f46a
7
+ data.tar.gz: 5992a645235303cb02a3b4367cbbfb5e1b6fa372140516b1912245ed8b8032fab68462020f2f1921c78dc624b77d383c9fa3c282649d1f7f3d5dbb3f0c31ee84
data/.gitignore ADDED
@@ -0,0 +1,105 @@
1
+ ./vendor/*
2
+ /.bundle/
3
+ /.yardoc
4
+ /Gemfile.lock
5
+ /_yardoc/
6
+ /coverage/
7
+ /doc/
8
+ /pkg/
9
+ /spec/reports/
10
+ /tmp/
11
+ ### https://raw.github.com/github/gitignore/77e29837cf03b59fc4d885ea011bbd683caaaf85/Global/OSX.gitignore
12
+
13
+ .DS_Store
14
+ .AppleDouble
15
+ .LSOverride
16
+
17
+ # Icon must end with two \r
18
+ Icon
19
+
20
+ # Thumbnails
21
+ ._*
22
+
23
+ # Files that might appear in the root of a volume
24
+ .DocumentRevisions-V100
25
+ .fseventsd
26
+ .Spotlight-V100
27
+ .TemporaryItems
28
+ .Trashes
29
+ .VolumeIcon.icns
30
+
31
+ # Directories potentially created on remote AFP share
32
+ .AppleDB
33
+ .AppleDesktop
34
+ Network Trash Folder
35
+ Temporary Items
36
+ .apdisk
37
+
38
+
39
+ ### https://raw.github.com/github/gitignore/77e29837cf03b59fc4d885ea011bbd683caaaf85/Ruby.gitignore
40
+
41
+ *.gem
42
+ *.rbc
43
+ /.config
44
+ /coverage/
45
+ /InstalledFiles
46
+ /pkg/
47
+ /spec/reports/
48
+ /test/tmp/
49
+ /test/version_tmp/
50
+ /tmp/
51
+
52
+ ## Specific to RubyMotion:
53
+ .dat*
54
+ .repl_history
55
+ build/
56
+
57
+ ## Documentation cache and generated files:
58
+ /.yardoc/
59
+ /_yardoc/
60
+ /doc/
61
+ /rdoc/
62
+
63
+ ## Environment normalisation:
64
+ /.bundle/
65
+ /vendor/bundle
66
+ /lib/bundler/man/
67
+
68
+ # for a library or gem, you might want to ignore these files since the code is
69
+ # intended to run in multiple environments; otherwise, check them in:
70
+ # Gemfile.lock
71
+ # .ruby-version
72
+ # .ruby-gemset
73
+
74
+ # unless supporting rvm < 1.11.0 or doing something fancy, ignore this:
75
+ .rvmrc
76
+
77
+
78
+ ### https://raw.github.com/github/gitignore/77e29837cf03b59fc4d885ea011bbd683caaaf85/Global/OSX.gitignore
79
+
80
+ .DS_Store
81
+ .AppleDouble
82
+ .LSOverride
83
+
84
+ # Icon must end with two \r
85
+ Icon
86
+
87
+ # Thumbnails
88
+ ._*
89
+
90
+ # Files that might appear in the root of a volume
91
+ .DocumentRevisions-V100
92
+ .fseventsd
93
+ .Spotlight-V100
94
+ .TemporaryItems
95
+ .Trashes
96
+ .VolumeIcon.icns
97
+
98
+ # Directories potentially created on remote AFP share
99
+ .AppleDB
100
+ .AppleDesktop
101
+ Network Trash Folder
102
+ Temporary Items
103
+ .apdisk
104
+
105
+
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --format documentation
2
+ --color
data/.travis.yml ADDED
@@ -0,0 +1,4 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.2.1
4
+ before_install: gem install bundler -v 1.10.2
data/Gemfile ADDED
@@ -0,0 +1,6 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gemspec
4
+ gem 'thor', '~>0.19.1'
5
+ gem 'json'
6
+ gem 'activesupport'
data/README.md ADDED
@@ -0,0 +1,43 @@
1
+ # Fab
2
+
3
+ Japan only.
4
+ Your looking book.
5
+ This command is easy Your looking book.
6
+
7
+ ## Installation
8
+
9
+
10
+ ```
11
+ ruby
12
+ gem 'fab'
13
+ or
14
+ gem 'fab', github:"https://github.com/kodaitakahashi/fab"
15
+ ```
16
+
17
+ And then execute:
18
+
19
+ $ bundle
20
+
21
+ Or install it yourself as:
22
+
23
+ $ gem install fab
24
+
25
+ ## Usage
26
+ Get APIKey in Kariru
27
+ [カーリル](https://calil.jp/"calil")
28
+
29
+ $fab registratin { -a , --apikey} [Your APIkey]
30
+ APIkey add to apikey.rb
31
+ [option]
32
+ {-a , --apikey} add apikey.rb
33
+ {-r , --remake} remake apikey.rb
34
+
35
+ $fab find {-i , --isbn} {-p , --pref} {-c , --city}
36
+ search your looking book
37
+ [option]
38
+ {-i , --isbn} Your looking book isbn.
39
+ {-p , --pref} Search for prefectures.
40
+ {-c , --city} Serarch for city.
41
+
42
+ $fab delete
43
+ delete apikey.rb
data/Rakefile ADDED
@@ -0,0 +1,6 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "fab"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start
data/bin/fab ADDED
@@ -0,0 +1,51 @@
1
+ #!/usr/bin/env ruby
2
+ # -*- coding: utf-8-*-
3
+
4
+ require 'fab/version'
5
+ require 'fab'
6
+ require 'apikey'
7
+ require 'generate'
8
+ require 'thor'
9
+
10
+ module Fab
11
+ #= Fab CLI
12
+ class CLI < Thor
13
+ default_command :help
14
+
15
+ option :apikey , :type => :string , :required => true , :aliases => "a"
16
+ option :remake , :type => :boolean, :aliases => "r"
17
+ desc "registration" ,"APIKey registration"
18
+ def registration
19
+ if options[:remake]
20
+ Fab::Api.new.remake_apifile(options[:apikey].to_s)
21
+ else
22
+ Fab::Api.new.create_apifile(options[:apikey].to_s)
23
+ end
24
+ end
25
+
26
+ option :pref,:type => :string ,:required => true, :aliases => "p"
27
+ option :city,:type => :string ,:required => true , :aliases => "c"
28
+ option :isbn,:type=> :numeric ,:required => true , :aliases => "i"
29
+ desc "find","find book"
30
+ def find()
31
+ find_book = Fab::Library.new
32
+ find_book.library_set_param(options[:pref].to_s,options[:city].to_s)
33
+ find_book.library_get_params()
34
+ find_book.book_set_param(options[:isbn].to_s)
35
+ find_book.book_get_params()
36
+ find_book.echo_book()
37
+ end
38
+
39
+ desc "delete","delete apikey.rb"
40
+ def delete()
41
+ Fab::Api.new.delete()
42
+ end
43
+
44
+ desc "version","show version"
45
+ def version
46
+ p Fab::VERSION
47
+ end
48
+ end
49
+ end
50
+
51
+ Fab::CLI.start(ARGV)
data/bin/setup ADDED
@@ -0,0 +1,7 @@
1
+ #!/bin/bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+
5
+ bundle install
6
+
7
+ # Do any other automated setup that you need to do here
data/fab.gemspec ADDED
@@ -0,0 +1,27 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'fab/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "find-a-book"
8
+ spec.version = Fab::VERSION
9
+ spec.authors = ["kodaitakahashi"]
10
+ spec.email = ["kodaitakahashi.kt@gmail.com"]
11
+
12
+ spec.summary = %q{Japan only. Your looking book. This command is easy Your looking book.}
13
+ spec.description = %q{This command is easy Your looking book.}
14
+ spec.homepage = "https://github.com/kodaitakahashi/fab"
15
+
16
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
17
+ spec.bindir = "exe"
18
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_development_dependency "thor", "~> 0.19.1"
22
+ spec.add_development_dependency "json"
23
+ spec.add_development_dependency "activesupport"
24
+ spec.add_development_dependency "bundler", "~> 1.10"
25
+ spec.add_development_dependency "rake", "~> 10.0"
26
+ spec.add_development_dependency "rspec"
27
+ end
data/lib/apikey.rb ADDED
File without changes
data/lib/fab.rb ADDED
@@ -0,0 +1,108 @@
1
+ #!/usr/local/env ruby
2
+ #coding:utf-8
3
+ require "apikey"
4
+ require "json"
5
+ require "open-uri"
6
+ require "uri"
7
+ require 'active_support/all'
8
+
9
+ module Fab
10
+
11
+ class Output
12
+
13
+ LINE_TEMPLATE = "---------------------------"
14
+ LINE_BREAK_TEMPLATE = "---------------------------"
15
+
16
+ def echo_book()
17
+ puts LINE_TEMPLATE
18
+ for i in 0..@id_count
19
+ puts "場所 #{@libraries[i]["formal"]}"
20
+ situation_appraisal(@books[i]["situation"])
21
+ puts LINE_BREAK_TEMPLATE
22
+ end
23
+ end
24
+
25
+ private
26
+
27
+ POSSIBLE_TEMPLATE = "貸出可能"
28
+ IMPOSSIBLE_TEMPLATE = "貸出不可"
29
+ NON_BOOK_TEMPLATE = "蔵書無し"
30
+
31
+ def situation_appraisal(situation)
32
+ if situation.nil?
33
+ puts "状況 #{NON_BOOK_TEMPLATE}"
34
+ else
35
+ puts "状況 #{situation["libkey"]}"
36
+ end
37
+ end
38
+ end
39
+
40
+ class Book < Output
41
+
42
+ def book_set_param(isbn)
43
+ @book_send_param = "http://api.calil.jp/check?"
44
+ @book_send_param << "appkey=#{Fab::Apikey::APIKEY}"
45
+ @book_send_param << "&isbn=#{isbn}"
46
+ @book_send_param << "&format=xml"
47
+ end
48
+
49
+ SLEEP_TIME = 5
50
+ def book_get_params()
51
+ @books = Hash.new { | h , k | h[k] = {} }
52
+ count = 0
53
+ @libraries.each_value do | library |
54
+ temp_send_param = @book_send_param+"&systemid=#{library["systemid"]}"
55
+ encode_uri = URI.encode(temp_send_param)
56
+ result = nil
57
+ loop do
58
+ get_xml = open(encode_uri).read
59
+ convert_json = Hash.from_xml(get_xml).to_json
60
+ result = JSON.load(convert_json)
61
+ break if result["result"]["continue"].to_i == 0
62
+ sleep(SLEEP_TIME.to_i)
63
+ end
64
+ @books[count]["situation"] = result["result"]["books"]["book"]["system"]["libkeys"]
65
+ count += 1
66
+ end
67
+ end
68
+ end
69
+
70
+ class Library < Book
71
+ def initialize()
72
+ @library_send_param = "http://api.calil.jp/library?"
73
+ end
74
+
75
+ NONE_APIKEY_TEMPLATE = <<-EOS
76
+ not set apikey
77
+ fab registration -apikey,-a [APIKEY]
78
+ EOS
79
+ def library_set_param(pref,city)
80
+ begin
81
+ @library_send_param << "appkey=#{Fab::Apikey::APIKEY}"
82
+ rescue
83
+ puts NONE_APIKEY_TEMPLATE
84
+ exit
85
+ end
86
+ @library_send_param << "&pref=#{pref}"
87
+ @library_send_param << "&city=#{city}"
88
+ end
89
+
90
+ def library_get_params()
91
+ encode_uri = URI.encode(@library_send_param)
92
+ get_xml = open(encode_uri).read
93
+ convert_json = Hash.from_xml(get_xml).to_json
94
+ result = JSON.load(convert_json)
95
+ @libraries = Hash.new { | h , k | h[k] = {} }
96
+ count_id(result)
97
+ for i in 0..@id_count
98
+ @libraries[i]["systemid"] = result["Libraries"]["Library"][i]["systemid"]
99
+ @libraries[i]["formal"] = result["Libraries"]["Library"][i]["formal"]
100
+ end
101
+ end
102
+
103
+ private
104
+ def count_id(target)
105
+ @id_count = target.to_s.scan(/sys[a-z]*d/).size - 1
106
+ end
107
+ end
108
+ end
@@ -0,0 +1,3 @@
1
+ module Fab
2
+ VERSION = "0.1.0"
3
+ end
data/lib/generate.rb ADDED
@@ -0,0 +1,68 @@
1
+ #/usr/local/env ruby
2
+ #coding:utf-8
3
+
4
+ module Fab
5
+ class Api
6
+
7
+ ERROR_MASSEGE = <<-EOS
8
+ That already exists
9
+ Please , $fab {-r , --remake} {-a , --apikey} [APIKey]
10
+ EOS
11
+ def create_apifile(apikey)
12
+ if file_empty?
13
+ write_file(path(),apikey)
14
+ true
15
+ else
16
+ puts ERROR_MASSEGE
17
+ false
18
+ end
19
+ end
20
+
21
+ def remake_apifile(apikey)
22
+ delete()
23
+ write_file(path(),apikey)
24
+ true
25
+ end
26
+
27
+ def delete()
28
+ path()
29
+ File.open(path() , "w") do | file |
30
+ file = nil
31
+ end
32
+ end
33
+
34
+ private
35
+
36
+ def path()
37
+ api_path = File.expand_path('../../lib',__FILE__)
38
+ api_path << "/apikey.rb"
39
+ api_path
40
+ end
41
+
42
+ def write_file(path,apikey)
43
+ File.open(path(),"w") do | file |
44
+ file.puts(<<"EOS")
45
+ #!/usr/local/env ruby
46
+ #codinf:utf-8
47
+
48
+ module Fab
49
+ class Apikey
50
+ APIKEY = \"#{apikey}\"
51
+ end
52
+ end
53
+ EOS
54
+ end
55
+ end
56
+
57
+ def file_empty?()
58
+ File.open(path(), "r") do | file |
59
+ if file.read == ""
60
+ true
61
+ else
62
+ false
63
+ end
64
+ end
65
+ end
66
+
67
+ end
68
+ end
metadata ADDED
@@ -0,0 +1,141 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: find-a-book
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - kodaitakahashi
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2015-10-02 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: thor
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: 0.19.1
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: 0.19.1
27
+ - !ruby/object:Gem::Dependency
28
+ name: json
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
+ - !ruby/object:Gem::Dependency
42
+ name: activesupport
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: bundler
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '1.10'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '1.10'
69
+ - !ruby/object:Gem::Dependency
70
+ name: rake
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '10.0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '10.0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: rspec
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ">="
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
97
+ description: This command is easy Your looking book.
98
+ email:
99
+ - kodaitakahashi.kt@gmail.com
100
+ executables: []
101
+ extensions: []
102
+ extra_rdoc_files: []
103
+ files:
104
+ - ".gitignore"
105
+ - ".rspec"
106
+ - ".travis.yml"
107
+ - Gemfile
108
+ - README.md
109
+ - Rakefile
110
+ - bin/console
111
+ - bin/fab
112
+ - bin/setup
113
+ - fab.gemspec
114
+ - lib/apikey.rb
115
+ - lib/fab.rb
116
+ - lib/fab/version.rb
117
+ - lib/generate.rb
118
+ homepage: https://github.com/kodaitakahashi/fab
119
+ licenses: []
120
+ metadata: {}
121
+ post_install_message:
122
+ rdoc_options: []
123
+ require_paths:
124
+ - lib
125
+ required_ruby_version: !ruby/object:Gem::Requirement
126
+ requirements:
127
+ - - ">="
128
+ - !ruby/object:Gem::Version
129
+ version: '0'
130
+ required_rubygems_version: !ruby/object:Gem::Requirement
131
+ requirements:
132
+ - - ">="
133
+ - !ruby/object:Gem::Version
134
+ version: '0'
135
+ requirements: []
136
+ rubyforge_project:
137
+ rubygems_version: 2.4.5
138
+ signing_key:
139
+ specification_version: 4
140
+ summary: Japan only. Your looking book. This command is easy Your looking book.
141
+ test_files: []