Class: CMIS::Connection

Inherits:
Object
  • Object
show all
Defined in:
lib/cmis/connection.rb,
lib/cmis/connection/response_parser.rb,
lib/cmis/connection/request_modifier.rb

Defined Under Namespace

Classes: RequestModifier, ResponseParser

Instance Method Summary collapse

Constructor Details

#initialize(options) ⇒ Connection

Returns a new instance of Connection


9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/cmis/connection.rb', line 9

def initialize(options)
  message = "option `service_url` must be set"
  @service_url = options[:service_url] or raise message

  @http = Faraday.new(connection_options(options)) do |builder|
    builder.options.params_encoder = Faraday::FlatParamsEncoder
    builder.use RequestModifier
    builder.request :multipart
    builder.request :url_encoded

    if options[:username]
      builder.basic_auth(options[:username], options[:password])
    end

    builder.response :follow_redirects, standards_compliant: true
    builder.response :logger if options[:log_requests]
    builder.use ResponseParser

    # The adapter must be the last one
    builder.adapter (options[:adapter] || :net_http).to_sym
  end

  @repository_infos = {}
end

Instance Method Details

#do_request(params, query, headers) ⇒ Object


34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/cmis/connection.rb', line 34

def do_request(params, query, headers)
  repository_id = params.delete(:repositoryId)
  url = infer_url(repository_id, params[:objectId])

  if params[:cmisaction]
    @http.post(url, params, headers) { |req| req.params = query }
  else
    @http.get(url, params.merge(query), headers)
  end

rescue Exception
  raise_enriched_exception(repository_id, params)
end