Class: Cotendo

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

Constant Summary collapse

VERSION =
File.read( File.join(File.dirname(__FILE__),'..','VERSION') ).strip
WSDL =
"https://api.cotendo.net/cws?wsdl"
NAMESPACE =
'http://api.cotendo.net/'

Instance Method Summary collapse

Constructor Details

#initialize(options) ⇒ Cotendo

Returns a new instance of Cotendo.



8
9
10
11
# File 'lib/cotendo.rb', line 8

def initialize(options)
  @user = options[:user] or raise("missing :user")
  @password = options[:password] or raise("missing :password")
end

Instance Method Details

#api_namespaced(method) ⇒ Object



41
42
43
# File 'lib/cotendo.rb', line 41

def api_namespaced(method)
  "api:#{method.to_s.gsub(/_./){|x| x.slice(1,1).upcase }}"
end

#clientObject



22
23
24
25
26
27
28
29
30
31
# File 'lib/cotendo.rb', line 22

def client
  @client ||= begin
    client = Savon::Client.new do
      wsdl.document = WSDL
      wsdl.endpoint = WSDL + '&ver=1.0'
    end
    client.wsdl.request.auth.basic @user, @password
    client
  end
end

#flush(cname, expressions, options = {}) ⇒ Object



13
14
15
16
17
18
19
20
# File 'lib/cotendo.rb', line 13

def flush(cname, expressions, options = {})
  expressions = [*expressions]
  request(:do_flush,
    'api:cname' => cname,
    'api:flushExpression' => expressions.join("\n"),
    'api:flushType' => options[:flush_type] || 'hard'
  )
end

#request(method, options) ⇒ Object



33
34
35
36
37
38
39
# File 'lib/cotendo.rb', line 33

def request(method, options)
  response = client.request(api_namespaced(method)) do |soap|
    soap.namespaces['xmlns:api'] = NAMESPACE
    soap.body = options
  end
  response.to_hash
end