wsato_gem 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: c650e6c482d9ed1680afd09756dc6d3bbaf3fe38
4
+ data.tar.gz: d05097d8bd55516a30171ce052698de164253672
5
+ SHA512:
6
+ metadata.gz: 1aae2cbc8c1df93166e7364f6360eb809c3df0b5f234a48d02159e24eea4836e3016a2bc3641d66e2b3403b6a14be49a99ae439dbb4171b70721995977e5eee5
7
+ data.tar.gz: bd50b4c6c73ae989245558a2c7b5be045a1b25e2a4089c3f559bed084a29aaf75c58788f434f227b819d5ecc7be07d79859797ce6a2539e171a0fbe7b2d6f0d2
@@ -0,0 +1,9 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
@@ -0,0 +1,6 @@
1
+ sudo: false
2
+ language: ruby
3
+ rvm:
4
+ - 2.3.1
5
+ gemfile:
6
+ - Gemfile
data/Gemfile ADDED
@@ -0,0 +1,5 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gem 'json'
4
+ gem 'rspec'
5
+ gem 'rake'
@@ -0,0 +1,38 @@
1
+ # WsatoGem
2
+
3
+ Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/wsato_gem`. To experiment with that code, run `bin/console` for an interactive prompt.
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ ```ruby
10
+ gem 'wsato_gem'
11
+ ```
12
+
13
+ And then execute:
14
+
15
+ $ bundle
16
+
17
+ Or install it yourself as:
18
+
19
+ $ gem install wsato_gem
20
+
21
+ ## Usage
22
+
23
+ This API searches libraries from your address.
24
+
25
+ search_library(address:, calilapp_key:)
26
+ parameter: address, a API key for http://calil.jp
27
+ return: library lists if found
28
+
29
+ ## Development
30
+
31
+ After checking out the repo, run `bin/setup` to install dependencies. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
32
+
33
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
34
+
35
+ ## Contributing
36
+
37
+ Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/wsato_gem.
38
+
@@ -0,0 +1,8 @@
1
+ require 'bundler/gem_tasks'
2
+ require 'rspec/core/rake_task'
3
+
4
+ task :default => [:spec]
5
+
6
+ RSpec::Core::RakeTask.new(:spec) do |spec|
7
+ spec.pattern = 'spec/**/*_spec.rb'
8
+ end
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "wsato_gem"
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
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,8 @@
1
+ require_relative 'wsato_gem/version'
2
+ require_relative 'wsato_gem/library'
3
+
4
+ module WsatoGem
5
+ def self.search_library(address:, calilapp_key:)
6
+ return Library.new.search(address: address, calilapp_key: calilapp_key)
7
+ end
8
+ end
@@ -0,0 +1,77 @@
1
+ require 'json'
2
+ require 'open-uri'
3
+
4
+ class Library
5
+ def search(address:, calilapp_key:, libraries_limit: 30)
6
+ begin
7
+ results = request_to_geocode_api(address: address)
8
+ contents = JSON.load(results)
9
+ location = contents['results'][0]['geometry']['location']
10
+ geocode = location['lng'].to_s << ',' << location['lat'].to_s
11
+
12
+ results = request_to_calil_api(calilapp_key: calilapp_key, geocode: geocode, libraries_limit: libraries_limit)
13
+ contents = JSON.parse(results)
14
+ if contents.length < 1
15
+ output('お近くに図書館がないようです')
16
+ raise
17
+ else
18
+ output('お近くの図書館を検索しました')
19
+ output_br
20
+ libraries = libraries_in_neihborhood(contents)
21
+ libraries.each do | distance, formal_name |
22
+ output("#{distance} km #{formal_name}")
23
+ end
24
+ return libraries
25
+ end
26
+ rescue
27
+ raise
28
+ end
29
+ end
30
+
31
+ def request_to_geocode_api(address:)
32
+ return get_request(
33
+ 'http://maps.google.com/maps/api/geocode/json?address=' +
34
+ address + '&sensor=false')
35
+ end
36
+
37
+ def request_to_calil_api(calilapp_key:, geocode:, libraries_limit: 10)
38
+ return get_request(
39
+ 'http://api.calil.jp/library?appkey=' <<
40
+ calilapp_key << '&geocode=' << geocode <<
41
+ '&limit=' + libraries_limit.to_s + '&format=json&callback=')
42
+ end
43
+
44
+ def libraries_in_neihborhood(contents)
45
+ libraries = {}
46
+ contents.each do |content|
47
+ libraries[content['distance']] = content['formal']
48
+ end
49
+ return Hash[libraries.sort]
50
+ end
51
+
52
+ def input()
53
+ input = STDIN.gets()
54
+ if input.include?("exit")
55
+ exit(0)
56
+ end
57
+ return input
58
+ end
59
+
60
+ def output(message)
61
+ printf("library > %s\n", message)
62
+ end
63
+
64
+ def output_br()
65
+ printf("library >\n")
66
+ end
67
+
68
+ def get_request(url)
69
+ results = open(url)
70
+ code, message = results.status # res.status => ["200", "OK"]
71
+ if code != '200'
72
+ raise "HTTP error!" # => RuntimeError
73
+ else
74
+ return results.read
75
+ end
76
+ end
77
+ end
@@ -0,0 +1,3 @@
1
+ module WsatoGem
2
+ VERSION = "0.1.0"
3
+ end
@@ -0,0 +1,22 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'wsato_gem/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "wsato_gem"
8
+ spec.version = WsatoGem::VERSION
9
+ spec.authors = ["a1616ts"]
10
+ spec.email = ["a1616ts@aiit.ac.jp"]
11
+
12
+ spec.summary = %q{20162Q Framework Class Ex. Group Work}
13
+ spec.description = %q{neighbor library search gem}
14
+
15
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
16
+ spec.bindir = "exe"
17
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
18
+ spec.require_paths = ["lib"]
19
+
20
+ spec.add_development_dependency "bundler", "~> 1.12"
21
+ spec.add_development_dependency "rake", "~> 10.0"
22
+ end
metadata ADDED
@@ -0,0 +1,82 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: wsato_gem
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - a1616ts
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2016-08-11 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.12'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.12'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '10.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '10.0'
41
+ description: neighbor library search gem
42
+ email:
43
+ - a1616ts@aiit.ac.jp
44
+ executables: []
45
+ extensions: []
46
+ extra_rdoc_files: []
47
+ files:
48
+ - ".gitignore"
49
+ - ".travis.yml"
50
+ - Gemfile
51
+ - README.md
52
+ - Rakefile
53
+ - bin/console
54
+ - bin/setup
55
+ - lib/wsato_gem.rb
56
+ - lib/wsato_gem/library.rb
57
+ - lib/wsato_gem/version.rb
58
+ - wsato_gem.gemspec
59
+ homepage:
60
+ licenses: []
61
+ metadata: {}
62
+ post_install_message:
63
+ rdoc_options: []
64
+ require_paths:
65
+ - lib
66
+ required_ruby_version: !ruby/object:Gem::Requirement
67
+ requirements:
68
+ - - ">="
69
+ - !ruby/object:Gem::Version
70
+ version: '0'
71
+ required_rubygems_version: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ requirements: []
77
+ rubyforge_project:
78
+ rubygems_version: 2.5.1
79
+ signing_key:
80
+ specification_version: 4
81
+ summary: 20162Q Framework Class Ex. Group Work
82
+ test_files: []