epo-ops 0.2.6 → 0.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +3 -0
- data/.travis.yml +6 -0
- data/README.md +78 -38
- data/epo-ops.gemspec +2 -2
- data/lib/epo_ops.rb +46 -0
- data/lib/epo_ops/client.rb +46 -0
- data/lib/epo_ops/error.rb +87 -0
- data/lib/epo_ops/factories.rb +9 -0
- data/lib/epo_ops/factories/name_and_address_factory.rb +54 -0
- data/lib/epo_ops/factories/patent_application_factory.rb +116 -0
- data/lib/epo_ops/factories/register_search_result_factory.rb +42 -0
- data/lib/epo_ops/ipc_class_hierarchy.rb +146 -0
- data/lib/epo_ops/ipc_class_hierarchy_loader.rb +60 -0
- data/lib/epo_ops/ipc_class_util.rb +71 -0
- data/lib/epo_ops/limits.rb +20 -0
- data/lib/epo_ops/logger.rb +15 -0
- data/lib/epo_ops/name_and_address.rb +58 -0
- data/lib/epo_ops/patent_application.rb +159 -0
- data/lib/epo_ops/rate_limit.rb +47 -0
- data/lib/epo_ops/register.rb +100 -0
- data/lib/epo_ops/register_search_result.rb +40 -0
- data/lib/epo_ops/search_query_builder.rb +65 -0
- data/lib/epo_ops/token_store.rb +33 -0
- data/lib/epo_ops/token_store/redis.rb +45 -0
- data/lib/epo_ops/util.rb +52 -0
- data/lib/epo_ops/version.rb +3 -0
- metadata +26 -20
- data/lib/epo/ops.rb +0 -43
- data/lib/epo/ops/address.rb +0 -60
- data/lib/epo/ops/bibliographic_document.rb +0 -196
- data/lib/epo/ops/client.rb +0 -27
- data/lib/epo/ops/error.rb +0 -89
- data/lib/epo/ops/ipc_class_hierarchy.rb +0 -148
- data/lib/epo/ops/ipc_class_hierarchy_loader.rb +0 -62
- data/lib/epo/ops/ipc_class_util.rb +0 -73
- data/lib/epo/ops/limits.rb +0 -22
- data/lib/epo/ops/logger.rb +0 -11
- data/lib/epo/ops/rate_limit.rb +0 -49
- data/lib/epo/ops/register.rb +0 -152
- data/lib/epo/ops/search_query_builder.rb +0 -65
- data/lib/epo/ops/token_store.rb +0 -35
- data/lib/epo/ops/token_store/redis.rb +0 -47
- data/lib/epo/ops/util.rb +0 -32
- data/lib/epo/ops/version.rb +0 -6
@@ -1,47 +0,0 @@
|
|
1
|
-
require 'redis'
|
2
|
-
require 'connection_pool'
|
3
|
-
|
4
|
-
module Epo
|
5
|
-
module Ops
|
6
|
-
class TokenStore
|
7
|
-
class Redis < TokenStore
|
8
|
-
def initialize(redis_host)
|
9
|
-
fail "Please install gems 'redis' and 'connection_pool' to use this feature" unless defined?(::Redis) && defined?(ConnectionPool)
|
10
|
-
|
11
|
-
@redis = ConnectionPool.new(size: 5, timeout: 5) { ::Redis.new(host: redis_host) }
|
12
|
-
end
|
13
|
-
|
14
|
-
def token
|
15
|
-
token = nil
|
16
|
-
@redis.with do |conn|
|
17
|
-
token = conn.get("epo_token_#{id}")
|
18
|
-
end
|
19
|
-
|
20
|
-
token.present? ? OAuth2::AccessToken.new(client, token) : generate_token
|
21
|
-
end
|
22
|
-
|
23
|
-
def reset
|
24
|
-
@redis.with do |conn|
|
25
|
-
conn.del("epo_token_#{id}")
|
26
|
-
end
|
27
|
-
end
|
28
|
-
|
29
|
-
private
|
30
|
-
|
31
|
-
def id
|
32
|
-
Digest::MD5.hexdigest(Epo::Ops.config.consumer_key + Epo::Ops.config.consumer_secret)
|
33
|
-
end
|
34
|
-
|
35
|
-
def generate_token
|
36
|
-
token = super
|
37
|
-
|
38
|
-
@redis.with do |conn|
|
39
|
-
conn.set("epo_token_#{id}", token.token, ex: token.expires_in, nx: true)
|
40
|
-
end
|
41
|
-
|
42
|
-
token
|
43
|
-
end
|
44
|
-
end
|
45
|
-
end
|
46
|
-
end
|
47
|
-
end
|
data/lib/epo/ops/util.rb
DELETED
@@ -1,32 +0,0 @@
|
|
1
|
-
module Epo
|
2
|
-
module Ops
|
3
|
-
class Util
|
4
|
-
# the path should be an array of strings indicating the path you want to go in the hash
|
5
|
-
def self.find_in_data(epo_hash, path)
|
6
|
-
path.reduce(epo_hash) { |res, c| parse_hash_flat(res, c) }
|
7
|
-
end
|
8
|
-
|
9
|
-
def self.parse_hash_flat(hash_layer, target)
|
10
|
-
result = []
|
11
|
-
if hash_layer.nil?
|
12
|
-
return []
|
13
|
-
elsif hash_layer.class == String
|
14
|
-
return []
|
15
|
-
elsif hash_layer.class == Array
|
16
|
-
result.concat(hash_layer.map { |x| parse_hash_flat(x, target) })
|
17
|
-
elsif hash_layer[target]
|
18
|
-
result << hash_layer[target]
|
19
|
-
elsif hash_layer.class == Hash || hash_layer.respond_to?(:to_h)
|
20
|
-
result.concat(hash_layer.to_h.map { |_x, y| parse_hash_flat(y, target) })
|
21
|
-
end
|
22
|
-
result.flatten
|
23
|
-
end
|
24
|
-
|
25
|
-
def self.parse_change_gazette_num(num)
|
26
|
-
res = /^(?<year>\d{4})\/(?<week>\d{2})$/.match(num)
|
27
|
-
return nil if res.nil?
|
28
|
-
Date.commercial(Integer(res[:year], 10), week = Integer(res[:week], 10))
|
29
|
-
end
|
30
|
-
end
|
31
|
-
end
|
32
|
-
end
|