mediawiki_api-wikidata 0.2.1 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,174 +1,246 @@
1
- require 'spec_helper'
2
- require "webmock/rspec"
3
- require "support/request_helpers"
4
-
5
- describe MediawikiApi::Wikidata::WikidataClient do
6
- include MediawikiApi::Wikidata::RequestHelpers
7
-
8
- let(:client) { MediawikiApi::Wikidata::WikidataClient.new(api_url) }
9
-
10
- subject { client }
11
-
12
- describe "#create_entity" do
13
- subject { client.create_entity(data, type) }
14
-
15
- let(:data) { '{"labels":{"en":{"language":"en","value":"test_label"}},
16
- "descriptions":{"en":{"language":"en","value":"test_description"}}}' }
17
- let(:type) { "item" }
18
- let(:response) { {} }
19
-
20
- before do
21
- stub_token_request(:csrf)
22
- @edit_request = stub_action_request(:wbeditentity, data: data, new: type).
23
- to_return(body: response.to_json)
24
- end
25
-
26
- it "makes the right request" do
27
- subject
28
- expect(@edit_request).to have_been_requested
29
- end
30
- end
31
-
32
- describe "#create_item" do
33
- subject { client.create_item(data) }
34
-
35
- let(:data) { '{"labels":{"en":{"language":"en","value":"test_label"}},
36
- "descriptions":{"en":{"language":"en","value":"test_description"}}}' }
37
- let(:response) { {} }
38
-
39
- before do
40
- stub_token_request(:csrf)
41
- @edit_request = stub_action_request(:wbeditentity, data: data, new: "item").
42
- to_return(body: response.to_json)
43
- end
44
-
45
- it "makes the right request" do
46
- subject
47
- expect(@edit_request).to have_been_requested
48
- end
49
- end
50
-
51
- describe "#create_property" do
52
- subject { client.create_property(data) }
53
-
54
- let(:data) { '{"labels":{"en":{"language":"en","value":"test_label"}},
55
- "descriptions":{"en":{"language":"en","value":"test_description"}},"datatype":"string"}' }
56
- let(:response) { {} }
57
-
58
- before do
59
- stub_token_request(:csrf)
60
- @edit_request = stub_action_request(:wbeditentity, data: data, new: "property").
61
- to_return(body: response.to_json)
62
- end
63
-
64
- it "makes the right request" do
65
- subject
66
- expect(@edit_request).to have_been_requested
67
- end
68
- end
69
-
70
- describe "#create_property" do
71
- subject { client.create_property(data) }
72
-
73
- let(:data) { '{"labels":{"en":{"language":"en","value":"test_label"}},
74
- "descriptions":{"en":{"language":"en","value":"test_description"}},"datatype":"string"}' }
75
- let(:response) { {} }
76
-
77
- before do
78
- stub_token_request(:csrf)
79
- @edit_request = stub_action_request(:wbeditentity, data: data, new: "property").
80
- to_return(body: response.to_json)
81
- end
82
-
83
- it "makes the right request" do
84
- subject
85
- expect(@edit_request).to have_been_requested
86
- end
87
- end
88
-
89
- describe "#set_sitelink (item identified by site/title)" do
90
- subject { client.set_sitelink(entity_identifier, sitelink_site_id, sitelink_title, badges) }
91
-
92
- let(:entity_identifier) { {site_id: "dewiki", title: "Berlin"} }
93
- let(:sitelink_site_id) { "itwiki" }
94
- let(:sitelink_title) { "Berlino" }
95
- let(:badges) { true }
96
- let(:response) { {} }
97
-
98
- before do
99
- stub_token_request(:csrf)
100
- @edit_request = stub_action_request(:wbsetsitelink, site: "dewiki", title: "Berlin", linksite: sitelink_site_id,
101
- linktitle: sitelink_title, badges: badges).
102
- to_return(body: response.to_json)
103
- end
104
-
105
- it "makes the right request" do
106
- subject
107
- expect(@edit_request).to have_been_requested
108
- end
109
- end
110
-
111
- describe "#set_sitelink (item identified by ID)" do
112
- subject { client.set_sitelink(entity_identifier, sitelink_site_id, sitelink_title, badges) }
113
-
114
- let(:entity_identifier) { "Q1234" }
115
- let(:sitelink_site_id) { "itwiki" }
116
- let(:sitelink_title) { "Berlino" }
117
- let(:badges) { true }
118
- let(:response) { {} }
119
-
120
- before do
121
- stub_token_request(:csrf)
122
- @edit_request = stub_action_request(:wbsetsitelink, id: "Q1234", linksite: sitelink_site_id,
123
- linktitle: sitelink_title, badges: badges).
124
- to_return(body: response.to_json)
125
- end
126
-
127
- it "makes the right request" do
128
- subject
129
- expect(@edit_request).to have_been_requested
130
- end
131
- end
132
-
133
- describe "#create_claim" do
134
- subject { client.create_claim(entity_id, snaktype, property_id, value) }
135
-
136
- let(:entity_id) { "Q1234" }
137
- let(:snaktype) { "value" }
138
- let(:property_id) { "P1234" }
139
- let(:value) { '"stringtest"' }
140
- let(:response) { {} }
141
-
142
- before do
143
- stub_token_request(:csrf)
144
- @edit_request = stub_action_request(:wbcreateclaim, entity: entity_id, snaktype: snaktype, property: property_id, value: value).
145
- to_return(body: response.to_json)
146
- end
147
-
148
- it "makes the right request" do
149
- subject
150
- expect(@edit_request).to have_been_requested
151
- end
152
- end
153
- describe "#search_entities" do
154
- subject { client.search_entities(search, language, entity_type, limit, continue) }
155
-
156
- let(:search) { "test" }
157
- let(:language) { "en" }
158
- let(:entity_type) { "item" }
159
- let(:limit) { 10 }
160
- let(:continue) { "" }
161
- let(:response) { {} }
162
-
163
- before do
164
- @edit_request = stub_action_request_without_token(:wbsearchentities, search: search, language: language, type: entity_type,
165
- limit: limit, continue: continue).
166
- to_return(body: response.to_json)
167
- end
168
-
169
- it "makes the right request" do
170
- subject
171
- expect(@edit_request).to have_been_requested
172
- end
173
- end
174
- end
1
+ require 'spec_helper'
2
+ require "webmock/rspec"
3
+ require "support/request_helpers"
4
+
5
+ describe MediawikiApi::Wikidata::WikidataClient do
6
+ include MediawikiApi::Wikidata::RequestHelpers
7
+
8
+ let(:client) { MediawikiApi::Wikidata::WikidataClient.new(api_url) }
9
+
10
+ subject { client }
11
+
12
+ describe "#create_entity" do
13
+ subject { client.create_entity(data, type) }
14
+
15
+ let(:data) { '{"labels":{"en":{"language":"en","value":"test_label"}},
16
+ "descriptions":{"en":{"language":"en","value":"test_description"}}}' }
17
+ let(:type) { "item" }
18
+ let(:response) { {} }
19
+
20
+ before do
21
+ stub_token_request(:csrf)
22
+ @edit_request = stub_action_request(:wbeditentity, data: data, new: type).
23
+ to_return(body: response.to_json)
24
+ end
25
+
26
+ it "makes the right request" do
27
+ subject
28
+ expect(@edit_request).to have_been_requested
29
+ end
30
+ end
31
+
32
+ describe "#create_item" do
33
+ subject { client.create_item(data) }
34
+
35
+ let(:data) { '{"labels":{"en":{"language":"en","value":"test_label"}},
36
+ "descriptions":{"en":{"language":"en","value":"test_description"}}}' }
37
+ let(:response) { {} }
38
+
39
+ before do
40
+ stub_token_request(:csrf)
41
+ @edit_request = stub_action_request(:wbeditentity, data: data, new: "item").
42
+ to_return(body: response.to_json)
43
+ end
44
+
45
+ it "makes the right request" do
46
+ subject
47
+ expect(@edit_request).to have_been_requested
48
+ end
49
+ end
50
+
51
+ describe "#create_property" do
52
+ subject { client.create_property(data) }
53
+
54
+ let(:data) { '{"labels":{"en":{"language":"en","value":"test_label"}},
55
+ "descriptions":{"en":{"language":"en","value":"test_description"}},"datatype":"string"}' }
56
+ let(:response) { {} }
57
+
58
+ before do
59
+ stub_token_request(:csrf)
60
+ @edit_request = stub_action_request(:wbeditentity, data: data, new: "property").
61
+ to_return(body: response.to_json)
62
+ end
63
+
64
+ it "makes the right request" do
65
+ subject
66
+ expect(@edit_request).to have_been_requested
67
+ end
68
+ end
69
+
70
+ describe "#create_property" do
71
+ subject { client.create_property(data) }
72
+
73
+ let(:data) { '{"labels":{"en":{"language":"en","value":"test_label"}},
74
+ "descriptions":{"en":{"language":"en","value":"test_description"}},"datatype":"string"}' }
75
+ let(:response) { {} }
76
+
77
+ before do
78
+ stub_token_request(:csrf)
79
+ @edit_request = stub_action_request(:wbeditentity, data: data, new: "property").
80
+ to_return(body: response.to_json)
81
+ end
82
+
83
+ it "makes the right request" do
84
+ subject
85
+ expect(@edit_request).to have_been_requested
86
+ end
87
+ end
88
+
89
+ describe "#set_sitelink (item identified by site/title)" do
90
+ subject { client.set_sitelink(entity_identifier, sitelink_site_id, sitelink_title, badges) }
91
+
92
+ let(:entity_identifier) { {site_id: "dewiki", title: "Berlin"} }
93
+ let(:sitelink_site_id) { "itwiki" }
94
+ let(:sitelink_title) { "Berlino" }
95
+ let(:badges) { true }
96
+ let(:response) { {} }
97
+
98
+ before do
99
+ stub_token_request(:csrf)
100
+ @edit_request = stub_action_request(:wbsetsitelink, site: "dewiki", title: "Berlin", linksite: sitelink_site_id,
101
+ linktitle: sitelink_title, badges: badges).
102
+ to_return(body: response.to_json)
103
+ end
104
+
105
+ it "makes the right request" do
106
+ subject
107
+ expect(@edit_request).to have_been_requested
108
+ end
109
+ end
110
+
111
+ describe "#set_sitelink (item identified by ID)" do
112
+ subject { client.set_sitelink(entity_identifier, sitelink_site_id, sitelink_title, badges) }
113
+
114
+ let(:entity_identifier) { "Q1234" }
115
+ let(:sitelink_site_id) { "itwiki" }
116
+ let(:sitelink_title) { "Berlino" }
117
+ let(:badges) { true }
118
+ let(:response) { {} }
119
+
120
+ before do
121
+ stub_token_request(:csrf)
122
+ @edit_request = stub_action_request(:wbsetsitelink, id: "Q1234", linksite: sitelink_site_id,
123
+ linktitle: sitelink_title, badges: badges).
124
+ to_return(body: response.to_json)
125
+ end
126
+
127
+ it "makes the right request" do
128
+ subject
129
+ expect(@edit_request).to have_been_requested
130
+ end
131
+ end
132
+
133
+ describe "#create_claim" do
134
+ subject { client.create_claim(entity_id, snaktype, property_id, value) }
135
+
136
+ let(:entity_id) { "Q1234" }
137
+ let(:snaktype) { "value" }
138
+ let(:property_id) { "P1234" }
139
+ let(:value) { '"stringtest"' }
140
+ let(:response) { {} }
141
+
142
+ before do
143
+ stub_token_request(:csrf)
144
+ @edit_request = stub_action_request(:wbcreateclaim, entity: entity_id, snaktype: snaktype, property: property_id, value: value).
145
+ to_return(body: response.to_json)
146
+ end
147
+
148
+ it "makes the right request" do
149
+ subject
150
+ expect(@edit_request).to have_been_requested
151
+ end
152
+ end
153
+ describe "#search_entities" do
154
+ subject { client.search_entities(search, language, entity_type, limit, continue) }
155
+
156
+ let(:search) { "test" }
157
+ let(:language) { "en" }
158
+ let(:entity_type) { "item" }
159
+ let(:limit) { 10 }
160
+ let(:continue) { "" }
161
+ let(:response) { {} }
162
+
163
+ before do
164
+ @edit_request = stub_action_request_without_token(:wbsearchentities, search: search, language: language, type: entity_type,
165
+ limit: limit, continue: continue).
166
+ to_return(body: response.to_json)
167
+ end
168
+
169
+ it "makes the right request" do
170
+ subject
171
+ expect(@edit_request).to have_been_requested
172
+ end
173
+ end
174
+ describe "#get_entities" do
175
+ subject { client.get_entities(entity_ids) }
176
+
177
+ let(:entity_ids) { ["Q1234","Q234"] }
178
+ let(:response) { {} }
179
+
180
+ before do
181
+ @edit_request = stub_action_request_without_token(:wbgetentities, ids: entity_ids.join("|")).
182
+ to_return(body: response.to_json)
183
+ end
184
+
185
+ it "makes the right request" do
186
+ subject
187
+ expect(@edit_request).to have_been_requested
188
+ end
189
+ end
190
+ describe "#get_entities_by_titles" do
191
+ subject { client.get_entities_by_titles(titles, site_ids) }
192
+
193
+ let(:titles) { "mediawiki" }
194
+ let(:site_ids) { ["jawiki"] }
195
+ let(:response) { {} }
196
+
197
+ before do
198
+ @edit_request = stub_action_request_without_token(:wbgetentities, titles: titles, sites: site_ids.join("|")).
199
+ to_return(body: response.to_json)
200
+ end
201
+
202
+ it "makes the right request" do
203
+ subject
204
+ expect(@edit_request).to have_been_requested
205
+ end
206
+ end
207
+ describe "#set_qualifier" do
208
+ subject { client.set_qualifier(claim_id, property_id, value) }
209
+
210
+ let(:claim_id) { "Q2$4554c0f4-47b2-1cd9-2db9-aa270064c9f3" }
211
+ let(:snaktype) { "value" }
212
+ let(:property_id) { "P1234" }
213
+ let(:value) { "stringtest".to_json }
214
+ let(:response) { {} }
215
+
216
+ before do
217
+ stub_token_request(:csrf)
218
+ @edit_request = stub_action_request(:wbsetqualifier, claim: claim_id, snaktype: snaktype, property: property_id, value: value).
219
+ to_return(body: response.to_json)
220
+ end
221
+
222
+ it "makes the right request" do
223
+ subject
224
+ expect(@edit_request).to have_been_requested
225
+ end
226
+ end
227
+ describe "#set_reference" do
228
+ subject { client.set_reference(statement_id, snaks) }
229
+
230
+ let(:statement_id) { "Q76$D4FDE516-F20C-4154-ADCE-7C5B609DFDFF" }
231
+ let(:property_id) { "P1234" }
232
+ let(:snaks) {{property_id=>[{"snaktype"=>"value", "property"=>property_id, "datavalue"=>"stringtest"}]}.to_json}
233
+ let(:response) { {} }
234
+
235
+ before do
236
+ stub_token_request(:csrf)
237
+ @edit_request = stub_action_request(:wbsetreference, statement: statement_id, snaks: snaks).
238
+ to_return(body: response.to_json)
239
+ end
240
+
241
+ it "makes the right request" do
242
+ subject
243
+ expect(@edit_request).to have_been_requested
244
+ end
245
+ end
246
+ end
metadata CHANGED
@@ -1,123 +1,123 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mediawiki_api-wikidata
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.1
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tobias Gritschacher
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-05-27 00:00:00.000000000 Z
11
+ date: 2021-06-08 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: mediawiki_api
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - ~>
17
+ - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: 0.6.0
19
+ version: 0.7.1
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
- - - ~>
24
+ - - "~>"
25
25
  - !ruby/object:Gem::Version
