Class: EtherpadLite::Client

Inherits:
Object
  • Object
show all
Defined in:
lib/etherpad-lite/client.rb

Overview

A thin wrapper around Etherpad Lite’s HTTP JSON API. See the API documentation at etherpad.org/doc/v1.2.0/#index_api_methods.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(url_or_port, api_key_or_file, api_version = nil) ⇒ Client

Instantiate a new Etherpad Lite Client. You may pass a full url or just a port number. The api key may be a string or a File object. If you do not specify an API version, it will default to the latest version.



45
46
47
48
49
50
51
# File 'lib/etherpad-lite/client.rb', line 45

def initialize(url_or_port, api_key_or_file, api_version=nil)
  url_or_port = "http://localhost:#{url_or_port}" if url_or_port.is_a? Integer
  @uri = URI.parse(url_or_port)
  @api_key = api_key_or_file.is_a?(IO) ? api_key_or_file.read : api_key_or_file
  @api_version = api_version ? api_version.to_s : current_api_version.to_s
  @ssl_verify = OpenSSL::SSL::VERIFY_PEER
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(method, params = {}) ⇒ Object

Call an API method



59
60
61
# File 'lib/etherpad-lite/client.rb', line 59

def method_missing(method, params={})
  call(method, params)
end

Instance Attribute Details

#api_keyObject (readonly)

The API key



39
40
41
# File 'lib/etherpad-lite/client.rb', line 39

def api_key
  @api_key
end

#api_versionObject (readonly)

The API version string



41
42
43
# File 'lib/etherpad-lite/client.rb', line 41

def api_version
  @api_version
end

#uriObject (readonly)

A URI object containing the URL of the Etherpad Lite instance



37
38
39
# File 'lib/etherpad-lite/client.rb', line 37

def uri
  @uri
end

Instance Method Details

#ssl_verify(mode) ⇒ Object

Whether peer must be verified if the API URL is SSL



54
55
56
# File 'lib/etherpad-lite/client.rb', line 54

def ssl_verify(mode)
  @ssl_verify = mode
end