daily_menu 0.0.3 → 0.0.4

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: d9dac4c4aefd8b0ae07213b067796b1b8549cb58
4
- data.tar.gz: 29f79133826fda036006d8c1be180ce2c33507f8
3
+ metadata.gz: f2251d2762b347b76eb2d52b435d304bfbee47ad
4
+ data.tar.gz: 1ee58769ad8b6b08fe023fcaf7b352cf293f5db7
5
5
  SHA512:
6
- metadata.gz: 171f24c7268b09c74f84229cde011492ec96e42cc6e623b0cadafe5bbc0cef3ff6de98dea8877af7fcfafaa34bea4d9f912ff74f1a0beb06f19f2f13d1c18bb7
7
- data.tar.gz: 9954572fb0a09cf301e0585d8b66a821f2962c74a3c42575abcce14880f1c12c2d867172534dc596e196512e2115728b7b0e53a458543679b12009cc6ba20f38
6
+ metadata.gz: c55c836df1a13046b91bd43d625f75e6b0a91079d6e939236a73eef8e2d09b24ae52731132f1d09643b5da178608c3a3f4287848004e4045105fade526087197
7
+ data.tar.gz: f6afe3c0d92fa42f4a0b8c014d5c54fe8507770d2f7a8c20c97c880ff4450e1e7f3ee1bab21e2fd373d8015ec2c6472bff7f6df29baab3073f38461de944f0c7
@@ -47,3 +47,10 @@
47
47
  - 'sueltomama'
48
48
  :filter:
49
49
  :class: Hungarian
50
+ - :name: 'Cafe Vian Gozsdu'
51
+ :scraper:
52
+ :class: Facebook
53
+ :params:
54
+ - '179130202109'
55
+ :filter:
56
+ :class: Hungarian
data/daily_menu.gemspec CHANGED
@@ -21,7 +21,7 @@ Gem::Specification.new do |spec|
21
21
  spec.require_paths = ['lib']
22
22
 
23
23
  spec.add_dependency 'koala'
24
- spec.add_dependency 'awesome_print'
24
+ spec.add_dependency 'colorize'
25
25
 
26
26
  spec.add_development_dependency 'bundler', '~> 1.3'
27
27
  spec.add_development_dependency 'rake'
@@ -1,19 +1,44 @@
1
- require 'awesome_print'
1
+ require 'colorize'
2
2
 
3
3
  module DailyMenu
4
+ class ColoredFormatter
5
+ def self.print(restaurant, entry)
6
+ puts restaurant.name.green
7
+ puts entry.content
8
+ puts entry.time.to_s.yellow
9
+ puts ''
10
+ end
11
+ end
12
+
13
+ class MarkdownFormatter
14
+ def self.print(restaurant, entry)
15
+ puts "# #{restaurant.name}"
16
+ puts ''
17
+ puts entry.content
18
+ puts ''
19
+ puts "*#{entry.time}*"
20
+ puts ''
21
+ puts '- - -'
22
+ puts ''
23
+ end
24
+ end
25
+
4
26
  class CLI
5
27
  RC_FILE = File.expand_path('.daily_menurc', ENV['HOME']).freeze
6
28
 
7
29
  def self.start(arguments)
8
30
  location = arguments.empty? ? read_rc : arguments.first
9
- ap fetch(location)
31
+ print(DailyMenu.menus_for(location))
10
32
  end
11
33
 
12
- def self.fetch(location)
13
- menus = DailyMenu.menus_for(location)
14
- Hash[menus]
34
+ def self.print(menus)
35
+ formatter = STDOUT.tty? ? ColoredFormatter : MarkdownFormatter
36
+
37
+ menus.each do |restaurant, entry|
38
+ formatter.print(restaurant, entry)
39
+ end
15
40
  end
16
- private_class_method :fetch
41
+ private_class_method :print
17
42
 
18
43
  def self.read_rc
19
44
  raise 'Unable to read the config file' unless DailyMenu.file_accessible?(RC_FILE)
@@ -21,6 +46,7 @@ module DailyMenu
21
46
  File.new(RC_FILE).read.chomp
22
47
  end
23
48
  private_class_method :read_rc
49
+
24
50
  end
25
51
 
26
52
  end
