capitan 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
data/MIT-LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2012, The Pittsburgh Cultural Trust
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README ADDED
@@ -0,0 +1,60 @@
1
+ Capitan
2
+ =======
3
+
4
+ Capitan is a Ruby plugin built to serve as a connector to Culturaldistrict.org through its API. cAPI provides read-only access to show listings and details, as well a as a monthly calendar feed. All responses are returned as JSON. Capitan handles the connection to cAPI, and serializes all JSON responses for use in your site.
5
+
6
+ An API key is required. To receive on, contact us at helpdesk@cuturaldistrict.org
7
+
8
+ Once received, the API key must be placed in your config.yml file as:
9
+
10
+ capitan:
11
+ api_key: API_KEY
12
+
13
+
14
+ Shows
15
+ ======
16
+
17
+ Capitan divides shows into three types:
18
+ - Productions (Shows with that are ticketed.)
19
+ - Non-Ticketed Events (Shows that are not ticketed.)
20
+ - Exhibitions (Installations and galleries that are open long-term.)
21
+
22
+ Each of these show types can be searched through the Show object, and a type can be passed to restrict what's returned.
23
+ Available types: ("all", "productions", "events", "exhibitions")
24
+
25
+ Shows can also be searched based on a variety of criteria.
26
+
27
+ Search parameters:
28
+ min_date
29
+ max_date
30
+ product_line
31
+ genre
32
+ title
33
+ venue
34
+ description
35
+ organization_id
36
+
37
+ Example
38
+ ======
39
+
40
+ For all shows:
41
+ shows = Capitan::Shows.all()
42
+
43
+ For all Non-Ticketed Events:
44
+ shows = Capitan::Shows.all('events')
45
+
46
+ For all Productions Before December 31, 2013 in the Jazz genre:
47
+ shows = Capitan::Shows.find('productions', {max_date="12/31/2013", genre="Jazz"})
48
+
49
+
50
+ Calendar
51
+ =======
52
+
53
+ Events returned as a structured calendar can also be returned.
54
+
55
+ Example
56
+ =======
57
+ month = Capitan::Calendar::Monthly.new(year, month)
58
+
59
+
60
+ Copyright (c) 2012 The Pittsburgh Cultural Trust, released under the MIT license
data/Rakefile ADDED
@@ -0,0 +1,23 @@
1
+ require 'rake'
2
+ require 'rake/testtask'
3
+ require 'rake/rdoctask'
4
+
5
+ desc 'Default: run unit tests.'
6
+ task :default => :test
7
+
8
+ desc 'Test the capitan plugin.'
9
+ Rake::TestTask.new(:test) do |t|
10
+ t.libs << 'lib'
11
+ t.libs << 'test'
12
+ t.pattern = 'test/**/*_test.rb'
13
+ t.verbose = true
14
+ end
15
+
16
+ desc 'Generate documentation for the capitan plugin.'
17
+ Rake::RDocTask.new(:rdoc) do |rdoc|
18
+ rdoc.rdoc_dir = 'rdoc'
19
+ rdoc.title = 'Capitan'
20
+ rdoc.options << '--line-numbers' << '--inline-source'
21
+ rdoc.rdoc_files.include('README')
22
+ rdoc.rdoc_files.include('lib/**/*.rb')
23
+ end
data/capitan.gemspec ADDED
@@ -0,0 +1,26 @@
1
+ # -*- encoding: utf-8 -*-
2
+ $:.push File.expand_path("../lib", __FILE__)
3
+ require "capitan"
4
+
5
+ Gem::Specification.new do |s|
6
+ s.name = "capitan"
7
+ s.version = '1.0.0'
8
+ s.platform = Gem::Platform::RUBY
9
+ s.authors = ["Eric Sipple"]
10
+ s.email = ["sipple@trustarts.org"]
11
+ s.homepage = "https://github.com/pgharts/capitan/"
12
+ s.summary = %q{Interface for culturaldistrict.org's read-only API}
13
+ s.description = %q{Culturaldistrict.org provides access to all events through cAPI, and capitan can get that data for you.}
14
+
15
+ s.add_dependency 'rest-client'
16
+
17
+ ignores = if File.exist?('.gitignore')
18
+ File.read('.gitignore').split("\n").inject([]) {|a,p| a + Dir[p] }
19
+ else
20
+ []
21
+ end
22
+ s.files = Dir['**/*'] - ignores
23
+ s.test_files = Dir['test/**/*','spec/**/*','features/**/*'] - ignores
24
+ # s.executables = Dir['bin/*'] - ignores
25
+ s.require_paths = ["lib"]
26
+ end
data/init.rb ADDED
@@ -0,0 +1,2 @@
1
+ # Include hook code here'
2
+ require 'capitan'
data/install.rb ADDED
@@ -0,0 +1 @@
1
+ # Install hook code here
data/lib/capitan.rb ADDED
@@ -0,0 +1,4 @@
1
+ module Capitan
2
+
3
+
4
+ end
@@ -0,0 +1,25 @@
1
+ module Capitan
2
+ module Calendar
3
+ class CalendarShow
4
+ include Capitan::ObjectInitializer
5
+
6
+ attr_accessor :presenter_name, :capi_show_detail_url, :show_detail_url, :title, :venue,
7
+ :date, :show_type, :calendar_text, :buy_tickets_url
8
+
9
+ def show_type_class
10
+ klass = nil
11
+ klass = Capitan::Production if show_type == 'Production'
12
+ klass = Capitan::NonTicketedEvent if show_type == 'Non-Ticketed Event'
13
+ klass = Capitan::Exhibition if show_type == 'Exhibition'
14
+ klass
15
+ end
16
+
17
+ def get_detail
18
+ connection = Capitan::Connection.new
19
+ response = connection.invoke_with_full_url(capi_show_detail_url)
20
+ show_type_class.new(response)
21
+ end
22
+
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,24 @@
1
+ module Capitan
2
+ module Calendar
3
+ class Day
4
+
5
+ attr_accessor :day, :shows
6
+
7
+ def initialize(day_hash)
8
+ @day = Date.parse(day_hash['day'])
9
+ @shows = process_shows(day_hash['shows'])
10
+ end
11
+
12
+ private
13
+
14
+ def process_shows(shows_hash)
15
+ shows = []
16
+ shows_hash.each do |show|
17
+ shows << Capitan::Calendar::CalendarShow.new(show)
18
+ end
19
+ shows
20
+ end
21
+
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,33 @@
1
+ module Capitan
2
+ module Calendar
3
+
4
+ class Monthly
5
+
6
+ attr_reader :month, :year, :weeks
7
+
8
+ def initialize(year, month)
9
+ url = "calendar/monthly/#{year}/#{month}"
10
+ connection = Capitan::Connection.new
11
+ response = connection.invoke_with_path(url)
12
+ process_response(response)
13
+ end
14
+
15
+ private
16
+
17
+ def process_response(response)
18
+ @month = response['month']
19
+ @year = response['year']
20
+ @weeks = process_weeks(response['weeks'])
21
+ end
22
+
23
+ def process_weeks(weeks_hash)
24
+ weeks = []
25
+ weeks_hash.each do |week|
26
+ weeks << Capitan::Calendar::Week.new(week)
27
+ end
28
+ weeks
29
+ end
30
+
31
+ end
32
+ end
33
+ end
@@ -0,0 +1,25 @@
1
+ module Capitan
2
+ module Calendar
3
+ class Week
4
+
5
+ attr_reader :week, :days
6
+
7
+ def initialize(week_hash)
8
+ @week = week_hash['week']
9
+ @days = process_days(week_hash['days'])
10
+ end
11
+
12
+
13
+ private
14
+
15
+ def process_days(days_hash)
16
+ days = []
17
+ days_hash.each do |day|
18
+ days << Capitan::Calendar::Day.new(day)
19
+ end
20
+ days
21
+ end
22
+
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,54 @@
1
+ class Capitan::Connection
2
+ require 'rest_client'
3
+ require 'json'
4
+
5
+ def initialize
6
+ @config = load_config_file
7
+ end
8
+
9
+ def invoke_with_path(url, params = {})
10
+ params[:api_key] = api_key
11
+ response = get_response("#{base_url}/#{url}?#{hash_to_querystring(params)}")
12
+ JSON.parse(response)
13
+ end
14
+
15
+ def invoke_with_full_url(url, params = {})
16
+ params[:api_key] = api_key
17
+ response = get_response("#{url}?#{hash_to_querystring(params)}")
18
+ JSON.parse(response)
19
+ end
20
+
21
+ private
22
+
23
+ def get_response(url)
24
+
25
+ Rails.cache.fetch(url) do
26
+ RestClient.get(url)
27
+ end
28
+
29
+ rescue RestClient::Unauthorized, SocketError => error
30
+ capitan_error = Capitan::Exceptions::ConnectionError.new(error)
31
+ capitan_error.set_backtrace(error.backtrace)
32
+ raise capitan_error
33
+ end
34
+
35
+ def base_url
36
+ @config["capitan"]["base_url"]
37
+ end
38
+
39
+ def api_key
40
+ @config["capitan"]["api_key"]
41
+ end
42
+
43
+ def load_config_file
44
+ YAML.load_file("#{Rails.root}/config/config.yml")[Rails.env]
45
+ end
46
+
47
+ def hash_to_querystring(hash)
48
+ hash.keys.inject('') do |query_string, key|
49
+ query_string << '&' unless key == hash.keys.first
50
+ query_string << "#{URI.encode(key.to_s)}=#{URI.encode(hash[key])}"
51
+ end
52
+ end
53
+
54
+ end
@@ -0,0 +1,20 @@
1
+ class Capitan::Exceptions::ConnectionError < StandardError
2
+
3
+ def initialize(error)
4
+ message = error.message
5
+ message = socket_error_message if error.class == SocketError
6
+ message = unauthorized_message if error.class == RestClient::Unauthorized
7
+ super(message)
8
+ end
9
+
10
+ private
11
+
12
+ def socket_error_message
13
+ "Unable to connect to CAPI. Be sure that you have the correct base_url set in config.yml."
14
+ end
15
+
16
+ def unauthorized_message
17
+ "Invalid API key. Make sure a valid key is set for api_key in config.yml."
18
+ end
19
+
20
+ end
@@ -0,0 +1,20 @@
1
+ class Capitan::Exhibition
2
+
3
+ include Capitan::ObjectInitializer
4
+ include Capitan::ShowMethods
5
+
6
+ attr_accessor :title, :production_name, :presenter_name, :presenter_phone,
7
+ :production_id, :slug, :genre, :keywords, :display_on_district_calendar,
8
+ :display_on_org_calendar, :status_id, :ticket_prices,
9
+ :organization_id, :updated_at, :error, :show_detail_url, :buy_tickets_url,
10
+ :group_sales_url, :season, :calendar_text, :description, :start_date,
11
+ :end_date, :show_type, :thumbnail_image_url, :main_image_url, :capi_show_detail_url
12
+
13
+
14
+ def self.get(id)
15
+ connection = Capitan::Connection.new
16
+ response = connection.invoke_with_path("exhibition/#{id}")
17
+ Capitan::Exhibition.new(response)
18
+ end
19
+
20
+ end
@@ -0,0 +1,20 @@
1
+ class Capitan::NonTicketedEvent
2
+
3
+ include Capitan::ObjectInitializer
4
+ include Capitan::ShowMethods
5
+
6
+ attr_accessor :title, :production_name, :presenter_name, :presenter_phone,
7
+ :production_id, :slug, :genre, :keywords, :display_on_district_calendar,
8
+ :display_on_org_calendar, :status_id, :ticket_prices,
9
+ :organization_id, :updated_at, :error, :show_detail_url, :buy_tickets_url,
10
+ :group_sales_url, :season, :calendar_text, :description, :start_date,
11
+ :end_date, :show_type, :thumbnail_image_url, :main_image_url, :capi_show_detail_url
12
+
13
+
14
+ def self.get(id)
15
+ connection = Capitan::Connection.new
16
+ response = connection.invoke_with_path("event/#{id}")
17
+ Capitan::NonTicketedEvent.new(response)
18
+ end
19
+
20
+ end
@@ -0,0 +1,15 @@
1
+ module Capitan
2
+ module ObjectInitializer
3
+ def initialize(hash = {})
4
+ @errors = []
5
+ hash.each do |key, value|
6
+ begin
7
+ send("#{key}=", value)
8
+ # If something passed in the API isn't defined for our model, log it and move on.
9
+ rescue NoMethodError => error
10
+ next
11
+ end
12
+ end
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,10 @@
1
+ class Capitan::Performance
2
+ include Capitan::ObjectInitializer
3
+ include Capitan::ShowMethods
4
+
5
+ attr_accessor :start_date, :end_date, :created_at, :updated_at, :notes, :restaurant_performance_id,
6
+ :parking_performance_id, :venue_id, :date, :id, :production_page_id,
7
+ :mode_of_sale, :on_sale, :non_ticketed_event_page_id
8
+
9
+
10
+ end
@@ -0,0 +1,21 @@
1
+ class Capitan::Production
2
+
3
+ include Capitan::ObjectInitializer
4
+ include Capitan::ShowMethods
5
+
6
+ attr_accessor :title, :production_name, :presenter_name, :presenter_phone,
7
+ :production_id, :slug, :genre, :keywords, :display_on_district_calendar,
8
+ :display_on_org_calendar, :status_id, :ticket_prices,
9
+ :organization_id, :updated_at, :error, :show_detail_url, :buy_tickets_url,
10
+ :group_sales_url, :season, :calendar_text, :description, :start_date,
11
+ :end_date, :show_type, :thumbnail_image_url, :main_image_url,
12
+ :capi_show_detail_url
13
+
14
+
15
+ def self.get(id)
16
+ connection = Capitan::Connection.new
17
+ response = connection.invoke_with_path("production/#{id}")
18
+ Capitan::Production.new(response)
19
+ end
20
+
21
+ end
@@ -0,0 +1,29 @@
1
+ module Capitan
2
+ module ShowMethods
3
+ def performances
4
+ @production_performances || []
5
+ end
6
+
7
+ def venue
8
+ @production_venue
9
+ end
10
+
11
+ def performances=(performances_json)
12
+ perfs = []
13
+ performances_json.each do |performance_json|
14
+ perfs << Capitan::Performance.new(performance_json)
15
+ end
16
+ @production_performances = perfs
17
+ end
18
+
19
+ def venue=(venue_hash)
20
+ @production_venue = Capitan::Venue.new(venue_hash)
21
+ end
22
+
23
+ def alphabetical_title
24
+ return "#{@title.gsub(/^The /, '')}, The" if @title.match(/^The /)
25
+ @title
26
+ end
27
+
28
+ end
29
+ end
@@ -0,0 +1,48 @@
1
+ class Capitan::Shows
2
+
3
+ def self.all(type = 'all')
4
+ connection = Capitan::Connection.new
5
+ response = connection.invoke_with_path("shows/#{type}")
6
+ process_response(response)
7
+ end
8
+
9
+ def self.find(type, params)
10
+ connection = Capitan::Connection.new
11
+ response = connection.invoke_with_path("shows/search/#{search_type(type)}", params)
12
+ process_response(response)
13
+ end
14
+
15
+ def self.types
16
+ {
17
+ :all => 'all',
18
+ :productions => 'productions',
19
+ :non_ticketed_events => 'events',
20
+ :exhibitions => 'exhibitions'
21
+ }
22
+
23
+ end
24
+
25
+ private
26
+
27
+ def self.search_type(type)
28
+ return "" if type == "all"
29
+ type
30
+ end
31
+
32
+ def self.process_response(response_hash)
33
+ shows = []
34
+ response_hash.each do |show|
35
+ shows << process_show(show)
36
+ end
37
+ shows
38
+ end
39
+
40
+ def self.process_show(show_hash)
41
+ show = nil
42
+ show = Capitan::Production.new(show_hash) if show_hash['show_type'] == "Production"
43
+ show = Capitan::NonTicketedEvent.new(show_hash) if show_hash['show_type'] == "Non-Ticketed Event"
44
+ show = Capitan::Exhibition.new(show_hash) if show_hash['show_type'] == "Exhibition"
45
+ show
46
+ end
47
+
48
+ end
@@ -0,0 +1,7 @@
1
+ class Capitan::Venue
2
+ include Capitan::ObjectInitializer
3
+
4
+ attr_accessor :title, :slug, :facility_phone, :street_address, :city, :state, :zip_code,
5
+ :google_map_url, :short_description, :venue_id, :short_description, :facility_days_open
6
+
7
+ end
@@ -0,0 +1,8 @@
1
+ require 'test_helper'
2
+
3
+ class CapitanTest < ActiveSupport::TestCase
4
+ # Replace this with your real tests.
5
+ test "the truth" do
6
+ assert true
7
+ end
8
+ end
@@ -0,0 +1,3 @@
1
+ require 'rubygems'
2
+ require 'active_support'
3
+ require 'active_support/test_case'
data/uninstall.rb ADDED
@@ -0,0 +1 @@
1
+ # Uninstall hook code here
metadata ADDED
@@ -0,0 +1,88 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: capitan
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Eric Sipple
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2014-12-08 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: rest-client
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: '0'
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ! '>='
28
+ - !ruby/object:Gem::Version
29
+ version: '0'
30
+ description: Culturaldistrict.org provides access to all events through cAPI, and
31
+ capitan can get that data for you.
32
+ email:
33
+ - sipple@trustarts.org
34
+ executables: []
35
+ extensions: []
36
+ extra_rdoc_files: []
37
+ files:
38
+ - capitan.gemspec
39
+ - init.rb
40
+ - install.rb
41
+ - lib/capitan/calendar/calendar_show.rb
42
+ - lib/capitan/calendar/day.rb
43
+ - lib/capitan/calendar/monthly.rb
44
+ - lib/capitan/calendar/week.rb
45
+ - lib/capitan/connection.rb
46
+ - lib/capitan/exceptions/connection_error.rb
47
+ - lib/capitan/exhibition.rb
48
+ - lib/capitan/non_ticketed_event.rb
49
+ - lib/capitan/object_initializer.rb
50
+ - lib/capitan/performance.rb
51
+ - lib/capitan/production.rb
52
+ - lib/capitan/show_methods.rb
53
+ - lib/capitan/shows.rb
54
+ - lib/capitan/venue.rb
55
+ - lib/capitan.rb
56
+ - MIT-LICENSE
57
+ - Rakefile
58
+ - README
59
+ - test/capitan_test.rb
60
+ - test/test_helper.rb
61
+ - uninstall.rb
62
+ homepage: https://github.com/pgharts/capitan/
63
+ licenses: []
64
+ post_install_message:
65
+ rdoc_options: []
66
+ require_paths:
67
+ - lib
68
+ required_ruby_version: !ruby/object:Gem::Requirement
69
+ none: false
70
+ requirements:
71
+ - - ! '>='
72
+ - !ruby/object:Gem::Version
73
+ version: '0'
74
+ required_rubygems_version: !ruby/object:Gem::Requirement
75
+ none: false
76
+ requirements:
77
+ - - ! '>='
78
+ - !ruby/object:Gem::Version
79
+ version: '0'
80
+ requirements: []
81
+ rubyforge_project:
82
+ rubygems_version: 1.8.29
83
+ signing_key:
84
+ specification_version: 3
85
+ summary: Interface for culturaldistrict.org's read-only API
86
+ test_files:
87
+ - test/capitan_test.rb
88
+ - test/test_helper.rb