wikidata_adaptor 1.0.0

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.
Files changed (48) hide show
  1. checksums.yaml +7 -0
  2. data/.env.test +7 -0
  3. data/.rspec +3 -0
  4. data/.rubocop.yml +45 -0
  5. data/.yardopts +10 -0
  6. data/CHANGELOG.md +106 -0
  7. data/CLAUDE.md +200 -0
  8. data/CODE_OF_CONDUCT.md +84 -0
  9. data/COVERAGE.md +77 -0
  10. data/Gemfile +20 -0
  11. data/Gemfile.lock +124 -0
  12. data/LICENSE.txt +21 -0
  13. data/README.md +269 -0
  14. data/Rakefile +18 -0
  15. data/integration/.env.example +20 -0
  16. data/integration/README.md +58 -0
  17. data/integration/config/99_IntegrationTesting.php +3 -0
  18. data/integration/config/wikibase-php.ini +15 -0
  19. data/integration/docker-compose.yml +98 -0
  20. data/lib/wikidata_adaptor/rest_api/aliases.rb +88 -0
  21. data/lib/wikidata_adaptor/rest_api/descriptions.rb +138 -0
  22. data/lib/wikidata_adaptor/rest_api/items.rb +36 -0
  23. data/lib/wikidata_adaptor/rest_api/labels.rb +138 -0
  24. data/lib/wikidata_adaptor/rest_api/open_api_document.rb +15 -0
  25. data/lib/wikidata_adaptor/rest_api/properties.rb +36 -0
  26. data/lib/wikidata_adaptor/rest_api/property_data_types.rb +15 -0
  27. data/lib/wikidata_adaptor/rest_api/search_item.rb +44 -0
  28. data/lib/wikidata_adaptor/rest_api/search_property.rb +44 -0
  29. data/lib/wikidata_adaptor/rest_api/sitelinks.rb +59 -0
  30. data/lib/wikidata_adaptor/rest_api/statements.rb +153 -0
  31. data/lib/wikidata_adaptor/rest_api.rb +32 -0
  32. data/lib/wikidata_adaptor/test_helpers/rest_api/aliases.rb +229 -0
  33. data/lib/wikidata_adaptor/test_helpers/rest_api/descriptions.rb +308 -0
  34. data/lib/wikidata_adaptor/test_helpers/rest_api/items.rb +213 -0
  35. data/lib/wikidata_adaptor/test_helpers/rest_api/labels.rb +302 -0
  36. data/lib/wikidata_adaptor/test_helpers/rest_api/open_api_document.rb +29 -0
  37. data/lib/wikidata_adaptor/test_helpers/rest_api/properties.rb +233 -0
  38. data/lib/wikidata_adaptor/test_helpers/rest_api/property_data_types.rb +23 -0
  39. data/lib/wikidata_adaptor/test_helpers/rest_api/search_item.rb +118 -0
  40. data/lib/wikidata_adaptor/test_helpers/rest_api/search_property.rb +118 -0
  41. data/lib/wikidata_adaptor/test_helpers/rest_api/sitelinks.rb +143 -0
  42. data/lib/wikidata_adaptor/test_helpers/rest_api/statements.rb +475 -0
  43. data/lib/wikidata_adaptor/test_helpers/rest_api/support/support.rb +310 -0
  44. data/lib/wikidata_adaptor/test_helpers/rest_api.rb +89 -0
  45. data/lib/wikidata_adaptor/version.rb +6 -0
  46. data/lib/wikidata_adaptor.rb +28 -0
  47. data/sig/wikidata_adaptor.rbs +4 -0
  48. metadata +106 -0
