class Camdram::Client

Attributes

api_token[R]

Public Class Methods

new() { |self| ... } click to toggle source

Initializes a new Client object using a block

@return [Camdram::Client] The top-level Camdram client.

# 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

Public Instance Methods

api_token=(token) click to toggle source

Sets the API access token

@param token [String] The access token used to authenticate API calls. @return [String] The token itself.

# File lib/camdram/client.rb, line 40
def api_token=(token)
  HTTP.instance.api_token = token
end
api_token?() click to toggle source

Returns true if the API access token is set

@return [Boolean] Whether the API token is set or not.

# File lib/camdram/client.rb, line 32
def api_token?
  HTTP.instance.api_token?
end
base_url() click to toggle source

Returns the API URL that each HTTP request is sent to

@return [String] The API hostname to send requests to.

# File lib/camdram/client.rb, line 47
def base_url
  HTTP.instance.base_url
end
base_url=(url) click to toggle source

Sets the API URL that each HTTP request is sent to

@param url [String] The API hostname to send requests to. @return [String] The url itself.

# File lib/camdram/client.rb, line 55
def base_url=(url)
  HTTP.instance.base_url = url
end
diary(start_date=nil, end_date=nil) click to toggle source

Gets a diary object which contains an array of upcoming calendar events

@return [Camdram::Diary] A Diary object.

# 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) click to toggle source

Lookup an organisation by its ID or slug

@param id [Integer] The numeric ID of the organisation. @param id [String] The slug of the organisation. @raise [ArgumentError] Error raised when an integer or string is not provided. @return [Camdram::Organisation] The organisation with the provided ID or slug.

# 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() click to toggle source

Returns an array of all registered organisations

@return [Array] An array of Organisation objects.

# File lib/camdram/client.rb, line 163
def get_orgs
  url = "#{Organisation.url}.json"
  response = get(url)
  split_object( response, Organisation )
end
get_people() click to toggle source

Returns an array containing a sample of people taking part in shows this week

@return [Array] An array of Role objects.

# 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) click to toggle source

Lookup a person by their ID or slug

@param id [Integer] The numeric ID of the person. @param id [String] The person's slug. @raise [ArgumentError] Error raised when an integer or string is not provided. @return [Camdram::Person] The person with the provided ID or slug.

# 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) click to toggle source

Lookup a show by its ID or slug

@param id [Integer] The numeric ID of the show. @param id [String] The slug of the show. @raise [ArgumentError] Error raised when an integer or string is not provided. @return [Camdram::Show] The show with the provided ID or slug.

# 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) click to toggle source

Lookup a venue by its ID or slug

@param id [Integer] The numeric ID of the venue. @param id [String] The slug of the venue. @raise [ArgumentError] Error raised when an integer or string is not provided. @return [Camdram::Venue] The venue with the provided ID or slug.

# 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() click to toggle source

Returns an array of all registered venues

@return [Array] An array of Venue objects.

# File lib/camdram/client.rb, line 172
def get_venues
  url = "#{Venue.url}.json"
  response = get(url)
  split_object( response, Venue )
end
termly_diary(year, term=nil) click to toggle source

Gets a diary object which contains an array of events occuring in the given year/term

@return [Camdram::Diary] A Diary object.

# 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() click to toggle source

Returns the user associated with the API token if set, otherwise raises an exception

@raise [StandardError] Error raised when the API token is not set. @return [Camdram::User] The associated User object.

# File lib/camdram/client.rb, line 78
def user
  slug = "/auth/account.json"
  response = get(slug)
  User.new(response)
end
user_agent() click to toggle source

Returns the user agent header sent in each HTTP request

@return [String] The user agent header to send with HTTP requests.

# File lib/camdram/client.rb, line 62
def user_agent
  HTTP.instance.user_agent
end
user_agent=(agent) click to toggle source

Sets the user agent header sent in each HTTP request

@param agent [String] The user agent header to send with HTTP requests. @return [String] The agent string itself.

# File lib/camdram/client.rb, line 70
def user_agent=(agent)
  HTTP.instance.user_agent = agent
end
version() click to toggle source

Returns the program version that is currently running

@return [String] The version of camdram-ruby that is currently running.

# File lib/camdram/client.rb, line 223
def version
  Camdram::VERSION
end