Class: MangoApps::Client

Inherits:
Object
  • Object
show all
Includes:
Attachments, Feeds, Learn, Libraries, Notifications, Posts, Recognitions, Tasks, Trackers, Users, Wikis
Defined in:
lib/mangoapps/client.rb,
lib/mangoapps/modules/feeds.rb,
lib/mangoapps/modules/learn.rb,
lib/mangoapps/modules/posts.rb,
lib/mangoapps/modules/tasks.rb,
lib/mangoapps/modules/users.rb,
lib/mangoapps/modules/wikis.rb,
lib/mangoapps/modules/trackers.rb,
lib/mangoapps/modules/libraries.rb,
lib/mangoapps/modules/attachments.rb,
lib/mangoapps/modules/feeds/feeds.rb,
lib/mangoapps/modules/recognitions.rb,
lib/mangoapps/modules/notifications.rb,
lib/mangoapps/modules/tasks/get_tasks.rb,
lib/mangoapps/modules/wikis/get_wikis.rb,
lib/mangoapps/modules/learn/my_learning.rb,
lib/mangoapps/modules/posts/get_all_posts.rb,
lib/mangoapps/modules/learn/course_catalog.rb,
lib/mangoapps/modules/learn/course_details.rb,
lib/mangoapps/modules/posts/get_post_by_id.rb,
lib/mangoapps/modules/trackers/get_trackers.rb,
lib/mangoapps/modules/tasks/get_task_details.rb,
lib/mangoapps/modules/wikis/get_wiki_details.rb,
lib/mangoapps/modules/attachments/get_folders.rb,
lib/mangoapps/modules/learn/course_categories.rb,
lib/mangoapps/modules/libraries/get_libraries.rb,
lib/mangoapps/modules/recognitions/gift_cards.rb,
lib/mangoapps/modules/libraries/get_library_items.rb,
lib/mangoapps/modules/notifications/notifications.rb,
lib/mangoapps/modules/attachments/get_folder_files.rb,
lib/mangoapps/modules/recognitions/core_value_tags.rb,
lib/mangoapps/modules/recognitions/get_award_feeds.rb,
lib/mangoapps/modules/recognitions/get_awards_list.rb,
lib/mangoapps/modules/recognitions/get_team_awards.rb,
lib/mangoapps/modules/recognitions/award_categories.rb,
lib/mangoapps/modules/recognitions/leaderboard_info.rb,
lib/mangoapps/modules/notifications/my_priority_items.rb,
lib/mangoapps/modules/recognitions/get_profile_awards.rb,
lib/mangoapps/modules/libraries/get_library_categories.rb

Defined Under Namespace

Modules: Attachments, Feeds, Learn, Libraries, Notifications, Posts, Recognitions, Tasks, Trackers, Users, Wikis

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Wikis::GetWikiDetails

#get_wiki_details

Methods included from Wikis::GetWikis

#get_wikis

Methods included from Tasks::GetTaskDetails

#get_task_details

Methods included from Tasks::GetTasks

#get_tasks

Methods included from Attachments::GetFolderFiles

#get_folder_files

Methods included from Attachments::GetFolders

#get_folders

Methods included from Trackers::GetTrackers

#get_trackers

Methods included from Libraries::GetLibraryItems

#get_library_items

Methods included from Libraries::GetLibraryCategories

#get_library_categories

Methods included from Libraries::GetLibraries

#get_libraries

Methods included from Posts::GetPostById

#get_post_by_id

Methods included from Posts::GetAllPosts

#get_all_posts

Methods included from Feeds::Feeds

#feeds

Methods included from Notifications::Notifications

#notifications

Methods included from Notifications::MyPriorityItems

#my_priority_items

Methods included from Recognitions::GetAwardFeeds

#get_award_feeds

Methods included from Recognitions::GetTeamAwards

#get_team_awards

Methods included from Recognitions::GetProfileAwards

#get_profile_awards

Methods included from Recognitions::GetAwardsList

#get_awards_list

Methods included from Recognitions::GiftCards

#gift_cards

Methods included from Recognitions::LeaderboardInfo

#leaderboard_info

Methods included from Recognitions::CoreValueTags

#core_value_tags

Methods included from Recognitions::AwardCategories

#award_categories

Methods included from Users

#me

Methods included from Learn::MyLearning

#my_learning

Methods included from Learn::CourseDetails

#course_details

Methods included from Learn::CourseCategories

#course_categories

Methods included from Learn::CourseCatalog

#course_catalog

Constructor Details

#initialize(config) ⇒ Client

Returns a new instance of Client.



12
13
14
15
16
# File 'lib/mangoapps/client.rb', line 12

def initialize(config)
  @config = config
  @oauth = OAuth.new(config)
  @http = build_http_client
end

Instance Attribute Details

#configObject (readonly)

Returns the value of attribute config.



10
11
12
# File 'lib/mangoapps/client.rb', line 10

def config
  @config
end

#httpObject (readonly)

Returns the value of attribute http.



10
11
12
# File 'lib/mangoapps/client.rb', line 10

def http
  @http
end

#oauthObject (readonly)

Returns the value of attribute oauth.



10
11
12
# File 'lib/mangoapps/client.rb', line 10

def oauth
  @oauth
end

Instance Method Details

#access_tokenObject

—- Authentication —-



19
20
21
# File 'lib/mangoapps/client.rb', line 19

def access_token
  @access_token ||= load_access_token
end

#authenticate!(authorization_code:, code_verifier: nil) ⇒ Object



27
28
29
30
31
32
# File 'lib/mangoapps/client.rb', line 27

def authenticate!(authorization_code:, code_verifier: nil)
  @access_token = oauth.get_token(
    authorization_code: authorization_code,
    code_verifier: code_verifier
  )
end

#authenticated?Boolean

Returns:

  • (Boolean)


23
24
25
# File 'lib/mangoapps/client.rb', line 23

def authenticated?
  access_token && !token_expired?
end

#authorization_url(state:, code_challenge: nil, code_challenge_method: "S256", **extra_params) ⇒ Object

—- OAuth Helpers —-



58
59
60
61
62
63
64
65
# File 'lib/mangoapps/client.rb', line 58

def authorization_url(state:, code_challenge: nil, code_challenge_method: "S256", **extra_params)
  oauth.authorization_url(
    state: state,
    code_challenge: code_challenge,
    code_challenge_method: code_challenge_method,
    extra_params: extra_params
  )
end

#delete(path, headers: {}) ⇒ Object



53
54
55
# File 'lib/mangoapps/client.rb', line 53

def delete(path, headers: {})
  request(:delete, path, headers: headers)
end

#get(path, params: {}, headers: {}) ⇒ Object

—- HTTP Methods —-



41
42
43
# File 'lib/mangoapps/client.rb', line 41

def get(path, params: {}, headers: {})
  request(:get, path, params: params, headers: headers)
end

#post(path, body: nil, headers: {}) ⇒ Object



45
46
47
# File 'lib/mangoapps/client.rb', line 45

def post(path, body: nil, headers: {})
  request(:post, path, body: body, headers: headers)
end

#put(path, body: nil, headers: {}) ⇒ Object



49
50
51
# File 'lib/mangoapps/client.rb', line 49

def put(path, body: nil, headers: {})
  request(:put, path, body: body, headers: headers)
end

#refresh_token!Object



34
35
36
37
38
# File 'lib/mangoapps/client.rb', line 34

def refresh_token!
  raise MangoApps::TokenExpiredError, "No refresh token available" unless access_token&.refresh_token

  @access_token = oauth.refresh!(access_token)
end