Class: Cotendo
- Inherits:
-
Object
- Object
- Cotendo
- 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
- #api_namespaced(method) ⇒ Object
- #client ⇒ Object
- #flush(cname, expressions, options = {}) ⇒ Object
-
#initialize(options) ⇒ Cotendo
constructor
A new instance of Cotendo.
- #request(method, options) ⇒ Object
Constructor Details
#initialize(options) ⇒ Cotendo
Returns a new instance of Cotendo.
8 9 10 11 |
# File 'lib/cotendo.rb', line 8 def initialize() @user = [:user] or raise("missing :user") @password = [:password] or raise("missing :password") end |
Instance Method Details
#api_namespaced(method) ⇒ Object
40 41 42 |
# File 'lib/cotendo.rb', line 40 def api_namespaced(method) "api:#{method.to_s.gsub(/_./){|x| x.slice(1,1).upcase }}" end |
#client ⇒ Object
22 23 24 25 26 27 28 29 30 |
# File 'lib/cotendo.rb', line 22 def client @client ||= begin Savon::Client.new do |wsdl, http, wsse| wsdl.document = WSDL wsdl.endpoint = WSDL + '&ver=1.0' http.auth.basic @user, @password end 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, = {}) expressions = [*expressions] request(:do_flush, 'api:cname' => cname, 'api:flushExpression' => expressions.join("\n"), 'api:flushType' => [:flush_type] || 'hard' ) end |
#request(method, options) ⇒ Object
32 33 34 35 36 37 38 |
# File 'lib/cotendo.rb', line 32 def request(method, ) response = client.request(api_namespaced(method)) do |soap| soap.namespaces['xmlns:api'] = NAMESPACE soap.body = end response.to_hash end |