26
- version: 0.6.0
26
+ version: 0.7.1
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: bundler
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
- - - ~>
31
+ - - "~>"
32
32
  - !ruby/object:Gem::Version
33
33
  version: '1.3'
34
34
  type: :development
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
- - - ~>
38
+ - - "~>"
39
39
  - !ruby/object:Gem::Version
40
40
  version: '1.3'
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: rake
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
- - - ~>
45
+ - - "~>"
46
46
  - !ruby/object:Gem::Version
47
47
  version: '0'
48
48
  type: :development
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
- - - ~>
52
+ - - "~>"
53
53
  - !ruby/object:Gem::Version
54
54
  version: '0'
55
55
  - !ruby/object:Gem::Dependency
56
56
  name: rspec
57
57
  requirement: !ruby/object:Gem::Requirement
58
58
  requirements:
59
- - - ~>
59
+ - - "~>"
60
60
  - !ruby/object:Gem::Version
61
61
  version: '3.0'
62
- - - '>='
62
+ - - ">="
63
63
  - !ruby/object:Gem::Version
64
64
  version: 3.0.0
65
65
  type: :development
66
66
  prerelease: false
67
67
  version_requirements: !ruby/object:Gem::Requirement
68
68
  requirements:
69
- - - ~>
69
+ - - "~>"
70
70
  - !ruby/object:Gem::Version
