zeit 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.
data/.gitignore CHANGED
@@ -22,3 +22,6 @@ pkg
22
22
 
23
23
  ## PROJECT::SPECIFIC
24
24
  report.html
25
+
26
+ .rbenv-version
27
+ .rbenv-vars
@@ -1,8 +1,9 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- zeit (0.0.2)
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/
@@ -1,4 +1,5 @@
1
1
  require 'faraday'
2
+ require 'faraday_middleware'
2
3
 
3
4
  require 'zeit/version'
4
5
  require 'zeit/resources/base'
@@ -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
- @connection ||= Faraday.new(:url => @base_url) do |faraday|
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 '/product' do |query|
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 "/product/#{id}" do |query|
12
+ @connection.get "/series/#{id}" do |query|
13
13
  apply_params(query, opts)
14
14
  end
15
15
  end
@@ -1,3 +1,3 @@
1
1
  module Zeit
2
- VERSION = "0.0.2"
2
+ VERSION = '0.0.3'
3
3
  end
@@ -35,7 +35,7 @@ describe Zeit::Resources::Author, :vcr do
35
35
  end
36
36
 
37
37
  it 'should have the right data type' do
38
- parsed_json['type'].should eql('author')
38
+ json['type'].should eql('author')
39
39
  end
40
40
  end
41
41
 
@@ -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
- parsed_json.has_key? 'requests'
15
- parsed_json.has_key? 'tier'
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
- parsed_json.has_key? 'title'
36
+ json.has_key? 'title'
37
37
 
38
- parsed_json['creators'].should be_instance_of(Array)
39
- parsed_json['relations'].should be_instance_of(Array)
40
- parsed_json['keywords'].should be_instance_of(Array)
41
- parsed_json['categories'].should be_instance_of(Array)
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
- parsed_json.has_key? 'uri'
39
- parsed_json.has_key? 'value'
40
- parsed_json.has_key? 'href'
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
- parsed_json.has_key? 'uri'
39
- parsed_json.has_key? 'value'
40
- parsed_json.has_key? 'href'
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
- pending "Zeit.de broken (product) :-("
5
- #it_behaves_like 'a resource'
6
-
7
- #describe '#find' do
8
- # context 'with a simple query' do
9
- # it_behaves_like 'a resource response' do
10
- # let(:query) { 'ZEIT*' }
11
- # subject { Zeit::Resources::Product.new(api_connection).find(query) }
12
-
13
- # context 'when authorized' do
14
- # it_behaves_like 'a successful response with some matches'
15
-
16
- # it_behaves_like 'all matches have the required keys' do
17
- # let(:keys) { %w(uri) }
18
- # end
19
- # end
20
-
21
- # context 'when unauthorized' do
22
- # it_behaves_like 'an unauthorized request'
23
- # end
24
- # end
25
- # end
26
- #end
27
-
28
- #describe '#get' do
29
- # it_behaves_like 'a resource response' do
30
- # context 'with an valid product id' do
31
- # let(:id) { 'tpi' }
32
-
33
- # subject { Zeit::Resources::Product.new(api_connection).get(id) }
34
-
35
- # context 'when authorized' do
36
- # it_behaves_like 'a successful response with some matches'
37
-
38
- # it 'should have some important values' do
39
- # parsed_json.has_key? 'uri'
40
- # parsed_json.has_key? 'value'
41
- # parsed_json.has_key? 'href'
42
- # end
43
- # end
44
-
45
- # context 'when unauthorized' do
46
- # it_behaves_like 'an unauthorized request'
47
- # end
48
- # end
49
-
50
- # end
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 value) }
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
- pending "Zeit.de currently broken (/series/id) :-("
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) { 'die-einzelkaempfer' }
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
- # parsed_json.has_key? 'uri'
40
- # parsed_json.has_key? 'value'
41
- # parsed_json.has_key? 'href'
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
@@ -12,7 +12,7 @@ Dir["./spec/support/**/*.rb"].sort.each {|f| require f}
12
12
 
13
13
  def authorized_api_client
14
14
  key = ENV['ZEIT_API_KEY'] || 'working'
15
- Zeit::API.new :api_key => key
15
+ Zeit::API.new :api_key => key, :debug => true
16
16
  end
17
17
 
18
18
  def unauthorized_api_client
@@ -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
- parsed_json['matches'].should have_at_least(10).items
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
- parsed_json['description'].should_not be_empty
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
- parsed_json['matches'].each do |match|
45
+ json['matches'].each do |match|
47
46
  keys.each do |required_key|
48
47
  match.keys.should include(required_key)
49
48
  end
@@ -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 = "http://github.com/rmoriz/zeit"
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.2
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-25 00:00:00.000000000 Z
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: -4197996778355535057
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: -4197996778355535057
253
+ hash: 2203375178907227553
238
254
  requirements: []
239
255
  rubyforge_project:
240
256
  rubygems_version: 1.8.23