Skip to content

Commit

Permalink
Merge branch 'feature-diary'
Browse files Browse the repository at this point in the history
  • Loading branch information
CHTJonas committed Dec 5, 2018
2 parents f03701b + bf20fcd commit 4a6f823
Show file tree
Hide file tree
Showing 6 changed files with 137 additions and 10 deletions.
24 changes: 24 additions & 0 deletions lib/camdram/client.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
require 'camdram/person'
require 'camdram/role'
require 'camdram/search'
require 'camdram/diary'

module Camdram
class Client
Expand Down Expand Up @@ -193,6 +194,29 @@ def search(query, limit=10, page=1)
split_object( response, Search )
end

# Gets a diary object which contains an array of upcoming calendar events
#
# @return [Camdram::Diary] A Diary object.
def diary(start_date=nil, end_date=nil)
url = "/diary.json"
if start_date && end_date
url = "/diary/#{start_date}.json?end=#{end_date}"
end
response = get(url)
Diary.new(response)
end

# Gets a diary object which contains an array of events occuring in the given year/term
#
# @return [Camdram::Diary] A Diary object.
def termly_diary(year, term=nil)
url = "/diary/#{year}"
url << "/#{term}" if term
url << ".json"
response = get(url)
Diary.new(response)
end

# Returns the program version that is currently running
#
# @return [String] The version of camdram-ruby that is currently running.
Expand Down
28 changes: 28 additions & 0 deletions lib/camdram/diary.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
require 'camdram/base'
require 'camdram/api'
require 'camdram/event'

module Camdram
class Diary < Base
include API
attr_accessor :events

# Instantiate a new Diary object from a JSON hash
#
# @param options [Hash] A single JSON hash with symbolized keys.
# @return [Camdram::Event] The new Diary object.
def initialize(options = {})
super(options)
@events = split_object( @events, Event ) unless @events.nil?
end

# Return a hash of the diary's attributes
#
# @return [Hash] Hash with symbolized keys.
def info
{
events: events,
}
end
end
end
36 changes: 36 additions & 0 deletions lib/camdram/event.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
require 'camdram/base'
require 'camdram/api'
require 'camdram/show'
require 'camdram/venue'

module Camdram
class Event < Base
include API
attr_accessor :id, :start_date, :end_date, :time, :other_venue, :show, :venue

# Instantiate a new Event object from a JSON hash
#
# @param options [Hash] A single JSON hash with symbolized keys.
# @return [Camdram::Event] The new Event object.
def initialize(options = {})
super(options)
@show = Show.new( @show ) unless @show.nil?
@venue = Venue.new( @venue ) unless @venue.nil?
end

# Return a hash of the image's attributes
#
# @return [Hash] Hash with symbolized keys.
def info
{
id: id,
start_date: start_date,
end_date: end_date,
time: time,
other_venue: other_venue,
show: show,
venue: venue,
}
end
end
end
2 changes: 1 addition & 1 deletion lib/camdram/version.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
module Camdram
VERSION = '1.1.0'
VERSION = '1.2.0'
BASE_URL = 'https://www.camdram.net'
end
38 changes: 38 additions & 0 deletions test/diary_tests.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
require 'test_helper'

class ClientTests < MiniTest::Unit::TestCase

# There is some real magic going on here. Not really sure why
# some of the shows have start dates of -0001. There is a
# special place reserved in hell for the data returned by the
# Camdram API.

def test_diary
diary = @client.diary("2005-01-01", "2005-01-02")
events = diary.events
assert_equal 6503, events.first.id
assert_equal 1840, events.first.show.id
assert_equal "ADC Theatre", events.first.venue.name
assert_equal 6577, events[2].id
assert_equal "1970-01-01T19:30:00+00:00", events[2].time
assert_equal 3899, events[2].show.id
assert_equal 90, events[2].venue.id
end

def test_termly_diary
diary = @client.termly_diary("2001", "summer-vacation")
events = diary.events
assert_equal 6455, events[0].id
assert_equal "2003-12-06T00:00:00+00:00", events[0].end_date
assert_equal 10, events[0].show.id
assert_equal "Alice in Wonderland", events[0].show.name
assert_equal 29, events[0].venue.id
assert_equal "ADC Theatre", events[0].venue.name
assert_equal 6503, events[1].id
assert_equal "2008-12-06T00:00:00+00:00", events[1].end_date
assert_equal 1840, events[1].show.id
assert_equal "Theseus and the Minotaur: ADC/Footlights Panto 2008", events[1].show.name
assert_equal 29, events[1].venue.id
assert_equal "ADC Theatre", events[1].venue.name
end
end
19 changes: 10 additions & 9 deletions test/user_tests.rb
Original file line number Diff line number Diff line change
Expand Up @@ -35,13 +35,14 @@ def test_user_organisations
assert_equal "1002481303", org.twitter_id
end

def test_user_venues
venue = @client.user.get_venues.first
assert_equal 29, venue.id
assert_equal "ADC Theatre", venue.name
assert_equal "ADC Theatre", venue.short_name
assert_equal "adc-theatre", venue.slug
assert_equal "33348320992", venue.facebook_id
assert_equal "36725639", venue.twitter_id
end
# This test requires being added as an ADC venue administrator on Camdram
# def test_user_venues
# venue = @client.user.get_venues.first
# assert_equal 29, venue.id
# assert_equal "ADC Theatre", venue.name
# assert_equal "ADC Theatre", venue.short_name
# assert_equal "adc-theatre", venue.slug
# assert_equal "33348320992", venue.facebook_id
# assert_equal "36725639", venue.twitter_id
# end
end

0 comments on commit 4a6f823

Please sign in to comment.