camdram 1.0.0 → 1.1.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 +4 -4
- data/lib/camdram/api.rb +4 -6
- data/lib/camdram/client.rb +15 -41
- data/lib/camdram/http.rb +59 -38
- data/lib/camdram/news.rb +5 -5
- data/lib/camdram/organisation.rb +3 -3
- data/lib/camdram/performance.rb +3 -3
- data/lib/camdram/role.rb +3 -3
- data/lib/camdram/search.rb +7 -8
- data/lib/camdram/show.rb +6 -6
- data/lib/camdram/user.rb +28 -2
- data/lib/camdram/version.rb +1 -1
- data/test/client_tests.rb +76 -0
- data/test/search_tests.rb +49 -0
- data/test/user_tests.rb +16 -7
- metadata +6 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 6edbfc7097a8f95d7f0a34442d48863474cfb29114a116f2b2a23893a0c07fcf
|
4
|
+
data.tar.gz: 57f71a203bad215155983e349fb8b3d195fbe6ee2a6611c664de7c49fdb3a876
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 654228216deca94ca5b1638a870051be04077c4bb348e2216c6d3026e4d058437fb6f7fae50d01f4fea8edb317d0ace41c6c80b54a5b9e76e8527f690718b83f
|
7
|
+
data.tar.gz: 2084f7ccde4b4f62b3e9ddca41f849a12494bb113cc63ada2f7b8d6f2c0137022ae2965c04d1112a45d7a7eef6a3aa5950ae5acbdd0e88a265d242316738b31d
|
data/lib/camdram/api.rb
CHANGED
@@ -8,11 +8,9 @@ module Camdram
|
|
8
8
|
# Instantiate a new object
|
9
9
|
#
|
10
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
11
|
# @return [Object] The newly instantiated object.
|
13
|
-
def initialize(options = {}
|
12
|
+
def initialize(options = {})
|
14
13
|
super(options)
|
15
|
-
@http = http
|
16
14
|
end
|
17
15
|
|
18
16
|
# Update the object
|
@@ -21,7 +19,7 @@ module Camdram
|
|
21
19
|
# @note The object this method is called on is updated 'in place'.
|
22
20
|
def update!
|
23
21
|
json = get(self.url_slug)
|
24
|
-
self.send(:initialize, json
|
22
|
+
self.send(:initialize, json)
|
25
23
|
return self
|
26
24
|
end
|
27
25
|
|
@@ -32,7 +30,7 @@ module Camdram
|
|
32
30
|
# @param url_slug [String] The URL slug to send the HTTP get request to.
|
33
31
|
# @return [Hash] A hash parsed from the JSON response with symbolized keys.
|
34
32
|
def get(url_slug)
|
35
|
-
response =
|
33
|
+
response = HTTP.instance.get(url_slug, 3)
|
36
34
|
JSON.parse(response, symbolize_names: true)
|
37
35
|
end
|
38
36
|
|
@@ -54,7 +52,7 @@ module Camdram
|
|
54
52
|
def split_object(json, object)
|
55
53
|
objects = Array.new
|
56
54
|
json.each do |obj|
|
57
|
-
objects << object.new( obj
|
55
|
+
objects << object.new( obj )
|
58
56
|
end
|
59
57
|
return objects
|
60
58
|
end
|
data/lib/camdram/client.rb
CHANGED
@@ -29,7 +29,7 @@ module Camdram
|
|
29
29
|
#
|
30
30
|
# @return [Boolean] Whether the API token is set or not.
|
31
31
|
def api_token?
|
32
|
-
|
32
|
+
HTTP.instance.api_token?
|
33
33
|
end
|
34
34
|
|
35
35
|
# Sets the API access token
|
@@ -37,15 +37,14 @@ module Camdram
|
|
37
37
|
# @param token [String] The access token used to authenticate API calls.
|
38
38
|
# @return [String] The token itself.
|
39
39
|
def api_token=(token)
|
40
|
-
|
41
|
-
@api_token = token
|
40
|
+
HTTP.instance.api_token = token
|
42
41
|
end
|
43
42
|
|
44
43
|
# Returns the API URL that each HTTP request is sent to
|
45
44
|
#
|
46
45
|
# @return [String] The API hostname to send requests to.
|
47
46
|
def base_url
|
48
|
-
|
47
|
+
HTTP.instance.base_url
|
49
48
|
end
|
50
49
|
|
51
50
|
# Sets the API URL that each HTTP request is sent to
|
@@ -53,15 +52,14 @@ module Camdram
|
|
53
52
|
# @param url [String] The API hostname to send requests to.
|
54
53
|
# @return [String] The url itself.
|
55
54
|
def base_url=(url)
|
56
|
-
|
57
|
-
@base_url = url
|
55
|
+
HTTP.instance.base_url = url
|
58
56
|
end
|
59
57
|
|
60
58
|
# Returns the user agent header sent in each HTTP request
|
61
59
|
#
|
62
60
|
# @return [String] The user agent header to send with HTTP requests.
|
63
61
|
def user_agent
|
64
|
-
|
62
|
+
HTTP.instance.user_agent
|
65
63
|
end
|
66
64
|
|
67
65
|
# Sets the user agent header sent in each HTTP request
|
@@ -69,8 +67,7 @@ module Camdram
|
|
69
67
|
# @param agent [String] The user agent header to send with HTTP requests.
|
70
68
|
# @return [String] The agent string itself.
|
71
69
|
def user_agent=(agent)
|
72
|
-
|
73
|
-
@user_agent = agent
|
70
|
+
HTTP.instance.user_agent = agent
|
74
71
|
end
|
75
72
|
|
76
73
|
# Returns the user associated with the API token if set, otherwise raises an exception
|
@@ -78,10 +75,9 @@ module Camdram
|
|
78
75
|
# @raise [StandardError] Error raised when the API token is not set.
|
79
76
|
# @return [Camdram::User] The associated User object.
|
80
77
|
def user
|
81
|
-
http_construct
|
82
78
|
slug = "/auth/account.json"
|
83
79
|
response = get(slug)
|
84
|
-
User.new(response
|
80
|
+
User.new(response)
|
85
81
|
end
|
86
82
|
|
87
83
|
# Lookup a show by its ID or slug
|
@@ -91,7 +87,6 @@ module Camdram
|
|
91
87
|
# @raise [ArgumentError] Error raised when an integer or string is not provided.
|
92
88
|
# @return [Camdram::Show] The show with the provided ID or slug.
|
93
89
|
def get_show(id)
|
94
|
-
http_construct(false)
|
95
90
|
url = nil
|
96
91
|
if id.is_a? Integer
|
97
92
|
url = "#{Show.url}/by-id/#{id}.json"
|
@@ -101,7 +96,7 @@ module Camdram
|
|
101
96
|
raise ArgumentError.new 'id must be an integer, or slug must be a string'
|
102
97
|
end
|
103
98
|
response = get(url)
|
104
|
-
return Show.new(response
|
99
|
+
return Show.new(response)
|
105
100
|
end
|
106
101
|
|
107
102
|
# Lookup an organisation by its ID or slug
|
@@ -111,7 +106,6 @@ module Camdram
|
|
111
106
|
# @raise [ArgumentError] Error raised when an integer or string is not provided.
|
112
107
|
# @return [Camdram::Organisation] The organisation with the provided ID or slug.
|
113
108
|
def get_org(id)
|
114
|
-
http_construct(false)
|
115
109
|
url = nil
|
116
110
|
if id.is_a? Integer
|
117
111
|
url = "#{Organisation.url}/by-id/#{id}.json"
|
@@ -121,7 +115,7 @@ module Camdram
|
|
121
115
|
raise ArgumentError.new 'id must be an integer, or slug must be a string'
|
122
116
|
end
|
123
117
|
response = get(url)
|
124
|
-
Organisation.new(response
|
118
|
+
Organisation.new(response)
|
125
119
|
end
|
126
120
|
|
127
121
|
# Lookup a venue by its ID or slug
|
@@ -131,7 +125,6 @@ module Camdram
|
|
131
125
|
# @raise [ArgumentError] Error raised when an integer or string is not provided.
|
132
126
|
# @return [Camdram::Venue] The venue with the provided ID or slug.
|
133
127
|
def get_venue(id)
|
134
|
-
http_construct(false)
|
135
128
|
url = nil
|
136
129
|
if id.is_a? Integer
|
137
130
|
url = "#{Venue.url}/by-id/#{id}.json"
|
@@ -141,7 +134,7 @@ module Camdram
|
|
141
134
|
raise ArgumentError.new 'id must be an integer, or slug must be a string'
|
142
135
|
end
|
143
136
|
response = get(url)
|
144
|
-
Venue.new(response
|
137
|
+
Venue.new(response)
|
145
138
|
end
|
146
139
|
|
147
140
|
# Lookup a person by their ID or slug
|
@@ -151,7 +144,6 @@ module Camdram
|
|
151
144
|
# @raise [ArgumentError] Error raised when an integer or string is not provided.
|
152
145
|
# @return [Camdram::Person] The person with the provided ID or slug.
|
153
146
|
def get_person(id)
|
154
|
-
http_construct(false)
|
155
147
|
url = nil
|
156
148
|
if id.is_a? Integer
|
157
149
|
url = "#{Person.url}/by-id/#{id}.json"
|
@@ -161,14 +153,13 @@ module Camdram
|
|
161
153
|
raise ArgumentError.new 'id must be an integer, or slug must be a string'
|
162
154
|
end
|
163
155
|
response = get(url)
|
164
|
-
Person.new(response
|
156
|
+
Person.new(response)
|
165
157
|
end
|
166
158
|
|
167
159
|
# Returns an array of all registered organisations
|
168
160
|
#
|
169
161
|
# @return [Array] An array of Organisation objects.
|
170
162
|
def get_orgs
|
171
|
-
http_construct(false)
|
172
163
|
url = "#{Organisation.url}.json"
|
173
164
|
response = get(url)
|
174
165
|
split_object( response, Organisation )
|
@@ -178,7 +169,6 @@ module Camdram
|
|
178
169
|
#
|
179
170
|
# @return [Array] An array of Venue objects.
|
180
171
|
def get_venues
|
181
|
-
http_construct(false)
|
182
172
|
url = "#{Venue.url}.json"
|
183
173
|
response = get(url)
|
184
174
|
split_object( response, Venue )
|
@@ -188,7 +178,6 @@ module Camdram
|
|
188
178
|
#
|
189
179
|
# @return [Array] An array of Role objects.
|
190
180
|
def get_people
|
191
|
-
http_construct(false)
|
192
181
|
url = "#{Person.url}.json"
|
193
182
|
response = get(url)
|
194
183
|
split_object( response, Role )
|
@@ -199,32 +188,17 @@ module Camdram
|
|
199
188
|
# @param query [String] The query string to search with.
|
200
189
|
# @return [Array] An array of Search objects.
|
201
190
|
def search(query, limit=10, page=1)
|
202
|
-
http_construct(false)
|
203
191
|
url = "/search.json?q=#{query}&limit=#{limit}&page=#{page}"
|
204
192
|
response = get(url)
|
205
193
|
split_object( response, Search )
|
206
194
|
end
|
207
195
|
|
208
|
-
|
209
|
-
|
210
|
-
# Construct a class to handle HTTP requests if necessary
|
196
|
+
# Returns the program version that is currently running
|
211
197
|
#
|
212
|
-
# @
|
213
|
-
def
|
214
|
-
|
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
|
198
|
+
# @return [String] The version of camdram-ruby that is currently running.
|
199
|
+
def version
|
200
|
+
Camdram::VERSION
|
220
201
|
end
|
221
202
|
|
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
203
|
end
|
230
204
|
end
|
data/lib/camdram/http.rb
CHANGED
@@ -1,22 +1,13 @@
|
|
1
|
+
require 'singleton'
|
1
2
|
require 'net/http'
|
2
3
|
require 'camdram/error'
|
4
|
+
require 'camdram/version'
|
3
5
|
|
4
6
|
module Camdram
|
5
7
|
class HTTP
|
8
|
+
include Singleton
|
6
9
|
attr_writer :api_token, :base_url, :user_agent
|
7
10
|
|
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
11
|
# Sends a HTTP-get request to the Camdram API
|
21
12
|
#
|
22
13
|
# @param url_slug [String] The URL slug to send the request to.
|
@@ -24,41 +15,71 @@ module Camdram
|
|
24
15
|
# @raise [Camdram::Error::RedirectError] Error raised when too many redirects occur.
|
25
16
|
# @return [String]
|
26
17
|
def get(url_slug, max_redirects = 10)
|
27
|
-
url =
|
18
|
+
url = base_url + url_slug
|
28
19
|
uri = URI(url)
|
29
20
|
inner_get(uri, max_redirects)
|
30
21
|
end
|
31
22
|
|
23
|
+
# Returns true if the API access token is set
|
24
|
+
#
|
25
|
+
# @return [Boolean] Whether the API token is set or not.
|
26
|
+
def api_token?
|
27
|
+
!@api_token.nil? && !(blank?(@api_token))
|
28
|
+
end
|
29
|
+
|
30
|
+
# Returns the API URL that each HTTP request is sent to
|
31
|
+
#
|
32
|
+
# @return [String] The API hostname to send requests to.
|
33
|
+
def base_url
|
34
|
+
@base_url ||= Camdram::BASE_URL
|
35
|
+
end
|
36
|
+
|
37
|
+
# Returns the user agent header sent in each HTTP request
|
38
|
+
#
|
39
|
+
# @return [String] The user agent header to send with HTTP requests.
|
40
|
+
def user_agent
|
41
|
+
@user_agent ||= "Camdram Ruby v#{Camdram::VERSION}"
|
42
|
+
end
|
43
|
+
|
32
44
|
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
45
|
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
46
|
+
# Returns true if a given string is blank
|
47
|
+
#
|
48
|
+
# @param string [String] The string to test.
|
49
|
+
# @return [Boolean] True if blank, false otherwise.
|
50
|
+
def blank?(string)
|
51
|
+
string.respond_to?(:empty?) ? string.empty? : false
|
52
|
+
end
|
45
53
|
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
54
|
+
def inner_get(uri, max_redirects)
|
55
|
+
# Raise an exception if we enter a redirect loop
|
56
|
+
if max_redirects == 0
|
57
|
+
new Error::RedirectError(310, 'Too many redirects', nil)
|
58
|
+
end
|
59
|
+
|
60
|
+
response = Net::HTTP.start(uri.hostname, uri.port, :use_ssl => true) {|http|
|
61
|
+
request = Net::HTTP::Get.new(uri)
|
62
|
+
request['Authorization'] = "Bearer #{@api_token}" if !@api_token.nil?
|
63
|
+
request['User-Agent'] = @user_agent if !@user_agent.nil?
|
64
|
+
http.request(request)
|
65
|
+
}
|
66
|
+
|
67
|
+
case response
|
68
|
+
when Net::HTTPSuccess then
|
69
|
+
response.body
|
70
|
+
when Net::HTTPRedirection then
|
71
|
+
location = response['location']
|
72
|
+
warn "redirected to #{location}"
|
73
|
+
if location.start_with?('http')
|
74
|
+
# Handles full URL and external redirects
|
75
|
+
inner_get(URI(location), max_redirects - 1)
|
59
76
|
else
|
60
|
-
|
77
|
+
# Handles slug-based redirects
|
78
|
+
get(location, max_redirects - 1)
|
61
79
|
end
|
80
|
+
else
|
81
|
+
Error.for(response)
|
62
82
|
end
|
83
|
+
end
|
63
84
|
end
|
64
85
|
end
|
data/lib/camdram/news.rb
CHANGED
@@ -12,12 +12,12 @@ module Camdram
|
|
12
12
|
#
|
13
13
|
# @param options [Hash] A single JSON hash with symbolized keys.
|
14
14
|
# @return [Camdram::News] The new News object.
|
15
|
-
def initialize(options = {}
|
16
|
-
super(options
|
15
|
+
def initialize(options = {})
|
16
|
+
super(options)
|
17
17
|
@entity = case @entity[:_type]
|
18
|
-
when "society" then Organisation.new( @entity
|
19
|
-
when "venue" then Venue.new( @entity
|
20
|
-
end
|
18
|
+
when "society" then Organisation.new( @entity )
|
19
|
+
when "venue" then Venue.new( @entity )
|
20
|
+
end unless @entity.nil?
|
21
21
|
end
|
22
22
|
|
23
23
|
# Return a hash of the news item's attributes
|
data/lib/camdram/organisation.rb
CHANGED
@@ -13,9 +13,9 @@ module Camdram
|
|
13
13
|
#
|
14
14
|
# @param options [Hash] A single JSON hash with symbolized keys.
|
15
15
|
# @return [Camdram::Organisation] The new Organisation object.
|
16
|
-
def initialize(options = {}
|
17
|
-
super(options
|
18
|
-
@image = Image.new( @image
|
16
|
+
def initialize(options = {})
|
17
|
+
super(options)
|
18
|
+
@image = Image.new( @image ) unless @image.nil?
|
19
19
|
end
|
20
20
|
|
21
21
|
# Return a hash of the organisation's attributes
|
data/lib/camdram/performance.rb
CHANGED
@@ -11,9 +11,9 @@ module Camdram
|
|
11
11
|
#
|
12
12
|
# @param options [Hash] A single JSON hash with symbolized keys.
|
13
13
|
# @return [Camdram::Performance] The new Performance object.
|
14
|
-
def initialize(options = {}
|
15
|
-
super(options
|
16
|
-
@venue = Venue.new( @venue
|
14
|
+
def initialize(options = {})
|
15
|
+
super(options)
|
16
|
+
@venue = Venue.new( @venue ) unless @venue.nil?
|
17
17
|
end
|
18
18
|
|
19
19
|
# Return a hash of the performance's attributes
|
data/lib/camdram/role.rb
CHANGED
@@ -11,10 +11,10 @@ module Camdram
|
|
11
11
|
#
|
12
12
|
# @param options [Hash] A single JSON hash with symbolized keys.
|
13
13
|
# @return [Camdram::Role] The new Role object.
|
14
|
-
def initialize(options = {}
|
14
|
+
def initialize(options = {})
|
15
15
|
super(options)
|
16
|
-
@show = Show.new( @show
|
17
|
-
@person = Person.new( @person
|
16
|
+
@show = Show.new( @show ) unless @show.nil?
|
17
|
+
@person = Person.new( @person ) unless @person.nil?
|
18
18
|
end
|
19
19
|
|
20
20
|
# Return a hash of the roles's attributes
|
data/lib/camdram/search.rb
CHANGED
@@ -14,16 +14,15 @@ module Camdram
|
|
14
14
|
#
|
15
15
|
# @return [Object] The Ruby object that is referenced by the search entity.
|
16
16
|
def entity
|
17
|
-
|
18
|
-
|
19
|
-
when "
|
20
|
-
when "
|
21
|
-
when "
|
22
|
-
when "person" then cls = Person
|
17
|
+
klass = case entity_type
|
18
|
+
when "show" then Show
|
19
|
+
when "society" then Organisation
|
20
|
+
when "venue" then Venue
|
21
|
+
when "person" then Person
|
23
22
|
end
|
24
|
-
url = "#{
|
23
|
+
url = "#{klass.url}/#{slug}.json"
|
25
24
|
response = get(url)
|
26
|
-
return
|
25
|
+
return klass.new(response)
|
27
26
|
end
|
28
27
|
|
29
28
|
# Return a hash of the search entity's attributes
|
data/lib/camdram/show.rb
CHANGED
@@ -15,12 +15,12 @@ module Camdram
|
|
15
15
|
#
|
16
16
|
# @param options [Hash] A single JSON hash with symbolized keys.
|
17
17
|
# @return [Camdram::Show] The new Show object.
|
18
|
-
def initialize(options = {}
|
19
|
-
super(options
|
20
|
-
@society = Organisation.new( @society
|
21
|
-
@venue = Venue.new( @venue
|
22
|
-
@performances = split_object( @performances, Performance )
|
23
|
-
@image = Image.new( @image
|
18
|
+
def initialize(options = {})
|
19
|
+
super(options)
|
20
|
+
@society = Organisation.new( @society ) unless @society.nil?
|
21
|
+
@venue = Venue.new( @venue ) unless @venue.nil?
|
22
|
+
@performances = split_object( @performances, Performance ) unless @performances.nil?
|
23
|
+
@image = Image.new( @image ) unless @image.nil?
|
24
24
|
end
|
25
25
|
|
26
26
|
# Gets an array of roles associated with the shows
|
data/lib/camdram/user.rb
CHANGED
@@ -36,10 +36,36 @@ module Camdram
|
|
36
36
|
|
37
37
|
# Return an array of societies the user is authorised for
|
38
38
|
#
|
39
|
-
# @return [Array] An array of Camdram::Organisation objects
|
39
|
+
# @return [Array] An array of Camdram::Organisation objects.
|
40
40
|
def get_orgs
|
41
|
+
orgs_share('society')
|
42
|
+
end
|
43
|
+
|
44
|
+
# Return an array of venues the user is authorised for
|
45
|
+
#
|
46
|
+
# @return [Array] An array of Camdram::Venue objects.
|
47
|
+
def get_venues
|
48
|
+
orgs_share('venue')
|
49
|
+
end
|
50
|
+
|
51
|
+
private
|
52
|
+
|
53
|
+
# Shared code because Camdram stores venues and societies together in the same table
|
54
|
+
#
|
55
|
+
# @param orm_type [String] The ORM type to match against (either "society" or "venue").
|
56
|
+
# @return [Array] An array of objects of the specified ORM type's class.
|
57
|
+
def orgs_share(orm_type)
|
58
|
+
object = case orm_type
|
59
|
+
when 'society' then Organisation
|
60
|
+
when 'venue' then Venue
|
61
|
+
end
|
41
62
|
slug = "/auth/account/organisations.json"
|
42
|
-
|
63
|
+
json = get(slug)
|
64
|
+
objects = Array.new
|
65
|
+
json.each do |obj|
|
66
|
+
objects << object.new( obj ) if obj[:_type] == orm_type
|
67
|
+
end
|
68
|
+
return objects
|
43
69
|
end
|
44
70
|
|
45
71
|
end
|
data/lib/camdram/version.rb
CHANGED
@@ -0,0 +1,76 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
class ClientTests < MiniTest::Unit::TestCase
|
4
|
+
|
5
|
+
def test_client
|
6
|
+
assert_equal true, @client.api_token?
|
7
|
+
assert_equal "https://www.camdram.net", @client.base_url
|
8
|
+
assert_equal "Camdram Ruby v#{@client.version}", @client.user_agent
|
9
|
+
end
|
10
|
+
|
11
|
+
def test_client_show_byid
|
12
|
+
show = @client.get_show(6514)
|
13
|
+
assert_equal "This show is a dummy used by Camdram for testing purposes only.", show.description
|
14
|
+
assert_equal "5b58b83bd534a.jpg", show.image.filename
|
15
|
+
assert_equal 1024, show.image.width
|
16
|
+
assert_equal "API Test 1", show.name
|
17
|
+
assert_equal "Camdram", show.other_society
|
18
|
+
assert_equal "ADC Theatre", show.other_venue
|
19
|
+
assert_equal 29, show.performances.first.venue.id
|
20
|
+
assert_equal "1997-api-test-1", show.slug
|
21
|
+
assert_equal 38, show.society.id
|
22
|
+
assert_equal "Camdram", show.society.name
|
23
|
+
assert_equal 29, show.venue.id
|
24
|
+
assert_equal "ADC Theatre", show.venue.name
|
25
|
+
end
|
26
|
+
|
27
|
+
def test_client_show_byslug
|
28
|
+
show = @client.get_show("1997-api-test-1")
|
29
|
+
assert_equal 6514, show.id
|
30
|
+
assert_equal "This show is a dummy used by Camdram for testing purposes only.", show.description
|
31
|
+
assert_equal "5b58b83bd534a.jpg", show.image.filename
|
32
|
+
assert_equal 1024, show.image.width
|
33
|
+
assert_equal "API Test 1", show.name
|
34
|
+
assert_equal "Camdram", show.other_society
|
35
|
+
assert_equal "ADC Theatre", show.other_venue
|
36
|
+
assert_equal 29, show.performances.first.venue.id
|
37
|
+
assert_equal 38, show.society.id
|
38
|
+
assert_equal "Camdram", show.society.name
|
39
|
+
assert_equal 29, show.venue.id
|
40
|
+
assert_equal "ADC Theatre", show.venue.name
|
41
|
+
end
|
42
|
+
|
43
|
+
def test_client_organisation_byid
|
44
|
+
org = @client.get_org(38)
|
45
|
+
assert_equal "Camdram", org.name
|
46
|
+
assert_equal "Camdram", org.short_name
|
47
|
+
assert_equal "camdram", org.slug
|
48
|
+
assert_equal "1002481303", org.twitter_id
|
49
|
+
end
|
50
|
+
|
51
|
+
def test_client_organisation_byslug
|
52
|
+
org = @client.get_org("camdram")
|
53
|
+
assert_equal 38, org.id
|
54
|
+
assert_equal "Camdram", org.name
|
55
|
+
assert_equal "Camdram", org.short_name
|
56
|
+
assert_equal "1002481303", org.twitter_id
|
57
|
+
end
|
58
|
+
|
59
|
+
def test_client_venue_byid
|
60
|
+
venue = @client.get_venue(29)
|
61
|
+
assert_equal "ADC Theatre", venue.name
|
62
|
+
assert_equal "ADC Theatre", venue.short_name
|
63
|
+
assert_equal "adc-theatre", venue.slug
|
64
|
+
assert_equal "33348320992", venue.facebook_id
|
65
|
+
assert_equal "36725639", venue.twitter_id
|
66
|
+
end
|
67
|
+
|
68
|
+
def test_client_venue_byslug
|
69
|
+
venue = @client.get_venue("adc-theatre")
|
70
|
+
assert_equal 29, venue.id
|
71
|
+
assert_equal "ADC Theatre", venue.name
|
72
|
+
assert_equal "ADC Theatre", venue.short_name
|
73
|
+
assert_equal "33348320992", venue.facebook_id
|
74
|
+
assert_equal "36725639", venue.twitter_id
|
75
|
+
end
|
76
|
+
end
|
@@ -0,0 +1,49 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
class SearchTests < MiniTest::Unit::TestCase
|
4
|
+
|
5
|
+
def test_search_show
|
6
|
+
entity = @client.search("API Test")[0].entity
|
7
|
+
assert_equal 6514, entity.id
|
8
|
+
assert_equal "This show is a dummy used by Camdram for testing purposes only.", entity.description
|
9
|
+
assert_equal "5b58b83bd534a.jpg", entity.image.filename
|
10
|
+
assert_equal 1024, entity.image.width
|
11
|
+
assert_equal "API Test 1", entity.name
|
12
|
+
assert_equal "Camdram", entity.other_society
|
13
|
+
assert_equal "ADC Theatre", entity.other_venue
|
14
|
+
assert_equal 29, entity.performances.first.venue.id
|
15
|
+
assert_equal "1997-api-test-1", entity.slug
|
16
|
+
assert_equal 38, entity.society.id
|
17
|
+
assert_equal "Camdram", entity.society.name
|
18
|
+
assert_equal 29, entity.venue.id
|
19
|
+
assert_equal "ADC Theatre", entity.venue.name
|
20
|
+
end
|
21
|
+
|
22
|
+
def test_search_organisation
|
23
|
+
entity = @client.search("CUADC")[0].entity
|
24
|
+
assert_equal 1, entity.id
|
25
|
+
assert_equal "Cambridge University Amateur Dramatic Club", entity.name
|
26
|
+
assert_equal "CUADC", entity.short_name
|
27
|
+
assert_equal "cambridge-university-amateur-dramatic-club", entity.slug
|
28
|
+
assert_equal "189141344500085", entity.facebook_id
|
29
|
+
assert_equal "472457773", entity.twitter_id
|
30
|
+
end
|
31
|
+
|
32
|
+
def test_search_venue
|
33
|
+
entity = @client.search("ADC Theatre")[0].entity
|
34
|
+
assert_equal 29, entity.id
|
35
|
+
assert_equal "ADC Theatre", entity.name
|
36
|
+
assert_equal "ADC Theatre", entity.short_name
|
37
|
+
assert_equal "adc-theatre", entity.slug
|
38
|
+
assert_equal "33348320992", entity.facebook_id
|
39
|
+
assert_equal "36725639", entity.twitter_id
|
40
|
+
end
|
41
|
+
|
42
|
+
def test_search_person
|
43
|
+
entity = @client.search("Charlie Jonas")[0].entity
|
44
|
+
assert_equal 13865, entity.id
|
45
|
+
assert_equal "Charlie Jonas", entity.name
|
46
|
+
assert_equal "charlie-jonas", entity.slug
|
47
|
+
end
|
48
|
+
|
49
|
+
end
|
data/test/user_tests.rb
CHANGED
@@ -1,6 +1,7 @@
|
|
1
1
|
require 'test_helper'
|
2
2
|
|
3
|
-
class
|
3
|
+
class ClientTests < MiniTest::Unit::TestCase
|
4
|
+
|
4
5
|
def test_user
|
5
6
|
user = @client.user
|
6
7
|
assert_equal 3807, user.id
|
@@ -8,9 +9,8 @@ class UserTests < MiniTest::Unit::TestCase
|
|
8
9
|
assert_equal "charlie@charliejonas.co.uk", user.email
|
9
10
|
end
|
10
11
|
|
11
|
-
def
|
12
|
-
|
13
|
-
show = user.get_shows.first
|
12
|
+
def test_user_shows
|
13
|
+
show = @client.user.get_shows.first
|
14
14
|
assert_equal 6514, show.id
|
15
15
|
assert_equal "This show is a dummy used by Camdram for testing purposes only.", show.description
|
16
16
|
assert_equal "5b58b83bd534a.jpg", show.image.filename
|
@@ -26,13 +26,22 @@ class UserTests < MiniTest::Unit::TestCase
|
|
26
26
|
assert_equal "ADC Theatre", show.venue.name
|
27
27
|
end
|
28
28
|
|
29
|
-
def
|
30
|
-
|
31
|
-
org = user.get_orgs.first
|
29
|
+
def test_user_organisations
|
30
|
+
org = @client.user.get_orgs.first
|
32
31
|
assert_equal 38, org.id
|
33
32
|
assert_equal "Camdram", org.name
|
34
33
|
assert_equal "Camdram", org.short_name
|
35
34
|
assert_equal "camdram", org.slug
|
36
35
|
assert_equal "1002481303", org.twitter_id
|
37
36
|
end
|
37
|
+
|
38
|
+
def test_user_venues
|
39
|
+
venue = @client.user.get_venues.first
|
40
|
+
assert_equal 29, venue.id
|
41
|
+
assert_equal "ADC Theatre", venue.name
|
42
|
+
assert_equal "ADC Theatre", venue.short_name
|
43
|
+
assert_equal "adc-theatre", venue.slug
|
44
|
+
assert_equal "33348320992", venue.facebook_id
|
45
|
+
assert_equal "36725639", venue.twitter_id
|
46
|
+
end
|
38
47
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: camdram
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Charlie Jonas
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2018-
|
11
|
+
date: 2018-10-21 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: json
|
@@ -99,6 +99,8 @@ files:
|
|
99
99
|
- lib/camdram/user.rb
|
100
100
|
- lib/camdram/venue.rb
|
101
101
|
- lib/camdram/version.rb
|
102
|
+
- test/client_tests.rb
|
103
|
+
- test/search_tests.rb
|
102
104
|
- test/test_helper.rb
|
103
105
|
- test/user_tests.rb
|
104
106
|
homepage: https://github.com/CHTJonas/camdram-ruby
|
@@ -126,5 +128,7 @@ signing_key:
|
|
126
128
|
specification_version: 4
|
127
129
|
summary: A lovely API wrapper for Camdram written in Ruby
|
128
130
|
test_files:
|
131
|
+
- test/client_tests.rb
|
132
|
+
- test/search_tests.rb
|
129
133
|
- test/test_helper.rb
|
130
134
|
- test/user_tests.rb
|