mediawiki_api-wikidata 0.0.1 → 0.0.2

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
- ZmU1ZmNjZWI2OGQ0Njc3OWU5MzA2NTQwM2JjYmE0NjExMzhkNjVkYg==
4
+ MzQzYTUzZTM1ZTAxZGRlMWFiZDc0ODYwNWZkZWZlMjBmOTQ4ZWUzYg==
5
5
  data.tar.gz: !binary |-
6
- NGNhYzBmMjNmZTc4ODBiN2RjMzdjMTZlZmQ1NmFlNWZmMTkzZjUyZQ==
6
+ YTEzNjNiZTBkOWE4ZGFjNjQzZTJlMmY4ZWI2ZjlmY2Q2MTZjYWI5ZQ==
7
7
  !binary "U0hBNTEy":
8
8
  metadata.gz: !binary |-
9
- YmEzZmYyNjJiNjQwMmZkOGU3N2NhZWMwMDg2ODc1NjhkNWQ4NzJkZTM4ZjBm
10
- YTc2ZTI4MTI2ODc0OWRlYzQyNmQ0NTkyMDMzNTQ5NGY5MzcyN2VhMmIzOGZi
11
- MWYzODUzNThhN2ZiYzI4YmYxYjE5YTE4NWI1Y2U0NTI0YjgwN2E=
9
+ OTFkMzM3MTk5NDViY2MwZmQzNjc5OTA0ODdkM2FiNTg2OWRkZGNkYmYzM2E2
10
+ NjEyNTIyZTQ5N2IwNDE5YTlkOGRiYmZhZTcwNTQwZWUxMmMwNDBiZGY0YTk1
11
+ OGJlY2Q5OGZmN2VjZThjMWEwNjRmYmNmYjVkYTBlZWJmN2Q4M2Y=
12
12
  data.tar.gz: !binary |-
13
- MjA4MGU4MDk0OTE5YmViMzZmOGU1OWRhMGY2ZWUzNTAyNTkyMDg5MzcyMmNl
14
- ZTUzZjY5NTVjNDZiZDI4NjI1ZDQ4NjFhMTI1ZDkzMTZhYzc0NzQ0ZTQ2ZGI1
15
- NDRhZmRkMTY5MDM5YjVjMTlmY2E1MmI1YjE4MzkxODRhNTA5NTU=
13
+ MTNjZGU0NWQ3YTgxYWMzZDEwYmZmZTRkZDdkZWIwNDY2MmMyMWQzYzE0OTZi
14
+ NjI0M2M5ZDJjNDFmYjljMzE3YWE0OTBhYTkzY2FjZTk4YzY4NmFmZWU5ZTky
15
+ MmFiNmM4ZTE0ZmVjZGRmYThlY2UzZGZhODE3MzE5YWU5YWQ4YWU=
data/README.md CHANGED
@@ -31,6 +31,15 @@ wikidata_client.create_entity "data" #create a new item specified by "data"
31
31
 
32
32
  ## Release notes
33
33
 
34
+ ### 0.0.2 (2014-10-09)
35
+
36
+ - support adding sitelinks
37
+ - support changing sitelinks
38
+ - support removing sitelinks
39
+ - support checking for existing sitelinks
40
+ - provide separate methods for creating items and properties
41
+ - removed custom edit summaries
42
+
34
43
  ### 0.0.1 (2014-09-29)
35
44
 
36
45
  - Initial version
@@ -0,0 +1,10 @@
1
+ module MediawikiApi
2
+ module Wikidata
3
+ class WikidataApiError < ApiError
4
+
5
+ end
6
+
7
+ class EntityIdentifierMismatchError < StandardError
8
+ end
9
+ end
10
+ end
@@ -1,5 +1,5 @@
1
1
  module MediawikiApi
2
2
  module Wikidata
3
- VERSION = "0.0.1"
3
+ VERSION = "0.0.2"
4
4
  end
5
5
  end
@@ -2,13 +2,52 @@
2
2
  # License:: GNU GPL v2+
3
3
 
4
4
  require "mediawiki_api/wikidata/version"
5
+ require "mediawiki_api/wikidata/exceptions"
5
6
 
