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
-
#auth_type ⇒ Object
readonly
TODO: create profile.
-
#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.
- #head(url) ⇒ Object
-
#initialize(options = {}) ⇒ Connection
constructor
A new instance of Connection.
Methods included from PersistentCachingConfig
Methods included from Root
#group, #groups, #roles, #root, #user, #users
Methods included from Caching
Constructor Details
#initialize(options = {}) ⇒ Connection
Returns a new instance of Connection.
53 54 55 56 57 58 59 60 61 62 63 |
# File 'lib/activesp/connection.rb', line 53 def initialize( = {}) = .dup @root_url = .delete(:root) or raise ArgumentError, "missing :root option" @login = .delete(:login) @password = .delete(:password) @auth_type = .delete(:auth_type) || :ntlm @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
#auth_type ⇒ Object (readonly)
TODO: create profile
46 47 48 |
# File 'lib/activesp/connection.rb', line 46 def auth_type @auth_type end |
#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.
109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 |
# File 'lib/activesp/connection.rb', line 109 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")) if @login case auth_type when :ntlm request.ntlm_auth(@login, @password) when :basic request.basic_auth(@login, @password) else raise ArgumentError, "Unknown authentication type #{auth_type.inspect}" end end 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
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 100 101 |
# File 'lib/activesp/connection.rb', line 68 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 |
#head(url) ⇒ Object
135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 |
# File 'lib/activesp/connection.rb', line 135 def head(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::Head.new(URL(url).full_path.gsub(/ /, "%20")) if @login case auth_type when :ntlm request.ntlm_auth(@login, @password) when :basic request.basic_auth(@login, @password) else raise ArgumentError, "Unknown authentication type #{auth_type.inspect}" end end response = http.request(request) # if Net::HTTPFound === response # response = fetch(response["location"]) # end # response end end |