@@ -4,7 +4,7 @@ module DailyMenu::Filters
4
4
  def_delegator :@filter, :matches?
5
5
 
6
6
  def initialize
7
- @filter = Regexp.new(/\b(?:menü|ebéd|leves)/i)
7
+ @filter = DailyMenu::Filters::Regexp.new(/\b(?:menü|ebéd|leves)/i)
8
8
  end
9
9
  end
10
10
  end
@@ -13,7 +13,11 @@ module DailyMenu
13
13
  @api
14
14
  .get_connections(user_id, 'feed')
15
15
  .select { |feed_item| feed_item['from']['id'] == user_id && feed_item['message'] }
16
- .map { |entry| Entry.new(entry['message'], parse_time(entry['created_time'])) }
16
+ .map { |entry| Entry.new(strip_content(entry['message']), parse_time(entry['created_time'])) }
17
+ rescue Koala::Facebook::ClientError => e
18
+ error = RuntimeError.new(e.message)
19
+ error.set_backtrace(e.backtrace)
20
+ raise error
17
21
  end
18
22
 
19
23
  def user_id
@@ -26,5 +30,10 @@ module DailyMenu
26
30
  end
27
31
  private :parse_time
28
32
 
33
+ def strip_content(message)
34
+ message.gsub("\r\n", "\n")
35
+ end
36
+ private :strip_content
37
+
29
38
  end
30
39
  end
@@ -1,3 +1,3 @@
1
1
  module DailyMenu
2
- VERSION = '0.0.3'.freeze
2
+ VERSION = '0.0.4'.freeze
3
3
  end
@@ -34,6 +34,61 @@ module DailyMenu
34
34
  end
35
35
  end
36
36
 
37
+ context 'when there are fetched menus' do
38
+ let(:location) { double('Location') }
39
+ let(:restaurant) { double('Restaurant', name: 'Name') }
40
+ let(:entry) { double('Entry', content: 'Content', time: DateTime.now) }
41
+ let(:menus) { [[restaurant, entry]] }
42
+
43
+ before do
44
+ DailyMenu.stub(:menus_for).with(location) { menus }
45
+ end
46
+
47
+ context 'and using terminal' do
48
+ before do
49
+ STDOUT.stub(:tty?) { true }
50
+ end
51
+
52
+ it 'should use the ColoredFormatter' do
53
+ ColoredFormatter.stub(:print)
54
+
55
+ described_class.start([location])
56
+
57
+ expect(ColoredFormatter).to have_received(:print).with(restaurant, entry)
58
+ end
59
+
60
+ it 'should print out to console' do
61
+ STDOUT.stub(:puts)
62
+
63
+ described_class.start([location])
64
+
65
+ expect(STDOUT).to have_received(:puts).at_least(:once)
66
+ end
67
+ end
68
+
69
+ context 'and using pipe' do
70
+ before do
71
+ STDOUT.stub(:tty?) { false }
72
+ end
73
+
74
+ it 'should use the MarkdownFormatter' do
75
+ MarkdownFormatter.stub(:print)
76
+
77
+ described_class.start([location])
78
+
79
+ expect(MarkdownFormatter).to have_received(:print).with(restaurant, entry)
80
+ end
81
+
82
+ it 'should print out to console' do
83
+ STDOUT.stub(:puts)
84
+
85
+ described_class.start([location])
86
+
87
+ expect(STDOUT).to have_received(:puts).at_least(:once)
88
+ end
89
+ end
90
+ end
91
+
37
92
  end
38
93
  end
39
94
  end
@@ -32,21 +32,38 @@ module DailyMenu
32
32
 
33
33
  describe '#entries' do
34
34
  before do
35
- ::Koala::Facebook::API.any_instance.stub(:get_connections) { feed_items }
36
- ::Koala::Facebook::API.any_instance.stub(:get_object) { { 'id' => user_id } }
35
+ Koala::Facebook::API.any_instance.stub(:get_object) { { 'id' => user_id } }
37
36
  end
38
37
 
39
- it 'should create Entry items' do
40
- entries = scraper.entries
38
+ context 'when an error occurs' do
39
+ it 'should raise RuntimeError' do
40
+ Koala::Facebook::API.any_instance.stub(:get_connections) { raise Koala::Facebook::ClientError.new(nil, nil) }
41
41
 
