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: Net::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: Net::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


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

def initialize(base_url: '', client: Net::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


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

def base_url
  @base_url
end

#clientObject (readonly)

Returns the value of attribute client


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

def client
  @client
end

#serviceObject (readonly)

Returns the value of attribute service


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

def service
  @service
end

Instance Method Details

#fetchString

Fetch data from the CONTENTdm API

Returns:

  • (String)

    either XML or JSON


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

def fetch
  request
end

#urlString

A URL for a given service

Returns:

  • (String)

    a url string


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

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