Class: CMIS::Connection

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

Direct Known Subclasses

Server

Defined Under Namespace

Classes: RequestModifier, ResponseParser, URLResolver

Instance Method Summary collapse

Constructor Details

#initialize(options) ⇒ Connection

Returns a new instance of Connection.



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/cmis/connection.rb', line 11

def initialize(options)
  options.symbolize_keys!

  message = "option `service_url` must be set"
  service_url = options[:service_url] or raise message

  adapter = (options[:adapter] || :net_http).to_sym

  headers = {
    user_agent: "cmis-ruby/#{VERSION} [#{adapter}]"
  }.merge(options[:headers] || {})
  conn_opts = { headers: headers, ssl: options[:ssl] }.compact

  @http = Faraday.new(conn_opts) do |builder|
    builder.use RequestModifier
    builder.request :multipart
    builder.request :url_encoded

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

    builder.adapter adapter
    builder.response :logger if options[:log_requests]
    builder.use ResponseParser
  end

  @url_resolver = URLResolver.new(@http, service_url)
end

Instance Method Details

#execute!(params = {}, options = {}) ⇒ Object



41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
# File 'lib/cmis/connection.rb', line 41

def execute!(params = {}, options = {})
  params.symbolize_keys!
  options.symbolize_keys!

  query = options[:query] || {}
  headers = options[:headers] || {}
  url = @url_resolver.url(params.delete(:repositoryId), params[:objectId])

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

  response.body
end