wikidata-client 0.0.2 → 0.0.3

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 574fa6611ad2c28edfe22c33ef380ac5126f6b0e
4
- data.tar.gz: 629b49700bb84e330bbd798d0a98acb3c034aada
3
+ metadata.gz: 3a47b99cc065919cae23f6814ef438317834ef88
4
+ data.tar.gz: 15c43966bb2829da222915cf79b62ec2f6b8aa92
5
5
  SHA512:
6
- metadata.gz: 0d23c328efba521a691be46048e82f8fe7912683f130583dc4297057ae3b106a395cf37c56005580eccda19160cbfbeae399d820af16327ef85923d6721b0e1a
7
- data.tar.gz: 09de214a928f2886b2d4eaffc75199ac01b16325434f052752066db31528ce58f34a08b3dac72dc0ed2aa22b7e6a8535d30fb466c2663c673268733472a270b8
6
+ metadata.gz: 850765921f85b991bd8c55eeef67c456ee0b95b4a547c1e77f6f419ce8c4be1dd7e63fb83252ff2bb5ee82010ecaad4a22271cac2283ddc9c7b3f3ca5bebdb43
7
+ data.tar.gz: 0acedc3ef7a2c35f9191a2721c3e19e12459838f9eaadb9a46b3e85f40d54f0c0cebd6c10c4d0b1149be5fb982ca4e2c870946898488c5b51a157e0671e84c2c
data/.travis.yml CHANGED
@@ -2,6 +2,8 @@ language: ruby
2
2
  rvm:
3
3
  - 2.0.0
4
4
  - 2.1.0
5
+ - ruby-head
6
+ - jruby-head
5
7
  addons:
6
8
  code_climate:
7
9
  repo_token: 743f972ae03be14575c4cda0bf254af861a9a788527267015c5a8d487f43c371
data/CHANGELOG.md ADDED
@@ -0,0 +1,10 @@
1
+ # Changelog
2
+
3
+ ## 0.0.3
4
+
5
+ - Jruby support
6
+ - Searching by title/id without results should not return an empty item
7
+
8
+ ## 0.0.2
9
+
10
+ - Various fixes
data/Gemfile.lock CHANGED
@@ -1,11 +1,11 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- wikidata-client (0.0.2)
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.1', require: 'wikidata'`
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 [patron](https://github.com/toland/patron)
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 |c|
28
- c.client_options = {
29
- request: {
30
- open_timeout: 2,
31
- timeout: 9
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
  ```
@@ -26,10 +26,10 @@ module Wikidata
26
26
  end
27
27
 
28
28
  def api
29
- Faraday.new({url: Wikidata.settings.api.url}.merge(Wikidata.client_options)) do |faraday|
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.adapter :patron
32
+ Wikidata.faraday.call faraday
33
33
  end
34
34
  end
35
35
  end
@@ -1,14 +1,14 @@
1
1
  module Wikidata
2
2
  class Config
3
3
  class << self
4
- attr_accessor :client_options, :settings, :mapping
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
- @client_options = {}
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.to_datetime..::Time::at(to).utc.to_datetime)
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
@@ -25,7 +25,7 @@ module Wikidata
25
25
 
26
26
  def raw_results
27
27
  return [] if empty?
28
- @raw.body['entities'].values
28
+ @raw.body['entities'].values.reject{|r| r['missing'] }
29
29
  end
30
30
  end
31
31
  end
@@ -1,3 +1,3 @@
1
1
  module Wikidata
2
- VERSION = "0.0.2".freeze
2
+ VERSION = "0.0.3".freeze
3
3
  end
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 client_options
16
- Config.client_options
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
@@ -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
@@ -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.client_options = {
7
- request: {
8
- open_timeout: 10,
9
- timeout: 10
10
- }
11
- }
15
+ c.faraday = builder
12
16
  end
13
- Wikidata.client_options.should eq({
14
- request: {
15
- open_timeout: 10,
16
- timeout: 10
17
- }
18
- })
17
+ Wikidata.faraday.should be builder
19
18
  end
20
19
  end
@@ -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("patron", "~> 0.4")
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.2
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-01 00:00:00.000000000 Z
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: patron
42
+ name: excon
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
45
  - - "~>"
46
46
  - !ruby/object:Gem::Version
47
- version: '0.4'
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.4'
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