class SharepointApi
Constants
- VERSION
Attributes
logger[W]
host[R]
library_name[RW]
site[R]
Public Class Methods
log_as(method, exception_or_message, level: :info)
click to toggle source
# File lib/sharepoint_api.rb, line 35 def log_as(method, exception_or_message, level: :info) message = if exception_or_message.respond_to?(:message) exception_or_message.message else exception_or_message end logger.send(level, "#{name}: #{method}: #{message}") end
logger()
click to toggle source
# File lib/sharepoint_api.rb, line 27 def logger @logger ||= begin logger = Logger.new($stdout) logger.level = Logger::WARN logger end end
new(library_name: '', **config)
click to toggle source
# File lib/sharepoint_api.rb, line 52 def initialize(library_name: '', **config) @library_name = library_name @host = config.fetch(:host) @username = config.fetch(:username) @password = config.fetch(:password) @site_name = config[:site_name] || '' @ntlm = config[:ntlm] || false @verbose = config[:verbose] || false @login_name_extractor = config[:login_name_extractor] @site = build_connection end
Public Instance Methods
base_path()
click to toggle source
# File lib/sharepoint_api.rb, line 80 def base_path "#{protocol}://#{host}/#{site_path}" end
encode_path(path, safe_quote: true)
click to toggle source
# File lib/sharepoint_api.rb, line 84 def encode_path(path, safe_quote: true) path = Addressable::URI.encode(path) path.gsub!(/'/, '%27%27') if safe_quote path.gsub!('+', '%2B') path end
login_name(*args, **kwargs)
click to toggle source
# File lib/sharepoint_api.rb, line 91 def login_name(*args, **kwargs) @login_name_extractor.call(*args, **kwargs) end
server_relative_path(path)
click to toggle source
# File lib/sharepoint_api.rb, line 72 def server_relative_path(path) "/#{site_path}/#{site_relative_path(path)}" end
site_path()
click to toggle source
# File lib/sharepoint_api.rb, line 76 def site_path @site.name end
site_relative_path(path, safe_quote: true)
click to toggle source
# File lib/sharepoint_api.rb, line 65 def site_relative_path(path, safe_quote: true) file_path = [ library_name, path ].reject { |p| p.nil? || p == '' }.join('/') encode_path(file_path, safe_quote: safe_quote) end
Private Instance Methods
build_connection()
click to toggle source
# File lib/sharepoint_api.rb, line 99 def build_connection site = Sharepoint::Site.new(@host, @site_name) site.verbose = @verbose site.session = Sharepoint::HttpAuth::Session.new(site) if @ntlm site.session.authenticate(@username, @password) # custom STS? site end