zeit 0.0.2 → 0.0.3
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +3 -0
- data/Gemfile.lock +12 -1
- data/README.md +4 -9
- data/lib/zeit.rb +1 -0
- data/lib/zeit/api.rb +14 -8
- data/lib/zeit/resources/series.rb +2 -2
- data/lib/zeit/version.rb +1 -1
- data/spec/resources/author_spec.rb +1 -1
- data/spec/resources/client_spec.rb +2 -2
- data/spec/resources/content_spec.rb +5 -5
- data/spec/resources/department_spec.rb +3 -3
- data/spec/resources/keyword_spec.rb +3 -3
- data/spec/resources/product_spec.rb +47 -48
- data/spec/resources/series_spec.rb +8 -7
- data/spec/spec_helper.rb +1 -1
- data/spec/support/shared_examples_for_resources.rb +3 -4
- data/zeit.gemspec +2 -1
- metadata +20 -4
data/.gitignore
CHANGED
data/Gemfile.lock
CHANGED
@@ -1,8 +1,9 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
zeit (0.0.
|
4
|
+
zeit (0.0.3)
|
5
5
|
faraday
|
6
|
+
faraday_middleware
|
6
7
|
|
7
8
|
GEM
|
8
9
|
remote: https://rubygems.org/
|
@@ -12,6 +13,8 @@ GEM
|
|
12
13
|
fakeweb (1.3.0)
|
13
14
|
faraday (0.8.4)
|
14
15
|
multipart-post (~> 1.1)
|
16
|
+
faraday_middleware (0.9.0)
|
17
|
+
faraday (>= 0.7.4, < 0.9)
|
15
18
|
guard (1.5.4)
|
16
19
|
listen (>= 0.4.2)
|
17
20
|
lumberjack (>= 1.0.2)
|
@@ -21,6 +24,7 @@ GEM
|
|
21
24
|
guard (>= 1.1)
|
22
25
|
rspec (~> 2.11)
|
23
26
|
json (1.7.5)
|
27
|
+
json (1.7.5-java)
|
24
28
|
listen (0.6.0)
|
25
29
|
lumberjack (1.0.2)
|
26
30
|
method_source (0.8.1)
|
@@ -29,6 +33,11 @@ GEM
|
|
29
33
|
coderay (~> 1.0.5)
|
30
34
|
method_source (~> 0.8)
|
31
35
|
slop (~> 3.3.1)
|
36
|
+
pry (0.9.10-java)
|
37
|
+
coderay (~> 1.0.5)
|
38
|
+
method_source (~> 0.8)
|
39
|
+
slop (~> 3.3.1)
|
40
|
+
spoon (~> 0.0)
|
32
41
|
rake (10.0.2)
|
33
42
|
rb-fsevent (0.9.2)
|
34
43
|
rspec (2.12.0)
|
@@ -40,11 +49,13 @@ GEM
|
|
40
49
|
diff-lcs (~> 1.1.3)
|
41
50
|
rspec-mocks (2.12.0)
|
42
51
|
slop (3.3.3)
|
52
|
+
spoon (0.0.1)
|
43
53
|
thor (0.16.0)
|
44
54
|
vcr (2.3.0)
|
45
55
|
yard (0.8.3)
|
46
56
|
|
47
57
|
PLATFORMS
|
58
|
+
java
|
48
59
|
ruby
|
49
60
|
|
50
61
|
DEPENDENCIES
|
data/README.md
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
# Zeit
|
2
2
|
|
3
|
-
This gem is a ruby client for the Zeit.de API (http://developer.zeit.de/).
|
3
|
+
This gem is a ruby 1.9+ client for the Zeit.de API (http://developer.zeit.de/).
|
4
4
|
|
5
5
|
The german newspaper "Die Zeit" recently announced a so called "content
|
6
6
|
API" to access their large collection of printed and online articles of
|
@@ -37,15 +37,11 @@ Or install it yourself as:
|
|
37
37
|
|
38
38
|
# author
|
39
39
|
result = zeit.author.find '*Schmidt*'
|
40
|
-
|
41
|
-
data = JSON.parse(result.body)
|
42
|
-
data['matches'].inspect
|
40
|
+
result['matches'].inspect
|
43
41
|
|
44
42
|
# content
|
45
43
|
result = zeit.content.find '*Software*', :limit => 200, :offset => 100
|
46
|
-
|
47
|
-
data = JSON.parse(result.body)
|
48
|
-
data['matches'].inspect
|
44
|
+
result['matches'].inspect
|
49
45
|
|
50
46
|
# department
|
51
47
|
result = zeit.department.find '*internet*'
|
@@ -63,7 +59,6 @@ Or install it yourself as:
|
|
63
59
|
|
64
60
|
# client
|
65
61
|
result = zeit.client.get
|
66
|
-
data = JSON.parse(result.body)
|
67
62
|
# => {"reset"=>1353785293,
|
68
63
|
# "name"=>"my name",
|
69
64
|
# "quota"=>10000,
|
@@ -87,4 +82,4 @@ see LICENSE.txt
|
|
87
82
|
|
88
83
|
## Copyright
|
89
84
|
|
90
|
-
2012 Roland Moriz, https://roland.io/
|
85
|
+
2012 Roland Moriz, https://roland.io/
|
data/lib/zeit.rb
CHANGED
data/lib/zeit/api.rb
CHANGED
@@ -6,19 +6,13 @@ module Zeit
|
|
6
6
|
@debug = params[:debug]
|
7
7
|
@base_url = params[:base_url] || 'http://api.zeit.de/'
|
8
8
|
@faraday_adapter = params[:faraday_adapter] || Faraday.default_adapter
|
9
|
+
@faraday = params[:faraday] || default_faraday
|
9
10
|
|
10
11
|
raise ArgumentError, ':api_key missing' unless @api_key
|
11
|
-
|
12
|
-
connection
|
13
12
|
end
|
14
13
|
|
15
14
|
def connection
|
16
|
-
@
|
17
|
-
faraday.use Zeit::AuthenticationMiddleware, @api_key
|
18
|
-
faraday.request :url_encoded
|
19
|
-
faraday.response(:logger) if @debug
|
20
|
-
faraday.adapter @faraday_adapter
|
21
|
-
end
|
15
|
+
@faraday
|
22
16
|
end
|
23
17
|
|
24
18
|
def author(opts = {})
|
@@ -48,5 +42,17 @@ module Zeit
|
|
48
42
|
def series(opts = {})
|
49
43
|
Zeit::Resources::Series.new(connection, opts)
|
50
44
|
end
|
45
|
+
|
46
|
+
private
|
47
|
+
|
48
|
+
def default_faraday
|
49
|
+
Faraday.new(:url => @base_url) do |faraday|
|
50
|
+
faraday.use Zeit::AuthenticationMiddleware, @api_key
|
51
|
+
faraday.request :url_encoded
|
52
|
+
faraday.response :json
|
53
|
+
faraday.response(:logger) if @debug
|
54
|
+
faraday.adapter @faraday_adapter
|
55
|
+
end
|
56
|
+
end
|
51
57
|
end
|
52
58
|
end
|
@@ -3,13 +3,13 @@ module Zeit
|
|
3
3
|
class Series < Base
|
4
4
|
def find(q, opts = {})
|
5
5
|
opts[:q] = q
|
6
|
-
@connection.get '/
|
6
|
+
@connection.get '/series' do |query|
|
7
7
|
apply_params(query, opts)
|
8
8
|
end
|
9
9
|
end
|
10
10
|
|
11
11
|
def get(id, opts = {})
|
12
|
-
@connection.get "/
|
12
|
+
@connection.get "/series/#{id}" do |query|
|
13
13
|
apply_params(query, opts)
|
14
14
|
end
|
15
15
|
end
|
data/lib/zeit/version.rb
CHANGED
@@ -11,8 +11,8 @@ describe Zeit::Resources::Client, :vcr do
|
|
11
11
|
it_behaves_like 'a successful response'
|
12
12
|
|
13
13
|
it 'should return information about the api usage of the current account' do
|
14
|
-
|
15
|
-
|
14
|
+
json.has_key? 'requests'
|
15
|
+
json.has_key? 'tier'
|
16
16
|
end
|
17
17
|
end
|
18
18
|
|
@@ -33,12 +33,12 @@ describe Zeit::Resources::Content, :vcr do
|
|
33
33
|
|
34
34
|
context 'when authorized' do
|
35
35
|
it 'should have some important values' do
|
36
|
-
|
36
|
+
json.has_key? 'title'
|
37
37
|
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
38
|
+
json['creators'].should be_instance_of(Array)
|
39
|
+
json['relations'].should be_instance_of(Array)
|
40
|
+
json['keywords'].should be_instance_of(Array)
|
41
|
+
json['categories'].should be_instance_of(Array)
|
42
42
|
end
|
43
43
|
end
|
44
44
|
|
@@ -35,9 +35,9 @@ describe Zeit::Resources::Department, :vcr do
|
|
35
35
|
it_behaves_like 'a successful response with some matches'
|
36
36
|
|
37
37
|
it 'should have some important values' do
|
38
|
-
|
39
|
-
|
40
|
-
|
38
|
+
json.has_key? 'uri'
|
39
|
+
json.has_key? 'value'
|
40
|
+
json.has_key? 'href'
|
41
41
|
end
|
42
42
|
end
|
43
43
|
|
@@ -35,9 +35,9 @@ describe Zeit::Resources::Keyword, :vcr do
|
|
35
35
|
it_behaves_like 'a successful response with some matches'
|
36
36
|
|
37
37
|
it 'should have some important values' do
|
38
|
-
|
39
|
-
|
40
|
-
|
38
|
+
json.has_key? 'uri'
|
39
|
+
json.has_key? 'value'
|
40
|
+
json.has_key? 'href'
|
41
41
|
end
|
42
42
|
end
|
43
43
|
|
@@ -1,52 +1,51 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
3
|
describe Zeit::Resources::Product, :vcr do
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
#end
|
4
|
+
it_behaves_like 'a resource'
|
5
|
+
|
6
|
+
describe '#find' do
|
7
|
+
context 'with a simple query' do
|
8
|
+
it_behaves_like 'a resource response' do
|
9
|
+
let(:query) { 'ZEIT*' }
|
10
|
+
subject { Zeit::Resources::Product.new(api_connection).find(query) }
|
11
|
+
|
12
|
+
context 'when authorized' do
|
13
|
+
it_behaves_like 'a successful response with some matches'
|
14
|
+
|
15
|
+
it_behaves_like 'all matches have the required keys' do
|
16
|
+
let(:keys) { %w(uri) }
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
context 'when unauthorized' do
|
21
|
+
it_behaves_like 'an unauthorized request'
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
describe '#get' do
|
28
|
+
it_behaves_like 'a resource response' do
|
29
|
+
context 'with an valid product id' do
|
30
|
+
let(:id) { 'zede' }
|
31
|
+
|
32
|
+
subject { Zeit::Resources::Product.new(api_connection).get(id) }
|
33
|
+
|
34
|
+
context 'when authorized' do
|
35
|
+
it_behaves_like 'a successful response with some matches'
|
36
|
+
|
37
|
+
it 'should have some important values' do
|
38
|
+
json.has_key? 'uri'
|
39
|
+
json.has_key? 'value'
|
40
|
+
json.has_key? 'href'
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
context 'when unauthorized' do
|
45
|
+
it_behaves_like 'an unauthorized request'
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
end
|
50
|
+
end
|
52
51
|
end
|
@@ -13,7 +13,7 @@ describe Zeit::Resources::Series, :vcr do
|
|
13
13
|
it_behaves_like 'a successful response with some matches'
|
14
14
|
|
15
15
|
it_behaves_like 'all matches have the required keys' do
|
16
|
-
let(:keys) { %w(uri
|
16
|
+
let(:keys) { %w(uri href) }
|
17
17
|
end
|
18
18
|
end
|
19
19
|
|
@@ -25,10 +25,12 @@ describe Zeit::Resources::Series, :vcr do
|
|
25
25
|
end
|
26
26
|
|
27
27
|
describe '#get' do
|
28
|
-
|
28
|
+
# FIXME still broken at api.zeit.de :(
|
29
|
+
#
|
30
|
+
#
|
29
31
|
#it_behaves_like 'a resource response' do
|
30
32
|
# context 'with an valid series id' do
|
31
|
-
# let(:id) { '
|
33
|
+
# let(:id) { 'ausprobiert' }
|
32
34
|
|
33
35
|
# subject { Zeit::Resources::Series.new(api_connection).get(id) }
|
34
36
|
|
@@ -36,9 +38,9 @@ describe Zeit::Resources::Series, :vcr do
|
|
36
38
|
# it_behaves_like 'a successful response with some matches'
|
37
39
|
|
38
40
|
# it 'should have some important values' do
|
39
|
-
#
|
40
|
-
#
|
41
|
-
#
|
41
|
+
# json.has_key? 'uri'
|
42
|
+
# json.has_key? 'value'
|
43
|
+
# json.has_key? 'href'
|
42
44
|
# end
|
43
45
|
# end
|
44
46
|
|
@@ -46,7 +48,6 @@ describe Zeit::Resources::Series, :vcr do
|
|
46
48
|
# it_behaves_like 'an unauthorized request'
|
47
49
|
# end
|
48
50
|
# end
|
49
|
-
|
50
51
|
#end
|
51
52
|
end
|
52
53
|
end
|
data/spec/spec_helper.rb
CHANGED
@@ -9,7 +9,6 @@ end
|
|
9
9
|
shared_examples 'a resource response' do
|
10
10
|
let(:json) { subject.body }
|
11
11
|
let(:api_connection) { authorized_api_client.connection }
|
12
|
-
let(:parsed_json) { JSON.parse(json) }
|
13
12
|
end
|
14
13
|
|
15
14
|
shared_examples 'a successful response' do
|
@@ -20,7 +19,7 @@ shared_examples 'a successful response with some matches' do
|
|
20
19
|
it_behaves_like 'a successful response'
|
21
20
|
|
22
21
|
it 'should return matches' do
|
23
|
-
|
22
|
+
json['matches'].should have_at_least(10).items
|
24
23
|
end
|
25
24
|
end
|
26
25
|
|
@@ -35,7 +34,7 @@ shared_examples 'an error message response' do
|
|
35
34
|
its(:success?) { should be_false }
|
36
35
|
|
37
36
|
it 'should return an error message' do
|
38
|
-
|
37
|
+
json['description'].should_not be_empty
|
39
38
|
end
|
40
39
|
end
|
41
40
|
|
@@ -43,7 +42,7 @@ end
|
|
43
42
|
# FIXME allow new keys
|
44
43
|
shared_examples 'all matches have the required keys' do
|
45
44
|
it 'matches should have at least the basic keys' do
|
46
|
-
|
45
|
+
json['matches'].each do |match|
|
47
46
|
keys.each do |required_key|
|
48
47
|
match.keys.should include(required_key)
|
49
48
|
end
|
data/zeit.gemspec
CHANGED
@@ -10,7 +10,7 @@ Gem::Specification.new do |gem|
|
|
10
10
|
gem.email = ['roland@moriz.de']
|
11
11
|
gem.description = %q{API client for Zeit.de API}
|
12
12
|
gem.summary = %q{API client for Zeit.de API}
|
13
|
-
gem.homepage =
|
13
|
+
gem.homepage = 'http://github.com/rmoriz/zeit'
|
14
14
|
gem.license = 'MIT'
|
15
15
|
|
16
16
|
gem.files = `git ls-files`.split($/).select { |file| file !~ /^spec\/vcr/ }
|
@@ -23,6 +23,7 @@ Gem::Specification.new do |gem|
|
|
23
23
|
end
|
24
24
|
|
25
25
|
gem.add_dependency 'faraday'
|
26
|
+
gem.add_dependency 'faraday_middleware'
|
26
27
|
|
27
28
|
gem.add_development_dependency 'bundler', '~> 1.0'
|
28
29
|
gem.add_development_dependency 'json', '~> 1.7.5'
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: zeit
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.3
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-11-
|
12
|
+
date: 2012-11-27 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: faraday
|
@@ -27,6 +27,22 @@ dependencies:
|
|
27
27
|
- - ! '>='
|
28
28
|
- !ruby/object:Gem::Version
|
29
29
|
version: '0'
|
30
|
+
- !ruby/object:Gem::Dependency
|
31
|
+
name: faraday_middleware
|
32
|
+
requirement: !ruby/object:Gem::Requirement
|
33
|
+
none: false
|
34
|
+
requirements:
|
35
|
+
- - ! '>='
|
36
|
+
- !ruby/object:Gem::Version
|
37
|
+
version: '0'
|
38
|
+
type: :runtime
|
39
|
+
prerelease: false
|
40
|
+
version_requirements: !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
42
|
+
requirements:
|
43
|
+
- - ! '>='
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
version: '0'
|
30
46
|
- !ruby/object:Gem::Dependency
|
31
47
|
name: bundler
|
32
48
|
requirement: !ruby/object:Gem::Requirement
|
@@ -225,7 +241,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
225
241
|
version: '0'
|
226
242
|
segments:
|
227
243
|
- 0
|
228
|
-
hash:
|
244
|
+
hash: 2203375178907227553
|
229
245
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
230
246
|
none: false
|
231
247
|
requirements:
|
@@ -234,7 +250,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
234
250
|
version: '0'
|
235
251
|
segments:
|
236
252
|
- 0
|
237
|
-
hash:
|
253
|
+
hash: 2203375178907227553
|
238
254
|
requirements: []
|
239
255
|
rubyforge_project:
|
240
256
|
rubygems_version: 1.8.23
|