class TTSApiClient
Attributes
config[R]
Public Class Methods
new(opts = {})
click to toggle source
# File lib/tts/api/client.rb, line 14 def initialize(opts = {}) # Configuration defaults @config = { :base_uri => "api.techtalentsouth.com", :token => "" } #establish valid config keys based on keys in @config hash @valid_config_keys = @config.keys #set configuration based on options passed in configure(opts) #setup HTTParty based on cofig setup end
Public Instance Methods
add_campus(campus)
click to toggle source
add a campus
# File lib/tts/api/client.rb, line 152 def add_campus(campus) handle_errors do self.class.post("/campuses", :body => {"campus" => campus}) end end
add_course(course)
click to toggle source
add a courses
# File lib/tts/api/client.rb, line 41 def add_course(course) handle_errors do self.class.post("/courses", :body => {"course" => course}) end end
add_course_location(course_location)
click to toggle source
add a course_locations (class)
# File lib/tts/api/client.rb, line 189 def add_course_location(course_location) handle_errors do self.class.post("/course_locations", :body => {"course_location" => course_location}) end end
add_instructor(instructor)
click to toggle source
add an instructor
# File lib/tts/api/client.rb, line 78 def add_instructor(instructor) handle_errors do self.class.post("/instructors", :body => {"instructor" => instructor}) end end
add_location(location)
click to toggle source
add an location
# File lib/tts/api/client.rb, line 115 def add_location(location) handle_errors do self.class.post("/locations", :body => {"location" => location}) end end
configure(opts = {})
click to toggle source
Configure through hash
# File lib/tts/api/client.rb, line 234 def configure(opts = {}) opts.each {|k,v| @config[k.to_sym] = v if @valid_config_keys.include? k.to_sym} setup end
configure_with_yaml(path_to_yaml_file)
click to toggle source
Configure through yaml file
# File lib/tts/api/client.rb, line 240 def configure_with_yaml(path_to_yaml_file) begin config = YAML::load(IO.read(path_to_yaml_file)) rescue Errno::ENOENT => e raise e, "YAML configuration file couldn't be found. Using defaults." rescue Psych::SyntaxError raise e, "YAML configuration file contains invalid syntax. Using defaults." end configure(config) end
delete_campus(campus_id)
click to toggle source
delete an campus
# File lib/tts/api/client.rb, line 166 def delete_campus(campus_id) handle_errors do self.class.delete("/campuses/" + campus_id.to_s) end end
delete_course(course_id)
click to toggle source
delete a course
# File lib/tts/api/client.rb, line 55 def delete_course(course_id) handle_errors do self.class.delete("/courses/" + course_id.to_s) end end
delete_course_location(course_location_id)
click to toggle source
delete a course_location (class)
# File lib/tts/api/client.rb, line 203 def delete_course_location(course_location_id) handle_errors do self.class.delete("/course_locations/" + course_location_id.to_s) end end
delete_instructor(instructor_id)
click to toggle source
delete an instructor
# File lib/tts/api/client.rb, line 92 def delete_instructor(instructor_id) handle_errors do self.class.delete("/instructors/" + instructor_id.to_s) end end
delete_location(location_id)
click to toggle source
delete an location
# File lib/tts/api/client.rb, line 129 def delete_location(location_id) handle_errors do self.class.delete("/locations/" + location_id.to_s) end end
get_campus(campus_id)
click to toggle source
get a specific campus
# File lib/tts/api/client.rb, line 159 def get_campus(campus_id) handle_errors do self.class.get("/campuses/" + campus_id.to_s) end end
get_campuses()
click to toggle source
Campuses ###
get all available campuses
# File lib/tts/api/client.rb, line 145 def get_campuses() handle_errors do self.class.get("/campuses") end end
get_course(course_id)
click to toggle source
get a specific course
# File lib/tts/api/client.rb, line 48 def get_course(course_id) handle_errors do self.class.get("/courses/" + course_id.to_s) end end
get_course_location(course_location_id)
click to toggle source
get a specific course_location (class)
# File lib/tts/api/client.rb, line 196 def get_course_location(course_location_id) handle_errors do self.class.get("/course_locations/" + course_location_id.to_s) end end
get_course_locations()
click to toggle source
Course_Locations (classes) ###
get all available course_locations (classes)
# File lib/tts/api/client.rb, line 182 def get_course_locations() handle_errors do self.class.get("/course_locations") end end
get_courses()
click to toggle source
Courses ###
get all available courses
# File lib/tts/api/client.rb, line 34 def get_courses() handle_errors do self.class.get("/courses") end end
get_instructor(instructor_id)
click to toggle source
get a specific instructor
# File lib/tts/api/client.rb, line 85 def get_instructor(instructor_id) handle_errors do self.class.get("/instructors/" + instructor_id.to_s) end end
get_instructors()
click to toggle source
Instructors ###
get all available istructors
# File lib/tts/api/client.rb, line 71 def get_instructors() handle_errors do self.class.get("/instructors") end end
get_location(location_id)
click to toggle source
get a specific location
# File lib/tts/api/client.rb, line 122 def get_location(location_id) handle_errors do self.class.get("/locations/" + location_id.to_s) end end
get_locations()
click to toggle source
Locations ###
get all available locations
# File lib/tts/api/client.rb, line 108 def get_locations() handle_errors do self.class.get("/locations") end end
handle_errors() { || ... }
click to toggle source
handle HTTParty errors
# File lib/tts/api/client.rb, line 225 def handle_errors begin yield rescue Net::OpenTimeout, Net::ReadTimeout, SocketError => e raise e, "Cannot connect to host: #{@config[:base_uri]}" end end
setup()
click to toggle source
set HTTParty options based on @config
# File lib/tts/api/client.rb, line 218 def setup self.class.base_uri @config[:base_uri] self.class.headers 'Authorization' => @config[:token] #self.class.headers 'Content-Type' => 'application/json' end
update_campus(campus)
click to toggle source
update a campus
# File lib/tts/api/client.rb, line 173 def update_campus(campus) id = campus["id"] handle_errors do self.class.put("/campuses/" + id, :body => {"campus" => campus}) end end
update_course(course)
click to toggle source
update a course
# File lib/tts/api/client.rb, line 62 def update_course(course) id = course["id"] handle_errors do self.class.put("/courses/" + id, :body => {"course" => course}) end end
update_course_location(course_location)
click to toggle source
update a course_location (class)
# File lib/tts/api/client.rb, line 210 def update_course_location(course_location) id = course_location["id"] handle_errors do self.class.put("/course_locations/" + id, :body => {"course_location" => course_location}) end end
update_instructor(instructor)
click to toggle source
update a instructor
# File lib/tts/api/client.rb, line 99 def update_instructor(instructor) id = instructor["id"] handle_errors do self.class.put("/instructors/" + id, :body => {"instructor" => instructor}) end end
update_location(location)
click to toggle source
update a location
# File lib/tts/api/client.rb, line 136 def update_location(location) id = location["id"] handle_errors do self.class.put("/locations/" + id, :body => {"location" => location}) end end