71
71
  version: '3.0'
72
- - - '>='
72
+ - - ">="
73
73
  - !ruby/object:Gem::Version
74
74
  version: 3.0.0
75
75
  - !ruby/object:Gem::Dependency
76
76
  name: webmock
77
77
  requirement: !ruby/object:Gem::Requirement
78
78
  requirements:
79
- - - ~>
79
+ - - "~>"
80
80
  - !ruby/object:Gem::Version
81
81
  version: '1.17'
82
- - - '>='
82
+ - - ">="
83
83
  - !ruby/object:Gem::Version
84
84
  version: 1.17.2
85
85
  type: :development
86
86
  prerelease: false
87
87
  version_requirements: !ruby/object:Gem::Requirement
88
88
  requirements:
89
- - - ~>
89
+ - - "~>"
90
90
  - !ruby/object:Gem::Version
91
91
  version: '1.17'
92
- - - '>='
92
+ - - ">="
93
93
  - !ruby/object:Gem::Version
94
94
  version: 1.17.2
95
95
  - !ruby/object:Gem::Dependency
96
96
  name: redcarpet
97
97
  requirement: !ruby/object:Gem::Requirement
98
98
  requirements:
99
- - - '>='
99
+ - - ">="
100
100
  - !ruby/object:Gem::Version
