hotchoc 0.3.1 → 0.4.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (36) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +12 -0
  3. data/README.md +3 -3
  4. data/lib/hotchoc.rb +10 -10
  5. data/lib/hotchoc/album.rb +55 -0
  6. data/lib/hotchoc/base.rb +20 -0
  7. data/lib/hotchoc/{presenters/topic.rb → blocks/base.rb} +6 -10
  8. data/lib/hotchoc/blocks/image.rb +17 -0
  9. data/lib/hotchoc/blocks/text.rb +17 -0
  10. data/lib/hotchoc/client.rb +1 -1
  11. data/lib/hotchoc/client/api.rb +4 -4
  12. data/lib/hotchoc/client/version.rb +1 -1
  13. data/lib/hotchoc/file.rb +56 -0
  14. data/lib/hotchoc/page.rb +63 -0
  15. data/lib/hotchoc/post.rb +47 -0
  16. data/lib/hotchoc/thumbnail.rb +31 -0
  17. data/lib/hotchoc/topic.rb +27 -0
  18. data/spec/hotchoc/{presenters/album_spec.rb → album_spec.rb} +4 -4
  19. data/spec/hotchoc/{presenters/blocks → blocks}/image_spec.rb +2 -2
  20. data/spec/hotchoc/{presenters/blocks → blocks}/text_spec.rb +1 -1
  21. data/spec/hotchoc/client/api_spec.rb +4 -4
  22. data/spec/hotchoc/{presenters/file_spec.rb → file_spec.rb} +3 -3
  23. data/spec/hotchoc/{presenters/page_spec.rb → page_spec.rb} +3 -3
  24. data/spec/hotchoc/{presenters/post_spec.rb → post_spec.rb} +3 -3
  25. data/spec/hotchoc/{presenters/thumbnail_spec.rb → thumbnail_spec.rb} +2 -2
  26. data/spec/hotchoc/{presenters/topic_spec.rb → topic_spec.rb} +2 -2
  27. metadata +28 -28
  28. data/lib/hotchoc/presenters/album.rb +0 -57
  29. data/lib/hotchoc/presenters/base.rb +0 -22
  30. data/lib/hotchoc/presenters/blocks/base.rb +0 -27
  31. data/lib/hotchoc/presenters/blocks/image.rb +0 -19
  32. data/lib/hotchoc/presenters/blocks/text.rb +0 -19
  33. data/lib/hotchoc/presenters/file.rb +0 -58
  34. data/lib/hotchoc/presenters/page.rb +0 -65
  35. data/lib/hotchoc/presenters/post.rb +0 -49
  36. data/lib/hotchoc/presenters/thumbnail.rb +0 -33
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 4343918396edff5deef7f5b6f9f2b4056f49ac85
4
- data.tar.gz: 6a7735696aef0581aae2eb2707053e7497ec8eac
3
+ metadata.gz: 906bf6c641ca369e29effabcc2238b7d6143befe
4
+ data.tar.gz: 20a9b7fc5bcb94186a9d92c9fd029726c52a2e19
5
5
  SHA512:
6
- metadata.gz: 0a9ce027a457ea6ea088c41fce52e5f6e4e3dc2eeaa925a5b5a380be77c52e24fe07a7c472916b1ad5032934cb028c5cb365f1389d781352d4ad6fb33b7c1f66
7
- data.tar.gz: c044fefbf11ad365ef3035269b369df8f8acb91ca9a1ac8d93061115047446b762ba5a25ef95c1814e28148aaa64fbba5290b075d8c11acbd8f377971819c446
6
+ metadata.gz: 8d99f1414b96f84ffe1bb7bcadd57d7d4ba357a1f2b2d944925c2b359914eb57381d036904820297ea2a4ede6a2b00b14456eb873a07e3668d5377caf7298a1d
7
+ data.tar.gz: dca562a26a8e584c55471aded8d35c41ce1e1ec1e04490f308237c931a79acd47c5da01bde1a102e974e09050e30f01213a4c5da0a326560fa6a137bba3c3f04
data/CHANGELOG.md CHANGED
@@ -2,6 +2,18 @@
2
2
 
3
3
  ## Master
4
4
 
