almanack 1.0.3 → 1.0.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/almanack.gemspec +1 -0
- data/lib/almanack/calendar.rb +6 -2
- data/lib/almanack/configuration.rb +6 -6
- data/lib/almanack/event_source/ical_feed.rb +10 -9
- data/lib/almanack/event_source/meetup_group.rb +5 -8
- data/lib/almanack/server/helpers.rb +36 -0
- data/lib/almanack/server.rb +2 -26
- data/lib/almanack/themes/starter/views/layout.erb +3 -0
- data/lib/almanack/version.rb +1 -1
- data/lib/almanack.rb +5 -0
- data/spec/event_source/ical_feed_spec.rb +2 -5
- data/spec/event_source/meetup_group_spec.rb +6 -2
- metadata +17 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: fe53eb2cd99063253c8164224af13ad6a9d8c0e4
|
4
|
+
data.tar.gz: d9bea9d46b17cbdd855b15a88ca31453b1cd8789
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: fb5812256cb74b0d8045df525078dd1946206f8523da3a88b9b924bde801b4d35f64117bce407e0433261bb2f3c5e58ea84adeca9af659d1230126ea2350c39e
|
7
|
+
data.tar.gz: 91bf2d03200306091280e7df21e53313ef7b956f0b8e3a1fa8e3df16454bf02a7dbfc316751226c3c2f3934caed0a708d08a1eeccf7a83432396eb500e06a1f1
|
data/almanack.gemspec
CHANGED
@@ -23,6 +23,7 @@ Gem::Specification.new do |spec|
|
|
23
23
|
spec.add_dependency "ri_cal"
|
24
24
|
spec.add_dependency "addressable"
|
25
25
|
spec.add_dependency "thor"
|
26
|
+
spec.add_dependency "faraday"
|
26
27
|
|
27
28
|
spec.add_development_dependency "bundler", "~> 1.5"
|
28
29
|
spec.add_development_dependency "rake"
|
data/lib/almanack/calendar.rb
CHANGED
@@ -21,9 +21,13 @@ module Almanack
|
|
21
21
|
end
|
22
22
|
|
23
23
|
def events_between(date_range)
|
24
|
-
event_sources.map do |event_source|
|
24
|
+
event_list = event_sources.map do |event_source|
|
25
25
|
event_source.events_between(date_range)
|
26
|
-
end.flatten
|
26
|
+
end.flatten
|
27
|
+
|
28
|
+
event_list.sort_by do |event|
|
29
|
+
event.start_date.to_time
|
30
|
+
end
|
27
31
|
end
|
28
32
|
|
29
33
|
def ical_feed
|
@@ -1,7 +1,3 @@
|
|
1
|
-
require 'net/http'
|
2
|
-
require 'uri'
|
3
|
-
require 'ri_cal'
|
4
|
-
|
5
1
|
module Almanack
|
6
2
|
class Configuration
|
7
3
|
class ThemeNotFound < StandardError; end
|
@@ -16,6 +12,10 @@ module Almanack
|
|
16
12
|
reset!
|
17
13
|
end
|
18
14
|
|
15
|
+
def connection
|
16
|
+
@connection ||= Faraday.new
|
17
|
+
end
|
18
|
+
|
19
19
|
def reset!
|
20
20
|
@theme = DEFAULT_THEME
|
21
21
|
@days_lookahead = DEFAULT_DAYS_LOOKAHEAD
|
@@ -34,7 +34,7 @@ module Almanack
|
|
34
34
|
end
|
35
35
|
|
36
36
|
def add_ical_feed(url)
|
37
|
-
@event_sources << EventSource::IcalFeed.new(url)
|
37
|
+
@event_sources << EventSource::IcalFeed.new(url, connection: connection)
|
38
38
|
end
|
39
39
|
|
40
40
|
def add_events(events)
|
@@ -42,7 +42,7 @@ module Almanack
|
|
42
42
|
end
|
43
43
|
|
44
44
|
def add_meetup_group(options)
|
45
|
-
@event_sources << EventSource::MeetupGroup.new(options)
|
45
|
+
@event_sources << EventSource::MeetupGroup.new(options.merge(connection: connection))
|
46
46
|
end
|
47
47
|
end
|
48
48
|
end
|
@@ -1,12 +1,9 @@
|
|
1
|
-
require 'net/http'
|
2
|
-
require 'uri'
|
3
|
-
require 'ri_cal'
|
4
|
-
|
5
1
|
module Almanack
|
6
2
|
module EventSource
|
7
3
|
class IcalFeed
|
8
|
-
def initialize(url)
|
4
|
+
def initialize(url, options = {})
|
9
5
|
@url = url
|
6
|
+
@options = options
|
10
7
|
end
|
11
8
|
|
12
9
|
def events_between(date_range)
|
@@ -49,12 +46,16 @@ module Almanack
|
|
49
46
|
end
|
50
47
|
|
51
48
|
def entities
|
52
|
-
RiCal.parse_string(body)
|
49
|
+
RiCal.parse_string(response.body)
|
50
|
+
end
|
51
|
+
|
52
|
+
def connection
|
53
|
+
@options[:connection]
|
53
54
|
end
|
54
55
|
|
55
|
-
def
|
56
|
-
uri = URI(@url)
|
57
|
-
|
56
|
+
def response
|
57
|
+
uri = Addressable::URI.parse(@url)
|
58
|
+
connection.get(uri)
|
58
59
|
end
|
59
60
|
|
60
61
|
end
|
@@ -1,7 +1,3 @@
|
|
1
|
-
require 'net/http'
|
2
|
-
require 'json'
|
3
|
-
require 'addressable/uri'
|
4
|
-
|
5
1
|
module Almanack
|
6
2
|
module EventSource
|
7
3
|
class MeetupGroup
|
@@ -18,7 +14,7 @@ module Almanack
|
|
18
14
|
private
|
19
15
|
|
20
16
|
def events
|
21
|
-
request = MeetupAPIRequest.new(@request_options)
|
17
|
+
request = MeetupAPIRequest.new(@request_options.clone)
|
22
18
|
request.results.map { |result| event_from(result) }
|
23
19
|
end
|
24
20
|
|
@@ -59,9 +55,10 @@ module Almanack
|
|
59
55
|
class MeetupAPIRequest
|
60
56
|
REQUIRED_OPTIONS = [:group_domain, :group_urlname, :group_id]
|
61
57
|
|
62
|
-
|
58
|
+
attr_reader :options, :connection
|
63
59
|
|
64
60
|
def initialize(options = {})
|
61
|
+
@connection = options.delete(:connection)
|
65
62
|
@options = options
|
66
63
|
end
|
67
64
|
|
@@ -86,8 +83,8 @@ module Almanack
|
|
86
83
|
end
|
87
84
|
|
88
85
|
def response
|
89
|
-
|
90
|
-
data = JSON.parse(
|
86
|
+
response = connection.get(uri)
|
87
|
+
data = JSON.parse(response.body)
|
91
88
|
|
92
89
|
if data['problem']
|
93
90
|
raise MeetupAPIError, data['problem']
|
@@ -0,0 +1,36 @@
|
|
1
|
+
Almanack::Server.helpers do
|
2
|
+
# @return The URL to your consolidated iCal feed.
|
3
|
+
def feed_url
|
4
|
+
"webcal://#{request.host}:#{request.port}/#{settings.feed_path}"
|
5
|
+
end
|
6
|
+
|
7
|
+
# @return The URL to Almanack's project homepage.
|
8
|
+
def almanack_project_url
|
9
|
+
Almanack::HOMEPAGE
|
10
|
+
end
|
11
|
+
|
12
|
+
# @return The URL to Almanack's issues page.
|
13
|
+
def almanack_issues_url
|
14
|
+
Almanack::ISSUES
|
15
|
+
end
|
16
|
+
|
17
|
+
# @return The current time.
|
18
|
+
def now
|
19
|
+
Time.now
|
20
|
+
end
|
21
|
+
|
22
|
+
# @return The calendar.
|
23
|
+
def calendar
|
24
|
+
@calendar ||= Almanack.calendar
|
25
|
+
end
|
26
|
+
|
27
|
+
# @return The title of the page.
|
28
|
+
def page_title(separator: " – ")
|
29
|
+
[@title, calendar.title].compact.join(separator)
|
30
|
+
end
|
31
|
+
|
32
|
+
# Use to set the title of the page.
|
33
|
+
def title(value)
|
34
|
+
@title = value
|
35
|
+
end
|
36
|
+
end
|
data/lib/almanack/server.rb
CHANGED
@@ -5,6 +5,8 @@ require "almanack"
|
|
5
5
|
|
6
6
|
module Almanack
|
7
7
|
class Server < Sinatra::Base
|
8
|
+
require "almanack/server/helpers"
|
9
|
+
|
8
10
|
configure :development do
|
9
11
|
register Sinatra::Reloader
|
10
12
|
end
|
@@ -13,32 +15,6 @@ module Almanack
|
|
13
15
|
set :protection, except: :frame_options
|
14
16
|
set :feed_path, "feed.ics"
|
15
17
|
|
16
|
-
helpers do
|
17
|
-
def feed_url
|
18
|
-
"webcal://#{request.host}:#{request.port}/#{settings.feed_path}"
|
19
|
-
end
|
20
|
-
|
21
|
-
def almanack_project_url
|
22
|
-
Almanack::HOMEPAGE
|
23
|
-
end
|
24
|
-
|
25
|
-
def almanack_issues_url
|
26
|
-
Almanack::ISSUES
|
27
|
-
end
|
28
|
-
|
29
|
-
def calendar
|
30
|
-
@calendar ||= Almanack.calendar
|
31
|
-
end
|
32
|
-
|
33
|
-
def page_title(separator: " – ")
|
34
|
-
[@title, calendar.title].compact.join(separator)
|
35
|
-
end
|
36
|
-
|
37
|
-
def title(value)
|
38
|
-
@title = value
|
39
|
-
end
|
40
|
-
end
|
41
|
-
|
42
18
|
not_found do
|
43
19
|
status 404
|
44
20
|
erb :error
|
@@ -7,6 +7,9 @@
|
|
7
7
|
</head>
|
8
8
|
<body>
|
9
9
|
|
10
|
+
<!-- See http://strftime.net and http://strftimer.com for datee syntax reference -->
|
11
|
+
<p>The time is now <b><%= now.strftime('%A, %-d %B, %Y at %-l:%M%P %z') %></b>.</p>
|
12
|
+
|
10
13
|
<header>
|
11
14
|
<h1><a href="/"><%= calendar.title %></a></h1>
|
12
15
|
<h2>The Next <%= calendar.days_lookahead %> Days</h2>
|
data/lib/almanack/version.rb
CHANGED
data/lib/almanack.rb
CHANGED
@@ -2,13 +2,10 @@ require 'spec_helper'
|
|
2
2
|
|
3
3
|
module Almanack::EventSource
|
4
4
|
describe IcalFeed do
|
5
|
-
it "accepts a URL" do
|
6
|
-
IcalFeed.new("http://example.org/ical.ics")
|
7
|
-
end
|
8
|
-
|
9
5
|
describe "#events_between" do
|
10
6
|
it "returns a list of events" do
|
11
|
-
feed = IcalFeed.new('https://www.google.com/calendar/ical/61s2re9bfk01abmla4d17tojuo%40group.calendar.google.com/public/basic.ics'
|
7
|
+
feed = IcalFeed.new('https://www.google.com/calendar/ical/61s2re9bfk01abmla4d17tojuo%40group.calendar.google.com/public/basic.ics',
|
8
|
+
connection: Faraday.new)
|
12
9
|
events = nil
|
13
10
|
|
14
11
|
Timecop.freeze(2014, 4, 3) do
|
@@ -4,7 +4,9 @@ module Almanack::EventSource
|
|
4
4
|
describe MeetupGroup do
|
5
5
|
describe "#events_between" do
|
6
6
|
it "returns a list of events" do
|
7
|
-
feed = MeetupGroup.new(group_urlname: 'The-Foundation-Christchurch',
|
7
|
+
feed = MeetupGroup.new(group_urlname: 'The-Foundation-Christchurch',
|
8
|
+
key: 'secrettoken',
|
9
|
+
connection: Faraday.new)
|
8
10
|
events = nil
|
9
11
|
|
10
12
|
Timecop.freeze(2014, 5, 24) do
|
@@ -22,7 +24,9 @@ module Almanack::EventSource
|
|
22
24
|
end
|
23
25
|
|
24
26
|
it "handles a missing location" do
|
25
|
-
feed = MeetupGroup.new(group_urlname: 'adventurewellington',
|
27
|
+
feed = MeetupGroup.new(group_urlname: 'adventurewellington',
|
28
|
+
key: 'secrettoken',
|
29
|
+
connection: Faraday.new)
|
26
30
|
|
27
31
|
Timecop.freeze(2014, 7, 23) do
|
28
32
|
VCR.use_cassette('meetup-without-location') do
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: almanack
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Pete Nicholls
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-
|
11
|
+
date: 2014-08-11 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: sinatra
|
@@ -94,6 +94,20 @@ dependencies:
|
|
94
94
|
- - ">="
|
95
95
|
- !ruby/object:Gem::Version
|
96
96
|
version: '0'
|
97
|
+
- !ruby/object:Gem::Dependency
|
98
|
+
name: faraday
|
99
|
+
requirement: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - ">="
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: '0'
|
104
|
+
type: :runtime
|
105
|
+
prerelease: false
|
106
|
+
version_requirements: !ruby/object:Gem::Requirement
|
107
|
+
requirements:
|
108
|
+
- - ">="
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: '0'
|
97
111
|
- !ruby/object:Gem::Dependency
|
98
112
|
name: bundler
|
99
113
|
requirement: !ruby/object:Gem::Requirement
|
@@ -246,6 +260,7 @@ files:
|
|
246
260
|
- lib/almanack/event_source/meetup_group.rb
|
247
261
|
- lib/almanack/event_source/static.rb
|
248
262
|
- lib/almanack/server.rb
|
263
|
+
- lib/almanack/server/helpers.rb
|
249
264
|
- lib/almanack/themes/legacy/stylesheets/calendar.scss
|
250
265
|
- lib/almanack/themes/legacy/views/error.erb
|
251
266
|
- lib/almanack/themes/legacy/views/events.erb
|