116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
|
# File 'lib/sharepoint-ruby.rb', line 116
def query method, uri, body = nil, skip_json=false, &block
uri = if uri =~ /^http/ then uri else api_path(uri) end
arguments = [ uri ]
arguments << body if method != :get
result = Curl::Easy.send "http_#{method}", *arguments do |curl|
curl.["Cookie"] = @session.cookie
curl.["Accept"] = "application/json;odata=verbose"
if method != :get
curl.["Content-Type"] = curl.["Accept"]
if session.instance_of?(Sharepoint::HttpAuth::Session)
curl.["X-RequestDigest"] = form_digest unless @getting_form_digest == true
else
curl.["X-RequestDigest"] = form_digest unless @getting_form_digest == true
curl.["Authorization"] = "Bearer " + form_digest unless @getting_form_digest == true
end
end
curl.verbose = @verbose
@session.send :curl, curl unless not @session.methods.include? :curl
block.call curl unless block.nil?
end
if !(skip_json || (result.body_str.nil? || result.body_str.empty?))
begin
data = JSON.parse result.body_str
raise Sharepoint::SPException.new data, uri, body unless data['error'].nil?
self.class.make_object_from_response self, data
rescue JSON::ParserError => e
raise SharepointError.new("Exception with body=#{body}, e=#{e.inspect}, #{e.backtrace.inspect}, response=#{result.body_str}")
end
elsif result.status.to_i >= 400
raise SharepointError.new("#{method.to_s.upcase} #{uri} responded with #{result.status}")
else
result.body_str
end
end
|