zeit 0.0.1pre → 0.0.1pre2
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/Gemfile.lock +1 -1
- data/lib/zeit/api.rb +30 -8
- data/lib/zeit/resources/author.rb +10 -0
- data/lib/zeit/resources/base.rb +15 -4
- data/lib/zeit/resources/client.rb +3 -8
- data/lib/zeit/resources/content.rb +11 -0
- data/lib/zeit/resources/department.rb +11 -0
- data/lib/zeit/resources/keyword.rb +11 -0
- data/lib/zeit/resources/product.rb +11 -0
- data/lib/zeit/resources/series.rb +11 -0
- data/lib/zeit/version.rb +1 -1
- data/spec/api_spec.rb +32 -11
- data/spec/resources/author_spec.rb +46 -5
- data/spec/resources/client_spec.rb +17 -12
- data/spec/resources/content_spec.rb +48 -5
- data/spec/resources/department_spec.rb +47 -5
- data/spec/resources/keyword_spec.rb +46 -5
- data/spec/resources/product_spec.rb +49 -7
- data/spec/resources/series_spec.rb +47 -5
- data/spec/spec_helper.rb +19 -4
- data/spec/support/shared_examples_for_resources.rb +54 -0
- data/spec/support/vcr.rb +8 -0
- data/zeit.gemspec +2 -3
- metadata +7 -3
data/Gemfile.lock
CHANGED
data/lib/zeit/api.rb
CHANGED
@@ -2,28 +2,50 @@ module Zeit
|
|
2
2
|
class API
|
3
3
|
|
4
4
|
def initialize(params = {})
|
5
|
-
@api_key
|
6
|
-
@base_url
|
5
|
+
@api_key = params[:api_key]
|
6
|
+
@base_url = params[:base_url] || 'http://api.zeit.de/'
|
7
|
+
@faraday_adapter = params[:faraday_adapter] || Faraday.default_adapter
|
8
|
+
|
9
|
+
raise ArgumentError, ':api_key missing' unless @api_key
|
7
10
|
|
8
11
|
connection
|
9
12
|
end
|
10
13
|
|
11
14
|
def connection
|
12
15
|
@connection ||= Faraday.new(url: @base_url) do |faraday|
|
13
|
-
#faraday.request :url_encoded
|
14
16
|
faraday.use Zeit::AuthenticationMiddleware, @api_key
|
17
|
+
faraday.request :url_encoded
|
15
18
|
faraday.response :logger
|
16
|
-
faraday.adapter
|
19
|
+
faraday.adapter @faraday_adapter
|
17
20
|
end
|
18
21
|
end
|
19
22
|
|
20
|
-
def author
|
21
|
-
Zeit::Resources::Author.new
|
23
|
+
def author(opts = {})
|
24
|
+
Zeit::Resources::Author.new(connection, opts)
|
25
|
+
end
|
26
|
+
|
27
|
+
def client(opts = {})
|
28
|
+
Zeit::Resources::Client.new(connection, opts)
|
29
|
+
end
|
30
|
+
|
31
|
+
def content(opts = {})
|
32
|
+
Zeit::Resources::Content.new(connection, opts)
|
22
33
|
end
|
23
34
|
|
24
|
-
def
|
25
|
-
Zeit::Resources::
|
35
|
+
def department(opts = {})
|
36
|
+
Zeit::Resources::Department.new(connection, opts)
|
26
37
|
end
|
27
38
|
|
39
|
+
def keyword(opts = {})
|
40
|
+
Zeit::Resources::Keyword.new(connection, opts)
|
41
|
+
end
|
42
|
+
|
43
|
+
def product(opts = {})
|
44
|
+
Zeit::Resources::Product.new(connection, opts)
|
45
|
+
end
|
46
|
+
|
47
|
+
def series(opts = {})
|
48
|
+
Zeit::Resources::Series.new(connection, opts)
|
49
|
+
end
|
28
50
|
end
|
29
51
|
end
|
@@ -1,7 +1,17 @@
|
|
1
1
|
module Zeit
|
2
2
|
module Resources
|
3
3
|
class Author < Base
|
4
|
+
def find(query, opts = {})
|
5
|
+
@connection.get '/author' do |query|
|
6
|
+
apply_params(query, opts)
|
7
|
+
end
|
8
|
+
end
|
4
9
|
|
10
|
+
def get(id, opts = {})
|
11
|
+
@connection.get "/author/#{id}" do |query|
|
12
|
+
apply_params(query, opts)
|
13
|
+
end
|
14
|
+
end
|
5
15
|
end
|
6
16
|
end
|
7
17
|
end
|
data/lib/zeit/resources/base.rb
CHANGED
@@ -6,14 +6,25 @@ module Zeit
|
|
6
6
|
attr_accessor :limit
|
7
7
|
attr_accessor :offset
|
8
8
|
|
9
|
-
def initialize(connection)
|
9
|
+
def initialize(connection, options = {})
|
10
10
|
@connection = connection
|
11
|
+
|
12
|
+
@limit = options[:limit] || 10
|
11
13
|
@fields = []
|
12
14
|
end
|
13
|
-
end
|
14
15
|
|
15
|
-
|
16
|
-
|
16
|
+
private
|
17
|
+
|
18
|
+
def apply_params(query, opts)
|
19
|
+
apply_default_params(query)
|
17
20
|
|
21
|
+
opts.each_pair do |key, value|
|
22
|
+
query.params[key] = value
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
def apply_default_params(query)
|
27
|
+
end
|
28
|
+
end
|
18
29
|
end
|
19
30
|
end
|
@@ -1,16 +1,11 @@
|
|
1
1
|
module Zeit
|
2
2
|
module Resources
|
3
3
|
class Client < Base
|
4
|
-
def
|
5
|
-
|
4
|
+
def get
|
5
|
+
@connection.get '/client'
|
6
6
|
end
|
7
7
|
|
8
|
-
|
9
|
-
@connection.get '/client' do |request|
|
10
|
-
end
|
11
|
-
end
|
12
|
-
|
13
|
-
alias_method :get, :client
|
8
|
+
alias_method :client, :get
|
14
9
|
end
|
15
10
|
end
|
16
11
|
end
|
@@ -1,7 +1,18 @@
|
|
1
1
|
module Zeit
|
2
2
|
module Resources
|
3
3
|
class Content < Base
|
4
|
+
def find(q, opts = {})
|
5
|
+
opts[:q] = q
|
6
|
+
@connection.get '/content' do |query|
|
7
|
+
apply_params(query, opts)
|
8
|
+
end
|
9
|
+
end
|
4
10
|
|
11
|
+
def get(id, opts = {})
|
12
|
+
@connection.get "/content/#{id}" do |query|
|
13
|
+
apply_params(query, opts)
|
14
|
+
end
|
15
|
+
end
|
5
16
|
end
|
6
17
|
end
|
7
18
|
end
|
@@ -1,7 +1,18 @@
|
|
1
1
|
module Zeit
|
2
2
|
module Resources
|
3
3
|
class Department < Base
|
4
|
+
def find(q, opts = {})
|
5
|
+
opts[:q] = q
|
6
|
+
@connection.get '/department' do |query|
|
7
|
+
apply_params(query, opts)
|
8
|
+
end
|
9
|
+
end
|
4
10
|
|
11
|
+
def get(id, opts = {})
|
12
|
+
@connection.get "/department/#{id}" do |query|
|
13
|
+
apply_params(query, opts)
|
14
|
+
end
|
15
|
+
end
|
5
16
|
end
|
6
17
|
end
|
7
18
|
end
|
@@ -1,7 +1,18 @@
|
|
1
1
|
module Zeit
|
2
2
|
module Resources
|
3
3
|
class Keyword < Base
|
4
|
+
def find(q, opts = {})
|
5
|
+
opts[:q] = q
|
6
|
+
@connection.get '/keyword' do |query|
|
7
|
+
apply_params(query, opts)
|
8
|
+
end
|
9
|
+
end
|
4
10
|
|
11
|
+
def get(id, opts = {})
|
12
|
+
@connection.get "/keyword/#{id}" do |query|
|
13
|
+
apply_params(query, opts)
|
14
|
+
end
|
15
|
+
end
|
5
16
|
end
|
6
17
|
end
|
7
18
|
end
|
@@ -1,7 +1,18 @@
|
|
1
1
|
module Zeit
|
2
2
|
module Resources
|
3
3
|
class Product < Base
|
4
|
+
def find(q, opts = {})
|
5
|
+
opts[:q] = q
|
6
|
+
@connection.get '/product' do |query|
|
7
|
+
apply_params(query, opts)
|
8
|
+
end
|
9
|
+
end
|
4
10
|
|
11
|
+
def get(id, opts = {})
|
12
|
+
@connection.get "/product/#{id}" do |query|
|
13
|
+
apply_params(query, opts)
|
14
|
+
end
|
15
|
+
end
|
5
16
|
end
|
6
17
|
end
|
7
18
|
end
|
@@ -1,7 +1,18 @@
|
|
1
1
|
module Zeit
|
2
2
|
module Resources
|
3
3
|
class Series < Base
|
4
|
+
def find(q, opts = {})
|
5
|
+
opts[:q] = q
|
6
|
+
@connection.get '/product' do |query|
|
7
|
+
apply_params(query, opts)
|
8
|
+
end
|
9
|
+
end
|
4
10
|
|
11
|
+
def get(id, opts = {})
|
12
|
+
@connection.get "/product/#{id}" do |query|
|
13
|
+
apply_params(query, opts)
|
14
|
+
end
|
15
|
+
end
|
5
16
|
end
|
6
17
|
end
|
7
18
|
end
|
data/lib/zeit/version.rb
CHANGED
data/spec/api_spec.rb
CHANGED
@@ -1,27 +1,48 @@
|
|
1
1
|
require 'zeit'
|
2
2
|
require 'spec_helper'
|
3
3
|
|
4
|
-
describe
|
5
|
-
|
4
|
+
describe Zeit::API do
|
5
|
+
subject { authorized_api_client }
|
6
|
+
|
7
|
+
describe '.new' do
|
6
8
|
it 'should be able to initialized with an api_key' do
|
7
|
-
|
8
|
-
|
9
|
+
subject.should be_instance_of(Zeit::API)
|
10
|
+
end
|
11
|
+
|
12
|
+
it 'should initialize a faraday connection object' do
|
13
|
+
subject.connection.should be_instance_of(Faraday::Connection)
|
9
14
|
end
|
10
15
|
|
11
|
-
it 'should
|
12
|
-
|
13
|
-
zeit.connection.should be_instance_of(Faraday::Connection)
|
16
|
+
it 'should raise an error when :api_key parameter is missing' do
|
17
|
+
expect { Zeit::API.new }.to raise_error
|
14
18
|
end
|
15
19
|
end
|
16
20
|
|
17
|
-
describe '
|
18
|
-
subject { Zeit::API.new api_key: 'something' }
|
21
|
+
describe '#author' do
|
19
22
|
its(:author) { should be_instance_of(Zeit::Resources::Author) }
|
20
23
|
end
|
21
24
|
|
22
|
-
describe '
|
23
|
-
subject { Zeit::API.new api_key: 'something' }
|
25
|
+
describe '#client' do
|
24
26
|
its(:client) { should be_instance_of(Zeit::Resources::Client) }
|
25
27
|
end
|
26
28
|
|
29
|
+
describe '#content' do
|
30
|
+
its(:content) { should be_instance_of(Zeit::Resources::Content) }
|
31
|
+
end
|
32
|
+
|
33
|
+
describe '#department' do
|
34
|
+
its(:department) { should be_instance_of(Zeit::Resources::Department) }
|
35
|
+
end
|
36
|
+
|
37
|
+
describe '#keyword' do
|
38
|
+
its(:keyword) { should be_instance_of(Zeit::Resources::Keyword) }
|
39
|
+
end
|
40
|
+
|
41
|
+
describe '#product' do
|
42
|
+
its(:product) { should be_instance_of(Zeit::Resources::Product) }
|
43
|
+
end
|
44
|
+
|
45
|
+
describe '#series' do
|
46
|
+
its(:series) { should be_instance_of(Zeit::Resources::Series) }
|
47
|
+
end
|
27
48
|
end
|
@@ -1,10 +1,51 @@
|
|
1
|
-
require 'zeit'
|
2
1
|
require 'spec_helper'
|
3
2
|
|
4
|
-
describe
|
5
|
-
|
6
|
-
|
7
|
-
|
3
|
+
describe Zeit::Resources::Author, :vcr do
|
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
|
+
subject { Zeit::Resources::Author.new(api_connection).find(query) }
|
10
|
+
let(:query) { '*Helmut*Schmidt*' }
|
11
|
+
|
12
|
+
context 'when authorized' do
|
13
|
+
it_behaves_like 'a successful response with some matches'
|
14
|
+
end
|
15
|
+
|
16
|
+
context 'when unauthorized' do
|
17
|
+
it_behaves_like 'an unauthorized request'
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
describe '#get' do
|
24
|
+
it_behaves_like 'a resource response' do
|
25
|
+
|
26
|
+
context 'with an valid author id' do
|
27
|
+
subject { Zeit::Resources::Author.new(api_connection).get(author_id) }
|
28
|
+
let(:author_id) { 'Helmut-Schmidt' }
|
29
|
+
|
30
|
+
context 'when authorized' do
|
31
|
+
it_behaves_like 'a successful response with some matches'
|
32
|
+
|
33
|
+
it_behaves_like 'all matches have the required keys' do
|
34
|
+
let(:keys) { %w(subtitle uuid title href release_date uri supertitle teaser_title) }
|
35
|
+
end
|
36
|
+
|
37
|
+
it 'should have the right data type' do
|
38
|
+
parsed_json['type'].should eql('author')
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
context 'when unauthorized' do
|
43
|
+
it_behaves_like 'an unauthorized request'
|
44
|
+
end
|
45
|
+
end
|
8
46
|
end
|
9
47
|
end
|
48
|
+
|
49
|
+
|
10
50
|
end
|
51
|
+
|
@@ -1,19 +1,24 @@
|
|
1
|
-
require 'zeit'
|
2
1
|
require 'spec_helper'
|
3
2
|
|
4
|
-
describe
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
3
|
+
describe Zeit::Resources::Client, :vcr do
|
4
|
+
it_behaves_like 'a resource'
|
5
|
+
|
6
|
+
describe '#get' do
|
7
|
+
it_behaves_like 'a resource response' do
|
8
|
+
subject { Zeit::Resources::Client.new(api_connection).get }
|
9
|
+
|
10
|
+
context 'when authorized' do
|
11
|
+
it_behaves_like 'a successful response'
|
10
12
|
|
11
|
-
|
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'
|
16
|
+
end
|
17
|
+
end
|
14
18
|
|
15
|
-
|
16
|
-
|
19
|
+
context 'when unauthorized' do
|
20
|
+
it_behaves_like 'an unauthorized request'
|
21
|
+
end
|
17
22
|
end
|
18
23
|
end
|
19
24
|
end
|
@@ -1,10 +1,53 @@
|
|
1
|
-
require 'zeit'
|
2
1
|
require 'spec_helper'
|
3
2
|
|
4
|
-
describe
|
5
|
-
|
6
|
-
|
7
|
-
|
3
|
+
describe Zeit::Resources::Content, :vcr do
|
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) { 'Kim Schmitz' }
|
10
|
+
subject { Zeit::Resources::Content.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(subtitle uuid title href release_date uri supertitle snippet teaser_title) }
|
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 content id' do
|
30
|
+
let(:uuid) { '3GbcIDjwbcH4DZKMZj0Ndd' }
|
31
|
+
|
32
|
+
subject { Zeit::Resources::Content.new(api_connection).get(uuid) }
|
33
|
+
|
34
|
+
context 'when authorized' do
|
35
|
+
it 'should have some important values' do
|
36
|
+
parsed_json.has_key? 'title'
|
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)
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
context 'when unauthorized' do
|
46
|
+
it_behaves_like 'an unauthorized request'
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
8
50
|
end
|
9
51
|
end
|
10
52
|
end
|
53
|
+
|
@@ -1,10 +1,52 @@
|
|
1
|
-
require 'zeit'
|
2
1
|
require 'spec_helper'
|
3
2
|
|
4
|
-
describe
|
5
|
-
|
6
|
-
|
7
|
-
|
3
|
+
describe Zeit::Resources::Department, :vcr do
|
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) { '*i*' }
|
10
|
+
subject { Zeit::Resources::Department.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(href uri value) }
|
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 department id' do
|
30
|
+
let(:id) { 'internet' }
|
31
|
+
|
32
|
+
subject { Zeit::Resources::Department.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
|
+
parsed_json.has_key? 'uri'
|
39
|
+
parsed_json.has_key? 'value'
|
40
|
+
parsed_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
|
+
|
8
49
|
end
|
9
50
|
end
|
10
51
|
end
|
52
|
+
|
@@ -1,10 +1,51 @@
|
|
1
|
-
require 'zeit'
|
2
1
|
require 'spec_helper'
|
3
2
|
|
4
|
-
describe
|
5
|
-
|
6
|
-
|
7
|
-
|
3
|
+
describe Zeit::Resources::Keyword, :vcr do
|
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) { '*rom*' }
|
10
|
+
subject { Zeit::Resources::Keyword.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(href uri value type) }
|
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 keyword id' do
|
30
|
+
let(:id) { 'internet' }
|
31
|
+
|
32
|
+
subject { Zeit::Resources::Keyword.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
|
+
parsed_json.has_key? 'uri'
|
39
|
+
parsed_json.has_key? 'value'
|
40
|
+
parsed_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
|
+
|
8
49
|
end
|
9
50
|
end
|
10
51
|
end
|
@@ -1,10 +1,52 @@
|
|
1
|
-
require 'zeit'
|
2
1
|
require 'spec_helper'
|
3
2
|
|
4
|
-
describe
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
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
|
10
52
|
end
|
@@ -1,10 +1,52 @@
|
|
1
|
-
require 'zeit'
|
2
1
|
require 'spec_helper'
|
3
2
|
|
4
|
-
describe
|
5
|
-
|
6
|
-
|
7
|
-
|
3
|
+
describe Zeit::Resources::Series, :vcr do
|
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) { '*er*' }
|
10
|
+
subject { Zeit::Resources::Series.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 value) }
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
context 'when unauthorized' do
|
21
|
+
it_behaves_like 'an unauthorized request'
|
22
|
+
end
|
23
|
+
end
|
8
24
|
end
|
9
25
|
end
|
26
|
+
|
27
|
+
describe '#get' do
|
28
|
+
pending "Zeit.de currently broken (/series/id) :-("
|
29
|
+
#it_behaves_like 'a resource response' do
|
30
|
+
# context 'with an valid series id' do
|
31
|
+
# let(:id) { 'die-einzelkaempfer' }
|
32
|
+
|
33
|
+
# subject { Zeit::Resources::Series.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
|
10
52
|
end
|
data/spec/spec_helper.rb
CHANGED
@@ -1,6 +1,21 @@
|
|
1
|
-
require '
|
1
|
+
require 'zeit'
|
2
|
+
require 'json'
|
2
3
|
|
3
|
-
|
4
|
-
|
5
|
-
|
4
|
+
RSpec.configure do |c|
|
5
|
+
# VCR:
|
6
|
+
# so we can use :vcr rather than :vcr => true;
|
7
|
+
# in RSpec 3 this will no longer be necessary.
|
8
|
+
c.treat_symbols_as_metadata_keys_with_true_values = true
|
6
9
|
end
|
10
|
+
|
11
|
+
Dir["./spec/support/**/*.rb"].sort.each {|f| require f}
|
12
|
+
|
13
|
+
def authorized_api_client
|
14
|
+
key = ENV['ZEIT_API_KEY'] || 'working'
|
15
|
+
Zeit::API.new api_key: key
|
16
|
+
end
|
17
|
+
|
18
|
+
def unauthorized_api_client
|
19
|
+
Zeit::API.new api_key: 'felix_von_springer' # bild.css
|
20
|
+
end
|
21
|
+
|
@@ -0,0 +1,54 @@
|
|
1
|
+
shared_examples 'a resource' do
|
2
|
+
describe '.new' do
|
3
|
+
it 'should require a connection object to be initalized' do
|
4
|
+
expect { described_class.new }.to raise_error
|
5
|
+
end
|
6
|
+
end
|
7
|
+
end
|
8
|
+
|
9
|
+
shared_examples 'a resource response' do
|
10
|
+
let(:json) { subject.body }
|
11
|
+
let(:api_connection) { authorized_api_client.connection }
|
12
|
+
let(:parsed_json) { JSON.parse(json) }
|
13
|
+
end
|
14
|
+
|
15
|
+
shared_examples 'a successful response' do
|
16
|
+
its(:success?) { should be_true }
|
17
|
+
end
|
18
|
+
|
19
|
+
shared_examples 'a successful response with some matches' do
|
20
|
+
it_behaves_like 'a successful response'
|
21
|
+
|
22
|
+
it 'should return matches' do
|
23
|
+
parsed_json['matches'].should have_at_least(10).items
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
shared_examples 'an unauthorized request' do
|
28
|
+
let(:api_connection) { unauthorized_api_client.connection }
|
29
|
+
its(:status) { should eql(401) } # UNAUTHORIZED
|
30
|
+
|
31
|
+
it_behaves_like 'an error message response'
|
32
|
+
end
|
33
|
+
|
34
|
+
shared_examples 'an error message response' do
|
35
|
+
its(:success?) { should be_false }
|
36
|
+
|
37
|
+
it 'should return an error message' do
|
38
|
+
parsed_json['description'].should_not be_empty
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
# todo custom matchers
|
43
|
+
# FIXME allow new keys
|
44
|
+
shared_examples 'all matches have the required keys' do
|
45
|
+
it 'matches should have at least the basic keys' do
|
46
|
+
parsed_json['matches'].each do |match|
|
47
|
+
keys.each do |required_key|
|
48
|
+
match.keys.should include(required_key)
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
|
data/spec/support/vcr.rb
ADDED
data/zeit.gemspec
CHANGED
@@ -12,12 +12,11 @@ Gem::Specification.new do |gem|
|
|
12
12
|
gem.summary = %q{API client for Zeit.de API, not working yet}
|
13
13
|
gem.homepage = "http://github.com/rmoriz/zeit"
|
14
14
|
|
15
|
-
gem.files = `git ls-files`.split($/)
|
15
|
+
gem.files = `git ls-files`.split($/).select { |file| file !~ /^spec\/vcr/ }
|
16
16
|
gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
|
17
|
-
gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
|
17
|
+
gem.test_files = gem.files.grep(%r{^(test|spec|features)/}).select { |file| file !~ /^spec\/vcr/ }
|
18
18
|
gem.require_paths = ['lib']
|
19
19
|
|
20
|
-
|
21
20
|
if RUBY_PLATFORM == 'java'
|
22
21
|
gem.add_runtime_dependency 'jruby-openssl'
|
23
22
|
end
|
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.1pre2
|
5
5
|
prerelease: 5
|
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-25 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: faraday
|
@@ -159,6 +159,8 @@ files:
|
|
159
159
|
- spec/resources/product_spec.rb
|
160
160
|
- spec/resources/series_spec.rb
|
161
161
|
- spec/spec_helper.rb
|
162
|
+
- spec/support/shared_examples_for_resources.rb
|
163
|
+
- spec/support/vcr.rb
|
162
164
|
- zeit.gemspec
|
163
165
|
homepage: http://github.com/rmoriz/zeit
|
164
166
|
licenses: []
|
@@ -174,7 +176,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
174
176
|
version: '0'
|
175
177
|
segments:
|
176
178
|
- 0
|
177
|
-
hash: -
|
179
|
+
hash: -777588896169395003
|
178
180
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
179
181
|
none: false
|
180
182
|
requirements:
|
@@ -197,3 +199,5 @@ test_files:
|
|
197
199
|
- spec/resources/product_spec.rb
|
198
200
|
- spec/resources/series_spec.rb
|
199
201
|
- spec/spec_helper.rb
|
202
|
+
- spec/support/shared_examples_for_resources.rb
|
203
|
+
- spec/support/vcr.rb
|