contentful 0.3.4 → 0.3.5

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.
Files changed (57) hide show
  1. checksums.yaml +7 -0
  2. data/.travis.yml +1 -1
  3. data/CHANGELOG.md +43 -24
  4. data/README.md +22 -0
  5. data/RELEASE.md +8 -0
  6. data/Rakefile +4 -6
  7. data/contentful.gemspec +7 -9
  8. data/examples/custom_classes.rb +1 -2
  9. data/examples/dynamic_entries.rb +2 -4
  10. data/examples/example_queries.rb +2 -3
  11. data/examples/raise_errors.rb +3 -5
  12. data/examples/raw_mode.rb +2 -3
  13. data/examples/resource_mapping.rb +3 -4
  14. data/lib/contentful/array.rb +0 -1
  15. data/lib/contentful/asset.rb +1 -1
  16. data/lib/contentful/client.rb +47 -38
  17. data/lib/contentful/deleted_entry.rb +1 -1
  18. data/lib/contentful/request.rb +1 -2
  19. data/lib/contentful/resource.rb +1 -1
  20. data/lib/contentful/resource/array_like.rb +2 -3
  21. data/lib/contentful/resource/asset_fields.rb +1 -1
  22. data/lib/contentful/resource/fields.rb +2 -3
  23. data/lib/contentful/resource/system_properties.rb +1 -1
  24. data/lib/contentful/resource_builder.rb +14 -23
  25. data/lib/contentful/response.rb +40 -35
  26. data/lib/contentful/sync.rb +1 -3
  27. data/lib/contentful/sync_page.rb +2 -3
  28. data/lib/contentful/version.rb +1 -1
  29. data/spec/array_spec.rb +20 -20
  30. data/spec/asset_spec.rb +14 -14
  31. data/spec/auto_includes_spec.rb +4 -4
  32. data/spec/client_class_spec.rb +22 -24
  33. data/spec/client_configuration_spec.rb +48 -49
  34. data/spec/coercions_spec.rb +4 -4
  35. data/spec/content_type_spec.rb +12 -12
  36. data/spec/deleted_asset_spec.rb +10 -11
  37. data/spec/deleted_entry_spec.rb +9 -10
  38. data/spec/dynamic_entry_spec.rb +11 -11
  39. data/spec/entry_spec.rb +14 -14
  40. data/spec/error_class_spec.rb +15 -18
  41. data/spec/error_requests_spec.rb +6 -7
  42. data/spec/field_spec.rb +9 -9
  43. data/spec/file_spec.rb +7 -7
  44. data/spec/link_spec.rb +14 -14
  45. data/spec/locale_spec.rb +6 -6
  46. data/spec/location_spec.rb +10 -10
  47. data/spec/request_spec.rb +13 -13
  48. data/spec/resource_building_spec.rb +7 -8
  49. data/spec/resource_spec.rb +14 -14
  50. data/spec/response_spec.rb +25 -24
  51. data/spec/space_spec.rb +10 -10
  52. data/spec/spec_helper.rb +1 -2
  53. data/spec/support/json_responses.rb +2 -2
  54. data/spec/support/vcr.rb +3 -3
  55. data/spec/sync_page_spec.rb +26 -27
  56. data/spec/sync_spec.rb +22 -24
  57. metadata +41 -66
@@ -1,34 +1,34 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  describe Contentful::DynamicEntry do
4
- let(:content_type){ vcr('content_type'){ create_client.content_type 'cat' } }
4
+ let(:content_type) { vcr('content_type') { create_client.content_type 'cat' } }
5
5
 
6
6
  it 'create as a class' do
7
- expect( Contentful::DynamicEntry.create(content_type) ).to be_instance_of Class
7
+ expect(Contentful::DynamicEntry.create(content_type)).to be_instance_of Class
8
8
  end
9
9
 
10
10
  it 'also works with raw json object input as argument' do
11
- expect( Contentful::DynamicEntry.create(json_fixture('content_type')) ).to be_instance_of Class
11
+ expect(Contentful::DynamicEntry.create(json_fixture('content_type'))).to be_instance_of Class
12
12
  end