5
+ ## 0.4.0
6
+
7
+ [Full changelog](https://github.com/choc/hotchoc-ruby/compare/v0.3.1...v0.4.0)
8
+
9
+ Changes:
10
+
11
+ * Removed presenter namespace
12
+
13
+ Bugfixes:
14
+
15
+ * Client options merging fixed (this time for real)
16
+
5
17
  ## 0.3.1
6
18
 
7
19
  [Full changelog](https://github.com/choc/hotchoc-ruby/compare/v0.3.0...v0.3.1)
data/README.md CHANGED
@@ -31,15 +31,15 @@ Or install it manually as:
31
31
 
32
32
  # Get single album by ID
33
33
  client.get_albums(id: '77774dc8-4edf-4b3a-8571-a6b64c8adace')
34
- => [#<Hotchoc::Presenters::Album: title="Test album 1">]
34
+ => [#<Hotchoc::Album: title="Test album 1">]
35
35
 
36
36
  # Get all albums
37
37
  client.get_albums
38
- => [#<Hotchoc::Presenters::Album: title="Test album 2">, #<Hotchoc::Presenters::Album: title="Test album 1">]
38
+ => [#<Hotchoc::Album: title="Test album 2">, #<Hotchoc::Album: title="Test album 1">]
39
39
 
40
40
  # Get only first 10 albums
41
41
  client.get_albums(limit: 10)
42
- => [#<Hotchoc::Presenters::Album: title="Test album 2">, #<Hotchoc::Presenters::Album: title="Test album 1">]
42
+ => [#<Hotchoc::Album: title="Test album 2">, #<Hotchoc::Album: title="Test album 1">]
43
43
 
44
44
  ## API
45
45
 
data/lib/hotchoc.rb CHANGED
@@ -1,13 +1,13 @@
1
- require 'hotchoc/presenters/base'
2
- require 'hotchoc/presenters/album'
3
- require 'hotchoc/presenters/blocks/base'
4
- require 'hotchoc/presenters/blocks/image'
5
- require 'hotchoc/presenters/blocks/text'
6
- require 'hotchoc/presenters/file'
7
- require 'hotchoc/presenters/page'
8
- require 'hotchoc/presenters/post'
9
- require 'hotchoc/presenters/thumbnail'
10
- require 'hotchoc/presenters/topic'
1
+ require 'hotchoc/base'
2
+ require 'hotchoc/album'
3
+ require 'hotchoc/blocks/base'
4
+ require 'hotchoc/blocks/image'
5
+ require 'hotchoc/blocks/text'
6
+ require 'hotchoc/file'
7
+ require 'hotchoc/page'
8
+ require 'hotchoc/post'
9
+ require 'hotchoc/thumbnail'
10
+ require 'hotchoc/topic'
11
11
 
12
12
  require 'hotchoc/client/version'
13
13
  require 'hotchoc/client/errors'
@@ -0,0 +1,55 @@
1
+ module Hotchoc
2
+ class Album < Hotchoc::Base
3
+ def id
4
+ @item['id']
5
+ end
6
+
7
+ def title
8
+ @item['title']
9
+ end
10
+
11
+ def subtitle
12
+ @item['subtitle']
13
+ end
14
+
15
+ def description
16
+ @item['description']
17
+ end
18
+
19
+ def identifier
20
+ @item['identifier']
21
+ end
22
+
23
+ def status
24
+ @item['status']
25
+ end
26
+
27
+ def publish_date
28
+ Time.parse(@item['publish_date'])
29
+ end
30
+
31
+ def cover
32
+ @item['cover'] ? block_for(@item['cover']) : nil
33
+ end
34
+
35
+ def blocks
36
+ @item['blocks'].to_a.map { |block| block_for(block) }
37
+ end
38
+
39
+ def topics
40
+ @item['topics'].to_a.map { |topic| Hotchoc::Topic.new(topic) }
41
+ end
42
+
43
+ def created_at
44
+ Time.parse(@item['created_at'])
45
+ end
46
+
47
+ def updated_at
48
+ Time.parse(@item['updated_at'])
49
+ end
50
+
51
+ def inspect
52
+ %(#<Hotchoc::Album: title="#{title}">)
53
+ end
54
+ end
55
+ end
@@ -0,0 +1,20 @@
1
+ module Hotchoc
2
+ class Base
3
+ attr_reader :item
4
+
5
+ def initialize(item = {})
6
+ @item = item
7
+ end
8
+
9
+ private
10
+
11
+ def block_for(block)
12
+ case block['type']
13
+ when 'text'
14
+ Hotchoc::Blocks::Text.new(block)
15
+ when 'image'
16
+ Hotchoc::Blocks::Image.new(block)
17
+ end
18
+ end
19
+ end
20
+ end
@@ -1,16 +1,16 @@
1
1
  module Hotchoc
2
- module Presenters
3
- class Topic < Hotchoc::Presenters::Base
2
+ module Blocks
3
+ class Base < Hotchoc::Base
4
4
  def id
5
5
  @item['id']
6
6
  end
7
7
 
8
- def name
9
- @item['name']
8
+ def type
9
+ @item['type']
10
10
  end
11
11
 
12
- def identifier
13
- @item['identifier']
12
+ def position
13
+ @item['position']
14
14
  end
15
15
 
16
16
  def created_at
@@ -20,10 +20,6 @@ module Hotchoc
20
20
  def updated_at
21
21
  Time.parse(@item['updated_at'])
22
22
  end
23
-
24
- def inspect
25
- %(#<Hotchoc::Presenters::Topic: name="#{name}">)
26
- end
27
23
  end
28
24
  end
29
25
  end
@@ -0,0 +1,17 @@
1
+ module Hotchoc
2
+ module Blocks
3
+ class Image < Hotchoc::Blocks::Base
4
+ def title
5
+ @item['content']['title']
6
+ end
7
+
8
+ def image
9
+ @item['content']['image'] ? Hotchoc::File.new(@item['content']['image']) : nil
10
+ end
11
+
12
+ def inspect
13
+ %(#<Hotchoc::Blocks::Image: title="#{title}" position="#{position}">)
14
+ end
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,17 @@
1
+ module Hotchoc
2
+ module Blocks
3
+ class Text < Hotchoc::Blocks::Base
4
+ def markdown
5
+ @item['content']['markdown']
6
+ end
7
+
8
+ def html
9
+ @item['content']['html']
10
+ end
11
+
12
+ def inspect
13
+ %(#<Hotchoc::Blocks::Text: position="#{position}">)
14
+ end
15
+ end
16
+ end
17
+ end
@@ -8,7 +8,7 @@ module Hotchoc
8
8
  attr_accessor(*Configuration::VALID_CONFIG_KEYS)
9
9
 
10
10
  def initialize(opts = {})
11
- options = Hotchoc.options.merge(opts) { |key, oldval, newval| oldval || newval }
11
+ options = Hotchoc.options.merge(opts) { |_key, oldval, newval| newval.nil? ? oldval : newval }
12
12
 
13
13
  fail ArgumentError, 'API key is required' unless options[:api_key]
14
14
  fail ArgumentError, 'Site name is required' unless options[:site]
@@ -2,19 +2,19 @@ module Hotchoc
2
2
  class Client
3
3
  module API
4
4
  def get_albums(opts = {})
5
- get('albums', opts)['albums'].map { |album| Hotchoc::Presenters::Album.new(album) }
5
+ get('albums', opts)['albums'].map { |album| Hotchoc::Album.new(album) }
6
6
  end
7
7
 
8
8
  def get_pages(opts = {})
9
- get('pages', opts)['pages'].map { |page| Hotchoc::Presenters::Page.new(page) }
9
+ get('pages', opts)['pages'].map { |page| Hotchoc::Page.new(page) }
10
10
  end
11
11
 
12
12
  def get_posts(opts = {})
13
- get('posts', opts)['posts'].map { |post| Hotchoc::Presenters::Post.new(post) }
13
+ get('posts', opts)['posts'].map { |post| Hotchoc::Post.new(post) }
14
14
  end
15
15
 
16
16
  def get_topics(opts = {})
17
- get('topics', opts)['topics'].map { |topic| Hotchoc::Presenters::Topic.new(topic) }
17
+ get('topics', opts)['topics'].map { |topic| Hotchoc::Topic.new(topic) }
18
18
  end
19
19
  end
20
20
  end
@@ -1,5 +1,5 @@
1
1
  module Hotchoc
2
2
  class Client
3
- VERSION = '0.3.1'
3
+ VERSION = '0.4.0'
4
4
  end
5
5
  end
@@ -0,0 +1,56 @@
1
+ module Hotchoc
2
+ class File < Hotchoc::Base
3
+ def id
4
+ @item['id']
5
+ end
6
+
7
+ def name
8
+ @item['name']
9
+ end
10
+
11
+ def url
12
+ @item['url']
13
+ end
14
+
15
+ def width
16
+ @item['width']
17
+ end
18
+
19
+ def height
20
+ @item['height']
21
+ end
22
+
23
+ def size
24
+ @item['size']
25
+ end
26
+
27
+ def content_type
28
+ @item['content_type']
29
+ end
30
+
31
+ def thumbnails
32
+ if @item['thumbnails']
33
+ @item['thumbnails']['original'].map { |thumbnail| Hotchoc::Thumbnail.new(thumbnail) } +
34
+ @item['thumbnails']['square'].map { |thumbnail| Hotchoc::Thumbnail.new(thumbnail) }
35
+ else
36
+ []
37
+ end
38
+ end
39
+
40
+ def exif
41
+ @item['exif']
42
+ end
43
+
44
+ def created_at
45
+ Time.parse(@item['created_at'])
46
+ end
47
+
48
+ def updated_at
49
+ Time.parse(@item['updated_at'])
50
+ end
51
+
52
+ def inspect
53
+ %(#<Hotchoc::File: name="#{name}">)
54
+ end
55
+ end
56
+ end
@@ -0,0 +1,63 @@
1
+ module Hotchoc
2
+ class Page < Hotchoc::Base
3
+ def id
4
+ @item['id']
5
+ end
6
+
7
+ def title
8
+ @item['title']
9
+ end
10
+
11
+ def subtitle
12
+ @item['subtitle']
13
+ end
14
+
15
+ def identifier
16
+ @item['identifier']
17
+ end
18
+
19
+ def status
20
+ @item['status']
21
+ end
22
+
23
+ def path
24
+ @item['path']
25
+ end
26
+
27
+ def parent_id
28
+ @item['parent_id']
29
+ end
30
+
31
+ def position
32
+ @item['position']
33
+ end
34
+
35
+ def level
36
+ @item['level']
37
+ end
38
+
39
+ def publish_date
40
+ Time.parse(@item['publish_date'])
41
+ end
42
+
43
+ def blocks
44
+ @item['blocks'].to_a.map { |block| block_for(block) }
45
+ end
46
+
47
+ def topics
48
+ @item['topics'].to_a.map { |topic| Hotchoc::Topic.new(topic) }
49
+ end
50
+
51
+ def created_at
52
+ Time.parse(@item['created_at'])
53
+ end
54
+
55
+ def updated_at
56
+ Time.parse(@item['updated_at'])
57
+ end
58
+
59
+ def inspect
60
+ %(#<Hotchoc::Page: title="#{title}">)
61
+ end
62
+ end
63
+ end
@@ -0,0 +1,47 @@
1
+ module Hotchoc
2
+ class Post < Hotchoc::Base
3
+ def id
4
+ @item['id']
5
+ end
6
+
7
+ def title
8
+ @item['title']
9
+ end
10
+
11
+ def subtitle
12
+ @item['subtitle']
13
+ end
14
+
15
+ def identifier
16
+ @item['identifier']
17
+ end
18
+
19
+ def status
20
+ @item['status']
21
+ end
22
+
23
+ def publish_date
24
+ Time.parse(@item['publish_date'])
25
+ end
26
+
27
+ def blocks
28
+ @item['blocks'].to_a.map { |block| block_for(block) }
29
+ end
30
+
31
+ def topics
32
+ @item['topics'].to_a.map { |topic| Hotchoc::Topic.new(topic) }
33
+ end
34
+
35
+ def created_at
36
+ Time.parse(@item['created_at'])
37
+ end
38
+
39
+ def updated_at
40
+ Time.parse(@item['updated_at'])
41
+ end
42
+
43
+ def inspect
44
+ %(#<Hotchoc::Post: title="#{title}">)
45
+ end
46
+ end
47
+ end
@@ -0,0 +1,31 @@
1
+ module Hotchoc
2
+ class Thumbnail < Hotchoc::Base
3
+ def name
4
+ @item['name']
5
+ end
6
+
7
+ def width
8
+ @item['width']
9
+ end
10
+
11
+ def height
12
+ @item['height']
13
+ end
14
+
15
+ def square?
16
+ width == height
17
+ end
18
+
19
+ def size
20
+ @item['size']
21
+ end
22
+
23
+ def url
24
+ @item['url']
25
+ end
26
+
27
+ def inspect
28
+ %(#<Hotchoc::Thumbnail:>)
29
+ end
30
+ end
31
+ end
@@ -0,0 +1,27 @@
1
+ module Hotchoc
2
+ class Topic < Hotchoc::Base
3
+ def id
4
+ @item['id']
5
+ end
6
+
7
+ def name
8
+ @item['name']
9
+ end
10
+
11
+ def identifier
12
+ @item['identifier']
13
+ end
14
+
15
+ def created_at
16
+ Time.parse(@item['created_at'])
17
+ end
18
+
19
+ def updated_at
20
+ Time.parse(@item['updated_at'])
21
+ end
22
+
23
+ def inspect
24
+ %(#<Hotchoc::Topic: name="#{name}">)
25
+ end
26
+ end
27
+ end
@@ -1,6 +1,6 @@
1
1
  require 'spec_helper'
2
2
 
3
- describe Hotchoc::Presenters::Album do
3
+ describe Hotchoc::Album do
4
4
  let(:data) do
5
5
  JSON.parse(File.read(response_stub('albums')))['albums'].first
6
6
  end
@@ -38,17 +38,17 @@ describe Hotchoc::Presenters::Album do
38
38
  end
39
39
 
40
40
  it 'has a cover' do
41
- expect(album.cover).to be_a(Hotchoc::Presenters::Blocks::Image)
41
+ expect(album.cover).to be_a(Hotchoc::Blocks::Image)
42
42
  end
43
43
 
44
44
  it 'has blocks' do
45
45
  expect(album.blocks).to_not be_empty
46
- expect(album.blocks.first).to be_a(Hotchoc::Presenters::Blocks::Image)
46
+ expect(album.blocks.first).to be_a(Hotchoc::Blocks::Image)
47
47
  end
48
48
 
49
49
  it 'has topics' do
50
50
  expect(album.topics).to_not be_empty
51
- expect(album.topics.first).to be_a(Hotchoc::Presenters::Topic)
51
+ expect(album.topics.first).to be_a(Hotchoc::Topic)
52
52
  end
53
53
 
54
54
  it 'has a created_at' do
@@ -1,6 +1,6 @@
1
1
  require 'spec_helper'
2
2
 
3
- describe Hotchoc::Presenters::Blocks::Image do
3
+ describe Hotchoc::Blocks::Image do
4
4
  let(:data) do
5
5
  JSON.parse(File.read(response_stub('albums')))['albums'].first['blocks'].first
6
6
  end
@@ -14,6 +14,6 @@ describe Hotchoc::Presenters::Blocks::Image do
14
14
  end
15
15
 
16
16
  it 'has an image' do
17
- expect(block.image).to be_a(Hotchoc::Presenters::File)
17
+ expect(block.image).to be_a(Hotchoc::File)
18
18
  end
19
19
  end
@@ -1,6 +1,6 @@
1
1
  require 'spec_helper'
2
2
 
3
- describe Hotchoc::Presenters::Blocks::Text do
3
+ describe Hotchoc::Blocks::Text do
4
4
  let(:data) do
5
5
  blocks = JSON.parse(File.read(response_stub('pages')))['pages'].first['blocks']
6
6
  blocks.detect { |block| block['type'] == 'text' }
@@ -11,7 +11,7 @@ describe Hotchoc::Client::API do
11
11
  describe 'Albums' do
12
12
  context 'GET collection' do
13
13
  let(:albums) do
14
- JSON.parse(File.read(response_stub('albums')))['albums'].map { |album| Hotchoc::Presenters::Album.new(album) }
14
+ JSON.parse(File.read(response_stub('albums')))['albums'].map { |album| Hotchoc::Album.new(album) }
15
15
  end
16
16
 
17
17
  it 'returns an array with the albums' do
@@ -23,7 +23,7 @@ describe Hotchoc::Client::API do
23
23
  describe 'Pages' do
24
24
  context 'GET collection' do
25
25
  let(:pages) do
26
- JSON.parse(File.read(response_stub('pages')))['pages'].map { |page| Hotchoc::Presenters::Page.new(page) }
26
+ JSON.parse(File.read(response_stub('pages')))['pages'].map { |page| Hotchoc::Page.new(page) }
27
27
  end
28
28
 
29
29
  it 'returns an array with the pages' do
@@ -35,7 +35,7 @@ describe Hotchoc::Client::API do
35
35
  describe 'Posts' do
36
36
  context 'GET collection' do
37
37
  let(:posts) do
38
- JSON.parse(File.read(response_stub('posts')))['posts'].map { |post| Hotchoc::Presenters::Post.new(post) }
38
+ JSON.parse(File.read(response_stub('posts')))['posts'].map { |post| Hotchoc::Post.new(post) }
39
39
  end
40
40
 
41
41
  it 'returns an array with the posts' do
@@ -47,7 +47,7 @@ describe Hotchoc::Client::API do
47
47
  describe 'Topics' do
48
48
  context 'GET collection' do
49
49
  let(:topics) do
50
- JSON.parse(File.read(response_stub('topics')))['topics'].map { |topic| Hotchoc::Presenters::Topic.new(topic) }
50
+ JSON.parse(File.read(response_stub('topics')))['topics'].map { |topic| Hotchoc::Topic.new(topic) }
51
51
  end
52
52
 
53
53
  it 'returns an array with the topics' do
@@ -1,12 +1,12 @@
1
1
  require 'spec_helper'
2
2
 
3
- describe Hotchoc::Presenters::File do
3
+ describe Hotchoc::File do
4
4
  let(:data) do
5
5
  JSON.parse(File.read(response_stub('albums')))['albums'].first['blocks'].first
6
6
  end
7
7
 
8
8
  let(:file) do
9
- Hotchoc::Presenters::Blocks::Image.new(data).image
9
+ Hotchoc::Blocks::Image.new(data).image
10
10
  end
11
11
 
12
12
  it 'has an id' do
@@ -39,7 +39,7 @@ describe Hotchoc::Presenters::File do
39
39
 
40
40
  it 'has thumbnails' do
41
41
  expect(file.thumbnails).to_not be_empty
42
- expect(file.thumbnails.first).to be_a(Hotchoc::Presenters::Thumbnail)
42
+ expect(file.thumbnails.first).to be_a(Hotchoc::Thumbnail)
43
43
  end
44
44
 
45
45
  it 'has exif info' do
@@ -1,6 +1,6 @@
1
1
  require 'spec_helper'
2
2
 
3
- describe Hotchoc::Presenters::Page do
3
+ describe Hotchoc::Page do
4
4
  let(:data) do
5
5
  JSON.parse(File.read(response_stub('pages')))['pages'].first
6
6
  end
@@ -51,12 +51,12 @@ describe Hotchoc::Presenters::Page do
51
51
 
52
52
  it 'has blocks' do
53
53
  expect(page.blocks).to_not be_empty
54
- expect(page.blocks.first).to be_a(Hotchoc::Presenters::Blocks::Text)
54
+ expect(page.blocks.first).to be_a(Hotchoc::Blocks::Text)
55
55
  end
56
56
 
57
57
  it 'has topics' do
58
58
  expect(page.topics).to_not be_empty
59
- expect(page.topics.first).to be_a(Hotchoc::Presenters::Topic)
59
+ expect(page.topics.first).to be_a(Hotchoc::Topic)
60
60
  end
61
61
 
62
62
  it 'has a created_at' do
@@ -1,6 +1,6 @@
1
1
  require 'spec_helper'
2
2
 
3
- describe Hotchoc::Presenters::Post do
3
+ describe Hotchoc::Post do
4
4
  let(:data) do
5
5
  JSON.parse(File.read(response_stub('posts')))['posts'].first
6
6
  end
@@ -35,12 +35,12 @@ describe Hotchoc::Presenters::Post do
35
35
 
36
36
  it 'has blocks' do
37
37
  expect(post.blocks).to_not be_empty
38
- expect(post.blocks.first).to be_a(Hotchoc::Presenters::Blocks::Text)
38
+ expect(post.blocks.first).to be_a(Hotchoc::Blocks::Text)
39
39
  end
40
40
 
41
41
  it 'has topics' do
42
42
  expect(post.topics).to_not be_empty
43
- expect(post.topics.first).to be_a(Hotchoc::Presenters::Topic)
43
+ expect(post.topics.first).to be_a(Hotchoc::Topic)
44
44
  end
45
45
 
46
46
  it 'has a created_at' do
@@ -1,12 +1,12 @@
1
1
  require 'spec_helper'
2
2
 
3
- describe Hotchoc::Presenters::Thumbnail do
3
+ describe Hotchoc::Thumbnail do
4
4
  let(:data) do
5
5
  JSON.parse(File.read(response_stub('albums')))['albums'].first['blocks'].first
6
6
  end
7
7
 
8
8
  let(:thumbnail) do
9
- Hotchoc::Presenters::Blocks::Image.new(data).image.thumbnails.first
9
+ Hotchoc::Blocks::Image.new(data).image.thumbnails.first
10
10
  end
11
11
 
12
12
  it 'has a name' do
@@ -1,12 +1,12 @@
1
1
  require 'spec_helper'
2
2
 
3
- describe Hotchoc::Presenters::Topic do
3
+ describe Hotchoc::Topic do
4
4
  let(:data) do
5
5
  JSON.parse(File.read(response_stub('posts')))['posts'].first
6
6
  end
7
7
 
8
8
  let(:topic) do
9
- Hotchoc::Presenters::Post.new(data).topics.first
9
+ Hotchoc::Post.new(data).topics.first
10
10
  end
11
11
 
12
12
  it 'has an ID' do
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: hotchoc
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.1
4
+ version: 0.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Matthias Siegel
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-11-12 00:00:00.000000000 Z
11
+ date: 2015-12-03 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: httparty
@@ -140,34 +140,34 @@ files:
140
140
  - Rakefile
141
141
  - hotchoc.gemspec
142
142
  - lib/hotchoc.rb
143
+ - lib/hotchoc/album.rb
144
+ - lib/hotchoc/base.rb
145
+ - lib/hotchoc/blocks/base.rb
146
+ - lib/hotchoc/blocks/image.rb
147
+ - lib/hotchoc/blocks/text.rb
143
148
  - lib/hotchoc/client.rb
144
149
  - lib/hotchoc/client/api.rb
145
150
  - lib/hotchoc/client/configuration.rb
146
151
  - lib/hotchoc/client/errors.rb
147
152
  - lib/hotchoc/client/fetcher.rb
148
153
  - lib/hotchoc/client/version.rb
149
- - lib/hotchoc/presenters/album.rb
150
- - lib/hotchoc/presenters/base.rb
151
- - lib/hotchoc/presenters/blocks/base.rb
152
- - lib/hotchoc/presenters/blocks/image.rb
153
- - lib/hotchoc/presenters/blocks/text.rb
154
- - lib/hotchoc/presenters/file.rb
155
- - lib/hotchoc/presenters/page.rb
156
- - lib/hotchoc/presenters/post.rb
157
- - lib/hotchoc/presenters/thumbnail.rb
158
- - lib/hotchoc/presenters/topic.rb
154
+ - lib/hotchoc/file.rb
155
+ - lib/hotchoc/page.rb
156
+ - lib/hotchoc/post.rb
157
+ - lib/hotchoc/thumbnail.rb
158
+ - lib/hotchoc/topic.rb
159
+ - spec/hotchoc/album_spec.rb
160
+ - spec/hotchoc/blocks/image_spec.rb
161
+ - spec/hotchoc/blocks/text_spec.rb
159
162
  - spec/hotchoc/client/api_spec.rb
160
163
  - spec/hotchoc/client/configuration_spec.rb
161
164
  - spec/hotchoc/client/main_spec.rb
162
165
  - spec/hotchoc/client_spec.rb
163
- - spec/hotchoc/presenters/album_spec.rb
164
- - spec/hotchoc/presenters/blocks/image_spec.rb
165
- - spec/hotchoc/presenters/blocks/text_spec.rb
166
- - spec/hotchoc/presenters/file_spec.rb
167
- - spec/hotchoc/presenters/page_spec.rb
168
- - spec/hotchoc/presenters/post_spec.rb
169
- - spec/hotchoc/presenters/thumbnail_spec.rb
170
- - spec/hotchoc/presenters/topic_spec.rb
166
+ - spec/hotchoc/file_spec.rb
167
+ - spec/hotchoc/page_spec.rb
168
+ - spec/hotchoc/post_spec.rb
169
+ - spec/hotchoc/thumbnail_spec.rb
170
+ - spec/hotchoc/topic_spec.rb
171
171
  - spec/spec_helper.rb
172
172
  - spec/support/helpers.rb
173
173
  - spec/support/matchers.rb
@@ -201,18 +201,18 @@ signing_key:
201
201
  specification_version: 4
202
202
  summary: Ruby wrapper for the Hotchoc API.
203
203
  test_files:
204
+ - spec/hotchoc/album_spec.rb
205
+ - spec/hotchoc/blocks/image_spec.rb
206
+ - spec/hotchoc/blocks/text_spec.rb
204
207
  - spec/hotchoc/client/api_spec.rb
205
208
  - spec/hotchoc/client/configuration_spec.rb
206
209
  - spec/hotchoc/client/main_spec.rb
207
210
  - spec/hotchoc/client_spec.rb
208
- - spec/hotchoc/presenters/album_spec.rb
209
- - spec/hotchoc/presenters/blocks/image_spec.rb
210
- - spec/hotchoc/presenters/blocks/text_spec.rb
211
- - spec/hotchoc/presenters/file_spec.rb
212
- - spec/hotchoc/presenters/page_spec.rb
213
- - spec/hotchoc/presenters/post_spec.rb
214
- - spec/hotchoc/presenters/thumbnail_spec.rb
215
- - spec/hotchoc/presenters/topic_spec.rb
211
+ - spec/hotchoc/file_spec.rb
212
+ - spec/hotchoc/page_spec.rb
213
+ - spec/hotchoc/post_spec.rb
214
+ - spec/hotchoc/thumbnail_spec.rb
215
+ - spec/hotchoc/topic_spec.rb
216
216
  - spec/spec_helper.rb
217
217
  - spec/support/helpers.rb
218
218
  - spec/support/matchers.rb
@@ -1,57 +0,0 @@
1
- module Hotchoc
2
- module Presenters
3
- class Album < Hotchoc::Presenters::Base
4
- def id
5
- @item['id']
6
- end
7
-
8
- def title
9
- @item['title']
10
- end
11
-
12
- def subtitle
13
- @item['subtitle']
14
- end
15
-
16
- def description
17
- @item['description']
18
- end
19
-
20
- def identifier
21
- @item['identifier']
22
- end
23
-
24
- def status
25
- @item['status']
26
- end
27
-
28
- def publish_date
29
- Time.parse(@item['publish_date'])
30
- end
31
-
32
- def cover
33
- @item['cover'] ? block_for(@item['cover']) : nil
34
- end
35
-
36
- def blocks
37
- @item['blocks'].to_a.map { |block| block_for(block) }
38
- end
39
-
40
- def topics
41
- @item['topics'].to_a.map { |topic| Hotchoc::Presenters::Topic.new(topic) }
42
- end
43
-
44
- def created_at
45
- Time.parse(@item['created_at'])
46
- end
47
-
48
- def updated_at
49
- Time.parse(@item['updated_at'])
50
- end
51
-
52
- def inspect
53
- %(#<Hotchoc::Presenters::Album: title="#{title}">)
54
- end
55
- end
56
- end
57
- end
@@ -1,22 +0,0 @@
1
- module Hotchoc
2
- module Presenters
3
- class Base
4
- attr_reader :item
5
-
6
- def initialize(item = {})
7
- @item = item
8
- end
9
-
10
- private
11
-
12
- def block_for(block)
13
- case block['type']
14
- when 'text'
15
- Hotchoc::Presenters::Blocks::Text.new(block)
16
- when 'image'
17
- Hotchoc::Presenters::Blocks::Image.new(block)
18
- end
19
- end
20
- end
21
- end
22
- end
@@ -1,27 +0,0 @@
1
- module Hotchoc
2
- module Presenters
3
- module Blocks
4
- class Base < Hotchoc::Presenters::Base
5
- def id
6
- @item['id']
7
- end
8
-
9
- def type
10
- @item['type']
11
- end
12
-
13
- def position
14
- @item['position']
15
- end
16
-
17
- def created_at
18
- Time.parse(@item['created_at'])
19
- end
20
-
21
- def updated_at
22
- Time.parse(@item['updated_at'])
23
- end
24
- end
25
- end
26
- end
27
- end
@@ -1,19 +0,0 @@
1
- module Hotchoc
2
- module Presenters
3
- module Blocks
4
- class Image < Hotchoc::Presenters::Blocks::Base
5
- def title
6
- @item['content']['title']
7
- end
8
-
9
- def image
10
- @item['content']['image'] ? Hotchoc::Presenters::File.new(@item['content']['image']) : nil
11
- end
12
-
13
- def inspect
14
- %(#<Hotchoc::Presenters::Blocks::Image: title="#{title}" position="#{position}">)
15
- end
16
- end
17
- end
18
- end
19
- end
@@ -1,19 +0,0 @@
1
- module Hotchoc
2
- module Presenters
3
- module Blocks
4
- class Text < Hotchoc::Presenters::Blocks::Base
5
- def markdown
6
- @item['content']['markdown']
7
- end
8
-
9
- def html
10
- @item['content']['html']
11
- end
12
-
13
- def inspect
14
- %(#<Hotchoc::Presenters::Blocks::Text: position="#{position}">)
15
- end
16
- end
17
- end
18
- end
19
- end
@@ -1,58 +0,0 @@
1
- module Hotchoc
2
- module Presenters
3
- class File < Hotchoc::Presenters::Base
4
- def id
5
- @item['id']
6
- end
7
-
8
- def name
9
- @item['name']
10
- end
11
-
12
- def url
13
- @item['url']
14
- end
15
-
16
- def width
17
- @item['width']
18
- end
19
-
20
- def height
21
- @item['height']
22
- end
23
-
24
- def size
25
- @item['size']
26
- end
27
-
28
- def content_type
29
- @item['content_type']
30
- end
31
-
32
- def thumbnails
33
- if @item['thumbnails']
34
- @item['thumbnails']['original'].map { |thumbnail| Hotchoc::Presenters::Thumbnail.new(thumbnail) } +
35
- @item['thumbnails']['square'].map { |thumbnail| Hotchoc::Presenters::Thumbnail.new(thumbnail) }
36
- else
37
- []
38
- end
39
- end
40
-
41
- def exif
42
- @item['exif']
43
- end
44
-
45
- def created_at
46
- Time.parse(@item['created_at'])
47
- end
48
-
49
- def updated_at
50
- Time.parse(@item['updated_at'])
51
- end
52
-
53
- def inspect
54
- %(#<Hotchoc::Presenters::File: name="#{name}">)
55
- end
56
- end
57
- end
58
- end
@@ -1,65 +0,0 @@
1
- module Hotchoc
2
- module Presenters
3
- class Page < Hotchoc::Presenters::Base
4
- def id
5
- @item['id']
6
- end
7
-
8
- def title
9
- @item['title']
10
- end
11
-
12
- def subtitle
13
- @item['subtitle']
14
- end
15
-
16
- def identifier
17
- @item['identifier']
18
- end
19
-
20
- def status
21
- @item['status']
22
- end
23
-
24
- def path
25
- @item['path']
26
- end
27
-
28
- def parent_id
29
- @item['parent_id']
30
- end
31
-
32
- def position
33
- @item['position']
34
- end
35
-
36
- def level
37
- @item['level']
38
- end
39
-
40
- def publish_date
41
- Time.parse(@item['publish_date'])
42
- end
43
-
44
- def blocks
45
- @item['blocks'].to_a.map { |block| block_for(block) }
46
- end
47
-
48
- def topics
49
- @item['topics'].to_a.map { |topic| Hotchoc::Presenters::Topic.new(topic) }
50
- end
51
-
52
- def created_at
53
- Time.parse(@item['created_at'])
54
- end
55
-
56
- def updated_at
57
- Time.parse(@item['updated_at'])
58
- end
59
-
60
- def inspect
61
- %(#<Hotchoc::Presenters::Page: title="#{title}">)
62
- end
63
- end
64
- end
65
- end
@@ -1,49 +0,0 @@
1
- module Hotchoc
2
- module Presenters
3
- class Post < Hotchoc::Presenters::Base
4
- def id
5
- @item['id']
6
- end
7
-
8
- def title
9
- @item['title']
10
- end
11
-
12
- def subtitle
13
- @item['subtitle']
14
- end
15
-
16
- def identifier
17
- @item['identifier']
18
- end
19
-
20
- def status
21
- @item['status']
22
- end
23
-
24
- def publish_date
25
- Time.parse(@item['publish_date'])
26
- end
27
-
28
- def blocks
29
- @item['blocks'].to_a.map { |block| block_for(block) }
30
- end
31
-
32
- def topics
33
- @item['topics'].to_a.map { |topic| Hotchoc::Presenters::Topic.new(topic) }
34
- end
35
-
36
- def created_at
37
- Time.parse(@item['created_at'])
38
- end
39
-
40
- def updated_at
41
- Time.parse(@item['updated_at'])
42
- end
43
-
44
- def inspect
45
- %(#<Hotchoc::Presenters::Post: title="#{title}">)
46
- end
47
- end
48
- end
49
- end
@@ -1,33 +0,0 @@
1
- module Hotchoc
2
- module Presenters
3
- class Thumbnail < Hotchoc::Presenters::Base
4
- def name
5
- @item['name']
6
- end
7
-
8
- def width
9
- @item['width']
10
- end
11
-
12
- def height
13
- @item['height']
14
- end
15
-
16
- def square?
17
- width == height
18
- end
19
-
20
- def size
21
- @item['size']
22
- end
23
-
24
- def url
25
- @item['url']
26
- end
27
-
28
- def inspect
29
- %(#<Hotchoc::Presenters::Thumbnail:>)
30
- end
31
- end
32
- end
33
- end