42
- expect(entries.all? { |entry| entry.is_a?(Entry) }).to be_true
42
+ expect { scraper.entries }.to raise_error(RuntimeError)
43
+ end
43
44
  end
44
45
 
45
- it 'should fetch the entries of the specified user from Facebook' do
46
- entries = scraper.entries
46
+ context 'when there are no errors' do
47
+ before do
48
+ Koala::Facebook::API.any_instance.stub(:get_connections) { feed_items }
49
+ end
47
50
 
48
- expect(entries).to have(2).entries
49
- expect(entries).to include(Entry.new(greeting_text, greeting_time), Entry.new(daily_menu_text, daily_menu_time))
51
+ it 'should create Entry items' do
52
+ entries = scraper.entries
53
+
54
+ expect(entries.all? { |entry| entry.is_a?(Entry) }).to be_true
55
+ end
56
+
57
+ it 'should fetch the entries of the specified user from Facebook' do
58
+ entries = scraper.entries
59
+ expected_entries = [
60
+ Entry.new(greeting_text, greeting_time),
61
+ Entry.new(daily_menu_text, daily_menu_time)
62
+ ]
63
+
64
+ expect(entries).to have(2).entries
65
+ expect(entries).to include(*expected_entries)
66
+ end
50
67
  end
51
68
  end
52
69
  end
@@ -16,40 +16,55 @@ module Koala::Facebook
16
16
  end
17
17
 
18
18
  describe '.get_object' do
19
+
19
20
  it 'should contain the id' do
20
21
  pending('OAuth token is not provided') if token.nil?
21
22
 
22
23
  VCR.use_cassette('object') do
23
- expect(api.get_object('Koleves').keys).to include('id')
24
+ expect(api.get_object(user).keys).to include('id')
24
25
  end
25
26
  end
27
+
26
28
  end
27
29
 
28
- context('an item from the feed') do
29
- let(:item) do
30
- VCR.use_cassette('feed') do
31
- api.get_connections(user, 'feed').first
30
+ describe '.get_connections' do
31
+
32
+ context 'when not providing the OAuth token' do
33
+ it 'should raise an error' do
34
+ VCR.use_cassette('without_token') do
35
+ api = described_class.new(nil)
36
+
37
+ expect { api.get_connections(user, 'feed') }.to raise_error(Koala::Facebook::ClientError)
38
+ end
32
39
  end
33
40
  end
34
41
 
35
- it 'should be a Hash' do
36
- pending('OAuth token is not provided') if token.nil?
42
+ context('an item from the feed') do
43
+ let(:item) do
44
+ VCR.use_cassette('feed') do
45
+ api.get_connections(user, 'feed').first
46
+ end
47
+ end
37
48
 
38
- expect(item).to be_a(Hash)
39
- end
49
+ it 'should be a Hash' do
50
+ pending('OAuth token is not provided') if token.nil?
40
51
 
41
- it 'should have the correct keys' do
42
- pending('OAuth token is not provided') if token.nil?
52
+ expect(item).to be_a(Hash)
53
+ end
43
54
 
44
- expect(item.keys).to include(*%w(id from type created_time))
45
- end
55
+ it 'should have the correct keys' do
56
+ pending('OAuth token is not provided') if token.nil?
46
57
 
47
- it 'the from field should contain the id' do
48
- pending('OAuth token is not provided') if token.nil?
58
+ expect(item.keys).to include(*%w(id from type created_time))
59
+ end
49
60
 
50
- expect(item['from'].keys).to include('id')
51
- end
61
+ it 'the from field should contain the id' do
62
+ pending('OAuth token is not provided') if token.nil?
63
+
64
+ expect(item['from'].keys).to include('id')
65
+ end
52
66
 
67
+ end
53
68
  end
54
69
  end
55
70
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: daily_menu
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.3
4
+ version: 0.0.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - KARASZI István
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-08-16 00:00:00.000000000 Z
11
+ date: 2013-08-18 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: koala
@@ -25,7 +25,7 @@ dependencies:
25
25
  - !ruby/object:Gem::Version
26
26
  version: '0'
27
27
  - !ruby/object:Gem::Dependency
28
- name: awesome_print
28
+ name: colorize
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
31
  - - '>='