13
13
 
14
14
  it 'should create Contentful::DynamicEntry instances' do
15
- expect( Contentful::DynamicEntry.create(content_type).new(json_fixture('nyancat')) ).to \
15
+ expect(Contentful::DynamicEntry.create(content_type).new(json_fixture('nyancat'))).to \
16
16
  be_a Contentful::DynamicEntry
17
17
  end
18
18
 
19
19
  describe 'Example Entry Class' do
20
- before{
20
+ before do
21
21
  NyanCatEntry = Contentful::DynamicEntry.create(content_type)
22
- }
22
+ end
23
23
 
24
24
  it 'defines getters for entry fields' do
25
- nyancat = NyanCatEntry.new json_fixture("nyancat")
26
- expect( nyancat.color ).to eq "rainbow"
25
+ nyancat = NyanCatEntry.new json_fixture('nyancat')
26
+ expect(nyancat.color).to eq 'rainbow'
27
27
  end
28
28
 
29
29
  it 'automatically coerces types' do
30
- nyancat = NyanCatEntry.new json_fixture("nyancat")
31
- expect( nyancat.birthday ).to be_a DateTime
30
+ nyancat = NyanCatEntry.new json_fixture('nyancat')
31
+ expect(nyancat.birthday).to be_a DateTime
32
32
  end
33
33
  end
34
- end
34
+ end
data/spec/entry_spec.rb CHANGED
@@ -1,52 +1,52 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  describe Contentful::ContentType do
4
- let(:entry){ vcr('entry'){ create_client.entry 'nyancat' } }
4
+ let(:entry) { vcr('entry') { create_client.entry 'nyancat' } }
5
5
 
6
6
  describe 'SystemProperties' do
7
7
  it 'has a #sys getter returning a hash with symbol keys' do
8
- expect( entry.sys ).to be_a Hash
9
- expect( entry.sys.keys.sample ).to be_a Symbol
8
+ expect(entry.sys).to be_a Hash
9
+ expect(entry.sys.keys.sample).to be_a Symbol
10
10
  end
11
11
 
12
12
  it 'has #id' do
13
- expect( entry.id ).to eq "nyancat"
13
+ expect(entry.id).to eq 'nyancat'
14
14
  end
15
15
 
16
16
  it 'has #type' do
17
- expect( entry.type ).to eq "Entry"
17
+ expect(entry.type).to eq 'Entry'
18
18
  end
19
19
 
20
20
  it 'has #space' do
21
- expect( entry.space ).to be_a Contentful::Link
21
+ expect(entry.space).to be_a Contentful::Link
22
22
  end
23
23
 
24
24
  it 'has #content_type' do
25
- expect( entry.content_type ).to be_a Contentful::Link
25
+ expect(entry.content_type).to be_a Contentful::Link
26
26
  end
27
27
 
28
28
  it 'has #created_at' do
29
- expect( entry.created_at ).to be_a DateTime
29
+ expect(entry.created_at).to be_a DateTime
30
30
  end
31
31
 
32
32
  it 'has #updated_at' do
33
- expect( entry.updated_at ).to be_a DateTime
33
+ expect(entry.updated_at).to be_a DateTime
34
34
  end
35
35
 
36
36
  it 'has #revision' do
37
- expect( entry.revision ).to eq 5
37
+ expect(entry.revision).to eq 5
38
38
  end
39
39
  end
40
40
 
41
41
  describe 'Fields' do
42
42
  it 'has a #fields getter returning a hash with symbol keys' do
43
- expect( entry.sys ).to be_a Hash
44
- expect( entry.sys.keys.sample ).to be_a Symbol
43
+ expect(entry.sys).to be_a Hash
44
+ expect(entry.sys.keys.sample).to be_a Symbol
45
45
  end
46
46
 
47
47
  it "contains the entry's fields" do
