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 +4 -4
- data/configs/Budapest/Central.yml +7 -0
- data/daily_menu.gemspec +1 -1
- data/lib/daily_menu/cli.rb +32 -6
- data/lib/daily_menu/filters/hungarian.rb +1 -1
- data/lib/daily_menu/scrapers/facebook.rb +10 -1
- data/lib/daily_menu/version.rb +1 -1
- data/spec/daily_menu/cli_spec.rb +55 -0
- data/spec/daily_menu/scrapers/facebook_spec.rb +26 -9
- data/spec/integration/koala_spec.rb +32 -17
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f2251d2762b347b76eb2d52b435d304bfbee47ad
|
4
|
+
data.tar.gz: 1ee58769ad8b6b08fe023fcaf7b352cf293f5db7
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c55c836df1a13046b91bd43d625f75e6b0a91079d6e939236a73eef8e2d09b24ae52731132f1d09643b5da178608c3a3f4287848004e4045105fade526087197
|
7
|
+
data.tar.gz: f6afe3c0d92fa42f4a0b8c014d5c54fe8507770d2f7a8c20c97c880ff4450e1e7f3ee1bab21e2fd373d8015ec2c6472bff7f6df29baab3073f38461de944f0c7
|
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 '
|
24
|
+
spec.add_dependency 'colorize'
|
25
25
|
|
26
26
|
spec.add_development_dependency 'bundler', '~> 1.3'
|
27
27
|
spec.add_development_dependency 'rake'
|
data/lib/daily_menu/cli.rb
CHANGED
@@ -1,19 +1,44 @@
|
|
1
|
-
require '
|
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
|
-
|
31
|
+
print(DailyMenu.menus_for(location))
|
10
32
|
end
|
11
33
|
|
12
|
-
def self.
|
13
|
-
|
14
|
-
|
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 :
|
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
|
@@ -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
|
data/lib/daily_menu/version.rb
CHANGED
data/spec/daily_menu/cli_spec.rb
CHANGED
@@ -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
|
-
|
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
|
-
|
40
|
-
|
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
|
-
|
42
|
+
expect { scraper.entries }.to raise_error(RuntimeError)
|
43
|
+
end
|
43
44
|
end
|
44
45
|
|
45
|
-
|
46
|
-
|
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
|
-
|
49
|
-
|
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(
|
24
|
+
expect(api.get_object(user).keys).to include('id')
|
24
25
|
end
|
25
26
|
end
|
27
|
+
|
26
28
|
end
|
27
29
|
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
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
|
-
|
36
|
-
|
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
|
-
|
39
|
-
|
49
|
+
it 'should be a Hash' do
|
50
|
+
pending('OAuth token is not provided') if token.nil?
|
40
51
|
|
41
|
-
|
42
|
-
|
52
|
+
expect(item).to be_a(Hash)
|
53
|
+
end
|
43
54
|
|
44
|
-
|
45
|
-
|
55
|
+
it 'should have the correct keys' do
|
56
|
+
pending('OAuth token is not provided') if token.nil?
|
46
57
|
|
47
|
-
|
48
|
-
|
58
|
+
expect(item.keys).to include(*%w(id from type created_time))
|
59
|
+
end
|
49
60
|
|
50
|
-
|
51
|
-
|
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.
|
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-
|
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:
|
28
|
+
name: colorize
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
30
30
|
requirements:
|
31
31
|
- - '>='
|