zipclouder 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +15 -0
- data/.gitignore +17 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +51 -0
- data/Rakefile +1 -0
- data/lib/zipclouder.rb +100 -0
- data/lib/zipclouder/version.rb +4 -0
- data/spec/spec_helper.rb +2 -0
- data/spec/zipclouder_spec.rb +77 -0
- data/zipclouder.gemspec +23 -0
- metadata +84 -0
checksums.yaml
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
---
|
2
|
+
!binary "U0hBMQ==":
|
3
|
+
metadata.gz: !binary |-
|
4
|
+
MDcyZTZhOTFiZTcxYzYyNDc2ZDliZGYzYzAzODA1MmI1NGRkYWFkZQ==
|
5
|
+
data.tar.gz: !binary |-
|
6
|
+
ZWRmMWMzODdjZDhhYjU5NWVhYTdhYjA1YzQ5YTI4ZWM0MDA0NjFkYw==
|
7
|
+
SHA512:
|
8
|
+
metadata.gz: !binary |-
|
9
|
+
NzkyODUyZmFjYTA2ODRmNTg0YmM1NDRhNGEwMTFkZDgwNjZjZWExM2I4YTQ1
|
10
|
+
NGNhMjM2ZWM3MWRiOWQ5YTAyZjBjZGQzMDRlMmFlMjMxZDUzZTZlM2JmYjFj
|
11
|
+
YjI2OGRlOWZmY2E0NzUyZjI0OWJlZjAwNjUxYWEyNDlhMGY2ZTE=
|
12
|
+
data.tar.gz: !binary |-
|
13
|
+
YWY2MzUyMTkxMGU1NjAyMmYyM2YwYzJlNzIyMGIxY2E0NTRmZGQzMjRhYTk4
|
14
|
+
NjBlNGJjZjJlZGMzN2RiNTM4NzA1NDI1ZmI1NDNmODFhOGU0YWYwZWFhYmYw
|
15
|
+
ODZjYjhjNjRkNzZlNzc2ZDI0ZTU5Yjk5NDA0ZWEwYjE1MzZkZjc=
|
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2013 s-kobayashi
|
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,51 @@
|
|
1
|
+
# Zipclouder
|
2
|
+
|
3
|
+
zipcloud API( http://zipcloud.ibsnet.co.jp/doc/api )用のRubyライブラリ
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
gem 'zipclouder'
|
10
|
+
|
11
|
+
And then execute:
|
12
|
+
|
13
|
+
$ bundle
|
14
|
+
|
15
|
+
Or install it yourself as:
|
16
|
+
|
17
|
+
$ gem install zipclouder
|
18
|
+
|
19
|
+
## Usage
|
20
|
+
|
21
|
+
Zipclouder.search(<郵便番号(ハイフンありも可)>)
|
22
|
+
|
23
|
+
### ex)
|
24
|
+
|
25
|
+
zipclouder = Zipclouder.search(7830060)
|
26
|
+
|
27
|
+
zipclouder.address
|
28
|
+
#=> "高知県南国市蛍が丘"
|
29
|
+
|
30
|
+
zipclouder.kana
|
31
|
+
#=> "コウチケンナンコクシホタルガオカ"
|
32
|
+
|
33
|
+
zipclouder.pref_code
|
34
|
+
#=> "39"
|
35
|
+
|
36
|
+
zipclouder.zip_code
|
37
|
+
#=> "7830060"
|
38
|
+
|
39
|
+
zipclouder.success?
|
40
|
+
#=> true / false 通信の成功・失敗
|
41
|
+
|
42
|
+
zipclouder.error_message
|
43
|
+
#=> "パラメータ「郵便番号」の桁数が不正です。"
|
44
|
+
|
45
|
+
## Contributing
|
46
|
+
|
47
|
+
1. Fork it
|
48
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
49
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
50
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
51
|
+
5. Create new Pull Request
|
data/Rakefile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require "bundler/gem_tasks"
|
data/lib/zipclouder.rb
ADDED
@@ -0,0 +1,100 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
require "zipclouder/version"
|
3
|
+
require 'open-uri'
|
4
|
+
require 'openssl'
|
5
|
+
require 'net/http'
|
6
|
+
require 'uri'
|
7
|
+
require 'timeout'
|
8
|
+
require 'hashie'
|
9
|
+
|
10
|
+
class Zipclouder < Hashie::Mash
|
11
|
+
ZIPCLOUD_HOST = 'zipcloud.ibsnet.co.jp'.freeze
|
12
|
+
ZIPCLOUD_API_URI = '/api/search'.freeze
|
13
|
+
ZIPCLOUD_CONNECT_TIME = 10
|
14
|
+
|
15
|
+
def self.search zipcode
|
16
|
+
args = {
|
17
|
+
zipcode: zipcode
|
18
|
+
}
|
19
|
+
params = args.map {|k,v| "#{k}=#{v}"}.join('&')
|
20
|
+
|
21
|
+
json = post_connect params
|
22
|
+
unless json.blank?
|
23
|
+
self.new JSON.parse json
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
def success?
|
28
|
+
status.eql?(200) and results.present?
|
29
|
+
end
|
30
|
+
|
31
|
+
def address
|
32
|
+
res = result
|
33
|
+
[
|
34
|
+
res.address1,
|
35
|
+
res.address2,
|
36
|
+
res.address3
|
37
|
+
].join
|
38
|
+
end
|
39
|
+
|
40
|
+
def kana
|
41
|
+
res = result
|
42
|
+
[
|
43
|
+
res.kana1,
|
44
|
+
res.kana2,
|
45
|
+
res.kana3
|
46
|
+
].join
|
47
|
+
end
|
48
|
+
|
49
|
+
def pref_code
|
50
|
+
result.prefcode
|
51
|
+
end
|
52
|
+
|
53
|
+
def zip_code
|
54
|
+
result.zipcode
|
55
|
+
end
|
56
|
+
|
57
|
+
def result
|
58
|
+
if success?
|
59
|
+
if results.one?
|
60
|
+
results.first
|
61
|
+
else
|
62
|
+
"Error::Multpul Results"
|
63
|
+
end
|
64
|
+
else
|
65
|
+
if error_message.present?
|
66
|
+
error_message
|
67
|
+
else
|
68
|
+
"Error::No Result"
|
69
|
+
end
|
70
|
+
end
|
71
|
+
end
|
72
|
+
|
73
|
+
def error_message
|
74
|
+
message
|
75
|
+
end
|
76
|
+
|
77
|
+
private
|
78
|
+
def self.post_connect params
|
79
|
+
host = ZIPCLOUD_HOST
|
80
|
+
uri = ZIPCLOUD_API_URI
|
81
|
+
http = set_net_http host
|
82
|
+
resp = ""
|
83
|
+
|
84
|
+
begin
|
85
|
+
timeout(ZIPCLOUD_CONNECT_TIME) do
|
86
|
+
Rails.logger.info("////////// url:http://#{host}#{uri}?#{params}")
|
87
|
+
resp = http.post(uri, params)
|
88
|
+
end
|
89
|
+
rescue Exception => e
|
90
|
+
raise e
|
91
|
+
end
|
92
|
+
resp.body
|
93
|
+
end
|
94
|
+
|
95
|
+
def self.set_net_http host
|
96
|
+
http = Net::HTTP.new(host,80)
|
97
|
+
http.verify_mode = OpenSSL::SSL::VERIFY_NONE
|
98
|
+
http
|
99
|
+
end
|
100
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,77 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require "webmock/rspec"
|
3
|
+
WebMock.allow_net_connect!
|
4
|
+
ZIPCLOUD_LINK = "http://zipcloud.ibsnet.co.jp/api/search?zipcode=7830060".freeze
|
5
|
+
|
6
|
+
|
7
|
+
describe Zipclouder do
|
8
|
+
before do
|
9
|
+
@zipclouder = Zipclouder.new zipcloud_body
|
10
|
+
end
|
11
|
+
|
12
|
+
|
13
|
+
it 'should have a version number' do
|
14
|
+
Zipclouder::VERSION.should_not be_nil
|
15
|
+
end
|
16
|
+
|
17
|
+
describe 'search' do
|
18
|
+
it 'class is ziclouder' do
|
19
|
+
@zipclouder.class.should == Zipclouder
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
describe 'success?' do
|
24
|
+
it 'returns true when status is 200' do
|
25
|
+
@zipclouder.success?.should be_true
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
describe 'address' do
|
30
|
+
it 'returns specific text' do
|
31
|
+
@zipclouder.address.should == "高知県南国市蛍が丘"
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
describe 'kana' do
|
36
|
+
it 'returns specifix text' do
|
37
|
+
@zipclouder.kana.should == "コウチケンナンコクシホタルガオカ"
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
describe 'pref_code' do
|
42
|
+
it 'returns the prefecture code' do
|
43
|
+
@zipclouder.pref_code.should == "39"
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
describe 'zip_code' do
|
48
|
+
it 'returns the zip code' do
|
49
|
+
@zipclouder.zip_code.should == "7830060"
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
describe 'error_message' do
|
54
|
+
it 'returns message' do
|
55
|
+
@zipclouder.error_message.should be_nil
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
end
|
60
|
+
def zipcloud_body
|
61
|
+
{
|
62
|
+
"message" => nil,
|
63
|
+
"results" => [
|
64
|
+
{
|
65
|
+
"address1" => "高知県",
|
66
|
+
"address2"=> "南国市",
|
67
|
+
"address3" => "蛍が丘",
|
68
|
+
"kana1" => "コウチケン",
|
69
|
+
"kana2" => "ナンコクシ",
|
70
|
+
"kana3" => "ホタルガオカ",
|
71
|
+
"prefcode" => "39",
|
72
|
+
"zipcode" => "7830060"
|
73
|
+
}
|
74
|
+
],
|
75
|
+
"status" => 200
|
76
|
+
}
|
77
|
+
end
|
data/zipclouder.gemspec
ADDED
@@ -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 'zipclouder/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "zipclouder"
|
8
|
+
spec.version = "1.0.0"
|
9
|
+
spec.authors = ["tanayuk"]
|
10
|
+
spec.email = ["yuuki.tnk@gmail.com"]
|
11
|
+
spec.description = %q{A Ruby library for zipcloud API. https://github.com/tanayuk/zipclouder }
|
12
|
+
spec.summary = %q{A Ruby library for zipcloud API}
|
13
|
+
spec.homepage = "https://github.com/tanayuk/zipclouder"
|
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
|
metadata
ADDED
@@ -0,0 +1,84 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: zipclouder
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.0.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- tanayuk
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2015-03-24 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: ! 'A Ruby library for zipcloud API. https://github.com/tanayuk/zipclouder '
|
42
|
+
email:
|
43
|
+
- yuuki.tnk@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
|
+
- lib/zipclouder.rb
|
54
|
+
- lib/zipclouder/version.rb
|
55
|
+
- spec/spec_helper.rb
|
56
|
+
- spec/zipclouder_spec.rb
|
57
|
+
- zipclouder.gemspec
|
58
|
+
homepage: https://github.com/tanayuk/zipclouder
|
59
|
+
licenses:
|
60
|
+
- MIT
|
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.4.6
|
79
|
+
signing_key:
|
80
|
+
specification_version: 4
|
81
|
+
summary: A Ruby library for zipcloud API
|
82
|
+
test_files:
|
83
|
+
- spec/spec_helper.rb
|
84
|
+
- spec/zipclouder_spec.rb
|