Class: CONTENTdmAPI::Request

Inherits:
Object
  • Object
show all
Defined in:
lib/contentdm_api/request.rb

Overview

Form requests to the ContentDM API

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(base_url: '', client: HTTP, service: Service.new) ⇒ Void

Parameters:

  • base_url (String) (defaults to: '')

    URL to the CONTENTdm API “CdmServer.com:port/dmwebservices/index.php

  • client (Object) (defaults to: HTTP)

    An HTTP client to make requests of the API

  • service (Object) (defaults to: Service.new)

    A class to tell the Request class which function, params and format to request of the CONTENTdm API



14
15
16
17
18
# File 'lib/contentdm_api/request.rb', line 14

def initialize(base_url: '', client: HTTP, service: Service.new)
  @base_url = base_url
  @client   = client
  @service  = service
end

Instance Attribute Details

#base_urlObject (readonly)

Returns the value of attribute base_url.



6
7
8
# File 'lib/contentdm_api/request.rb', line 6

def base_url
  @base_url
end

#clientObject (readonly)

Returns the value of attribute client.



6
7
8
# File 'lib/contentdm_api/request.rb', line 6

def client
  @client
end

#serviceObject (readonly)

Returns the value of attribute service.



6
7
8
# File 'lib/contentdm_api/request.rb', line 6

def service
  @service
end

Instance Method Details

#fetchString

Fetch data from the CONTENTdm API

Returns:

  • (String)

    either XML or JSON



23
24
25
# File 'lib/contentdm_api/request.rb', line 23

def fetch
  client.get(unencoded_url).to_s
end

#unencoded_urlString

A URL for a given service

Returns:

  • (String)

    a url string



30
31
32
# File 'lib/contentdm_api/request.rb', line 30

def unencoded_url
  "#{base_url}?q=#{service.url_params}"
end