@@ -0,0 +1,118 @@
1
+ # frozen_string_literal: true
2
+
3
+ module WikidataAdaptor
4
+ module TestHelpers
5
+ module RestApi
6
+ # WebMock stubs for Wikibase REST API item search endpoints
7
+ module SearchItem
8
+ ########################################
9
+ # GET /v0/search/items
10
+ ########################################
11
+ def stub_search_items(query, lang, limit: 10, offset: 0, response_body: nil)
12
+ stub_rest_api_request(
13
+ :get,
14
+ "/v0/search/items",
15
+ with: {
16
+ query: {
17
+ q: query,
18
+ lang: lang,
19
+ limit: limit,
20
+ offset: offset
21
+ }
22
+ },
23
+ response_body: response_body || {
24
+ results: [
25
+ {
26
+ id: "Q123",
27
+ "display-label": {
28
+ language: "en",
29
+ value: "potato"
30
+ },
31
+ description: {
32
+ language: "en",
33
+ value: "staple food"
34
+ },
35
+ match: {
36
+ type: "label",
37
+ language: "en",
38
+ text: "potato"
39
+ }
40
+ },
41
+ {
42
+ id: "Q234",
43
+ "display-label": {
44
+ language: "en",
45
+ value: "potato"
46
+ },
47
+ description: {
48
+ language: "en",
49
+ value: "species of plant"
50
+ },
51
+ match: {
52
+ type: "label",
53
+ language: "en",
54
+ text: "potato"
55
+ }
56
+ }
57
+ ]
58
+ }
59
+ )
60
+ end
61
+
62
+ #########################################
63
+ # GET /v0/suggest/items
64
+ #########################################
65
+ def stub_suggest_items(query, lang, limit: 10, offset: 0, response_body: nil)
66
+ stub_rest_api_request(
67
+ :get,
68
+ "/v0/suggest/items",
69
+ with: {
70
+ query: {
71
+ q: query,
72
+ lang: lang,
73
+ limit: limit,
74
+ offset: offset
75
+ }
76
+ },
77
+ response_body: response_body || {
78
+ results: [
79
+ {
80
+ id: "Q456",
81
+ "display-label": {
82
+ language: "en",
83
+ value: "drinking water"
84
+ },
85
+ description: {
86
+ language: "en",
87
+ value: "water safe for consumption"
88
+ },
89
+ match: {
90
+ type: "alias",
91
+ language: "en",
92
+ text: "potable water"
93
+ }
94
+ },
95
+ {
96
+ id: "Q123",
97
+ "display-label": {
98
+ language: "en",
99
+ value: "potato"
100
+ },
101
+ description: {
102
+ language: "en",
103
+ value: "staple food"
104
+ },
105
+ match: {
106
+ type: "label",
107
+ language: "en",
108
+ text: "potato"
109
+ }
110
+ }
111
+ ]
112
+ }
113
+ )
114
+ end
115
+ end
116
+ end
117
+ end
118
+ end
@@ -0,0 +1,118 @@
1
+ # frozen_string_literal: true
2
+
3
+ module WikidataAdaptor
4
+ module TestHelpers
5
+ module RestApi
6
+ # WebMock stubs for Wikibase REST API property search endpoints
7
+ module SearchProperty
8
+ ########################################
9
+ # GET /v0/search/properties
10
+ ########################################
11
+ def stub_search_properties(query, lang, limit: 10, offset: 0, response_body: nil)
12
+ stub_rest_api_request(
13
+ :get,
14
+ "/v0/search/properties",
15
+ with: {
16
+ query: {
17
+ q: query,
18
+ lang: lang,
19
+ limit: limit,
20
+ offset: offset
21
+ }
22
+ },
23
+ response_body: response_body || {
24
+ results: [
25
+ {
26
+ id: "P123",
27
+ "display-label": {
28
+ language: "en",
29
+ value: "taxon name"
30
+ },
31
+ description: {
32
+ language: "en",
33
+ value: "scientific name of a taxon"
34
+ },
35
+ match: {
36
+ type: "label",
37
+ language: "en",
38
+ text: "taxon name"
39
+ }
40
+ },
41
+ {
42
+ id: "P234",
43
+ "display-label": {
44
+ language: "en",
45
+ value: "taxon rank"
46
+ },
47
+ description: {
48
+ language: "en",
49
+ value: "level in a taxonomic hierarchy"
50
+ },
51
+ match: {
52
+ type: "label",
53
+ language: "en",
54
+ text: "taxon rank"
55
+ }
56
+ }
57
+ ]
58
+ }
59
+ )
60
+ end
61
+
62
+ #########################################
63
+ # GET /v0/suggest/properties
64
+ #########################################
65
+ def stub_suggest_properties(query, lang, limit: 10, offset: 0, response_body: nil)
66
+ stub_rest_api_request(
67
+ :get,
68
+ "/v0/suggest/properties",
69
+ with: {
70
+ query: {
71
+ q: query,
72
+ lang: lang,
73
+ limit: limit,
74
+ offset: offset
75
+ }
76
+ },
77
+ response_body: response_body || {
78
+ results: [
79
+ {
80
+ id: "P123",
81
+ "display-label": {
82
+ language: "en",
83
+ value: "taxon name"
84
+ },
85
+ description: {
86
+ language: "en",
87
+ value: "scientific name of a taxon"
88
+ },
89
+ match: {
90
+ type: "label",
91
+ language: "en",
92
+ text: "taxon name"
93
+ }
94
+ },
95
+ {
96
+ id: "P234",
97
+ "display-label": {
98
+ language: "en",
99
+ value: "taxon rank"
100
+ },
101
+ description: {
102
+ language: "en",
103
+ value: "level in a taxonomic hierarchy"
104
+ },
105
+ match: {
106
+ type: "label",
107
+ language: "en",
108
+ text: "taxon rank"
109
+ }
110
+ }
111
+ ]
112
+ }
113
+ )
114
+ end
115
+ end
116
+ end
117
+ end
118
+ end
@@ -0,0 +1,143 @@
1
+ # frozen_string_literal: true
2
+
3
+ module WikidataAdaptor
4
+ module TestHelpers
5
+ module RestApi
6
+ # WebMock stubs for Wikibase REST API sitelinks endpoints
7
+ module Sitelinks
8
+ ########################################
9
+ # GET /v1/entities/items/:item_id/sitelinks
10
+ ########################################
11
+ def stub_get_item_sitelinks(item_id, response_body = nil)
12
+ stub_rest_api_request(
13
+ :get,
14
+ "/v1/entities/items/#{item_id}/sitelinks",
15
+ response_body: response_body || {
16
+ enwiki: {
17
+ title: "Douglas Adams",
18
+ badges: [],
19
+ url: "https://en.wikipedia.org/wiki/Douglas_Adams"
20
+ },
21
+ frwiki: {
22
+ title: "Douglas Adams",
23
+ badges: [],
24
+ url: "https://fr.wikipedia.org/wiki/Douglas_Adams"
25
+ }
26
+ }
27
+ )
28
+ end
29
+
30
+ #####################################################
31
+ # GET /v1/entities/items/:item_id/sitelinks/:site_id
32
+ #####################################################
33
+ def stub_get_item_sitelink(item_id, site_id, response_body = nil)
34
+ stub_rest_api_request(
35
+ :get,
36
+ "/v1/entities/items/#{item_id}/sitelinks/#{site_id}",
37
+ response_body: response_body || {
38
+ title: "Douglas Adams",
39
+ badges: [],
40
+ url: "https://en.wikipedia.org/wiki/Douglas_Adams"
41
+ }
42
+ )
43
+ end
44
+
45
+ #####################################################
46
+ # PUT /v1/entities/items/:item_id/sitelinks/:site_id
47
+ #####################################################
48
+ def stub_put_item_sitelink(item_id, site_id, payload, response_body: nil)
49
+ stub_rest_api_request(
50
+ :put,
51
+ "/v1/entities/items/#{item_id}/sitelinks/#{site_id}",
52
+ with: { body: payload.to_json },
53
+ response_body: response_body || {
54
+ title: "Douglas Adams",
55
+ badges: [],
56
+ url: "https://en.wikipedia.org/wiki/Douglas_Adams"
57
+ }
58
+ )
59
+ end
60
+
61
+ # Stub PUT item sitelink request returning 500 error
62
+ #
63
+ # @param item_id [String] The item ID
64
+ # @param site_id [String] The site ID
65
+ # @param payload [Hash] The request payload
66
+ #
67
+ # @return [WebMock::RequestStub]
68
+ def stub_put_item_sitelink_unexpected_error(item_id, site_id, payload)
69
+ stub_rest_api_request(
70
+ :put,
71
+ "/v1/entities/items/#{item_id}/sitelinks/#{site_id}",
72
+ response_status: 500,
73
+ with: { body: payload.to_json },
74
+ response_body: { code: "unexpected-error", message: "Unexpected Error" }
75
+ )
76
+ end
77
+
78
+ #############################################
79
+ # PATCH /v1/entities/items/:item_id/sitelinks
80
+ #############################################
81
+ def stub_patch_item_sitelinks(item_id, payload, response_body: nil)
82
+ stub_rest_api_request(
83
+ :patch,
84
+ "/v1/entities/items/#{item_id}/sitelinks",
85
+ with: { body: payload.to_json },
86
+ response_body: response_body || {
87
+ enwiki: {
88
+ title: "Douglas Adams",
89
+ badges: [],
90
+ url: "https://en.wikipedia.org/wiki/Douglas_Adams"
91
+ }
92
+ }
93
+ )
94
+ end
95
+
96
+ # Stub PATCH item sitelinks request returning 500 error
97
+ #
98
+ # @param item_id [String] The item ID
99
+ # @param payload [Hash] The request payload
100
+ #
101
+ # @return [WebMock::RequestStub]
102
+ def stub_patch_item_sitelinks_unexpected_error(item_id, payload)
103
+ stub_rest_api_request(
104
+ :patch,
105
+ "/v1/entities/items/#{item_id}/sitelinks",
106
+ response_status: 500,
107
+ with: { body: payload.to_json },
108
+ response_body: { code: "unexpected-error", message: "Unexpected Error" }
109
+ )
110
+ end
111
+
112
+ ########################################################
113
+ # DELETE /v1/entities/items/:item_id/sitelinks/:site_id
114
+ ########################################################
115
+ def stub_delete_item_sitelink(item_id, site_id, payload, response_body: "Sitelink deleted")
116
+ stub_rest_api_request(
117
+ :delete,
118
+ "/v1/entities/items/#{item_id}/sitelinks/#{site_id}",
119
+ with: { body: payload.to_json },
120
+ response_body: response_body
121
+ )
122
+ end
123
+
124
+ # Stub DELETE item sitelink request returning 500 error
125
+ #
126
+ # @param item_id [String] The item ID
127
+ # @param site_id [String] The site ID
128
+ # @param payload [Hash] The request payload
129
+ #
130
+ # @return [WebMock::RequestStub]
131
+ def stub_delete_item_sitelink_unexpected_error(item_id, site_id, payload)
132
+ stub_rest_api_request(
133
+ :delete,
134
+ "/v1/entities/items/#{item_id}/sitelinks/#{site_id}",
135
+ response_status: 500,
136
+ with: { body: payload.to_json },
137
+ response_body: { code: "unexpected-error", message: "Unexpected Error" }
138
+ )
139
+ end
140
+ end
141
+ end
142
+ end
143
+ end