Class: ActiveSP::Connection
- Inherits:
-
Object
- Object
- ActiveSP::Connection
- Includes:
- PersistentCachingConfig, Root, Util
- Defined in:
- lib/activesp/connection.rb,
lib/activesp/root.rb
Overview
This class is uses to configure the connection to a SharePoint repository. This is the starting point for doing anything with SharePoint.
Instance Attribute Summary collapse
-
#login ⇒ Object
readonly
TODO: create profile.
-
#password ⇒ Object
readonly
TODO: create profile.
-
#root_url ⇒ Object
readonly
TODO: create profile.
-
#trace ⇒ Object
readonly
TODO: create profile.
Instance Method Summary collapse
-
#fetch(url) ⇒ String
Fetches the content at the given URL using the login and password with which this connection was constructed, if any.
-
#find_by_key(key) ⇒ Base?
Finds the object with the given key.
-
#initialize(options = {}) ⇒ Connection
constructor
A new instance of Connection.
Methods included from PersistentCachingConfig
Methods included from Root
#group, #groups, #roles, #root, #user, #users
Constructor Details
#initialize(options = {}) ⇒ Connection
Returns a new instance of Connection.
52 53 54 55 56 57 58 59 60 61 |
# File 'lib/activesp/connection.rb', line 52 def initialize( = {}) = .dup @root_url = .delete(:root) or raise ArgumentError, "missing :root option" @login = .delete(:login) @password = .delete(:password) @trace = .delete(:trace) .empty? or raise ArgumentError, "unknown options #{.keys.map { |k| k.inspect }.join(", ")}" cache = nil configure_persistent_cache { |c| cache ||= c } end |
Instance Attribute Details
#login ⇒ Object (readonly)
TODO: create profile
46 47 48 |
# File 'lib/activesp/connection.rb', line 46 def login @login end |
#password ⇒ Object (readonly)
TODO: create profile
46 47 48 |
# File 'lib/activesp/connection.rb', line 46 def password @password end |
#root_url ⇒ Object (readonly)
TODO: create profile
46 47 48 |
# File 'lib/activesp/connection.rb', line 46 def root_url @root_url end |
#trace ⇒ Object (readonly)
TODO: create profile
46 47 48 |
# File 'lib/activesp/connection.rb', line 46 def trace @trace end |
Instance Method Details
#fetch(url) ⇒ String
Fetches the content at the given URL using the login and password with which this connection was constructed, if any. Always uses the GET method. Supports only HTTP as protocol at the time of writing. This is useful for fetching content files from the server.
107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 |
# File 'lib/activesp/connection.rb', line 107 def fetch(url) # TODO: support HTTPS too @open_params ||= begin u = URL(@root_url) [u.host, u.port] end Net::HTTP.start(*@open_params) do |http| request = Net::HTTP::Get.new(URL(url).full_path.gsub(/ /, "%20")) request.ntlm_auth(@login, @password) if @login response = http.request(request) # if Net::HTTPFound === response # response = fetch(response["location"]) # end # response end end |
#find_by_key(key) ⇒ Base?
Finds the object with the given key
66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 |
# File 'lib/activesp/connection.rb', line 66 def find_by_key(key) type, trail = decode_key(key) case type[0] when ?S ActiveSP::Site.new(self, trail[0] == "" ? @root_url : ::File.join(@root_url, trail[0]), trail[1].to_i) when ?L ActiveSP::List.new(find_by_key(trail[0]), trail[1]) when ?U ActiveSP::User.new(root, trail[0]) when ?G ActiveSP::Group.new(root, trail[0]) when ?R ActiveSP::Role.new(root, trail[0]) when ?A find_by_key(trail[0]).field(trail[1]) when ?P ActiveSP::PermissionSet.new(find_by_key(trail[0])) when ?F list = find_by_key(trail[0]) ActiveSP::Folder.new(list, trail[1]) when ?I list = find_by_key(trail[0]) ActiveSP::Item.new(list, trail[1]) when ?T parent = find_by_key(trail[0]) if ActiveSP::List === parent ActiveSP::ContentType.new(parent.site, parent, trail[1]) else ActiveSP::ContentType.new(parent, nil, trail[1]) end else raise "not yet #{key.inspect}" end end |