wikimelon 0.0.1 → 0.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 73e0c68c9927e39f872a5570907ac9b9a4ca43c792b322feb95c18c7e71fe188
4
- data.tar.gz: 4838097e4e1bbceab2c099ed10249880fd0cb7dd3544e41c929a7dc61efccc7e
3
+ metadata.gz: 677a3d97dca869666cc396285f938cb8c7031a8a1a0069509a19c4da03674cc1
4
+ data.tar.gz: 5ef0d3e678a81524ec039ae5ad1ef195fcd6d8c99f99409b664a912763a0d935
5
5
  SHA512:
6
- metadata.gz: 42240519777be349015be2d74361e5fd35720c15197bf1446758651bf0255205cf0afd8e88327d7dc10ff6813c88ffb54b36691d16d216c0549792dcf409e11d
7
- data.tar.gz: f3fed8067a8f116aa464562047552ea2f382d07d336848920ae5a35d01882c479fcc5c64c1201c58c53ad7dd6148eb1e83ab84ed058f49920763c1b896081b8c
6
+ metadata.gz: f5355abc87792d30d7a83095ed7c03af7ccab2fb8bc582b72112cc93982d46ac054ad14f9a6ca986246fecd92e78dd13b2408ce443cead076501686222e6adc6
7
+ data.tar.gz: 55853e53bc9287a429a413de4dc030d5e94d3efddc37feadae5a4f481a6d2ecae38577acfc3b45848a590b2cd44f6f81d6f57af1bdc3856796f1f7f337030b54
data/.gitignore CHANGED
@@ -1,3 +1,4 @@
1
+ .byebug_history
1
2
  .idea
2
3
  /.bundle/
3
4
  /.yardoc
data/CHANGELOG.md CHANGED
@@ -1,11 +1,7 @@
1
1
  ## [Unreleased]
2
- - Updated license from NCSA to MIT
2
+
3
+ ## [0.0.2] - 2025-03-06
4
+ - Added entity endpoint
3
5
 
4
- ## [0.1.1] - 2024-09-11
5
- - Updated documentation
6
- - Removed Gemfile.lock
7
- - Bumped development depency versions to avoid CVE-2024-43398
8
-
9
- ## [0.1.0] - 2022-01-20
10
-
11
- - Initial release
6
+ ## [0.0.1] - 2025-03-04
7
+ - Initial release wrapping the SPARQL query endpoint
data/Gemfile CHANGED
@@ -7,4 +7,4 @@ gemspec
7
7
 
8
8
  gem "rake", "~> 13.0"
9
9
 
10
- gem "minitest", "~> 5.0"
10
+ gem "minitest", "~> 5.0"
data/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # Wikimelon
2
2
 
