camdram 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/.gitignore +17 -0
- data/.yardopts +6 -0
- data/Gemfile +2 -0
- data/LICENSE +21 -0
- data/README.md +67 -0
- data/Rakefile +20 -0
- data/camdram-ruby.gemspec +24 -0
- data/lib/camdram.rb +1 -0
- data/lib/camdram/api.rb +63 -0
- data/lib/camdram/base.rb +28 -0
- data/lib/camdram/client.rb +230 -0
- data/lib/camdram/error.rb +78 -0
- data/lib/camdram/http.rb +64 -0
- data/lib/camdram/image.rb +31 -0
- data/lib/camdram/news.rb +39 -0
- data/lib/camdram/organisation.rb +68 -0
- data/lib/camdram/performance.rb +31 -0
- data/lib/camdram/person.rb +34 -0
- data/lib/camdram/role.rb +36 -0
- data/lib/camdram/search.rb +43 -0
- data/lib/camdram/show.rb +71 -0
- data/lib/camdram/user.rb +46 -0
- data/lib/camdram/venue.rb +62 -0
- data/lib/camdram/version.rb +4 -0
- data/test/test_helper.rb +12 -0
- data/test/user_tests.rb +38 -0
- metadata +130 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: c2b1b9f4b4a02b60dc3750550b00d07a16a455444e1bfc74fcef028e62349449
|
4
|
+
data.tar.gz: '082194f0d673dbb8d66cd5ad526a351ba95797b51e233d470a78514e2213b30a'
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 71020471188f7f710e26bb33b7cc1fbe302425dfb44d0c4c205d8d2bd0cf757021a5a4b024c50b8057ede2f09ad23d40e03656260d484912697c97ffd8bd3230
|
7
|
+
data.tar.gz: 0fea40b931b49d84e7cd70d00bae9ec693084ff592f0eb915942756e88a05408b922374720eebc3812b76cb9b58565fe3022f1d6dd4872697390d722866ba0ca
|
data/.gitignore
ADDED
data/.yardopts
ADDED
data/Gemfile
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
MIT License
|
2
|
+
|
3
|
+
Copyright (c) 2018 Charlie Jonas
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
13
|
+
copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
21
|
+
SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,67 @@
|
|
1
|
+
# The Camdram Ruby Gem
|
2
|
+
|
3
|
+
Camdram-ruby is an API wrapper & interface for [Camdram](https://www.camdram.net) 🎭 that's made with love ❤️ and written in Ruby 💎.
|
4
|
+
|
5
|
+
## Quick Start
|
6
|
+
Any of the lines inside the config block can be omitted.
|
7
|
+
```ruby
|
8
|
+
require 'camdram/client'
|
9
|
+
|
10
|
+
client = Camdram::Client.new do |config|
|
11
|
+
config.api_token = api_token
|
12
|
+
config.user_agent = "MyApp v1.0.0"
|
13
|
+
config.base_url = "https://www.camdram.net"
|
14
|
+
end
|
15
|
+
```
|
16
|
+
|
17
|
+
## Documentation
|
18
|
+
Full documentation is generated from the source code by [YARD](https://yardoc.org) and is available to view on
|
19
|
+
[RubyDocs](https://www.rubydoc.info/github/CHTJonas/camdram-ruby).
|
20
|
+
|
21
|
+
## Usage Examples
|
22
|
+
Just some of the things you can do after configuring a `client` object:
|
23
|
+
```ruby
|
24
|
+
client.user.get_shows
|
25
|
+
client.user.get_shows[0].society
|
26
|
+
client.user.get_shows[0].venue
|
27
|
+
client.user.get_shows[0].performances
|
28
|
+
client.user.get_orgs[0].name
|
29
|
+
client.user.get_orgs[0].twitter_id
|
30
|
+
```
|
31
|
+
|
32
|
+
These public actions don't require an API key (although you are still strongly advised to use one anyway):
|
33
|
+
```ruby
|
34
|
+
client.get_show(6171)
|
35
|
+
client.get_show("2018-lucky")
|
36
|
+
|
37
|
+
client.get_org(1)
|
38
|
+
client.get_org("cambridge-university-amateur-dramatic-club")
|
39
|
+
|
40
|
+
client.get_venue(29)
|
41
|
+
client.get_venue("adc-theatre")
|
42
|
+
|
43
|
+
client.get_person(13865)
|
44
|
+
client.get_person("charlie-jonas")
|
45
|
+
|
46
|
+
client.get_org("cambridge-footlights").shows
|
47
|
+
client.get_org("cambridge-footlights").news
|
48
|
+
client.get_venue("cambridge-arts-theatre").shows
|
49
|
+
client.get_venue("cambridge-arts-theatre").news
|
50
|
+
```
|
51
|
+
|
52
|
+
## Versioning
|
53
|
+
This library aims to adhere to [Semantic Versioning 2.0.0](http://semver.org/).
|
54
|
+
Violations of this scheme should be reported as bugs.
|
55
|
+
Specifically, if a minor or patch version is released that breaks backward compatibility,
|
56
|
+
that version should be immediately yanked and/or a new version should be immediately released that restores compatibility.
|
57
|
+
Breaking changes to the public API will only be introduced with new major versions.
|
58
|
+
As a result of this policy, you can (and should) specify a dependency on this gem using the
|
59
|
+
[Pessimistic Version Constraint](http://guides.rubygems.org/patterns/#pessimistic-version-constraint) with two digits of precision.
|
60
|
+
For example:
|
61
|
+
```ruby
|
62
|
+
spec.add_runtime_dependency 'camdram', '~> 1.0'
|
63
|
+
```
|
64
|
+
|
65
|
+
## Copyright
|
66
|
+
Copyright (c) 2018 Charlie Jonas.
|
67
|
+
See [LICENSE](LICENSE) for details.
|
data/Rakefile
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
lib = File.expand_path('../lib/', __FILE__)
|
2
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
3
|
+
|
4
|
+
# Unit test tasks
|
5
|
+
require 'rake/testtask'
|
6
|
+
Rake::TestTask.new do |t|
|
7
|
+
t.libs << 'test'
|
8
|
+
t.test_files = Dir.glob("test/*_tests.rb").sort
|
9
|
+
t.verbose = false
|
10
|
+
t.warning = false
|
11
|
+
end
|
12
|
+
|
13
|
+
# RubyGems tasks
|
14
|
+
require 'camdram/version'
|
15
|
+
task :build do
|
16
|
+
system "gem build camdram-ruby"
|
17
|
+
end
|
18
|
+
task :release => :build do
|
19
|
+
system "gem push camdram-#{Camdram::VERSION}.gem"
|
20
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
lib = File.expand_path('../lib', __FILE__)
|
2
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
3
|
+
require 'camdram/version'
|
4
|
+
|
5
|
+
Gem::Specification.new do |s|
|
6
|
+
s.name = 'camdram'
|
7
|
+
s.version = Camdram::VERSION
|
8
|
+
s.license = 'MIT'
|
9
|
+
s.summary = 'A lovely API wrapper for Camdram written in Ruby'
|
10
|
+
s.description = 'This gem acts as a convenient wrapper around the public API provided by a Camdram installation. See GitHub for a brief overview of available functionality and RubyDocs for more complete documentation.'
|
11
|
+
s.authors = ['Charlie Jonas']
|
12
|
+
s.email = ['devel@charliejonas.co.uk']
|
13
|
+
s.homepage = 'https://github.com/CHTJonas/camdram-ruby'
|
14
|
+
|
15
|
+
s.files = `git ls-files`.split($/)
|
16
|
+
s.executables = s.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
17
|
+
s.test_files = s.files.grep(%r{^(test|spec|features)/})
|
18
|
+
s.require_paths = ['lib']
|
19
|
+
|
20
|
+
s.add_dependency 'json', '~> 2.1'
|
21
|
+
s.add_dependency 'minitest', '~> 5.11'
|
22
|
+
s.add_development_dependency 'bundler', '~> 1.5'
|
23
|
+
s.add_development_dependency 'rake', '~> 12.3'
|
24
|
+
end
|
data/lib/camdram.rb
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require 'camdram/client'
|
data/lib/camdram/api.rb
ADDED
@@ -0,0 +1,63 @@
|
|
1
|
+
require 'json'
|
2
|
+
require 'camdram/http'
|
3
|
+
|
4
|
+
module Camdram
|
5
|
+
module API
|
6
|
+
attr_accessor :http
|
7
|
+
|
8
|
+
# Instantiate a new object
|
9
|
+
#
|
10
|
+
# @param options [Hash] A single JSON hash with symbolized keys.
|
11
|
+
# @param http [Camdram:HTTP] The HTTP class to which requests are sent.
|
12
|
+
# @return [Object] The newly instantiated object.
|
13
|
+
def initialize(options = {}, http = nil)
|
14
|
+
super(options)
|
15
|
+
@http = http
|
16
|
+
end
|
17
|
+
|
18
|
+
# Update the object
|
19
|
+
#
|
20
|
+
# @return [Object] The object the method is called on.
|
21
|
+
# @note The object this method is called on is updated 'in place'.
|
22
|
+
def update!
|
23
|
+
json = get(self.url_slug)
|
24
|
+
self.send(:initialize, json, @http)
|
25
|
+
return self
|
26
|
+
end
|
27
|
+
|
28
|
+
private
|
29
|
+
|
30
|
+
# Send a HTTP get request and parse the returned JSON
|
31
|
+
#
|
32
|
+
# @param url_slug [String] The URL slug to send the HTTP get request to.
|
33
|
+
# @return [Hash] A hash parsed from the JSON response with symbolized keys.
|
34
|
+
def get(url_slug)
|
35
|
+
response = @http.get(url_slug, 3)
|
36
|
+
JSON.parse(response, symbolize_names: true)
|
37
|
+
end
|
38
|
+
|
39
|
+
# Return an array of objects of the given class
|
40
|
+
#
|
41
|
+
# @param slug [String] The URL slug to send the HTTP get request to.
|
42
|
+
# @param object [Object] The class to instantiate.
|
43
|
+
# @return [Array] An array of objects of the specified class.
|
44
|
+
def get_array(url_slug, object)
|
45
|
+
json = get(url_slug)
|
46
|
+
split_object(json, object)
|
47
|
+
end
|
48
|
+
|
49
|
+
# Split a JSON array into a Ruby array of object of the specified class
|
50
|
+
#
|
51
|
+
# @param json [Array] The JSON array to itterate through.
|
52
|
+
# @param object [Object] The class to instantiate.
|
53
|
+
# @return [Array] An array of objects of the specified class.
|
54
|
+
def split_object(json, object)
|
55
|
+
objects = Array.new
|
56
|
+
json.each do |obj|
|
57
|
+
objects << object.new( obj, @http )
|
58
|
+
end
|
59
|
+
return objects
|
60
|
+
end
|
61
|
+
|
62
|
+
end
|
63
|
+
end
|
data/lib/camdram/base.rb
ADDED
@@ -0,0 +1,28 @@
|
|
1
|
+
require 'camdram/http'
|
2
|
+
|
3
|
+
module Camdram
|
4
|
+
class Base
|
5
|
+
attr_reader :id
|
6
|
+
|
7
|
+
# Instantiate a new object from a JSON hash
|
8
|
+
#
|
9
|
+
# @param options [Hash] A single JSON hash with symbolized keys.
|
10
|
+
# @return [Object] The new object.
|
11
|
+
def initialize(options = {})
|
12
|
+
set_from_hash(options)
|
13
|
+
end
|
14
|
+
|
15
|
+
private
|
16
|
+
|
17
|
+
# Sets the object's instance variables from a JSON hash
|
18
|
+
#
|
19
|
+
# @param options [Hash] A single JSON hash with symbolized keys.
|
20
|
+
def set_from_hash(options)
|
21
|
+
options.each do |key, value|
|
22
|
+
# Only set the instance variable if the class or sub-class
|
23
|
+
# has an associated attr_accessor for that variable
|
24
|
+
instance_variable_set("@#{key}", value) if self.respond_to?(key)
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
@@ -0,0 +1,230 @@
|
|
1
|
+
require 'camdram/api'
|
2
|
+
require 'camdram/error'
|
3
|
+
require 'camdram/version'
|
4
|
+
require 'camdram/user'
|
5
|
+
require 'camdram/show'
|
6
|
+
require 'camdram/organisation'
|
7
|
+
require 'camdram/venue'
|
8
|
+
require 'camdram/person'
|
9
|
+
require 'camdram/role'
|
10
|
+
require 'camdram/search'
|
11
|
+
|
12
|
+
module Camdram
|
13
|
+
class Client
|
14
|
+
include API
|
15
|
+
attr_reader :api_token
|
16
|
+
|
17
|
+
# Initializes a new Client object using a block
|
18
|
+
#
|
19
|
+
# @return [Camdram::Client] The top-level Camdram client.
|
20
|
+
def initialize
|
21
|
+
if !block_given?
|
22
|
+
warn 'Camdram::Client instantiated without config block - did you mean to add an API key?'
|
23
|
+
else
|
24
|
+
yield(self)
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
# Returns true if the API access token is set
|
29
|
+
#
|
30
|
+
# @return [Boolean] Whether the API token is set or not.
|
31
|
+
def api_token?
|
32
|
+
!@api_token.nil? && !(blank?(@api_token))
|
33
|
+
end
|
34
|
+
|
35
|
+
# Sets the API access token
|
36
|
+
#
|
37
|
+
# @param token [String] The access token used to authenticate API calls.
|
38
|
+
# @return [String] The token itself.
|
39
|
+
def api_token=(token)
|
40
|
+
@http.api_token = token if !@http.nil?
|
41
|
+
@api_token = token
|
42
|
+
end
|
43
|
+
|
44
|
+
# Returns the API URL that each HTTP request is sent to
|
45
|
+
#
|
46
|
+
# @return [String] The API hostname to send requests to.
|
47
|
+
def base_url
|
48
|
+
@base_url ||= Camdram::BASE_URL
|
49
|
+
end
|
50
|
+
|
51
|
+
# Sets the API URL that each HTTP request is sent to
|
52
|
+
#
|
53
|
+
# @param url [String] The API hostname to send requests to.
|
54
|
+
# @return [String] The url itself.
|
55
|
+
def base_url=(url)
|
56
|
+
@http.base_url = url if !@http.nil?
|
57
|
+
@base_url = url
|
58
|
+
end
|
59
|
+
|
60
|
+
# Returns the user agent header sent in each HTTP request
|
61
|
+
#
|
62
|
+
# @return [String] The user agent header to send with HTTP requests.
|
63
|
+
def user_agent
|
64
|
+
@user_agent ||= "Camdram Ruby v#{Camdram::VERSION}"
|
65
|
+
end
|
66
|
+
|
67
|
+
# Sets the user agent header sent in each HTTP request
|
68
|
+
#
|
69
|
+
# @param agent [String] The user agent header to send with HTTP requests.
|
70
|
+
# @return [String] The agent string itself.
|
71
|
+
def user_agent=(agent)
|
72
|
+
@http.user_agent = agent if !@http.nil?
|
73
|
+
@user_agent = agent
|
74
|
+
end
|
75
|
+
|
76
|
+
# Returns the user associated with the API token if set, otherwise raises an exception
|
77
|
+
#
|
78
|
+
# @raise [StandardError] Error raised when the API token is not set.
|
79
|
+
# @return [Camdram::User] The associated User object.
|
80
|
+
def user
|
81
|
+
http_construct
|
82
|
+
slug = "/auth/account.json"
|
83
|
+
response = get(slug)
|
84
|
+
User.new(response, @http)
|
85
|
+
end
|
86
|
+
|
87
|
+
# Lookup a show by its ID or slug
|
88
|
+
#
|
89
|
+
# @param id [Integer] The numeric ID of the show.
|
90
|
+
# @param id [String] The slug of the show.
|
91
|
+
# @raise [ArgumentError] Error raised when an integer or string is not provided.
|
92
|
+
# @return [Camdram::Show] The show with the provided ID or slug.
|
93
|
+
def get_show(id)
|
94
|
+
http_construct(false)
|
95
|
+
url = nil
|
96
|
+
if id.is_a? Integer
|
97
|
+
url = "#{Show.url}/by-id/#{id}.json"
|
98
|
+
elsif id.is_a? String
|
99
|
+
url = "#{Show.url}/#{id}.json"
|
100
|
+
else
|
101
|
+
raise ArgumentError.new 'id must be an integer, or slug must be a string'
|
102
|
+
end
|
103
|
+
response = get(url)
|
104
|
+
return Show.new(response, @http)
|
105
|
+
end
|
106
|
+
|
107
|
+
# Lookup an organisation by its ID or slug
|
108
|
+
#
|
109
|
+
# @param id [Integer] The numeric ID of the organisation.
|
110
|
+
# @param id [String] The slug of the organisation.
|
111
|
+
# @raise [ArgumentError] Error raised when an integer or string is not provided.
|
112
|
+
# @return [Camdram::Organisation] The organisation with the provided ID or slug.
|
113
|
+
def get_org(id)
|
114
|
+
http_construct(false)
|
115
|
+
url = nil
|
116
|
+
if id.is_a? Integer
|
117
|
+
url = "#{Organisation.url}/by-id/#{id}.json"
|
118
|
+
elsif id.is_a? String
|
119
|
+
url = "#{Organisation.url}/#{id}.json"
|
120
|
+
else
|
121
|
+
raise ArgumentError.new 'id must be an integer, or slug must be a string'
|
122
|
+
end
|
123
|
+
response = get(url)
|
124
|
+
Organisation.new(response, @http)
|
125
|
+
end
|
126
|
+
|
127
|
+
# Lookup a venue by its ID or slug
|
128
|
+
#
|
129
|
+
# @param id [Integer] The numeric ID of the venue.
|
130
|
+
# @param id [String] The slug of the venue.
|
131
|
+
# @raise [ArgumentError] Error raised when an integer or string is not provided.
|
132
|
+
# @return [Camdram::Venue] The venue with the provided ID or slug.
|
133
|
+
def get_venue(id)
|
134
|
+
http_construct(false)
|
135
|
+
url = nil
|
136
|
+
if id.is_a? Integer
|
137
|
+
url = "#{Venue.url}/by-id/#{id}.json"
|
138
|
+
elsif id.is_a? String
|
139
|
+
url = "#{Venue.url}/#{id}.json"
|
140
|
+
else
|
141
|
+
raise ArgumentError.new 'id must be an integer, or slug must be a string'
|
142
|
+
end
|
143
|
+
response = get(url)
|
144
|
+
Venue.new(response, @http)
|
145
|
+
end
|
146
|
+
|
147
|
+
# Lookup a person by their ID or slug
|
148
|
+
#
|
149
|
+
# @param id [Integer] The numeric ID of the person.
|
150
|
+
# @param id [String] The person's slug.
|
151
|
+
# @raise [ArgumentError] Error raised when an integer or string is not provided.
|
152
|
+
# @return [Camdram::Person] The person with the provided ID or slug.
|
153
|
+
def get_person(id)
|
154
|
+
http_construct(false)
|
155
|
+
url = nil
|
156
|
+
if id.is_a? Integer
|
157
|
+
url = "#{Person.url}/by-id/#{id}.json"
|
158
|
+
elsif id.is_a? String
|
159
|
+
url = "#{Person.url}/#{id}.json"
|
160
|
+
else
|
161
|
+
raise ArgumentError.new 'id must be an integer, or slug must be a string'
|
162
|
+
end
|
163
|
+
response = get(url)
|
164
|
+
Person.new(response, @http)
|
165
|
+
end
|
166
|
+
|
167
|
+
# Returns an array of all registered organisations
|
168
|
+
#
|
169
|
+
# @return [Array] An array of Organisation objects.
|
170
|
+
def get_orgs
|
171
|
+
http_construct(false)
|
172
|
+
url = "#{Organisation.url}.json"
|
173
|
+
response = get(url)
|
174
|
+
split_object( response, Organisation )
|
175
|
+
end
|
176
|
+
|
177
|
+
# Returns an array of all registered venues
|
178
|
+
#
|
179
|
+
# @return [Array] An array of Venue objects.
|
180
|
+
def get_venues
|
181
|
+
http_construct(false)
|
182
|
+
url = "#{Venue.url}.json"
|
183
|
+
response = get(url)
|
184
|
+
split_object( response, Venue )
|
185
|
+
end
|
186
|
+
|
187
|
+
# Returns an array containing a sample of people taking part in shows this week
|
188
|
+
#
|
189
|
+
# @return [Array] An array of Role objects.
|
190
|
+
def get_people
|
191
|
+
http_construct(false)
|
192
|
+
url = "#{Person.url}.json"
|
193
|
+
response = get(url)
|
194
|
+
split_object( response, Role )
|
195
|
+
end
|
196
|
+
|
197
|
+
# Return an array of search entity results based on a search string
|
198
|
+
#
|
199
|
+
# @param query [String] The query string to search with.
|
200
|
+
# @return [Array] An array of Search objects.
|
201
|
+
def search(query, limit=10, page=1)
|
202
|
+
http_construct(false)
|
203
|
+
url = "/search.json?q=#{query}&limit=#{limit}&page=#{page}"
|
204
|
+
response = get(url)
|
205
|
+
split_object( response, Search )
|
206
|
+
end
|
207
|
+
|
208
|
+
private
|
209
|
+
|
210
|
+
# Construct a class to handle HTTP requests if necessary
|
211
|
+
#
|
212
|
+
# @raise [StandardError] Error raised when the API token is not set.
|
213
|
+
def http_construct(check_for_token = true)
|
214
|
+
if !check_for_token || api_token?
|
215
|
+
# Create a new HTTP object if one doesn't already exist
|
216
|
+
@http ||= HTTP.new(@api_token, base_url, user_agent)
|
217
|
+
else
|
218
|
+
raise Camdram::Error::NoApiKey.new 'api_token is not set'
|
219
|
+
end
|
220
|
+
end
|
221
|
+
|
222
|
+
# Returns true if a given string is blank
|
223
|
+
#
|
224
|
+
# @param string [String] The string to test.
|
225
|
+
# @return [Boolean] True if blank, false otherwise.
|
226
|
+
def blank?(string)
|
227
|
+
string.respond_to?(:empty?) ? string.empty? : false
|
228
|
+
end
|
229
|
+
end
|
230
|
+
end
|
@@ -0,0 +1,78 @@
|
|
1
|
+
require 'json'
|
2
|
+
|
3
|
+
module Camdram
|
4
|
+
module Error
|
5
|
+
|
6
|
+
# Error class raised when an API call is attempted but no API key is set
|
7
|
+
class NoApiKey < RuntimeError; end
|
8
|
+
|
9
|
+
# Error class for Camdram API calls
|
10
|
+
class CamdramError < StandardError
|
11
|
+
attr_reader :http_status_code, :http_headers, :response_body
|
12
|
+
attr_reader :error, :error_description
|
13
|
+
|
14
|
+
def initialize(code, body, headers)
|
15
|
+
@http_status_code = code
|
16
|
+
@response_body = body
|
17
|
+
@http_headers = headers
|
18
|
+
|
19
|
+
# Camdram doesn't always return errors in JSON format
|
20
|
+
# and when it does, the format is sometimes inconsistent
|
21
|
+
begin
|
22
|
+
error_hash = JSON.parse(@response_body)
|
23
|
+
@error = error_hash['error']
|
24
|
+
@error_description = error_hash['error_description']
|
25
|
+
rescue JSON::ParserError => e
|
26
|
+
# FIXME come up with a better solution for this
|
27
|
+
@error = http_status_code
|
28
|
+
@error_description = response_body
|
29
|
+
end
|
30
|
+
message = "#{error}: #{error_description}"
|
31
|
+
super(message)
|
32
|
+
raise self
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
# 3xx level errors
|
37
|
+
class RedirectError < CamdramError; end
|
38
|
+
# 4xx level errors
|
39
|
+
class ClientError < CamdramError; end
|
40
|
+
# 5xx level errors
|
41
|
+
class ServerError < CamdramError; end
|
42
|
+
# 400
|
43
|
+
class BadRequest < ClientError; end
|
44
|
+
# 403
|
45
|
+
class Forbidden < ClientError; end
|
46
|
+
# 404
|
47
|
+
class NotFound < ClientError; end
|
48
|
+
# 401
|
49
|
+
class Unauthorized < ClientError; end
|
50
|
+
# 429
|
51
|
+
class RateLimit < ClientError; end
|
52
|
+
|
53
|
+
# This is called by the HTTP class when a request
|
54
|
+
# is not successful and is not a redirect
|
55
|
+
def self.for(response)
|
56
|
+
code = response.code.to_i
|
57
|
+
error_class = case code
|
58
|
+
when 300..399
|
59
|
+
RedirectError
|
60
|
+
when 400
|
61
|
+
BadRequest
|
62
|
+
when 403
|
63
|
+
Forbidden
|
64
|
+
when 404
|
65
|
+
NotFound
|
66
|
+
when 401
|
67
|
+
Unauthorized
|
68
|
+
when 429
|
69
|
+
RateLimit
|
70
|
+
when 400..499
|
71
|
+
ClientError
|
72
|
+
else
|
73
|
+
CamdramError
|
74
|
+
end
|
75
|
+
error_class.new(code, response.body, response.header)
|
76
|
+
end
|
77
|
+
end
|
78
|
+
end
|
data/lib/camdram/http.rb
ADDED
@@ -0,0 +1,64 @@
|
|
1
|
+
require 'net/http'
|
2
|
+
require 'camdram/error'
|
3
|
+
|
4
|
+
module Camdram
|
5
|
+
class HTTP
|
6
|
+
attr_writer :api_token, :base_url, :user_agent
|
7
|
+
|
8
|
+
# Initializes a new HTTP object
|
9
|
+
#
|
10
|
+
# @param api_token [String] The API token to use to authenticate requests.
|
11
|
+
# @param base_url [String] The API hostname to use when sending API requests.
|
12
|
+
# @param user_agent [String] The User-Agent header to send to the server.
|
13
|
+
# @return [Camdram::HTTP]
|
14
|
+
def initialize(api_token, base_url, user_agent)
|
15
|
+
@api_token = api_token
|
16
|
+
@base_url = base_url
|
17
|
+
@user_agent = user_agent
|
18
|
+
end
|
19
|
+
|
20
|
+
# Sends a HTTP-get request to the Camdram API
|
21
|
+
#
|
22
|
+
# @param url_slug [String] The URL slug to send the request to.
|
23
|
+
# @param max_redirects [Integer] The maximum number of redirects.
|
24
|
+
# @raise [Camdram::Error::RedirectError] Error raised when too many redirects occur.
|
25
|
+
# @return [String]
|
26
|
+
def get(url_slug, max_redirects = 10)
|
27
|
+
url = @base_url + url_slug
|
28
|
+
uri = URI(url)
|
29
|
+
inner_get(uri, max_redirects)
|
30
|
+
end
|
31
|
+
|
32
|
+
private
|
33
|
+
def inner_get(uri, max_redirects)
|
34
|
+
# Raise an exception if we enter a redirect loop
|
35
|
+
if max_redirects == 0
|
36
|
+
new Error::RedirectError(310, 'Too many redirects', nil)
|
37
|
+
end
|
38
|
+
|
39
|
+
response = Net::HTTP.start(uri.hostname, uri.port, :use_ssl => true) {|http|
|
40
|
+
request = Net::HTTP::Get.new(uri)
|
41
|
+
request['Authorization'] = "Bearer #{@api_token}" if !@api_token.nil?
|
42
|
+
request['User-Agent'] = @user_agent if !@user_agent.nil?
|
43
|
+
http.request(request)
|
44
|
+
}
|
45
|
+
|
46
|
+
case response
|
47
|
+
when Net::HTTPSuccess then
|
48
|
+
response.body
|
49
|
+
when Net::HTTPRedirection then
|
50
|
+
location = response['location']
|
51
|
+
warn "redirected to #{location}"
|
52
|
+
if location.start_with?('http')
|
53
|
+
# Handles full URL and external redirects
|
54
|
+
inner_get(URI(location), max_redirects - 1)
|
55
|
+
else
|
56
|
+
# Handles slug-based redirects
|
57
|
+
get(location, max_redirects - 1)
|
58
|
+
end
|
59
|
+
else
|
60
|
+
Error.for(response)
|
61
|
+
end
|
62
|
+
end
|
63
|
+
end
|
64
|
+
end
|
@@ -0,0 +1,31 @@
|
|
1
|
+
require 'camdram/base'
|
2
|
+
require 'camdram/api'
|
3
|
+
|
4
|
+
module Camdram
|
5
|
+
class Image < Base
|
6
|
+
include API
|
7
|
+
attr_accessor :filename, :created_at, :width, :height, :extension, :type
|
8
|
+
|
9
|
+
# Return a hash of the image's attributes
|
10
|
+
#
|
11
|
+
# @return [Hash] Hash with symbolized keys.
|
12
|
+
def info
|
13
|
+
{
|
14
|
+
id: id,
|
15
|
+
filename: filename,
|
16
|
+
created_at: created_at,
|
17
|
+
width: width,
|
18
|
+
height: height,
|
19
|
+
extension: extension,
|
20
|
+
type: type,
|
21
|
+
}
|
22
|
+
end
|
23
|
+
|
24
|
+
# Return the image URL
|
25
|
+
#
|
26
|
+
# @return [String] The image URL.
|
27
|
+
def url
|
28
|
+
"/media/cache/preview/#{filename}"
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
data/lib/camdram/news.rb
ADDED
@@ -0,0 +1,39 @@
|
|
1
|
+
require 'camdram/base'
|
2
|
+
require 'camdram/api'
|
3
|
+
require 'camdram/organisation'
|
4
|
+
require 'camdram/venue'
|
5
|
+
|
6
|
+
module Camdram
|
7
|
+
class News < Base
|
8
|
+
include API
|
9
|
+
attr_accessor :entity, :remote_id, :source, :picture, :body, :posted_at, :created_at
|
10
|
+
|
11
|
+
# Instantiate a new News object from a JSON hash
|
12
|
+
#
|
13
|
+
# @param options [Hash] A single JSON hash with symbolized keys.
|
14
|
+
# @return [Camdram::News] The new News object.
|
15
|
+
def initialize(options = {}, http = nil)
|
16
|
+
super(options, http)
|
17
|
+
@entity = case @entity[:_type]
|
18
|
+
when "society" then Organisation.new( @entity, @http )
|
19
|
+
when "venue" then Venue.new( @entity, @http )
|
20
|
+
end if !@entity.nil?
|
21
|
+
end
|
22
|
+
|
23
|
+
# Return a hash of the news item's attributes
|
24
|
+
#
|
25
|
+
# @return [Hash] Hash with symbolized keys.
|
26
|
+
def info
|
27
|
+
{
|
28
|
+
id: id,
|
29
|
+
entity: entity,
|
30
|
+
remote_id: remote_id,
|
31
|
+
source: source,
|
32
|
+
picture: picture,
|
33
|
+
body: body,
|
34
|
+
posted_at: posted_at,
|
35
|
+
created_at: created_at,
|
36
|
+
}
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
@@ -0,0 +1,68 @@
|
|
1
|
+
require 'camdram/base'
|
2
|
+
require 'camdram/api'
|
3
|
+
require 'camdram/image'
|
4
|
+
require 'camdram/news'
|
5
|
+
require 'camdram/show'
|
6
|
+
|
7
|
+
module Camdram
|
8
|
+
class Organisation < Base
|
9
|
+
include API
|
10
|
+
attr_accessor :name, :description, :image, :facebook_id, :twitter_id, :short_name, :slug
|
11
|
+
|
12
|
+
# Instantiate a new Organisation object from a JSON hash
|
13
|
+
#
|
14
|
+
# @param options [Hash] A single JSON hash with symbolized keys.
|
15
|
+
# @return [Camdram::Organisation] The new Organisation object.
|
16
|
+
def initialize(options = {}, http = nil)
|
17
|
+
super(options, http)
|
18
|
+
@image = Image.new( @image, @http ) if !@image.nil?
|
19
|
+
end
|
20
|
+
|
21
|
+
# Return a hash of the organisation's attributes
|
22
|
+
#
|
23
|
+
# @return [Hash] Hash with symbolized keys.
|
24
|
+
def info
|
25
|
+
{
|
26
|
+
id: id,
|
27
|
+
name: name,
|
28
|
+
description: description,
|
29
|
+
facebook_id: facebook_id,
|
30
|
+
twitter_id: twitter_id,
|
31
|
+
short_name: short_name,
|
32
|
+
slug: slug,
|
33
|
+
}
|
34
|
+
end
|
35
|
+
|
36
|
+
# Gets an array of the organisation's news items
|
37
|
+
#
|
38
|
+
# @return [Array] An array of News objects.
|
39
|
+
def news
|
40
|
+
news_url = "#{self.class.url}/#{slug}/news.json"
|
41
|
+
response = get(news_url)
|
42
|
+
split_object( response, News )
|
43
|
+
end
|
44
|
+
|
45
|
+
# Gets an array of the organisation's upcoming shows
|
46
|
+
#
|
47
|
+
# @return [Array] An array of Show objects.
|
48
|
+
def shows
|
49
|
+
shows_url = "#{self.class.url}/#{slug}/shows.json"
|
50
|
+
response = get(shows_url)
|
51
|
+
split_object( response, Show )
|
52
|
+
end
|
53
|
+
|
54
|
+
# Returns the URL+slug of the organisation
|
55
|
+
#
|
56
|
+
# @return [String] The full URL and slug.
|
57
|
+
def url_slug
|
58
|
+
"#{self.class.url}/#{slug}.json"
|
59
|
+
end
|
60
|
+
|
61
|
+
# Returns the URL stub assocaited with all organisations
|
62
|
+
#
|
63
|
+
# @return [String] The URL stub.
|
64
|
+
def self.url
|
65
|
+
'/societies'
|
66
|
+
end
|
67
|
+
end
|
68
|
+
end
|
@@ -0,0 +1,31 @@
|
|
1
|
+
require 'camdram/base'
|
2
|
+
require 'camdram/api'
|
3
|
+
require 'camdram/venue'
|
4
|
+
|
5
|
+
module Camdram
|
6
|
+
class Performance < Base
|
7
|
+
include API
|
8
|
+
attr_accessor :start_date, :end_date, :time, :venue, :other_venue
|
9
|
+
|
10
|
+
# Instantiate a new Performance object from a JSON hash
|
11
|
+
#
|
12
|
+
# @param options [Hash] A single JSON hash with symbolized keys.
|
13
|
+
# @return [Camdram::Performance] The new Performance object.
|
14
|
+
def initialize(options = {}, http = nil)
|
15
|
+
super(options, http)
|
16
|
+
@venue = Venue.new( @venue, @http ) if !@venue.nil?
|
17
|
+
end
|
18
|
+
|
19
|
+
# Return a hash of the performance's attributes
|
20
|
+
#
|
21
|
+
# @return [Hash] Hash with symbolized keys.
|
22
|
+
def info
|
23
|
+
{
|
24
|
+
start_date: start_date,
|
25
|
+
end_date: end_date,
|
26
|
+
time: time,
|
27
|
+
other_venue: other_venue,
|
28
|
+
}
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
@@ -0,0 +1,34 @@
|
|
1
|
+
require 'camdram/base'
|
2
|
+
require 'camdram/api'
|
3
|
+
|
4
|
+
module Camdram
|
5
|
+
class Person < Base
|
6
|
+
include API
|
7
|
+
attr_accessor :name, :slug
|
8
|
+
|
9
|
+
# Return a hash of the person's attributes
|
10
|
+
#
|
11
|
+
# @return [Hash] Hash with symbolized keys.
|
12
|
+
def info
|
13
|
+
{
|
14
|
+
id: id,
|
15
|
+
name: name,
|
16
|
+
slug: slug,
|
17
|
+
}
|
18
|
+
end
|
19
|
+
|
20
|
+
# Returns the URL+slug of the person
|
21
|
+
#
|
22
|
+
# @return [String] The full URL and slug.
|
23
|
+
def url_slug
|
24
|
+
"#{self.class.url}/#{slug}.json"
|
25
|
+
end
|
26
|
+
|
27
|
+
# Returns the URL stub assocaited with all people
|
28
|
+
#
|
29
|
+
# @return [String] The URL stub.
|
30
|
+
def self.url
|
31
|
+
'/people'
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
data/lib/camdram/role.rb
ADDED
@@ -0,0 +1,36 @@
|
|
1
|
+
require 'camdram/base'
|
2
|
+
require 'camdram/api'
|
3
|
+
require 'camdram/show'
|
4
|
+
require 'camdram/person'
|
5
|
+
|
6
|
+
module Camdram
|
7
|
+
class Role < Base
|
8
|
+
attr_accessor :person_name, :person_slug, :type, :role, :order, :show, :person
|
9
|
+
|
10
|
+
# Instantiate a new Role object from a JSON hash
|
11
|
+
#
|
12
|
+
# @param options [Hash] A single JSON hash with symbolized keys.
|
13
|
+
# @return [Camdram::Role] The new Role object.
|
14
|
+
def initialize(options = {}, http = nil)
|
15
|
+
super(options)
|
16
|
+
@show = Show.new( @show, http ) if !@show.nil?
|
17
|
+
@person = Person.new( @person, http ) if !@person.nil?
|
18
|
+
end
|
19
|
+
|
20
|
+
# Return a hash of the roles's attributes
|
21
|
+
#
|
22
|
+
# @return [Hash] Hash with symbolized keys.
|
23
|
+
def info
|
24
|
+
{
|
25
|
+
person_name: person_name,
|
26
|
+
person_slug: person_slug,
|
27
|
+
id: id,
|
28
|
+
type: type,
|
29
|
+
role: role,
|
30
|
+
order: order,
|
31
|
+
show: show,
|
32
|
+
person: person,
|
33
|
+
}
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
@@ -0,0 +1,43 @@
|
|
1
|
+
require 'camdram/base'
|
2
|
+
require 'camdram/api'
|
3
|
+
require 'camdram/show'
|
4
|
+
require 'camdram/organisation'
|
5
|
+
require 'camdram/venue'
|
6
|
+
require 'camdram/person'
|
7
|
+
|
8
|
+
module Camdram
|
9
|
+
class Search < Base
|
10
|
+
include API
|
11
|
+
attr_accessor :name, :slug, :start_at, :rank, :entity_type
|
12
|
+
|
13
|
+
# Return the correct Ruby object referenced by the search entity
|
14
|
+
#
|
15
|
+
# @return [Object] The Ruby object that is referenced by the search entity.
|
16
|
+
def entity
|
17
|
+
cls = nil
|
18
|
+
case entity_type
|
19
|
+
when "show" then cls = Show
|
20
|
+
when "society" then cls = Organisation
|
21
|
+
when "venue" then cls = Venue
|
22
|
+
when "person" then cls = Person
|
23
|
+
end
|
24
|
+
url = "#{cls.url}/#{slug}.json"
|
25
|
+
response = get(url)
|
26
|
+
return cls.new(response, @http)
|
27
|
+
end
|
28
|
+
|
29
|
+
# Return a hash of the search entity's attributes
|
30
|
+
#
|
31
|
+
# @return [Hash] Hash with symbolized keys.
|
32
|
+
def info
|
33
|
+
{
|
34
|
+
name: name,
|
35
|
+
slug: slug,
|
36
|
+
start_at: start_at,
|
37
|
+
rank: rank,
|
38
|
+
id: id,
|
39
|
+
entity_type: entity_type,
|
40
|
+
}
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
data/lib/camdram/show.rb
ADDED
@@ -0,0 +1,71 @@
|
|
1
|
+
require 'camdram/base'
|
2
|
+
require 'camdram/api'
|
3
|
+
require 'camdram/organisation'
|
4
|
+
require 'camdram/venue'
|
5
|
+
require 'camdram/performance'
|
6
|
+
require 'camdram/image'
|
7
|
+
require 'camdram/role'
|
8
|
+
|
9
|
+
module Camdram
|
10
|
+
class Show < Base
|
11
|
+
include API
|
12
|
+
attr_accessor :name, :description, :image, :slug, :author, :prices, :other_venue, :other_society, :category, :performances, :online_booking_url, :society, :venue
|
13
|
+
|
14
|
+
# Instantiate a new Show object from a JSON hash
|
15
|
+
#
|
16
|
+
# @param options [Hash] A single JSON hash with symbolized keys.
|
17
|
+
# @return [Camdram::Show] The new Show object.
|
18
|
+
def initialize(options = {}, http = nil)
|
19
|
+
super(options, http)
|
20
|
+
@society = Organisation.new( @society, @http ) if !@society.nil?
|
21
|
+
@venue = Venue.new( @venue, @http ) if !@venue.nil?
|
22
|
+
@performances = split_object( @performances, Performance ) if !@performances.nil?
|
23
|
+
@image = Image.new( @image, @http ) if !@image.nil?
|
24
|
+
end
|
25
|
+
|
26
|
+
# Gets an array of roles associated with the shows
|
27
|
+
#
|
28
|
+
# @return [Array] An array of Role objects.
|
29
|
+
def roles
|
30
|
+
roles_url = "#{self.class.url}/#{slug}/roles.json"
|
31
|
+
response = get(roles_url)
|
32
|
+
split_object( response, Role )
|
33
|
+
end
|
34
|
+
|
35
|
+
# Return a hash of the shows's attributes
|
36
|
+
#
|
37
|
+
# @return [Hash] Hash with symbolized keys.
|
38
|
+
def info
|
39
|
+
{
|
40
|
+
id: id,
|
41
|
+
name: name,
|
42
|
+
description: description,
|
43
|
+
image: image,
|
44
|
+
slug: slug,
|
45
|
+
author: author,
|
46
|
+
prices: prices,
|
47
|
+
other_venue: other_venue,
|
48
|
+
other_society: other_society,
|
49
|
+
category: category,
|
50
|
+
performances: performances,
|
51
|
+
online_booking_url: online_booking_url,
|
52
|
+
society: society,
|
53
|
+
venue: venue,
|
54
|
+
}
|
55
|
+
end
|
56
|
+
|
57
|
+
# Returns the URL+slug of the show
|
58
|
+
#
|
59
|
+
# @return [String] The full URL and slug.
|
60
|
+
def url_slug
|
61
|
+
"#{self.class.url}/#{slug}.json"
|
62
|
+
end
|
63
|
+
|
64
|
+
# Returns the URL stub assocaited with all shows
|
65
|
+
#
|
66
|
+
# @return [String] The URL stub.
|
67
|
+
def self.url
|
68
|
+
'/shows'
|
69
|
+
end
|
70
|
+
end
|
71
|
+
end
|
data/lib/camdram/user.rb
ADDED
@@ -0,0 +1,46 @@
|
|
1
|
+
require 'camdram/base'
|
2
|
+
require 'camdram/api'
|
3
|
+
require 'camdram/show'
|
4
|
+
require 'camdram/organisation'
|
5
|
+
|
6
|
+
module Camdram
|
7
|
+
class User < Base
|
8
|
+
include API
|
9
|
+
attr_accessor :name, :email
|
10
|
+
|
11
|
+
# Return a hash of the user's attributes
|
12
|
+
#
|
13
|
+
# @return [Hash] Hash with symbolized keys.
|
14
|
+
def info
|
15
|
+
{
|
16
|
+
id: id,
|
17
|
+
name: name,
|
18
|
+
email: email,
|
19
|
+
}
|
20
|
+
end
|
21
|
+
|
22
|
+
# Return the unique Camdram URL slug of the user
|
23
|
+
#
|
24
|
+
# @return [String] The full URL slug.
|
25
|
+
def url_slug
|
26
|
+
"/auth/account.json"
|
27
|
+
end
|
28
|
+
|
29
|
+
# Return an array of shows the user is authorised for
|
30
|
+
#
|
31
|
+
# @return [Array] An array of Camdram::Show objects.
|
32
|
+
def get_shows
|
33
|
+
slug = "/auth/account/shows.json"
|
34
|
+
get_array(slug, Show)
|
35
|
+
end
|
36
|
+
|
37
|
+
# Return an array of societies the user is authorised for
|
38
|
+
#
|
39
|
+
# @return [Array] An array of Camdram::Organisation objects
|
40
|
+
def get_orgs
|
41
|
+
slug = "/auth/account/organisations.json"
|
42
|
+
get_array(slug, Organisation)
|
43
|
+
end
|
44
|
+
|
45
|
+
end
|
46
|
+
end
|
@@ -0,0 +1,62 @@
|
|
1
|
+
require 'camdram/base'
|
2
|
+
require 'camdram/api'
|
3
|
+
require 'camdram/news'
|
4
|
+
require 'camdram/show'
|
5
|
+
|
6
|
+
module Camdram
|
7
|
+
class Venue < Base
|
8
|
+
include API
|
9
|
+
attr_accessor :name, :description, :facebook_id, :twitter_id, :short_name, :college, :slug, :address, :latitude, :longitude
|
10
|
+
|
11
|
+
# Return a hash of the venue's attributes
|
12
|
+
#
|
13
|
+
# @return [Hash] Hash with symbolized keys.
|
14
|
+
def info
|
15
|
+
{
|
16
|
+
id: id,
|
17
|
+
name: name,
|
18
|
+
description: description,
|
19
|
+
facebook_id: facebook_id,
|
20
|
+
twitter_id: twitter_id,
|
21
|
+
short_name: short_name,
|
22
|
+
college: college,
|
23
|
+
slug: slug,
|
24
|
+
address: address,
|
25
|
+
latitude: latitude,
|
26
|
+
longitude: longitude,
|
27
|
+
}
|
28
|
+
end
|
29
|
+
|
30
|
+
# Gets an array of the venue's news items
|
31
|
+
#
|
32
|
+
# @return [Array] An array of News objects.
|
33
|
+
def news
|
34
|
+
news_url = "#{self.class.url}/#{slug}/news.json"
|
35
|
+
response = get(news_url)
|
36
|
+
split_object( response, News )
|
37
|
+
end
|
38
|
+
|
39
|
+
# Gets an array of the venue's upcoming shows
|
40
|
+
#
|
41
|
+
# @return [Array] An array of Show objects.
|
42
|
+
def shows
|
43
|
+
shows_url = "#{self.class.url}/#{slug}/shows.json"
|
44
|
+
response = get(shows_url)
|
45
|
+
split_object( response, Show )
|
46
|
+
end
|
47
|
+
|
48
|
+
# Returns the URL+slug of the venue
|
49
|
+
#
|
50
|
+
# @return [String] The full URL and slug.
|
51
|
+
def url_slug
|
52
|
+
"#{self.class.url}/#{slug}.json"
|
53
|
+
end
|
54
|
+
|
55
|
+
# Returns the URL stub assocaited with all venues
|
56
|
+
#
|
57
|
+
# @return [String] The URL stub.
|
58
|
+
def self.url
|
59
|
+
'/venues'
|
60
|
+
end
|
61
|
+
end
|
62
|
+
end
|
data/test/test_helper.rb
ADDED
@@ -0,0 +1,12 @@
|
|
1
|
+
require 'minitest/autorun'
|
2
|
+
require 'camdram/client'
|
3
|
+
|
4
|
+
raise "API test key is not set!" if !ENV["API_test_key"]
|
5
|
+
|
6
|
+
class MiniTest::Unit::TestCase
|
7
|
+
def setup
|
8
|
+
@client = Camdram::Client.new do |config|
|
9
|
+
config.api_token = ENV["API_test_key"]
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
data/test/user_tests.rb
ADDED
@@ -0,0 +1,38 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
class UserTests < MiniTest::Unit::TestCase
|
4
|
+
def test_user
|
5
|
+
user = @client.user
|
6
|
+
assert_equal 3807, user.id
|
7
|
+
assert_equal "Charlie Jonas", user.name
|
8
|
+
assert_equal "charlie@charliejonas.co.uk", user.email
|
9
|
+
end
|
10
|
+
|
11
|
+
def test_get_shows
|
12
|
+
user = @client.user
|
13
|
+
show = user.get_shows.first
|
14
|
+
assert_equal 6514, show.id
|
15
|
+
assert_equal "This show is a dummy used by Camdram for testing purposes only.", show.description
|
16
|
+
assert_equal "5b58b83bd534a.jpg", show.image.filename
|
17
|
+
assert_equal 1024, show.image.width
|
18
|
+
assert_equal "API Test 1", show.name
|
19
|
+
assert_equal "Camdram", show.other_society
|
20
|
+
assert_equal "ADC Theatre", show.other_venue
|
21
|
+
assert_equal 29, show.performances.first.venue.id
|
22
|
+
assert_equal "1997-api-test-1", show.slug
|
23
|
+
assert_equal 38, show.society.id
|
24
|
+
assert_equal "Camdram", show.society.name
|
25
|
+
assert_equal 29, show.venue.id
|
26
|
+
assert_equal "ADC Theatre", show.venue.name
|
27
|
+
end
|
28
|
+
|
29
|
+
def test_get_organisations
|
30
|
+
user = @client.user
|
31
|
+
org = user.get_orgs.first
|
32
|
+
assert_equal 38, org.id
|
33
|
+
assert_equal "Camdram", org.name
|
34
|
+
assert_equal "Camdram", org.short_name
|
35
|
+
assert_equal "camdram", org.slug
|
36
|
+
assert_equal "1002481303", org.twitter_id
|
37
|
+
end
|
38
|
+
end
|
metadata
ADDED
@@ -0,0 +1,130 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: camdram
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.0.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Charlie Jonas
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2018-08-27 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: json
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '2.1'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '2.1'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: minitest
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '5.11'
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '5.11'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: bundler
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '1.5'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '1.5'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: rake
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '12.3'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '12.3'
|
69
|
+
description: This gem acts as a convenient wrapper around the public API provided
|
70
|
+
by a Camdram installation. See GitHub for a brief overview of available functionality
|
71
|
+
and RubyDocs for more complete documentation.
|
72
|
+
email:
|
73
|
+
- devel@charliejonas.co.uk
|
74
|
+
executables: []
|
75
|
+
extensions: []
|
76
|
+
extra_rdoc_files: []
|
77
|
+
files:
|
78
|
+
- ".gitignore"
|
79
|
+
- ".yardopts"
|
80
|
+
- Gemfile
|
81
|
+
- LICENSE
|
82
|
+
- README.md
|
83
|
+
- Rakefile
|
84
|
+
- camdram-ruby.gemspec
|
85
|
+
- lib/camdram.rb
|
86
|
+
- lib/camdram/api.rb
|
87
|
+
- lib/camdram/base.rb
|
88
|
+
- lib/camdram/client.rb
|
89
|
+
- lib/camdram/error.rb
|
90
|
+
- lib/camdram/http.rb
|
91
|
+
- lib/camdram/image.rb
|
92
|
+
- lib/camdram/news.rb
|
93
|
+
- lib/camdram/organisation.rb
|
94
|
+
- lib/camdram/performance.rb
|
95
|
+
- lib/camdram/person.rb
|
96
|
+
- lib/camdram/role.rb
|
97
|
+
- lib/camdram/search.rb
|
98
|
+
- lib/camdram/show.rb
|
99
|
+
- lib/camdram/user.rb
|
100
|
+
- lib/camdram/venue.rb
|
101
|
+
- lib/camdram/version.rb
|
102
|
+
- test/test_helper.rb
|
103
|
+
- test/user_tests.rb
|
104
|
+
homepage: https://github.com/CHTJonas/camdram-ruby
|
105
|
+
licenses:
|
106
|
+
- MIT
|
107
|
+
metadata: {}
|
108
|
+
post_install_message:
|
109
|
+
rdoc_options: []
|
110
|
+
require_paths:
|
111
|
+
- lib
|
112
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
113
|
+
requirements:
|
114
|
+
- - ">="
|
115
|
+
- !ruby/object:Gem::Version
|
116
|
+
version: '0'
|
117
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
118
|
+
requirements:
|
119
|
+
- - ">="
|
120
|
+
- !ruby/object:Gem::Version
|
121
|
+
version: '0'
|
122
|
+
requirements: []
|
123
|
+
rubyforge_project:
|
124
|
+
rubygems_version: 2.7.6
|
125
|
+
signing_key:
|
126
|
+
specification_version: 4
|
127
|
+
summary: A lovely API wrapper for Camdram written in Ruby
|
128
|
+
test_files:
|
129
|
+
- test/test_helper.rb
|
130
|
+
- test/user_tests.rb
|