wikidata-client 0.0.2 → 0.0.3
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 +4 -4
- data/.travis.yml +2 -0
- data/CHANGELOG.md +10 -0
- data/Gemfile.lock +12 -3
- data/README.md +9 -7
- data/lib/wikidata/client.rb +2 -2
- data/lib/wikidata/config.rb +2 -2
- data/lib/wikidata/property/time.rb +7 -1
- data/lib/wikidata/response.rb +1 -1
- data/lib/wikidata/version.rb +1 -1
- data/lib/wikidata.rb +3 -3
- data/spec/fixtures/vcr/Wikidata_Item/_find_/should_return_nil_if_item_title_not_found.yml +54 -0
- data/spec/wikidata/item_spec.rb +4 -0
- data/spec/wikidata_spec.rb +11 -12
- data/wikidata-client.gemspec +1 -1
- metadata +8 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 3a47b99cc065919cae23f6814ef438317834ef88
|
4
|
+
data.tar.gz: 15c43966bb2829da222915cf79b62ec2f6b8aa92
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 850765921f85b991bd8c55eeef67c456ee0b95b4a547c1e77f6f419ce8c4be1dd7e63fb83252ff2bb5ee82010ecaad4a22271cac2283ddc9c7b3f3ca5bebdb43
|
7
|
+
data.tar.gz: 0acedc3ef7a2c35f9191a2721c3e19e12459838f9eaadb9a46b3e85f40d54f0c0cebd6c10c4d0b1149be5fb982ca4e2c870946898488c5b51a157e0671e84c2c
|
data/.travis.yml
CHANGED
data/CHANGELOG.md
ADDED
data/Gemfile.lock
CHANGED
@@ -1,11 +1,11 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
wikidata-client (0.0.
|
4
|
+
wikidata-client (0.0.3)
|
5
|
+
excon (~> 0.40)
|
5
6
|
faraday (~> 0.9)
|
6
7
|
faraday_middleware (~> 0.9)
|
7
8
|
hashie (~> 3.3)
|
8
|
-
patron (~> 0.4)
|
9
9
|
|
10
10
|
GEM
|
11
11
|
remote: https://rubygems.org/
|
@@ -18,19 +18,25 @@ GEM
|
|
18
18
|
safe_yaml (~> 1.0.0)
|
19
19
|
diff-lcs (1.2.5)
|
20
20
|
docile (1.1.5)
|
21
|
+
excon (0.40.0)
|
21
22
|
faraday (0.9.0)
|
22
23
|
multipart-post (>= 1.2, < 3)
|
23
24
|
faraday_middleware (0.9.1)
|
24
25
|
faraday (>= 0.7.4, < 0.10)
|
26
|
+
ffi (1.9.5-java)
|
25
27
|
hashie (3.3.1)
|
26
28
|
method_source (0.8.2)
|
27
29
|
multi_json (1.10.1)
|
28
30
|
multipart-post (2.0.0)
|
29
|
-
patron (0.4.18)
|
30
31
|
pry (0.10.1)
|
31
32
|
coderay (~> 1.1.0)
|
32
33
|
method_source (~> 0.8.1)
|
33
34
|
slop (~> 3.4)
|
35
|
+
pry (0.10.1-java)
|
36
|
+
coderay (~> 1.1.0)
|
37
|
+
method_source (~> 0.8.1)
|
38
|
+
slop (~> 3.4)
|
39
|
+
spoon (~> 0.0)
|
34
40
|
rake (10.3.2)
|
35
41
|
rspec (3.1.0)
|
36
42
|
rspec-core (~> 3.1.0)
|
@@ -51,12 +57,15 @@ GEM
|
|
51
57
|
simplecov-html (~> 0.8.0)
|
52
58
|
simplecov-html (0.8.0)
|
53
59
|
slop (3.6.0)
|
60
|
+
spoon (0.0.4)
|
61
|
+
ffi
|
54
62
|
vcr (2.9.3)
|
55
63
|
webmock (1.19.0)
|
56
64
|
addressable (>= 2.3.6)
|
57
65
|
crack (>= 0.3.2)
|
58
66
|
|
59
67
|
PLATFORMS
|
68
|
+
java
|
60
69
|
ruby
|
61
70
|
|
62
71
|
DEPENDENCIES
|
data/README.md
CHANGED
@@ -14,22 +14,24 @@ It provide an easy way to search for wikidata pages and read their contents.
|
|
14
14
|
|
15
15
|
## Installation
|
16
16
|
|
17
|
-
In bunler: `gem 'wikidata-client', '~> 0.0.
|
17
|
+
In bunler: `gem 'wikidata-client', '~> 0.0.3', require: 'wikidata'`
|
18
18
|
|
19
19
|
Otherwise: `gem install wikidata-client`
|
20
20
|
|
21
21
|
|
22
22
|
## Configuration
|
23
23
|
|
24
|
-
Only one thing is configurable for now, the HTTP client
|
24
|
+
Only one thing is configurable for now, the HTTP client and its options, via
|
25
|
+
[faraday](https://github.com/lostisland/faraday):
|
25
26
|
|
26
27
|
```ruby
|
27
|
-
Wikidata.configure do |
|
28
|
-
|
29
|
-
request
|
30
|
-
|
31
|
-
|
28
|
+
Wikidata.configure do |config|
|
29
|
+
config.faraday = -> (builder) {
|
30
|
+
builder.options[:request] = {
|
31
|
+
timeout: 10,
|
32
|
+
open_timeout: 2
|
32
33
|
}
|
34
|
+
builder.adapter :patron
|
33
35
|
}
|
34
36
|
end
|
35
37
|
```
|
data/lib/wikidata/client.rb
CHANGED
@@ -26,10 +26,10 @@ module Wikidata
|
|
26
26
|
end
|
27
27
|
|
28
28
|
def api
|
29
|
-
Faraday.new(
|
29
|
+
Faraday.new(url: Wikidata.settings.api.url) do |faraday|
|
30
30
|
faraday.request :url_encoded
|
31
31
|
faraday.response :json, content_type: /\bjson$/
|
32
|
-
faraday.
|
32
|
+
Wikidata.faraday.call faraday
|
33
33
|
end
|
34
34
|
end
|
35
35
|
end
|
data/lib/wikidata/config.rb
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
module Wikidata
|
2
2
|
class Config
|
3
3
|
class << self
|
4
|
-
attr_accessor :
|
4
|
+
attr_accessor :faraday, :settings, :mapping
|
5
5
|
|
6
6
|
def configure &block
|
7
7
|
yield self
|
8
8
|
end
|
9
9
|
end
|
10
10
|
|
11
|
-
@
|
11
|
+
@faraday = -> (builder) { builder.adapter :excon }
|
12
12
|
@settings = Hashie::Mash.new(
|
13
13
|
YAML.load_file(
|
14
14
|
File.expand_path('../../../config/settings.yml', __FILE__)
|
@@ -59,7 +59,13 @@ module Wikidata
|
|
59
59
|
to = DateTime.new(min_to_date.year, min_to_date.month, min_to_date.day, 23, 59, 59).to_time.utc.to_i
|
60
60
|
end
|
61
61
|
|
62
|
-
@_range ||= (::Time.at(from).utc
|
62
|
+
@_range ||= (to_datetime ::Time.at(from).utc)..(to_datetime ::Time::at(to).utc)
|
63
|
+
end
|
64
|
+
|
65
|
+
protected
|
66
|
+
|
67
|
+
def to_datetime(t)
|
68
|
+
DateTime.new t.year, t.month, t.day, t.hour, t.min, t.sec
|
63
69
|
end
|
64
70
|
end
|
65
71
|
end
|
data/lib/wikidata/response.rb
CHANGED
data/lib/wikidata/version.rb
CHANGED
data/lib/wikidata.rb
CHANGED
@@ -1,8 +1,8 @@
|
|
1
1
|
require 'faraday'
|
2
2
|
require 'faraday_middleware'
|
3
|
-
require 'patron'
|
4
3
|
require 'hashie'
|
5
4
|
require 'yaml'
|
5
|
+
require 'excon'
|
6
6
|
|
7
7
|
require 'wikidata/config'
|
8
8
|
|
@@ -12,8 +12,8 @@ module Wikidata
|
|
12
12
|
Config.configure &block
|
13
13
|
end
|
14
14
|
|
15
|
-
def
|
16
|
-
Config.
|
15
|
+
def faraday
|
16
|
+
Config.faraday
|
17
17
|
end
|
18
18
|
|
19
19
|
def settings
|
@@ -0,0 +1,54 @@
|
|
1
|
+
---
|
2
|
+
http_interactions:
|
3
|
+
- request:
|
4
|
+
method: get
|
5
|
+
uri: http://www.wikidata.org/w/api.php?action=wbgetentities&format=json&sites=enwiki&titles=THISISNOTAVALIDID
|
6
|
+
body:
|
7
|
+
encoding: US-ASCII
|
8
|
+
string: ''
|
9
|
+
headers:
|
10
|
+
User-Agent:
|
11
|
+
- Faraday v0.9.0
|
12
|
+
Expect:
|
13
|
+
- ''
|
14
|
+
response:
|
15
|
+
status:
|
16
|
+
code: 200
|
17
|
+
message: OK
|
18
|
+
headers:
|
19
|
+
Server:
|
20
|
+
- Apache
|
21
|
+
X-Content-Type-Options:
|
22
|
+
- nosniff
|
23
|
+
Cache-Control:
|
24
|
+
- private
|
25
|
+
X-Frame-Options:
|
26
|
+
- DENY
|
27
|
+
Content-Type:
|
28
|
+
- application/json; charset=utf-8
|
29
|
+
Vary:
|
30
|
+
- Accept-Encoding,X-Use-HHVM
|
31
|
+
X-Varnish:
|
32
|
+
- 2553942657, 3280608010, 2750255307
|
33
|
+
Via:
|
34
|
+
- 1.1 varnish, 1.1 varnish, 1.1 varnish
|
35
|
+
Transfer-Encoding:
|
36
|
+
- chunked
|
37
|
+
Date:
|
38
|
+
- Thu, 02 Oct 2014 16:22:46 GMT
|
39
|
+
Age:
|
40
|
+
- '0'
|
41
|
+
Connection:
|
42
|
+
- keep-alive
|
43
|
+
X-Cache:
|
44
|
+
- cp1066 miss (0), amssq47 miss (0), amssq32 frontend miss (0)
|
45
|
+
X-Analytics:
|
46
|
+
- php=zend
|
47
|
+
Set-Cookie:
|
48
|
+
- GeoIP=FR:Sainte-luce-sur-loire:47.2500:-1.5000:v4; Path=/; Domain=.wikidata.org
|
49
|
+
body:
|
50
|
+
encoding: ASCII-8BIT
|
51
|
+
string: '{"entities":{"-1":{"site":"enwiki","title":"THISISNOTAVALIDID","missing":""}},"success":1}'
|
52
|
+
http_version:
|
53
|
+
recorded_at: Thu, 02 Oct 2014 16:22:46 GMT
|
54
|
+
recorded_with: VCR 2.9.3
|
data/spec/wikidata/item_spec.rb
CHANGED
@@ -12,6 +12,10 @@ describe Wikidata::Item, :vcr do
|
|
12
12
|
Wikidata::Item.find('THISISNOTAVALIDID').should be_nil
|
13
13
|
end
|
14
14
|
|
15
|
+
it 'should return nil if item title not found' do
|
16
|
+
Wikidata::Item.find_by_title('THISISNOTAVALIDID', sites: 'enwiki').should be_nil
|
17
|
+
end
|
18
|
+
|
15
19
|
it 'should find by id' do
|
16
20
|
entity_by_id.should be_kind_of Wikidata::Item
|
17
21
|
end
|
data/spec/wikidata_spec.rb
CHANGED
@@ -1,20 +1,19 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
3
|
describe Wikidata do
|
4
|
+
let(:builder) {
|
5
|
+
-> (builder) {
|
6
|
+
builder.options[:request] = {
|
7
|
+
timeout: 10,
|
8
|
+
open_timeout: 2
|
9
|
+
}
|
10
|
+
builder.use :excon
|
11
|
+
}
|
12
|
+
}
|
4
13
|
it 'should be configurable' do
|
5
14
|
Wikidata.configure do |c|
|
6
|
-
c.
|
7
|
-
request: {
|
8
|
-
open_timeout: 10,
|
9
|
-
timeout: 10
|
10
|
-
}
|
11
|
-
}
|
15
|
+
c.faraday = builder
|
12
16
|
end
|
13
|
-
Wikidata.
|
14
|
-
request: {
|
15
|
-
open_timeout: 10,
|
16
|
-
timeout: 10
|
17
|
-
}
|
18
|
-
})
|
17
|
+
Wikidata.faraday.should be builder
|
19
18
|
end
|
20
19
|
end
|
data/wikidata-client.gemspec
CHANGED
@@ -17,7 +17,7 @@ Gem::Specification.new do |s|
|
|
17
17
|
|
18
18
|
s.add_dependency("faraday", "~> 0.9")
|
19
19
|
s.add_dependency("faraday_middleware", "~> 0.9")
|
20
|
-
s.add_dependency("
|
20
|
+
s.add_dependency("excon", "~> 0.40")
|
21
21
|
s.add_dependency("hashie", "~> 3.3")
|
22
22
|
s.add_development_dependency("rspec", "~> 3.1")
|
23
23
|
s.add_development_dependency("webmock", "~> 1.18")
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: wikidata-client
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Kévin Lacointe
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-10-
|
11
|
+
date: 2014-10-10 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: faraday
|
@@ -39,19 +39,19 @@ dependencies:
|
|
39
39
|
- !ruby/object:Gem::Version
|
40
40
|
version: '0.9'
|
41
41
|
- !ruby/object:Gem::Dependency
|
42
|
-
name:
|
42
|
+
name: excon
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
44
44
|
requirements:
|
45
45
|
- - "~>"
|
46
46
|
- !ruby/object:Gem::Version
|
47
|
-
version: '0.
|
47
|
+
version: '0.40'
|
48
48
|
type: :runtime
|
49
49
|
prerelease: false
|
50
50
|
version_requirements: !ruby/object:Gem::Requirement
|
51
51
|
requirements:
|
52
52
|
- - "~>"
|
53
53
|
- !ruby/object:Gem::Version
|
54
|
-
version: '0.
|
54
|
+
version: '0.40'
|
55
55
|
- !ruby/object:Gem::Dependency
|
56
56
|
name: hashie
|
57
57
|
requirement: !ruby/object:Gem::Requirement
|
@@ -144,6 +144,7 @@ extra_rdoc_files: []
|
|
144
144
|
files:
|
145
145
|
- ".rspec"
|
146
146
|
- ".travis.yml"
|
147
|
+
- CHANGELOG.md
|
147
148
|
- Gemfile
|
148
149
|
- Gemfile.lock
|
149
150
|
- LICENCE
|
@@ -190,6 +191,7 @@ files:
|
|
190
191
|
- spec/fixtures/vcr/Wikidata_Item/_find_/should_find_by_title.yml
|
191
192
|
- spec/fixtures/vcr/Wikidata_Item/_find_/should_find_by_titles.yml
|
192
193
|
- spec/fixtures/vcr/Wikidata_Item/_find_/should_return_nil_if_item_not_found.yml
|
194
|
+
- spec/fixtures/vcr/Wikidata_Item/_find_/should_return_nil_if_item_title_not_found.yml
|
193
195
|
- spec/fixtures/vcr/Wikidata_Item/_search/should_fetch_all_all_items_of_the_collection.yml
|
194
196
|
- spec/fixtures/vcr/Wikidata_Item/_search/should_return_a_response_with_an_empty_array_of_results_if_search_missing.yml
|
195
197
|
- spec/fixtures/vcr/Wikidata_Item/_search/should_return_an_array_of_Wikidata_Item.yml
|
@@ -252,6 +254,7 @@ test_files:
|
|
252
254
|
- spec/fixtures/vcr/Wikidata_Item/_find_/should_find_by_title.yml
|
253
255
|
- spec/fixtures/vcr/Wikidata_Item/_find_/should_find_by_titles.yml
|
254
256
|
- spec/fixtures/vcr/Wikidata_Item/_find_/should_return_nil_if_item_not_found.yml
|
257
|
+
- spec/fixtures/vcr/Wikidata_Item/_find_/should_return_nil_if_item_title_not_found.yml
|
255
258
|
- spec/fixtures/vcr/Wikidata_Item/_search/should_fetch_all_all_items_of_the_collection.yml
|
256
259
|
- spec/fixtures/vcr/Wikidata_Item/_search/should_return_a_response_with_an_empty_array_of_results_if_search_missing.yml
|
257
260
|
- spec/fixtures/vcr/Wikidata_Item/_search/should_return_an_array_of_Wikidata_Item.yml
|