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/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_awards_list.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

#get_feeds

Methods included from Notifications::Notifications

#get_notifications

Methods included from Notifications::MyPriorityItems

#get_my_priority_items

Methods included from Recognitions::GetProfileAwards

#get_profile_awards

Methods included from Recognitions::GetAwardsList

#get_awards_list

Methods included from Recognitions::LeaderboardInfo

#get_leaderboard_info

Methods included from Recognitions::CoreValueTags

#get_core_value_tags

Methods included from Recognitions::AwardCategories

#get_award_categories

Methods included from Users

#get_user, #get_users, #me

Methods included from Learn::MyLearning

#get_my_learning

Methods included from Learn::CourseDetails

#get_course_details

Methods included from Learn::CourseCategories

#get_course_categories

Methods included from Learn::CourseCatalog

#get_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: {}, unique_user_id: nil) ⇒ Object



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

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

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

—- HTTP Methods —-



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

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

#get_userinfo(unique_user_id: nil) ⇒ Object



67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
# File 'lib/mangoapps/client.rb', line 67

def get_userinfo(unique_user_id: nil)
  case config.authentication_method
  when :internal_api
    # For internal API, we can't use OAuth userinfo endpoint
    # Instead, we'll use the /me endpoint which provides user info
    response = get("v2/me.json", unique_user_id: unique_user_id)
    response..minimal_profile
  when :oauth
    raise MangoApps::TokenExpiredError, "No access token available" unless access_token
    
    userinfo_data = oauth.get_userinfo(access_token.token)
    MangoApps::Response.new(userinfo_data)
  else
    raise MangoApps::AuthenticationError, "No authentication method available"
  end
end

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



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

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

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



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

def put(path, body: nil, headers: {}, unique_user_id: nil)
  request(:put, path, body: body, headers: headers, unique_user_id: unique_user_id)
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