Class: TeamdriveApi::Base

Inherits:
Object
  • Object
show all
Includes:
HTTParty
Defined in:
lib/teamdrive_api/base.rb

Overview

API-Baseclass for all XML RPC APIs

Direct Known Subclasses

Host, Register

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(uri, api_checksum_salt, api_version) ⇒ Base

Create a new TD API Client.

Parameters:

  • uri (String)

    URI to the API. See README.

  • api_checksum_salt (String)

    the APIChecksumSalt system setting (“Edit Settings -> RegServer”).

  • api_version (String)

    optionally overwrite the api_version



18
19
20
21
22
# File 'lib/teamdrive_api/base.rb', line 18

def initialize(uri, api_checksum_salt, api_version)
  @api_checksum_salt = api_checksum_salt
  @api_version       = api_version
  @uri = uri.start_with?('http') ? uri : 'https://' + uri
end

Instance Attribute Details

#uriObject (readonly)

Returns the value of attribute uri.



9
10
11
# File 'lib/teamdrive_api/base.rb', line 9

def uri
  @uri
end

Instance Method Details

#payload_for(command, query = {}) ⇒ Object

Generates the XML payload for the RPC



25
26
27
28
29
30
31
32
33
34
# File 'lib/teamdrive_api/base.rb', line 25

def payload_for(command, query = {})
  out = header_for(command)
  query.each do |k, v|
    next if v.nil?
    v = v.to_s
    v = '$' + v if %w(true false).include?(v)
    out << "<#{k}>#{v}</#{k}>"
  end
  out << '</teamdrive>'
end