Class: MangoApps::Client
- Inherits:
 - 
      Object
      
        
- Object
 - MangoApps::Client
 
 
- 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
- 
  
    
      #config  ⇒ Object 
    
    
  
  
  
  
    
      readonly
    
    
  
  
  
  
  
  
    
Returns the value of attribute config.
 - 
  
    
      #http  ⇒ Object 
    
    
  
  
  
  
    
      readonly
    
    
  
  
  
  
  
  
    
Returns the value of attribute http.
 - 
  
    
      #oauth  ⇒ Object 
    
    
  
  
  
  
    
      readonly
    
    
  
  
  
  
  
  
    
Returns the value of attribute oauth.
 
Instance Method Summary collapse
- 
  
    
      #access_token  ⇒ Object 
    
    
  
  
  
  
  
  
  
  
  
    
—- Authentication —-.
 - #authenticate!(authorization_code:, code_verifier: nil) ⇒ Object
 - #authenticated? ⇒ Boolean
 - 
  
    
      #authorization_url(state:, code_challenge: nil, code_challenge_method: "S256", **extra_params)  ⇒ Object 
    
    
  
  
  
  
  
  
  
  
  
    
—- OAuth Helpers —-.
 - #delete(path, headers: {}, unique_user_id: nil) ⇒ Object
 - 
  
    
      #get(path, params: {}, headers: {}, unique_user_id: nil)  ⇒ Object 
    
    
  
  
  
  
  
  
  
  
  
    
—- HTTP Methods —-.
 - #get_userinfo(unique_user_id: nil) ⇒ Object
 - 
  
    
      #initialize(config)  ⇒ Client 
    
    
  
  
  
    constructor
  
  
  
  
  
  
  
    
A new instance of Client.
 - #post(path, body: nil, headers: {}, unique_user_id: nil) ⇒ Object
 - #put(path, body: nil, headers: {}, unique_user_id: nil) ⇒ Object
 - #refresh_token! ⇒ Object
 
Methods included from Wikis::GetWikiDetails
Methods included from Wikis::GetWikis
Methods included from Tasks::GetTaskDetails
Methods included from Tasks::GetTasks
Methods included from Attachments::GetFolderFiles
Methods included from Attachments::GetFolders
Methods included from Trackers::GetTrackers
Methods included from Libraries::GetLibraryItems
Methods included from Libraries::GetLibraryCategories
Methods included from Libraries::GetLibraries
Methods included from Posts::GetPostById
Methods included from Posts::GetAllPosts
Methods included from Feeds::Feeds
Methods included from Notifications::Notifications
Methods included from Notifications::MyPriorityItems
Methods included from Recognitions::GetProfileAwards
Methods included from Recognitions::GetAwardsList
Methods included from Recognitions::LeaderboardInfo
Methods included from Recognitions::CoreValueTags
Methods included from Recognitions::AwardCategories
Methods included from Users
Methods included from Learn::MyLearning
Methods included from Learn::CourseDetails
Methods included from Learn::CourseCategories
Methods included from Learn::CourseCatalog
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
#config ⇒ Object (readonly)
Returns the value of attribute config.
      10 11 12  | 
    
      # File 'lib/mangoapps/client.rb', line 10 def config @config end  | 
  
#http ⇒ Object (readonly)
Returns the value of attribute http.
      10 11 12  | 
    
      # File 'lib/mangoapps/client.rb', line 10 def http @http end  | 
  
#oauth ⇒ Object (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_token ⇒ Object
—- 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: , code_verifier: code_verifier ) end  | 
  
#authenticated? ⇒ 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 (state:, code_challenge: nil, code_challenge_method: "S256", **extra_params) oauth.( 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.user_profile.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  |