Class: YACCL::Services::Internal::BrowserBindingService

Inherits:
Object
  • Object
show all
Defined in:
lib/yaccl/services/internal/browser_binding_service.rb

Defined Under Namespace

Classes: Basement

Instance Method Summary collapse

Constructor Details

#initialize(service_url, basic_auth_username = nil, basic_auth_password = nil) ⇒ BrowserBindingService

Returns a new instance of BrowserBindingService.



12
13
14
15
16
17
18
19
# File 'lib/yaccl/services/internal/browser_binding_service.rb', line 12

def initialize(service_url, basic_auth_username=nil, basic_auth_password=nil)
  @service_url = service_url
  @basic_auth_username = basic_auth_username
  @basic_auth_password = basic_auth_password

  @repository_urls = LRUCache.new(ttl: 3600)
  @root_folder_urls = LRUCache.new(ttl: 3600)
end

Instance Method Details

#perform_request(required_params = {}, optional_params = {}) ⇒ Object



21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'lib/yaccl/services/internal/browser_binding_service.rb', line 21

def perform_request(required_params={}, optional_params={})
  url = get_url(required_params.delete(:repositoryId), required_params[:objectId])

  optional_params.reject! { |_, v| v.nil? }
  params = transform_hash(required_params.merge(optional_params))

  check(params)

  response = if params.has_key?(:cmisaction)
    if params.has_key?(:content)
      Basement.multipart_post(url, params)
    else
      Basement.post(url, body: params)
    end
  else
    Basement.get(url, query: params)
  end

  result = response.body
  if response.content_type == 'application/json'
    result = MultiJson.load(result, symbolize_keys: true)
    if result.is_a?(Hash) && result.has_key?(:exception)
      raise CMISRequestError, "#{result[:exception]} -- #{result[:message]}"
    end
  end
  result
end