class Springcm::Resource

A Resource is a SpringCM object that has an auto-assigned GUID.

Public Class Methods

resource_params() click to toggle source

Some resources have query parameters that must be passed when retrieving it, e.g. expand=attributegroups when retrieving a document.

# File lib/springcm-sdk/resource.rb, line 94
def self.resource_params
  {}
end

Public Instance Methods

delete() click to toggle source

Send a DELETE request for this resource.

# File lib/springcm-sdk/resource.rb, line 73
def delete
  conn = @client.authorized_connection(url: @client.object_api_url)
  res = conn.delete do |req|
    req.url resource_uri
  end
  if res.success?
    data = JSON.parse(res.body)
    reload
  else
    nil
  end
end
get() click to toggle source

Send a GET request for this resource.

# File lib/springcm-sdk/resource.rb, line 24
def get
  conn = @client.authorized_connection(url: @client.object_api_url)
  res = conn.get do |req|
    req.url resource_uri
    resource_params.each { |key, value|
      req.params[key] = value
    }
  end
  if res.success?
    data = JSON.parse(res.body)
    self.class.new(data, @client)
  else
    nil
  end
end
patch() click to toggle source

Send a PATCH request for this resource.

# File lib/springcm-sdk/resource.rb, line 41
def patch
  conn = @client.authorized_connection(url: @client.object_api_url)
  res = conn.patch do |req|
    req.headers['Content-Type'] = "application/json"
    req.url resource_uri
    req.body = raw.to_json
  end
  if res.success?
    data = JSON.parse(res.body)
    self.class.new(data, @client)
  else
    nil
  end
end
put() click to toggle source

Send a PUT request for this resource.

# File lib/springcm-sdk/resource.rb, line 57
def put
  conn = @client.authorized_connection(url: @client.object_api_url)
  res = conn.put do |req|
    req.headers['Content-Type'] = "application/json"
    req.url resource_uri
    req.body = raw.to_json
  end
  if res.success?
    data = JSON.parse(res.body)
    self.class.new(data, @client)
  else
    nil
  end
end
reload() click to toggle source

Resend a request to the API for this resource and return a new instance.

# File lib/springcm-sdk/resource.rb, line 12
def reload
  get
end
reload!() click to toggle source

Resend a request to the API for this resource and modify the data for the current object in-place.

# File lib/springcm-sdk/resource.rb, line 18
def reload!
  @data = reload.raw
  self
end
resource_name() click to toggle source

Pluralized resource name, e.g. documents or folders. Used to construct request URLs.

# File lib/springcm-sdk/resource.rb, line 104
def resource_name
  "#{self.class.to_s.split("::").last.downcase}s"
end
resource_params() click to toggle source
# File lib/springcm-sdk/resource.rb, line 98
def resource_params
  self.class.resource_params
end
resource_uri() click to toggle source

Retrieve the URI for this resource (relative to the base object API URL).

# File lib/springcm-sdk/resource.rb, line 88
def resource_uri
  "#{resource_name}/#{uid}"
end
uid() click to toggle source

@return [String] The object's unique identifier (UID)

# File lib/springcm-sdk/resource.rb, line 7
def uid
  href[-36..-1]
end