gn_crossmap 2.2.3 → 2.3.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: af88cbf0b3ca5ea98ebf8cbb37b41797ba696294
4
- data.tar.gz: 75bc41909f7c00eee0311a254e1390aa6ae8307c
3
+ metadata.gz: c84cc9c99fe6e3a70510415998c826928c4b7013
4
+ data.tar.gz: 870651fe4c32fbded76f3fb2cc60d94878b19150
5
5
  SHA512:
6
- metadata.gz: a784f2f6bab3b46fc4f4d7f3ef0aa69116d528589ff116ad85f050d28d430882672bdaef42e2c2fe21aa526bbaac5d27e55939ec9df4e0049b44f98311c9fc1f
7
- data.tar.gz: 2b054ace46de4c2f11b15ab52a47a8371c126a4274c4be439115f1a6e37ce77e6f2148bfc38034f096a6f7d21807c58b7101764a4f0e169589140767a485e38c
6
+ metadata.gz: fd3bbc558395d43e713bd35a58f2eee7bd40f24f37399095c08c3186de004df2752ea6180d4d02b9fd83b0d3419648e58c68a281f2ead4d88e90863e917ae048
7
+ data.tar.gz: 5d6a973a2bc965ae5015ced006a880e38b6c51231e73e6eabb6182dbc4e88849b2341097397436d7fdaabcf45f02d38ad92e0477a74baba53c75c3c66fd1bda0
data/CHANGELOG.md CHANGED
@@ -1,5 +1,9 @@
1
1
  # ``gn_crossmap`` CHANGELOG
2
2
 
3
+ ## 2.3.0
4
+
5
+ * @dimus - add option to supply url for global names resolver
6
+
3
7
  ## 2.2.3
4
8
 
5
9
  * @dimus - make csv processing more permissive, continue
data/README.md CHANGED
@@ -92,6 +92,9 @@ all original data is preserved
92
92
  : (array) empty array by default. If `alt_headers` are not empty they are used
93
93
  instead of the headers supplied with the file
94
94
 
95
+ ``resolver_url``
96
+ : URL to globalnames' resolver. Default is ``http://resolver.globalnames.org``
97
+
95
98
  #### `GnCrossmap.logger=`
96
99
 
97
100
  Allows to set logger to a custom logger (default is `STDERR`)
data/lib/gn_crossmap.rb CHANGED
@@ -37,14 +37,12 @@ module GnCrossmap
37
37
  # rubocop:disable Metrics/AbcSize
38
38
 
39
39
  def run(opts)
40
- opts = OpenStruct.new({ stats: Stats.new, alt_headers: [] }.merge(opts))
40
+ opts = opts_struct(opts)
41
41
  input_io, output_io = io(opts.input, opts.output)
42
- reader = Reader.new(input_io, input_name(opts.input),
43
- opts.skip_original, opts.alt_headers, opts.stats)
42
+ reader = create_reader(input_io, opts)
44
43
  data = block_given? ? reader.read(&Proc.new) : reader.read
45
- writer = Writer.new(output_io, reader.original_fields,
46
- output_name(opts.output))
47
- resolver = Resolver.new(writer, opts.data_source_id, opts.stats)
44
+ writer = create_writer(reader, output_io, opts)
45
+ resolver = create_resolver(writer, opts)
48
46
  block_given? ? resolver.resolve(data, &Proc.new) : resolver.resolve(data)
49
47
  opts.output
50
48
  end
@@ -61,6 +59,25 @@ module GnCrossmap
61
59
 
62
60
  private
63
61
 
62
+ def create_resolver(writer, opts)
63
+ Resolver.new(writer, opts.data_source_id, opts.resolver_url, opts.stats)
64
+ end
65
+
66
+ def create_writer(reader, output_io, opts)
67
+ Writer.new(output_io, reader.original_fields, output_name(opts.output))
68
+ end
69
+
70
+ def create_reader(input_io, opts)
71
+ Reader.new(input_io, input_name(opts.input),
72
+ opts.skip_original, opts.alt_headers, opts.stats)
73
+ end
74
+
75
+ def opts_struct(opts)
76
+ resolver_url = "http://resolver.globalnames.org/name_resolvers.json"
77
+ OpenStruct.new({ stats: Stats.new, alt_headers: [],
78
+ resolver_url: resolver_url }.merge(opts))
79
+ end
80
+
64
81
  def io(input, output)
65
82
  io_in = iogen(input, INPUT_MODE)
66
83
  io_out = iogen(output, OUTPUT_MODE)
@@ -1,10 +1,9 @@
1
1
  module GnCrossmap
2
2
  # Sends data to GN Resolver and collects results
3
3
  class Resolver
4
- URL = "http://resolver.globalnames.org/name_resolvers.json".freeze
5
-
6
- def initialize(writer, data_source_id, stats)
4
+ def initialize(writer, data_source_id, resolver_url, stats)
7
5
  @stats = stats
6
+ @resolver_url = resolver_url
8
7
  @processor = GnCrossmap::ResultProcessor.new(writer, @stats)
9
8
  @ds_id = data_source_id
10
9
  @count = 0
@@ -65,7 +64,7 @@ module GnCrossmap
65
64
 
66
65
  def remote_resolve(names)
67
66
  batch_start = Time.now
68
- res = RestClient.post(URL, data: names, data_source_ids: @ds_id)
67
+ res = RestClient.post(@resolver_url, data: names, data_source_ids: @ds_id)
69
68
  @processor.process(res, @current_data)
70
69
  rescue RestClient::Exception
71
70
  single_remote_resolve(names)
@@ -83,7 +82,8 @@ module GnCrossmap
83
82
  def single_remote_resolve(names)
84
83
  names.split("\n").each do |name|
85
84
  begin
86
- res = RestClient.post(URL, data: name, data_source_ids: @ds_id)
85
+ res = RestClient.post(@resolver_url, data: name,
86
+ data_source_ids: @ds_id)
87
87
  @processor.process(res, @current_data)
88
88
  rescue RestClient::Exception => e
89
89
  process_resolver_error(e, name)
@@ -1,6 +1,6 @@
1
1
  # Namespace module for crossmapping checklists to GN sources
2
2
  module GnCrossmap
3
- VERSION = "2.2.3".freeze
3
+ VERSION = "2.3.0".freeze
4
4
 
5
5
  def self.version
6
6
  VERSION
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: gn_crossmap
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.2.3
4
+ version: 2.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Dmitry Mozzherin
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2017-02-14 00:00:00.000000000 Z
11
+ date: 2017-03-07 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: trollop