101
101
  version: '0'
102
102
  type: :development
103
103
  prerelease: false
104
104
  version_requirements: !ruby/object:Gem::Requirement
105
105
  requirements:
106
- - - '>='
106
+ - - ">="
107
107
  - !ruby/object:Gem::Version
108
108
  version: '0'
109
109
  - !ruby/object:Gem::Dependency
110
110
  name: yard
111
111
  requirement: !ruby/object:Gem::Requirement
112
112
  requirements:
113
- - - '>='
113
+ - - ">="
114
114
  - !ruby/object:Gem::Version
115
115
  version: '0'
116
116
  type: :development
117
117
  prerelease: false
118
118
  version_requirements: !ruby/object:Gem::Requirement
119
119
  requirements:
120
- - - '>='
120
+ - - ">="
121
121
  - !ruby/object:Gem::Version
122
122
  version: '0'
123
123
  description: A library for interacting with the Wikidata API from Ruby.
@@ -127,9 +127,9 @@ executables: []
127
127
  extensions: []
128
128
  extra_rdoc_files: []
129
129
  files:
130
- - .gitignore
131
- - .rspec
132
- - .travis.yml
130
+ - ".gitignore"
131
+ - ".rspec"
132
+ - ".travis.yml"
133
133
  - Gemfile
134
134
  - LICENCE
135
135
  - README.md
@@ -151,17 +151,16 @@ require_paths:
151
151
  - lib
152
152
  required_ruby_version: !ruby/object:Gem::Requirement
153
153
  requirements:
154
- - - '>='
154
+ - - ">="
155
155
  - !ruby/object:Gem::Version
156
156
  version: '0'
157
157
  required_rubygems_version: !ruby/object:Gem::Requirement
158
158
  requirements:
159
- - - '>='
159
+ - - ">="
160
160
  - !ruby/object:Gem::Version
161
161
  version: '0'
162
162
  requirements: []
163
- rubyforge_project:
164
- rubygems_version: 2.0.14.1
163
+ rubygems_version: 3.1.2
165
164
  signing_key:
166
165
  specification_version: 4
167
166
  summary: Extends the MediaWiki API Gem.