6
7
  module MediawikiApi
7
8
  module Wikidata
8
9
  class WikidataClient < Client
9
10
 
10
- def create_entity(data, type = "item")
11
- action(:wbeditentity, token_type: "edit", new: type, data: data, summary:"Created entity using mediawiki_api/wikidata gem")
11
+ def create_entity(entity_data, type)
12
+ action(:wbeditentity, token_type: "edit", new: type, data: entity_data)
13
+ end
14
+
15
+ def create_item(item_data)
16
+ create_entity(item_data, "item")
17
+ end
18
+
19
+ def create_property(property_data)
20
+ create_entity(property_data, "property")
21
+ end
22
+
23
+ def set_sitelink(entity_identifier, sitelink_site_id, sitelink_title = nil, badges = nil)
24
+ params = { token_type: "edit", linksite: sitelink_site_id, linktitle: sitelink_title, badges: badges}
25
+ action(:wbsetsitelink, params.merge(parse_entity_identifier(entity_identifier)))
26
+ end
27
+
28
+ def add_sitelink(entity_identifier, sitelink_site_id, sitelink_title, badges = nil)
29
+ set_sitelink(entity_identifier, sitelink_site_id, sitelink_title, badges)
30
+ end
31
+
32
+ def remove_sitelink(entity_identifier, sitelink_site_id)
33
+ set_sitelink(entity_identifier, sitelink_site_id)
34
+ end
35
+
36
+ def sitelink_exists?(site_id, title)
37
+ resp = action(:wbgetentities, token_type: "edit", sites: [site_id], titles: [title] )
38
+ !resp.data["entities"]["-1"]
39
+ end
40
+
41
+ private
42
+
43
+ def parse_entity_identifier(identifier)
44
+ if identifier.is_a?(::Hash)
45
+ { site: identifier[:site_id], title: identifier[:title] }
46
+ elsif identifier.is_a?(String)
47
+ { id: identifier }
48
+ else
49
+ raise EntityIdentifierMismatchError, "Either entity id or site id and page title need to be set to identify the entity."
50
+ end
12
51
  end
13
52
 
14
53
  end
@@ -12,14 +12,115 @@ describe MediawikiApi::Wikidata::WikidataClient do
12
12
  describe "#create_entity" do
13
13
  subject { client.create_entity(data, type) }
14
14
 
15
- let(:data) { '{"labels":{"en":{"language":"en","value":"test_label"}},"descriptions":{"en":{"language":"en","value":"test_description"}}}' }
15
+ let(:data) { '{"labels":{"en":{"language":"en","value":"test_label"}},
16
+ "descriptions":{"en":{"language":"en","value":"test_description"}}}' }
16
17
  let(:type) { "item" }
17
- let(:summary) { "Created entity using mediawiki_api/wikidata gem" }
18
18
  let(:response) { {} }
19
19
 
20
20
  before do
21
21
  stub_token_request(:edit)
22
- @edit_request = stub_action_request(:wbeditentity, data: data, new: type, summary: summary).
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(:edit)
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(:edit)
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(:edit)
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) { nil }
96
+ let(:response) { {} }
97
+
98
+ before do
99
+ stub_token_request(:edit)
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) { nil }
118
+ let(:response) { {} }
119
+
120
+ before do
121
+ stub_token_request(:edit)
122
+ @edit_request = stub_action_request(:wbsetsitelink, id: "Q1234", linksite: sitelink_site_id,
123
+ linktitle: sitelink_title, badges: badges).
23
124
  to_return(body: response.to_json)
24
125
  end
25
126
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mediawiki_api-wikidata
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
  - Tobias Gritschacher
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-09-29 00:00:00.000000000 Z
11
+ date: 2014-10-09 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: mediawiki_api
@@ -134,6 +134,7 @@ files:
134
134
  - LICENCE
135
135
  - README.md
136
136
  - lib/mediawiki_api/wikidata.rb
137
+ - lib/mediawiki_api/wikidata/exceptions.rb
137
138
  - lib/mediawiki_api/wikidata/version.rb
138
139
  - lib/mediawiki_api/wikidata/wikidata_client.rb
139
140
  - mediawiki_api-wikidata.gemspec