3
- Wikimelon is a Ruby wrapper on the [Wikidata](https://wikidata.org) API. Code follow the spirit/approach of the Gem [serrano](https://github.com/sckott/serrano), and indeed much of the wrapping utility is copied 1:1 from that repo, thanks [@sckott](https://github.com/sckott).
3
+ Wikimelon is a lightweight Ruby wrapper on the [Wikidata](https://wikidata.org) API. Code follow the spirit/approach of the Gem [serrano](https://github.com/sckott/serrano), and indeed much of the wrapping utility is copied 1:1 from that repo, thanks [@sckott](https://github.com/sckott).
4
4
 
5
5
  ## Installation
6
6
 
@@ -25,16 +25,36 @@ Or install it yourself as:
25
25
  ### Queries
26
26
  Run a Wikidata query:
27
27
  ```ruby
28
- query = """
28
+ query = "
29
29
  SELECT ?human ?humanLabel ?zoobank WHERE {
30
30
  ?human wdt:P31 wd:Q5.
31
31
  ?human wdt:P2006 ?zoobank.
32
32
  SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en". }
33
33
  } LIMIT 100 OFFSET 0
34
- """
34
+ "
35
35
  Wikimelon.query(query) # => MultiJson object
36
36
  ```
37
37
 
38
+ ---
39
+ ### Entities
40
+ Fetch data on an item:
41
+ ```ruby
42
+ entity_id = "Q13"
43
+ Wikimelon.entity(entity_id) # => MultiJson object
44
+ ```
45
+
46
+ Fetch data on a property:
47
+ ```ruby
48
+ entity_id = "P31"
49
+ Wikimelon.entity(entity_id) # => MultiJson object
50
+ ```
51
+
52
+ Fetch data on an entity with a specific revision ID:
53
+ ```ruby
54
+ entity_id = "Q13"
55
+ Wikimelon.entity(entity_id, revision_id: 109) # => MultiJson object
56
+ ```
57
+
38
58
  ---
39
59
 
40
60
  ## Development
@@ -12,7 +12,7 @@ module Wikimelon
12
12
  attr_accessor :options
13
13
 
14
14
  def initialize(**args)
15
- @endpoint = args[:endpoint]
15
+ @url = args[:url]
16
16
  @verbose = args[:verbose]
17
17
  @query = args[:query]
18
18
  @limit = args[:limit]
@@ -27,17 +27,10 @@ module Wikimelon
27
27
 
28
28
  Faraday::Utils.default_space_encoding = "+"
29
29
 
30
- conn = if verbose
31
- Faraday.new(url: Wikimelon.base_url) do |f|
32
- f.response :logger
33
- f.use Faraday::WikimelonErrors::Middleware
34
- f.adapter Faraday.default_adapter
35
- end
36
- else
37
- Faraday.new(url: Wikimelon.base_url) do |f|
38
- f.use Faraday::WikimelonErrors::Middleware
39
- f.adapter Faraday.default_adapter
40
- end
30
+ conn = Faraday.new(url: @url) do |f|
31
+ f.response :logger if verbose
32
+ f.use Faraday::WikimelonErrors::Middleware
33
+ f.adapter Faraday.default_adapter
41
34
  end
42
35
 
43
36
  conn.headers['Accept'] = 'application/json,*/*'
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Wikimelon
4
- VERSION = "0.0.1"
4
+ VERSION = "0.0.2"
5
5
  end
data/lib/wikimelon.rb CHANGED
@@ -9,10 +9,9 @@ require "wikimelon/helpers/configuration"
9
9
  module Wikimelon
10
10
  extend Configuration
11
11
 
12
- define_setting :base_url, "https://query.wikidata.org/sparql"
13
12
  define_setting :mailto, ENV["WIKIMELON_API_EMAIL"]
14
13
 
15
- # Run a Wikidata query
14
+ # Run a Wikidata SPARQL query
16
15
  #
17
16
  # @param query [String] a Wikidata query
18
17
  #
@@ -21,9 +20,27 @@ module Wikimelon
21
20
  # @return [Array, Boolean] An array of hashes
22
21
  def self.query(query, verbose: false)
23
22
  Request.new(
24
- endpoint: "",
23
+ url: "https://query.wikidata.org/sparql",
25
24
  query: query,
26
25
  verbose: verbose
27
26
  ).perform
28
27
  end
28
+
29
+
30
+ # Get Wikidata entity data
31
+ #
32
+ # @param entity_id [String] a Wikidata entity ID
33
+ # @param revision_id [int] a revision ID
34
+ #
35
+ # @param verbose [Boolean] Print headers to STDOUT
36
+ #
37
+ # @return [Array, Boolean] An array of hashes
38
+ def self.entity(entity_id, revision_id: nil, verbose: false)
39
+ url = "https://www.wikidata.org/wiki/Special:EntityData/#{entity_id}.json"
40
+ url = "#{url}?revision=#{revision_id}" unless revision_id.nil?
41
+ Request.new(
42
+ url: url,
43
+ verbose: verbose
44
+ ).perform
45
+ end
29
46
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: wikimelon
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Geoff Ower, Matt Yoder
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2025-03-04 00:00:00.000000000 Z
11
+ date: 2025-03-06 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -197,7 +197,7 @@ licenses:
197
197
  metadata:
198
198
  homepage_uri: https://github.com/SpeciesFileGroup/wikimelon
199
199
  source_code_uri: https://github.com/SpeciesFileGroup/wikimelon
200
- changelog_uri: https://github.com/SpeciesFileGroup/wikimelon/releases/tag/v0.0.1
200
+ changelog_uri: https://github.com/SpeciesFileGroup/wikimelon/releases/tag/v0.0.2
201
201
  post_install_message:
202
202
  rdoc_options: []
203
203
  require_paths: