Class: YACCL::Services::Internal::BrowserBindingService
- Inherits:
-
Object
- Object
- YACCL::Services::Internal::BrowserBindingService
- Defined in:
- lib/yaccl/services/internal/browser_binding_service.rb
Defined Under Namespace
Classes: Basement
Constant Summary collapse
- @@url_cache =
SimpleCache::MemoryCache.new
Instance Method Summary collapse
-
#initialize(service_url, basic_auth_username = nil, basic_auth_password = nil, succinct_properties = true) ⇒ BrowserBindingService
constructor
A new instance of BrowserBindingService.
- #perform_request(required_params = {}, optional_params = {}) ⇒ Object
Constructor Details
#initialize(service_url, basic_auth_username = nil, basic_auth_password = nil, succinct_properties = true) ⇒ BrowserBindingService
Returns a new instance of BrowserBindingService.
17 18 19 20 21 |
# File 'lib/yaccl/services/internal/browser_binding_service.rb', line 17 def initialize(service_url, basic_auth_username=nil, basic_auth_password=nil, succinct_properties=true) @service_url = service_url @basement = Basement.new(basic_auth_username, basic_auth_password) @succinct_properties = succinct_properties end |
Instance Method Details
#perform_request(required_params = {}, optional_params = {}) ⇒ Object
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 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 |
# File 'lib/yaccl/services/internal/browser_binding_service.rb', line 23 def perform_request(required_params={}, optional_params={}) headers = required_params[:properties].delete(:headers) if required_params[:properties] headers ||= {} url = get_url(required_params.delete(:repositoryId), required_params[:objectId]) required_params[:succinct] ||= @succinct_properties 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, headers) else @basement.post(url: url, body: params, headers: headers) end else @basement.get(url: url, query: params, headers: headers) end result = response.body content_type = if response.respond_to?(:content_type) response.content_type else response.headers['Content-Type'] end result = MultiJson.load(result, symbolize_keys: true) if content_type =~ /application\/json/ unless (200...300).include?(response.code.to_i) if result.is_a?(Hash) && result.has_key?(:exception) if response.code.to_i == 404 && result[:exception] == "objectNotFound" raise ObjectNotFoundError else raise CMISRequestError, "#{response.code} -- #{result[:exception]} -- #{result[:message]}" end else raise CMISRequestError, "#{response.code} -- #{result}" end end result end |