48
- expect( entry.fields[:color] ).to eq "rainbow"
49
- expect( entry.fields[:bestFriend] ).to be_a Contentful::Link
48
+ expect(entry.fields[:color]).to eq 'rainbow'
49
+ expect(entry.fields[:bestFriend]).to be_a Contentful::Link
50
50
  end
51
51
  end
52
52
 
@@ -1,59 +1,56 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  describe Contentful::Error do
4
- let(:r){ Contentful::Response.new raw_fixture("not_found") }
5
-
4
+ let(:r) { Contentful::Response.new raw_fixture('not_found',404) }
6
5
 
7
6
  describe '#response' do
8
7
  it 'returns the response the error has been initialized with' do
9
- expect( Contentful::Error.new(r).response ).to be r
8
+ expect(Contentful::Error.new(r).response).to be r
10
9
  end
11
10
  end
12
11
 
13
12
  describe '#message' do
14
13
  it 'returns the message found in the response json' do
15
- expect( Contentful::Error.new(r).message ).not_to be_nil
16
- expect( Contentful::Error.new(r).message ).to \
17
- eq json_fixture("not_found")["message"]
14
+ expect(Contentful::Error.new(r).message).not_to be_nil
15
+ expect(Contentful::Error.new(r).message).to \
16
+ eq json_fixture('not_found')['message']
18
17
  end
19
18
  end
20
19
 
21
-
22
20
  describe Contentful::UnparsableJson do
23
21
  describe '#message' do
24
22
  it 'returns the json parser\'s message' do
25
- uj = Contentful::Response.new raw_fixture("unparsable")
26
- expect( Contentful::UnparsableJson.new(uj).message ).to \
27
- include "unexpected token"
23
+ uj = Contentful::Response.new raw_fixture('unparsable')
24
+ expect(Contentful::UnparsableJson.new(uj).message).to \
25
+ include 'unexpected token'
28
26
  end
29
27
  end
30
28
  end
31
29
 
32
-
33
30
  describe '.[]' do
34
31
  it 'returns NotFound error class for 404' do
35
- expect( Contentful::Error[404] ).to eq Contentful::NotFound
32
+ expect(Contentful::Error[404]).to eq Contentful::NotFound
36
33
  end
37
34
 
38
35
  it 'returns BadRequest error class for 400' do
39
- expect( Contentful::Error[400] ).to eq Contentful::BadRequest
36
+ expect(Contentful::Error[400]).to eq Contentful::BadRequest
40
37
  end
41
38
 
42
39
  it 'returns AccessDenied error class for 403' do
43
- expect( Contentful::Error[403] ).to eq Contentful::AccessDenied
40
+ expect(Contentful::Error[403]).to eq Contentful::AccessDenied
44
41
  end
45
42
 
46
43
  it 'returns Unauthorized error class for 401' do
47
- expect( Contentful::Error[401] ).to eq Contentful::Unauthorized
44
+ expect(Contentful::Error[401]).to eq Contentful::Unauthorized
48
45
  end
49
46
 
50
47
  it 'returns ServerError error class for 500' do
51
- expect( Contentful::Error[500] ).to eq Contentful::ServerError
48
+ expect(Contentful::Error[500]).to eq Contentful::ServerError
52
49
  end
53
50
 
54
51
  it 'returns generic error class for any other value' do
55
- expect( Contentful::Error[nil] ).to eq Contentful::Error
56
- expect( Contentful::Error[200] ).to eq Contentful::Error
52
+ expect(Contentful::Error[nil]).to eq Contentful::Error
53
+ expect(Contentful::Error[200]).to eq Contentful::Error
57
54
  end
58
55
  end
59
56
 
@@ -1,17 +1,16 @@
1
1
  require 'spec_helper'
2
2
 
3
-
4
3
  describe 'Error Requests' do
5
4
  it 'will return 404 (Unauthorized) if resource not found' do
6
- expect_vcr("not found"){
5
+ expect_vcr('not found')do
7
6
  create_client.entry 'not found'
8
- }.to raise_error(Contentful::NotFound)
7
+ end.to raise_error(Contentful::NotFound)
9
8
  end
