Class: Ixtlan::SimpleClient

Inherits:
Object
  • Object
show all
Defined in:
lib/ixtlan/simple_client.rb

Overview

restful XML client using HTTP (no HTTPS support !!)

Instance Method Summary collapse

Constructor Details

#initialize(options) ⇒ SimpleClient

Returns a new instance of SimpleClient.



8
9
10
11
12
13
# File 'lib/ixtlan/simple_client.rb', line 8

def initialize(options)
  @host = options[:host]
  @port = (options[:port] || 80).to_i # defaults to 80
  @username = options[:username]
  @password = options[:password]
end

Instance Method Details

#delete(path, payload = nil) ⇒ Object

restful delete for the given path (like ‘/users/1.xml’). delete a single resource (with no payload) or many resources (if the underlying service provides bulk updates - path like ‘/users.xml’)



42
43
44
45
# File 'lib/ixtlan/simple_client.rb', line 42

def delete(path, payload = nil)
  req = Net::HTTP::Delete.new(path)
  action(req, payload)
end

#get(path, payload = nil) ⇒ Object

restful get for the given path (like ‘/users.xml’ or ‘/users/1.xml’). which retrieves the data usually there is no payload - maybe a query if the service accepts it



18
19
20
21
# File 'lib/ixtlan/simple_client.rb', line 18

def get(path, payload = nil)
  req = Net::HTTP::Get.new(path)
  action(req, payload)
end

#post(path, payload) ⇒ Object

restful post for the given path (like ‘/users.xml’). which creates a new resource or new resources (if the underlying service provides bulk creation)



26
27
28
29
# File 'lib/ixtlan/simple_client.rb', line 26

def post(path, payload)
  req = Net::HTTP::Post.new(path)
  action(req, payload)
end

#put(path, payload) ⇒ Object

restful put for the given path (like ‘/users/1.xml’). which updates a given resource or many resources (if the underlying service provides bulk updates - path like ‘/users.xml’)



34
35
36
37
# File 'lib/ixtlan/simple_client.rb', line 34

def put(path, payload)
  req = Net::HTTP::Put.new(path)
  action(req, payload)
end