mediawiki_api-wikidata 0.0.2 → 0.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,15 +1,15 @@
1
1
  ---
2
2
  !binary "U0hBMQ==":
3
3
  metadata.gz: !binary |-
4
- MzQzYTUzZTM1ZTAxZGRlMWFiZDc0ODYwNWZkZWZlMjBmOTQ4ZWUzYg==
4
+ MzgwZTA1YmI5NjBlYzk1ODBhYzA2MDE3YWY0ODc0ODE5YTYyNDAxYQ==
5
5
  data.tar.gz: !binary |-
6
- YTEzNjNiZTBkOWE4ZGFjNjQzZTJlMmY4ZWI2ZjlmY2Q2MTZjYWI5ZQ==
6
+ MTVkZTM0ZjQ5ZTI5ZGU1NmIxOTA0MDM0ZDhkOWMwOTBhOGIzMjkwYw==
7
7
  !binary "U0hBNTEy":
8
8
  metadata.gz: !binary |-
9
- OTFkMzM3MTk5NDViY2MwZmQzNjc5OTA0ODdkM2FiNTg2OWRkZGNkYmYzM2E2
10
- NjEyNTIyZTQ5N2IwNDE5YTlkOGRiYmZhZTcwNTQwZWUxMmMwNDBiZGY0YTk1
11
- OGJlY2Q5OGZmN2VjZThjMWEwNjRmYmNmYjVkYTBlZWJmN2Q4M2Y=
9
+ Y2I1MWQ3MGM2MjEwNzJkYjc2MzZhZDBkMDJmNGE5MjE1ZWNkOTQyNjRjODEw
10
+ ODViZjEyZjE4NTU1ZDMwNWYwZThmZjc4OWIzMDEyZmUwN2RhZTE1MWZmOTIw
11
+ NDU0OTZiZGUzZDQ3YmU5MzYyMTFkZjA3MTFlZGM4YWU0OTA5NDA=
12
12
  data.tar.gz: !binary |-
13
- MTNjZGU0NWQ3YTgxYWMzZDEwYmZmZTRkZDdkZWIwNDY2MmMyMWQzYzE0OTZi
14
- NjI0M2M5ZDJjNDFmYjljMzE3YWE0OTBhYTkzY2FjZTk4YzY4NmFmZWU5ZTky
15
- MmFiNmM4ZTE0ZmVjZGRmYThlY2UzZGZhODE3MzE5YWU5YWQ4YWU=
13
+ ODY4NTQ2MjJkYTZlNjU4YzJmNjU4MDI3YWFkYjE0NWQ1MTY4NTE2OTRmYWU2
14
+ MTE4OTYyODUxZjk2N2QzNGM5NjdhYzkzNjAxZDY1NThkZTJlYjdjZTg4NGM5
15
+ ZGZjZjIwZGIyNDEwNzViNDRjMTAwNTY1M2Y4YWY5YzY0ZTliOWQ=
data/README.md CHANGED
@@ -26,11 +26,22 @@ require "mediawiki_api/wikidata"
26
26
 
27
27
  wikidata_client = MediawikiApi::Wikidata::WikidataClient.new "http://127.0.0.1/w/api.php" #instantiate new client
28
28
  wikidata_client.log_in "username", "password" #log in via the API
29
- wikidata_client.create_entity "data" #create a new item specified by "data"
29
+ wikidata_client.create_item "data" #create a new item specified by "data"
30
+ wikidata_client.create_property "data" #create a new property specified by "data"
31
+ wikidata_client.add_sitelink "Q1234", "enwiki", "Berlin" #add a new sitelink enwiki/Berlin to item Q1234
32
+ wikidata_client.remove_sitelink "Q1234", "enwiki" #remove enwiki sitelink from item Q1234
33
+ wikidata_client.sitelink_exists? "enwiki", "Berlin" #returns true if enwiki/Berlin sitelink exists, false otherwise
34
+ wikidata_client.create_claim "Q1234", "value", "P1234", '"test"' #adds claim with property P1234 and value "test" to item Q1234
35
+ wikidata_client.search_entities "test", "en", "item" #searches for items containing the string "test" in their english labels, descriptions and aliases
30
36
  ```
31
37
 
32
38
  ## Release notes
33
39
 
40
+ ### 0.1 (2014-10-09)
41
+ - feature complete for [Wikidata BrowserTests](https://github.com/wmde/WikidataBrowserTests)
42
+ - support creating claims
43
+ - support searching entities
44
+
34
45
  ### 0.0.2 (2014-10-09)
35
46
 
36
47
  - support adding sitelinks
@@ -1,5 +1,5 @@
1
- module MediawikiApi
2
- module Wikidata
3
- VERSION = "0.0.2"
4
- end
5
- end
1
+ module MediawikiApi
2
+ module Wikidata
3
+ VERSION = "0.1"
4
+ end
5
+ end
@@ -34,10 +34,19 @@ module MediawikiApi
34
34
  end
35
35
 
36
36
  def sitelink_exists?(site_id, title)
37
- resp = action(:wbgetentities, token_type: "edit", sites: [site_id], titles: [title] )
37
+ resp = action(:wbgetentities, token_type: false, sites: [site_id], titles: [title] )
38
38
  !resp.data["entities"]["-1"]
39
39
  end
40
40
 
41
+ def search_entities(search, language, entity_type, limit = 10, continue = nil)
42
+ action(:wbsearchentities, token_type: false, search: search, language: language, type: entity_type, limit: limit,
43
+ continue: continue)
44
+ end
45
+
46
+ def create_claim(entity_id, snaktype = "value", property_id, value_data)
47
+ action(:wbcreateclaim, token_type: "edit", entity: entity_id, snaktype: snaktype, property: property_id, value: value_data)
48
+ end
49
+
41
50
  private
42
51
 
43
52
  def parse_entity_identifier(identifier)
@@ -24,6 +24,12 @@ module MediawikiApi::Wikidata::RequestHelpers
24
24
  stub_api_request(method, params.merge(action: action, token: mock_token))
25
25
  end
26
26
 
27
+ def stub_action_request_without_token(action, params = {})
28
+ method = params.delete(:http_method) || :post
29
+
30
+ stub_api_request(method, params.merge(action: action))
31
+ end
32
+
27
33
  def stub_token_request(type, warning = nil)
28
34
  response = { tokens: { "#{type}token" => mock_token } }
29
35
  response[:warnings] = { type => { "*" => [warning] } } unless warning.nil?
@@ -130,4 +130,45 @@ describe MediawikiApi::Wikidata::WikidataClient do
130
130
  end
131
131
  end
132
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(:edit)
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
133
174
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mediawiki_api-wikidata
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: '0.1'
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tobias Gritschacher