Class: M365ActiveStorage::M365
- Inherits:
-
Object
- Object
- M365ActiveStorage::M365
- Defined in:
- lib/m365_active_storage/m365.rb
Overview
M365 SharePoint Interface
Provides high-level interface for interacting with Microsoft 365 SharePoint services. This class handles configuration loading, authentication, and basic SharePoint operations.
Responsibilities
-
Load and manage SharePoint configuration from config/storage.yml
-
Establish authenticated connections to Microsoft Graph API
-
Provide methods for site and drive discovery
-
Validate SharePoint endpoint connectivity
Example Usage
m365 = M365ActiveStorage::M365.new
site_id, drive_id = m365.config_site_and_drive_id
site = m365.find_site_by_id(site_id)
drive = m365.find_sharepoint_drive_by_id(site_id, drive_id)
if m365.ping?
puts "SharePoint connectivity is healthy"
end
Configuration
Configuration is loaded from config/storage.yml. Required parameters:
-
ms_graph_url: The Microsoft Graph API base URL
-
ms_graph_version: The Graph API version (e.g., “v1.0”)
-
auth_host: The OAuth2 authentication endpoint
-
oauth_tenant: Your Azure AD tenant ID
-
oauth_app_id: Your Azure AD application ID
-
oauth_secret: Your Azure AD client secret
-
sharepoint_site_id: The target SharePoint site ID
-
sharepoint_drive_id: The target SharePoint drive ID
Class Method Summary collapse
-
.load_configuration_from_storage_yml ⇒ Hash
Load configuration from config/storage.yml file.
Instance Method Summary collapse
-
#config_site_and_drive_id ⇒ Array<String>
Returns the configured site ID and drive ID as an array.
-
#find_sharepoint_drive_by_id(site_id, drive_id) ⇒ Hash?
Find a SharePoint drive within a specific site.
-
#find_site_by_id(site_id) ⇒ Hash?
Find a SharePoint site by its ID.
-
#initialize ⇒ M365
constructor
Initialize the M365 interface and load configuration.
-
#ping? ⇒ Boolean
Check SharePoint endpoint connectivity and configuration validity.
Constructor Details
#initialize ⇒ M365
Initialize the M365 interface and load configuration
Loads configuration from config/storage.yml and establishes authentication and HTTP handler instances.
58 59 60 61 62 63 64 |
# File 'lib/m365_active_storage/m365.rb', line 58 def initialize @config = Configuration.new(**M365.load_configuration_from_storage_yml) @auth = Authentication.new(@config) @http = Http.new(@auth) rescue KeyError => e raise e. end |
Class Method Details
.load_configuration_from_storage_yml ⇒ Hash
Load configuration from config/storage.yml file
Reads and parses the Rails storage configuration file, evaluating any ERB templates and extracting the SharePoint-specific configuration.
149 150 151 152 153 154 155 156 157 158 159 |
# File 'lib/m365_active_storage/m365.rb', line 149 def self.load_configuration_from_storage_yml storage_yml = Rails.root.join("config", "storage.yml") raise "Missing storage.yml configuration file" unless File.exist?(storage_yml) erb_template = ERB.new(File.read(storage_yml)) yaml_content = erb_template.result(binding) configuration = YAML.safe_load(yaml_content, permitted_classes: [Regexp], aliases: true) raise "Invalid sharepoint storage.yml configuration" unless configuration&.key?("sharepoint") configuration["sharepoint"] end |
Instance Method Details
#config_site_and_drive_id ⇒ Array<String>
Returns the configured site ID and drive ID as an array
71 72 73 |
# File 'lib/m365_active_storage/m365.rb', line 71 def config_site_and_drive_id [config.site_id, config.drive_id] end |
#find_sharepoint_drive_by_id(site_id, drive_id) ⇒ Hash?
Find a SharePoint drive within a specific site
Retrieves information about a drive associated with a SharePoint site. Requires valid authentication token and valid site and drive IDs.
111 112 113 114 115 116 117 118 |
# File 'lib/m365_active_storage/m365.rb', line 111 def find_sharepoint_drive_by_id(site_id, drive_id) auth.ensure_valid_token url = "#{auth.config.ms_graph_endpoint}/sites/#{site_id}/drives/#{drive_id}" response = http.get(url) return nil unless response.code.to_i == 200 JSON.parse(response.body) end |
#find_site_by_id(site_id) ⇒ Hash?
Find a SharePoint site by its ID
Queries the Microsoft Graph API to retrieve information about a specific SharePoint site. Requires valid authentication token.
88 89 90 91 92 93 94 95 |
# File 'lib/m365_active_storage/m365.rb', line 88 def find_site_by_id(site_id) auth.ensure_valid_token url = "#{auth.config.ms_graph_endpoint}/sites/#{site_id}" response = http.get(url) return nil unless response.code.to_i == 200 JSON.parse(response.body) end |
#ping? ⇒ Boolean
Check SharePoint endpoint connectivity and configuration validity
Performs a simple health check by querying the SharePoint sites endpoint. This validates that authentication is working and the SharePoint service is accessible.
132 133 134 135 136 137 |
# File 'lib/m365_active_storage/m365.rb', line 132 def ping? auth.ensure_valid_token url = "#{auth.config.ms_graph_endpoint}/sites/root/sites" response = http.get(url) response.code.to_i == 200 end |