pumi 0.19.0 → 0.20.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +14 -0
- data/README.md +8 -0
- data/bin/parse_data +2 -5
- data/data/communes.yml +9904 -0
- data/data/districts.yml +1576 -0
- data/data/provinces.yml +225 -0
- data/lib/pumi/bot/wikipedia/article.rb +13 -0
- data/lib/pumi/bot/wikipedia/communes_in_cambodia_article.rb +157 -0
- data/lib/pumi/bot/wikipedia/districts_in_cambodia_article.rb +122 -0
- data/lib/pumi/bot/wikipedia/templates/commune_list.wikitext.erb +46 -0
- data/lib/pumi/bot/wikipedia/templates/district_list.wikitext.erb +27 -0
- data/lib/pumi/bot/wikipedia.rb +10 -0
- data/lib/pumi/bot.rb +6 -0
- data/lib/pumi/data_source/geocoder.rb +251 -0
- data/lib/pumi/data_source/iso31662.rb +29 -0
- data/lib/pumi/data_source/wikipedia.rb +19 -524
- data/lib/pumi/data_source.rb +2 -0
- data/lib/pumi/geodata.rb +3 -0
- data/lib/pumi/location.rb +2 -0
- data/lib/pumi/parser.rb +7 -0
- data/lib/pumi/version.rb +1 -1
- data/lib/pumi/wikipedia/client.rb +68 -0
- data/lib/pumi/wikipedia/response.rb +15 -0
- data/lib/pumi/wikipedia.rb +7 -0
- data/lib/pumi.rb +1 -1
- data/pumi.gemspec +4 -1
- metadata +58 -4
- data/lib/pumi/scraper/result.rb +0 -5
@@ -0,0 +1,68 @@
|
|
1
|
+
require "faraday"
|
2
|
+
|
3
|
+
module Pumi
|
4
|
+
module Wikipedia
|
5
|
+
class Client
|
6
|
+
attr_reader :http_client
|
7
|
+
|
8
|
+
def initialize(http_client: default_http_client)
|
9
|
+
@http_client = http_client
|
10
|
+
end
|
11
|
+
|
12
|
+
def create_page(params)
|
13
|
+
execute_request(:post, build_url(resource: :page), params)
|
14
|
+
end
|
15
|
+
|
16
|
+
def update_page(title:, **params)
|
17
|
+
page = get_page(title:)
|
18
|
+
latest = page.fetch(:latest)
|
19
|
+
execute_request(:put, build_url(resource: "page/#{title}"), latest:, **params)
|
20
|
+
end
|
21
|
+
|
22
|
+
def submit_for_review(title:, **params)
|
23
|
+
page = get_page(title:)
|
24
|
+
execute_request(
|
25
|
+
:put,
|
26
|
+
build_url(resource: "page/#{title}"),
|
27
|
+
latest: page.fetch(:latest),
|
28
|
+
source: page.fetch(:source).prepend("{{subst:submit}}\n"),
|
29
|
+
title:,
|
30
|
+
comment: "Submit #{title} for review",
|
31
|
+
**params
|
32
|
+
)
|
33
|
+
end
|
34
|
+
|
35
|
+
def get_page(title:)
|
36
|
+
execute_request(:get, build_url(resource: "page/#{title}"))
|
37
|
+
end
|
38
|
+
|
39
|
+
def page_exists?(title:)
|
40
|
+
response = get_page(title:)
|
41
|
+
response.success?
|
42
|
+
end
|
43
|
+
|
44
|
+
private
|
45
|
+
|
46
|
+
def build_url(resource:, project: :wikipedia, language: :en, **_params)
|
47
|
+
"/core/v1/#{project}/#{language}/#{resource}"
|
48
|
+
end
|
49
|
+
|
50
|
+
def execute_request(http_method, url, params = {}, headers = {})
|
51
|
+
response = http_client.run_request(http_method, url, params.to_json, headers)
|
52
|
+
|
53
|
+
Response.new(response)
|
54
|
+
end
|
55
|
+
|
56
|
+
def default_http_client
|
57
|
+
Faraday.new(url: "https://api.wikimedia.org") do |conn|
|
58
|
+
conn.headers["Accept"] = "application/json"
|
59
|
+
conn.headers["Content-Type"] = "application/json"
|
60
|
+
|
61
|
+
conn.adapter Faraday.default_adapter
|
62
|
+
|
63
|
+
conn.request(:authorization, "Bearer", ENV["WIKIPEDIA_ACCESS_TOKEN"])
|
64
|
+
end
|
65
|
+
end
|
66
|
+
end
|
67
|
+
end
|
68
|
+
end
|
data/lib/pumi.rb
CHANGED
@@ -21,7 +21,7 @@ require_relative "pumi/location"
|
|
21
21
|
require_relative "pumi/province"
|
22
22
|
require_relative "pumi/district"
|
23
23
|
require_relative "pumi/commune"
|
24
|
+
require_relative "pumi/geodata"
|
24
25
|
require_relative "pumi/village"
|
25
26
|
require_relative "pumi/parser"
|
26
27
|
require_relative "pumi/data_file"
|
27
|
-
require_relative "pumi/data_source"
|
data/pumi.gemspec
CHANGED
@@ -25,6 +25,8 @@ Gem::Specification.new do |spec|
|
|
25
25
|
spec.add_development_dependency "bundler"
|
26
26
|
spec.add_development_dependency "capybara"
|
27
27
|
spec.add_development_dependency "coffee-rails"
|
28
|
+
spec.add_development_dependency "faraday"
|
29
|
+
spec.add_development_dependency "geocoder"
|
28
30
|
spec.add_development_dependency "jquery-rails"
|
29
31
|
spec.add_development_dependency "nokogiri"
|
30
32
|
spec.add_development_dependency "pry"
|
@@ -37,5 +39,6 @@ Gem::Specification.new do |spec|
|
|
37
39
|
spec.add_development_dependency "rubocop-rspec"
|
38
40
|
spec.add_development_dependency "selenium-webdriver"
|
39
41
|
spec.add_development_dependency "sprockets-rails"
|
40
|
-
spec.add_development_dependency "
|
42
|
+
spec.add_development_dependency "vcr"
|
43
|
+
spec.add_development_dependency "webmock"
|
41
44
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: pumi
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.20.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- David Wilkie
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2023-
|
11
|
+
date: 2023-08-02 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -52,6 +52,34 @@ dependencies:
|
|
52
52
|
- - ">="
|
53
53
|
- !ruby/object:Gem::Version
|
54
54
|
version: '0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: faraday
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ">="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ">="
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: geocoder
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - ">="
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - ">="
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0'
|
55
83
|
- !ruby/object:Gem::Dependency
|
56
84
|
name: jquery-rails
|
57
85
|
requirement: !ruby/object:Gem::Requirement
|
@@ -221,7 +249,21 @@ dependencies:
|
|
221
249
|
- !ruby/object:Gem::Version
|
222
250
|
version: '0'
|
223
251
|
- !ruby/object:Gem::Dependency
|
224
|
-
name:
|
252
|
+
name: vcr
|
253
|
+
requirement: !ruby/object:Gem::Requirement
|
254
|
+
requirements:
|
255
|
+
- - ">="
|
256
|
+
- !ruby/object:Gem::Version
|
257
|
+
version: '0'
|
258
|
+
type: :development
|
259
|
+
prerelease: false
|
260
|
+
version_requirements: !ruby/object:Gem::Requirement
|
261
|
+
requirements:
|
262
|
+
- - ">="
|
263
|
+
- !ruby/object:Gem::Version
|
264
|
+
version: '0'
|
265
|
+
- !ruby/object:Gem::Dependency
|
266
|
+
name: webmock
|
225
267
|
requirement: !ruby/object:Gem::Requirement
|
226
268
|
requirements:
|
227
269
|
- - ">="
|
@@ -275,22 +317,34 @@ files:
|
|
275
317
|
- data/villages.yml
|
276
318
|
- lib/pumi.rb
|
277
319
|
- lib/pumi/administrative_unit.rb
|
320
|
+
- lib/pumi/bot.rb
|
321
|
+
- lib/pumi/bot/wikipedia.rb
|
322
|
+
- lib/pumi/bot/wikipedia/article.rb
|
323
|
+
- lib/pumi/bot/wikipedia/communes_in_cambodia_article.rb
|
324
|
+
- lib/pumi/bot/wikipedia/districts_in_cambodia_article.rb
|
325
|
+
- lib/pumi/bot/wikipedia/templates/commune_list.wikitext.erb
|
326
|
+
- lib/pumi/bot/wikipedia/templates/district_list.wikitext.erb
|
278
327
|
- lib/pumi/commune.rb
|
279
328
|
- lib/pumi/data_file.rb
|
280
329
|
- lib/pumi/data_source.rb
|
330
|
+
- lib/pumi/data_source/geocoder.rb
|
331
|
+
- lib/pumi/data_source/iso31662.rb
|
281
332
|
- lib/pumi/data_source/ncdd.rb
|
282
333
|
- lib/pumi/data_source/wikipedia.rb
|
283
334
|
- lib/pumi/data_store.rb
|
284
335
|
- lib/pumi/district.rb
|
336
|
+
- lib/pumi/geodata.rb
|
285
337
|
- lib/pumi/location.rb
|
286
338
|
- lib/pumi/parser.rb
|
287
339
|
- lib/pumi/province.rb
|
288
340
|
- lib/pumi/rails.rb
|
289
341
|
- lib/pumi/rails/engine.rb
|
290
|
-
- lib/pumi/scraper/result.rb
|
291
342
|
- lib/pumi/store_cache.rb
|
292
343
|
- lib/pumi/version.rb
|
293
344
|
- lib/pumi/village.rb
|
345
|
+
- lib/pumi/wikipedia.rb
|
346
|
+
- lib/pumi/wikipedia/client.rb
|
347
|
+
- lib/pumi/wikipedia/response.rb
|
294
348
|
- pumi.gemspec
|
295
349
|
- pumi.jpg
|
296
350
|
- pumi_ui_en.png
|