Class: HordeRPC

Inherits:
Object
  • Object
show all
Defined in:
lib/horde_rpc.rb,
lib/horde_rpc/version.rb

Constant Summary collapse

VERSION =
"0.2.0"

Instance Method Summary collapse

Constructor Details

#initialize(uri, username = nil, password = nil) ⇒ HordeRPC

Create a new instance of the Horde connection

Parameters:

  • uri (String)

    XML-RPC URI for the horde instance

  • username (String, Optional) (defaults to: nil)
  • password (String, Optional) (defaults to: nil)


12
13
14
15
16
# File 'lib/horde_rpc.rb', line 12

def initialize(uri, username = nil, password = nil)
  @xmlrpc_client = XMLRPC::Client.new2 uri
  @xmlrpc_client.user     = username
  @xmlrpc_client.password = password
end

Instance Method Details

#first_client_for_company(name) ⇒ Hash?

Find the first client record for a particular company name

Parameters:

  • name (String)

    the name of the Company

Returns:

  • (Hash, nil)

    data for the client associated with the requested company



84
85
86
87
# File 'lib/horde_rpc.rb', line 84

def first_client_for_company(name)
  results = search_clients :company => name
  results[name].first
end

#get_client_by_id(id) ⇒ Hash?

Return data for a client by its ID

Parameters:

  • id (String)

    the clients ID

Returns:

  • (Hash, nil)

    client data



37
38
39
# File 'lib/horde_rpc.rb', line 37

def get_client_by_id(id)
  request 'clients.getClient', id
end

#record_time(options) ⇒ Object

Record time against a project

Parameters:

  • options (Hash)

    a customizable set of options

Options Hash (options):

  • :date (Date)

    the date of the billable activity

  • :client (String)

    the ID of the client to bill

  • :type (Integer)

    the type of billable activity

  • :hours (Float)

    the number of hours to bill

  • :description (String)

    a description of the billable activity

  • :employee (String)

    the username of the employee performing the billable activity

Raises:

  • (ArgumentError)


100
101
102
103
# File 'lib/horde_rpc.rb', line 100

def record_time(options)
  raise ArgumentError unless options.values_at(:date, :client, :type, :hours, :description, :employee).all?
  request 'time.recordTime', options
end

#request(method, *options) ⇒ Object

Make an RPC request against the Horde instance

Parameters:

  • method (String)

    the method name to execute

  • options (Object, Optional)

Returns:

  • (Object)

    response to the RPC



26
27
28
# File 'lib/horde_rpc.rb', line 26

def request(method, *options)
  @xmlrpc_client.call method, *options
end

#search_clients(search_params = {}) ⇒ Hash

Search clients by KV-pairs

Examples:

Search for clients by first name


horde.search_clients :firstname => 'Bob'
# => {'Acme' => [
       {
        "__key"       => "[email protected]",
        "__uid"       => "[email protected]",
        "firstname"   => "Joe",
        "lastname"    => "Bloggs",
        "name"        => "Joe Bloggs",
        "email"       => "[email protected]",
        "homePhone"   => "404 475 4840",
        "workPhone"   => "404 475 4840",
        "cellPhone"   => "404 475 4840",
        "homeAddress" => "Foo Lane, NY",
        "company"     => "Acme",
        "id"          => "[email protected]",
        "__type"      => "Object",
        "source"      => "bar_clients"
       }]
     }

Parameters:

  • search_params (Hash<#to_s, String>) (defaults to: {})

Returns:

  • (Hash)

    map of search terms to results



70
71
72
73
74
75
# File 'lib/horde_rpc.rb', line 70

def search_clients(search_params = {})
  # searchClients takes two arrays as params:
  # * list of search strings
  # * list of search fields
  request 'clients.searchClients', search_params.values, search_params.keys.map(&:to_s)
end