10
9
 
11
10
  it 'will return 400 (BadRequest) if invalid parameters have been passed' do
12
- expect_vcr("bad request"){
11
+ expect_vcr('bad request')do
13
12
  create_client.entries(some: 'parameter')
14
- }.to raise_error(Contentful::BadRequest)
13
+ end.to raise_error(Contentful::BadRequest)
15
14
  end
16
15
 
17
16
  it 'will return 403 (AccessDenied) if ...' do
@@ -19,9 +18,9 @@ describe 'Error Requests' do
19
18
  end
20
19
 
21
20
  it 'will return 401 (Unauthorized) if wrong credentials given' do
22
- client = Contentful::Client.new(space: "wrong", access_token: "credentials")
21
+ client = Contentful::Client.new(space: 'wrong', access_token: 'credentials')
23
22
 
24
- expect_vcr("unauthorized"){
23
+ expect_vcr('unauthorized'){
25
24
  client.entry 'nyancat'
26
25
  }.to raise_error(Contentful::Unauthorized)
27
26
  end
data/spec/field_spec.rb CHANGED
@@ -1,36 +1,36 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  describe Contentful::Field do
4
- let(:field){ vcr('field'){ create_client.content_type('cat').fields.first } }
4
+ let(:field) { vcr('field') { create_client.content_type('cat').fields.first } }
5
5
 
6
6
  describe 'Properties' do
7
7
  it 'has a #properties getter returning a hash with symbol keys' do
8
- expect( field.properties ).to be_a Hash
9
- expect( field.properties.keys.sample ).to be_a Symbol
8
+ expect(field.properties).to be_a Hash
9
+ expect(field.properties.keys.sample).to be_a Symbol
10
10
  end
11
11
 
12
12
  it 'has #id' do
13
- expect( field.id ).to eq "name"
13
+ expect(field.id).to eq 'name'
14
14
  end
15
15
 
16
16
  it 'has #name' do
17
- expect( field.name ).to eq "Name"
17
+ expect(field.name).to eq 'Name'
18
18
  end
19
19
 
20
20
  it 'has #type' do
21
- expect( field.type ).to eq "Text"
21
+ expect(field.type).to eq 'Text'
22
22
  end
23
23
 
24
24
  it 'could have #items' do
25
- expect( field ).to respond_to :items
25
+ expect(field).to respond_to :items
26
26
  end
27
27
 
28
28
  it 'has #required' do
29
- expect( field.required ).to be_true
29
+ expect(field.required).to be_true
30
30
  end
31
31
 
32
32
  it 'has #localized' do
33
- expect( field.required ).to be_true
33
+ expect(field.required).to be_true
34
34
  end
35
35
  end
36
36
  end
data/spec/file_spec.rb CHANGED
@@ -1,28 +1,28 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  describe Contentful::File do
4
- let(:file){ vcr('asset'){ create_client.asset('nyancat').file } }
4
+ let(:file) { vcr('asset') { create_client.asset('nyancat').file } }
5
5
 
6
6
  describe 'Properties' do
7
7
  it 'has a #properties getter returning a hash with symbol keys' do
8
- expect( file.properties ).to be_a Hash
9
- expect( file.properties.keys.sample ).to be_a Symbol
8
+ expect(file.properties).to be_a Hash
9
+ expect(file.properties.keys.sample).to be_a Symbol
10
10
  end
11
11
 
12
12
  it 'has #file_name' do
13
- expect( file.file_name ).to eq "Nyan_cat_250px_frame.png"
13
+ expect(file.file_name).to eq 'Nyan_cat_250px_frame.png'
14
14
  end
15
15
 
16
16
  it 'has #content_type' do
17
- expect( file.content_type ).to eq "image/png"
17
+ expect(file.content_type).to eq 'image/png'
18
18
  end
19
19
 
20
20
  it 'has #url' do
21
- expect( file.url ).to eq "//images.contentful.com/cfexampleapi/4gp6taAwW4CmSgumq2ekUm/9da0cd1936871b8d72343e895a00d611/Nyan_cat_250px_frame.png"
21
+ expect(file.url).to eq '//images.contentful.com/cfexampleapi/4gp6taAwW4CmSgumq2ekUm/9da0cd1936871b8d72343e895a00d611/Nyan_cat_250px_frame.png'
22
22
  end
23
23
 
24
24
  it 'has #details' do
25
- expect( file.details ).to be_instance_of Hash
25
+ expect(file.details).to be_instance_of Hash
26
26
  end
27
27
  end
28
28
  end
data/spec/link_spec.rb CHANGED
@@ -1,40 +1,40 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  describe Contentful::Link do
4
- let(:entry){ vcr('entry'){ create_client.entry('nyancat') } }
5
- let(:link){ entry.space }
6
- let(:content_type_link){ entry.content_type }
4
+ let(:entry) { vcr('entry') { create_client.entry('nyancat') } }
5
+ let(:link) { entry.space }
6
+ let(:content_type_link) { entry.content_type }
7
7
 
8
8
  describe 'SystemProperties' do
9
9
  it 'has a #sys getter returning a hash with symbol keys' do
10
- expect( link.sys ).to be_a Hash
11
- expect( link.sys.keys.sample ).to be_a Symbol
10
+ expect(link.sys).to be_a Hash
11
+ expect(link.sys.keys.sample).to be_a Symbol
12
12
  end
13
13
 
14
14
  it 'has #id' do
15
- expect( link.id ).to eq "cfexampleapi"
15
+ expect(link.id).to eq 'cfexampleapi'
16
16
  end
17
17
 
18
18
  it 'has #type' do
19
- expect( link.type ).to eq "Link"
19
+ expect(link.type).to eq 'Link'
20
20
  end
21
21
 
22
22
  it 'has #link_type' do
23
- expect( link.link_type ).to eq "Space"
23
+ expect(link.link_type).to eq 'Space'
24
24
  end
25
25
  end
26
26
 
27
27
  describe '#resolve' do
28
28
  it 'queries the api for the resource' do
29
- vcr('space'){
30
- expect( link.resolve ).to be_a Contentful::Space
31
- }
29
+ vcr('space')do
30
+ expect(link.resolve).to be_a Contentful::Space
31
+ end
32
32
  end
33
33
 
34
34
  it 'queries the api for the resource (different link object)' do
35
- vcr('content_type'){
36
- expect( content_type_link.resolve ).to be_a Contentful::ContentType
37
- }
35
+ vcr('content_type')do
36
+ expect(content_type_link.resolve).to be_a Contentful::ContentType
37
+ end
38
38
  end
39
39
  end
40
40
  end
data/spec/locale_spec.rb CHANGED
@@ -1,24 +1,24 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  describe Contentful::Locale do
4
- let(:locale){ vcr('locale'){ create_client.space.locales.first } }
4
+ let(:locale) { vcr('locale') { create_client.space.locales.first } }
5
5
 
6
6
  describe 'Properties' do
7
7
  it 'has a #properties getter returning a hash with symbol keys' do
8
- expect( locale.properties ).to be_a Hash
9
- expect( locale.properties.keys.sample ).to be_a Symbol
8
+ expect(locale.properties).to be_a Hash
9
+ expect(locale.properties.keys.sample).to be_a Symbol
10
10
  end
11
11
 
12
12
  it 'has #code' do
13
- expect( locale.code ).to eq "en-US"
13
+ expect(locale.code).to eq 'en-US'
14
14
  end
15
15
 
16
16
  it 'has #name' do
17
- expect( locale.name ).to eq "English"
17
+ expect(locale.name).to eq 'English'
18
18
  end
19
19
 
20
20
  it 'has #default' do
21
- expect( locale.default ).to eq true
21
+ expect(locale.default).to eq true
22
22
  end
23
23
  end
24
24
  end
@@ -1,30 +1,30 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  describe Contentful::Location do
4
- let(:location){
5
- vcr('location'){
4
+ let(:location)do
5
+ vcr('location')do
6
6
  Contentful::Client.new(
7
7
  space: 'lzjz8hygvfgu',
8
8
  access_token: '0c6ef483524b5e46b3bafda1bf355f38f5f40b4830f7599f790a410860c7c271',
9
9
  dynamic_entries: :auto,
10
10
  ).entry('3f6fq5ylFCi4kIYAQKsAYG').location
11
- }
12
- }
11
+ end
12
+ end
13
13
 
14
14
  describe 'Properties' do
15
15
  it 'has a #properties getter returning a hash with symbol keys' do
16
- expect( location.properties ).to be_a Hash
17
- expect( location.properties.keys.sample ).to be_a Symbol
16
+ expect(location.properties).to be_a Hash
17
+ expect(location.properties.keys.sample).to be_a Symbol
18
18
  end
19
19
 
20
20
  it 'has #lat' do
21
- expect( location.lat ).to be_a Float
22
- expect( location.lat.to_i ).to eq 36
21
+ expect(location.lat).to be_a Float
22
+ expect(location.lat.to_i).to eq 36
23
23
  end
24
24
 
25
25
  it 'has #lon' do
26
- expect( location.lon ).to be_a Float
27
- expect( location.lon.to_i ).to eq -94
26
+ expect(location.lon).to be_a Float
27
+ expect(location.lon.to_i).to eq -94
28
28
  end
29
29
  end
30
30
  end
data/spec/request_spec.rb CHANGED
@@ -7,49 +7,49 @@ describe Contentful::Request do
7
7
  stub(client).get
8
8
  request = Contentful::Request.new(client, '/content_types', nil, 'nyancat')
9
9
  request.get
10
- expect( client ).to have_received.get(request)
10
+ expect(client).to have_received.get(request)
11
11
  end
12
12
  end
13
13
 
14
14
  describe '#query' do
15
15
  it 'converts arrays given in query to comma strings' do
16
16
  client = create_client
17
- request = Contentful::Request.new(client, '/entries', {'fields.likes[in]' => ['jake', 'finn']})
18
- expect( request.query[:'fields.likes[in]'] ).to eq 'jake,finn'
17
+ request = Contentful::Request.new(client, '/entries', 'fields.likes[in]' => %w(jake finn))
18
+ expect(request.query[:'fields.likes[in]']).to eq 'jake,finn'
19
19
  end
20
20
  end
21
21
 
22
22
  context '[single resource]' do
23
- let(:request){
23
+ let(:request)do
24
24
  Contentful::Request.new(create_client, '/content_types', nil, 'nyancat')
25
- }
25
+ end
26
26
 
27
27
  describe '#url' do
28
28
  it 'contais endpoint' do
29
- expect( request.url ).to include 'content_types'
29
+ expect(request.url).to include 'content_types'
30
30
  end
31
31
 
32
32
  it 'contains id' do
33
- expect( request.url ).to include 'nyancat'
33
+ expect(request.url).to include 'nyancat'
34
34
  end
35
35
  end
36
36
  end
37
37
 
38
38
  context '[multi resource]' do
39
- let(:request){
40
- Contentful::Request.new(create_client, '/content_types', {"something" => 'requested'})
41
- }
39
+ let(:request)do
40
+ Contentful::Request.new(create_client, '/content_types', 'something' => 'requested')
41
+ end
42
42
 
43
43
  describe '#query' do
44
44
  it 'contains query' do
45
- expect( request.query ).not_to be_empty
46
- expect( request.query[:something] ).to eq 'requested'
45
+ expect(request.query).not_to be_empty
46
+ expect(request.query[:something]).to eq 'requested'
47
47
  end
48
48
  end
49
49
 
50
50
  describe '#url' do
51
51
  it 'contais endpoint' do
52
- expect( request.url ).to include 'content_types'
52
+ expect(request.url).to include 'content_types'
53
53
  end
54
54
  end
55
55
  end