docodoco_jp 0.0.2 → 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 0ab1cf9ade58f1a21aa7cb09fe29b12416f4fb32
4
- data.tar.gz: 09345ebbf6c5f403e8d7139a3b5739b98991b976
3
+ metadata.gz: c46a71ef87c49fdf19d8c7f61f4faefb92b58c98
4
+ data.tar.gz: 5eb81b51e8b6b3a56038afdd9039429daa09f8fe
5
5
  SHA512:
6
- metadata.gz: 2c931b442cd87638ad344d4e4c81eb83f335b8d369340dc933c4578947e51f3ec27eadc3fe453e68a8b50154f1d8920a0c725ed04073a7033c29294b1c51be4e
7
- data.tar.gz: 17e8026f63976b381a40adcfce6c7f07fd650eb11bd7a08ffb7fceefc7beac969047a266fe87d8e38ced6e378a0b9b8c582daccc5d92f08ad7df4e18b1836a8c
6
+ metadata.gz: 8028d83db86d072f6745b77b6465883e11ccfc4c76bd2249871ab5472eb44360fdd6eb57f9629421e5245f4a80163d8640a6261d6a89788740220bf589f80b99
7
+ data.tar.gz: b447edd31b665545a3b768b0462698f4008bc5b8cdd8df5c9ca5938b55d8009dfd058c08bba31cb8f5a64b54a6d02d14b7e45cac9a204ba288ca5df324c2e844
data/lib/docodoco_jp.rb CHANGED
@@ -1,6 +1,8 @@
1
1
  # coding: utf-8
2
2
 
3
3
  require "docodoco_jp/version"
4
+ require "docodoco_jp/ipv4_validation_error"
5
+ require "docodoco_jp/api_key_invalid"
4
6
 
5
7
  require "faraday"
6
8
  require "hashie"
@@ -45,11 +47,6 @@ class DocodocoJp
45
47
  end
46
48
  end
47
49
 
48
- def valid?
49
- return check_user unless @user_valid
50
- return @user_valid
51
- end
52
-
53
50
  def search(ipadr = nil)
54
51
  result = hash_nomalize(JSON.parse(search_api(ipadr).body))
55
52
  if config[:response_type] == :hashie
@@ -67,13 +64,19 @@ class DocodocoJp
67
64
  return result, {status: status, message: message}
68
65
  end
69
66
 
67
+ def check_user!()
68
+ result, json = check_user
69
+ raise DocodocoJp::ApiKeyInvalid unless result
70
+ return result, json
71
+ end
72
+
70
73
  private
71
74
  def check_user_api()
72
75
  return api_request "/v4/user_info", api_params
73
76
  end
74
77
 
75
78
  def search_api(ipadr = nil)
76
- raise "arg: ipadr is not IP ADDRESS." unless ipadr.nil? || Resolv::IPv4::Regex =~ ipadr
79
+ raise DocodocoJp::IPv4ValidationError unless ipadr.nil? || Resolv::IPv4::Regex =~ ipadr
77
80
  return api_request "/v4/search", api_params(format: :json, charset: config[:charset], ipadr: ipadr)
78
81
  end
79
82
 
@@ -86,11 +89,11 @@ class DocodocoJp
86
89
 
87
90
  def connection
88
91
  return @connection ||= ->() {
89
- protocol = config[:ssl] ? "https:" : "http"
92
+ protocol = config[:ssl] ? "https" : "http"
90
93
  options = config[:ssl] ? { ssl: { verify: true } } : {}
91
- Faraday.new("#{protocol}//#{API_HOST}", options) do |builder|
94
+ Faraday.new("#{protocol}://#{API_HOST}", options) do |builder|
92
95
  builder.request :url_encoded
93
- builder.response :logger if config[:debug]
96
+ builder.response :logger if config[:faraday_log]
94
97
  builder.adapter :net_http
95
98
  end
96
99
  }.call()
@@ -0,0 +1,6 @@
1
+ # coding: utf-8
2
+
3
+ class DocodocoJp
4
+ class ApiKeyInvalid < StandardError
5
+ end
6
+ end
@@ -0,0 +1,6 @@
1
+ # coding: utf-8
2
+
3
+ class DocodocoJp
4
+ class IPv4ValidationError < StandardError
5
+ end
6
+ end
@@ -1,3 +1,5 @@
1
+ # coding: utf-8
2
+
1
3
  class DocodocoJp
2
- VERSION = "0.0.2"
4
+ VERSION = "0.1.0"
3
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: docodoco_jp
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Hiroshi IKEGAMI
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2015-07-18 00:00:00.000000000 Z
11
+ date: 2015-07-26 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: faraday
@@ -113,6 +113,8 @@ files:
113
113
  - docodoco_jp.gemspec
114
114
  - fixtures/sample_api_key.yml
115
115
  - lib/docodoco_jp.rb
116
+ - lib/docodoco_jp/api_key_invalid.rb
117
+ - lib/docodoco_jp/ipv4_validation_error.rb
116
118
  - lib/docodoco_jp/version.rb
117
119
  homepage: https://github.com/magicdrive/ruby-docodoco_jp
118
120
  licenses: