Class: Udacity::UdacityAPI

Inherits:
Object
  • Object
show all
Defined in:
lib/share_learning/udacity_api.rb

Overview

Service for all Udacity API calls

Constant Summary collapse

UDACITY_URL =
'https://www.udacity.com/public-api/v0/courses'.freeze

Class Method Summary collapse

Class Method Details

.acquire_json_responseObject

get all courses info in json format through RESTful API



10
11
12
13
# File 'lib/share_learning/udacity_api.rb', line 10

def self.acquire_json_response
  response = HTTP.get(URI.parse(UDACITY_URL))
  JSON.parse(response)
end

.retrieve_total_course_numObject



20
21
22
23
24
25
26
# File 'lib/share_learning/udacity_api.rb', line 20

def self.retrieve_total_course_num
  return @total_course_num if @total_course_num

  # Retrieve the total number of courses on the catlog
  json_resp = acquire_json_response
  @total_course_num = json_resp['courses'].size
end

.total_course_numObject

get total courses number



16
17
18
# File 'lib/share_learning/udacity_api.rb', line 16

def self.total_course_num
  @total_course_num = retrieve_total_course_num
end