Class: Camdram::Client
Instance Attribute Summary collapse
-
#api_token ⇒ Object
Returns the value of attribute api_token.
Attributes included from API
Instance Method Summary collapse
-
#api_token? ⇒ Boolean
Returns true if the API access token is set.
-
#base_url ⇒ String
Returns the API URL that each HTTP request is sent to.
-
#base_url=(url) ⇒ String
Sets the API URL that each HTTP request is sent to.
-
#diary(start_date = nil, end_date = nil) ⇒ Camdram::Diary
Gets a diary object which contains an array of upcoming calendar events.
-
#get_org(id) ⇒ Camdram::Organisation
Lookup an organisation by its ID or slug.
-
#get_orgs ⇒ Array
Returns an array of all registered organisations.
-
#get_people ⇒ Array
Returns an array containing a sample of people taking part in shows this week.
-
#get_person(id) ⇒ Camdram::Person
Lookup a person by their ID or slug.
-
#get_show(id) ⇒ Camdram::Show
Lookup a show by its ID or slug.
-
#get_venue(id) ⇒ Camdram::Venue
Lookup a venue by its ID or slug.
-
#get_venues ⇒ Array
Returns an array of all registered venues.
-
#initialize ⇒ Camdram::Client
constructor
Initializes a new Client object using a block.
-
#search(query, limit = 10, page = 1) ⇒ Array
Return an array of search entity results based on a search string.
-
#termly_diary(year, term = nil) ⇒ Camdram::Diary
Gets a diary object which contains an array of events occuring in the given year/term.
-
#user ⇒ Camdram::User
Returns the user associated with the API token if set, otherwise raises an exception.
-
#user_agent ⇒ String
Returns the user agent header sent in each HTTP request.
-
#user_agent=(agent) ⇒ String
Sets the user agent header sent in each HTTP request.
-
#version ⇒ String
Returns the program version that is currently running.
Methods included from API
Constructor Details
#initialize ⇒ Camdram::Client
Initializes a new Client object using a block
21 22 23 24 25 26 27 |
# File 'lib/camdram/client.rb', line 21 def initialize if !block_given? warn 'Camdram::Client instantiated without config block - did you mean to add an API key?' else yield(self) end end |
Instance Attribute Details
#api_token ⇒ Object
Returns the value of attribute api_token.
16 17 18 |
# File 'lib/camdram/client.rb', line 16 def api_token @api_token end |
Instance Method Details
#api_token? ⇒ Boolean
Returns true if the API access token is set
32 33 34 |
# File 'lib/camdram/client.rb', line 32 def api_token? HTTP.instance.api_token? end |
#base_url ⇒ String
Returns the API URL that each HTTP request is sent to
47 48 49 |
# File 'lib/camdram/client.rb', line 47 def base_url HTTP.instance.base_url end |
#base_url=(url) ⇒ String
Sets the API URL that each HTTP request is sent to
55 56 57 |
# File 'lib/camdram/client.rb', line 55 def base_url=(url) HTTP.instance.base_url = url end |
#diary(start_date = nil, end_date = nil) ⇒ Camdram::Diary
Gets a diary object which contains an array of upcoming calendar events
200 201 202 203 204 205 206 207 |
# File 'lib/camdram/client.rb', line 200 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 |
#get_org(id) ⇒ Camdram::Organisation
Lookup an organisation by its ID or slug
109 110 111 112 113 114 115 116 117 118 119 120 |
# File 'lib/camdram/client.rb', line 109 def get_org(id) url = nil if id.is_a? Integer url = "#{Organisation.url}/by-id/#{id}.json" elsif id.is_a? String url = "#{Organisation.url}/#{id}.json" else raise ArgumentError.new 'id must be an integer, or slug must be a string' end response = get(url) Organisation.new(response) end |
#get_orgs ⇒ Array
Returns an array of all registered organisations
163 164 165 166 167 |
# File 'lib/camdram/client.rb', line 163 def get_orgs url = "#{Organisation.url}.json" response = get(url) split_object( response, Organisation ) end |
#get_people ⇒ Array
Returns an array containing a sample of people taking part in shows this week
181 182 183 184 185 |
# File 'lib/camdram/client.rb', line 181 def get_people url = "#{Person.url}.json" response = get(url) split_object( response, Role ) end |
#get_person(id) ⇒ Camdram::Person
Lookup a person by their ID or slug
147 148 149 150 151 152 153 154 155 156 157 158 |
# File 'lib/camdram/client.rb', line 147 def get_person(id) url = nil if id.is_a? Integer url = "#{Person.url}/by-id/#{id}.json" elsif id.is_a? String url = "#{Person.url}/#{id}.json" else raise ArgumentError.new 'id must be an integer, or slug must be a string' end response = get(url) Person.new(response) end |
#get_show(id) ⇒ Camdram::Show
Lookup a show by its ID or slug
90 91 92 93 94 95 96 97 98 99 100 101 |
# File 'lib/camdram/client.rb', line 90 def get_show(id) url = nil if id.is_a? Integer url = "#{Show.url}/by-id/#{id}.json" elsif id.is_a? String url = "#{Show.url}/#{id}.json" else raise ArgumentError.new 'id must be an integer, or slug must be a string' end response = get(url) return Show.new(response) end |
#get_venue(id) ⇒ Camdram::Venue
Lookup a venue by its ID or slug
128 129 130 131 132 133 134 135 136 137 138 139 |
# File 'lib/camdram/client.rb', line 128 def get_venue(id) url = nil if id.is_a? Integer url = "#{Venue.url}/by-id/#{id}.json" elsif id.is_a? String url = "#{Venue.url}/#{id}.json" else raise ArgumentError.new 'id must be an integer, or slug must be a string' end response = get(url) Venue.new(response) end |
#get_venues ⇒ Array
Returns an array of all registered venues
172 173 174 175 176 |
# File 'lib/camdram/client.rb', line 172 def get_venues url = "#{Venue.url}.json" response = get(url) split_object( response, Venue ) end |
#search(query, limit = 10, page = 1) ⇒ Array
Return an array of search entity results based on a search string
191 192 193 194 195 |
# File 'lib/camdram/client.rb', line 191 def search(query, limit=10, page=1) url = "/search.json?q=#{query}&limit=#{limit}&page=#{page}" response = get(url) split_object( response, Search ) end |
#termly_diary(year, term = nil) ⇒ Camdram::Diary
Gets a diary object which contains an array of events occuring in the given year/term
212 213 214 215 216 217 218 |
# File 'lib/camdram/client.rb', line 212 def termly_diary(year, term=nil) url = "/diary/#{year}" url << "/#{term}" if term url << ".json" response = get(url) Diary.new(response) end |
#user ⇒ Camdram::User
Returns the user associated with the API token if set, otherwise raises an exception
78 79 80 81 82 |
# File 'lib/camdram/client.rb', line 78 def user slug = "/auth/account.json" response = get(slug) User.new(response) end |
#user_agent ⇒ String
Returns the user agent header sent in each HTTP request
62 63 64 |
# File 'lib/camdram/client.rb', line 62 def user_agent HTTP.instance.user_agent end |
#user_agent=(agent) ⇒ String
Sets the user agent header sent in each HTTP request
70 71 72 |
# File 'lib/camdram/client.rb', line 70 def user_agent=(agent) HTTP.instance.user_agent = agent end |