Class: CMIS::Connection

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

Instance Method Summary collapse

Constructor Details

#initialize(options) ⇒ Connection

Returns a new instance of Connection.



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

def initialize(options)
  options.symbolize_keys!

  service_url = options[:service_url] || ENV['CMIS_BROWSER_URL']
  @service_url = service_url or raise "\
  option `:service_url` or ENV['CMIS_BROWSER_URL'] must be set"

  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 username = options[:username] || ENV['CMIS_USER']
      password = options[:password] || ENV['CMIS_PASSWORD']
      builder.basic_auth(username, password)
    end

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

  @url_cache = {}
end

Instance Method Details

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



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

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

  query = options[:query] || {}
  headers = options[:headers]|| {}
  url = 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