Command disabled: edit
 

16h00 - Fil rouge « Client Sympa SOAP »

Navigation rapide : Lundi / Mardi / Mercredi / Jeudi / Vendredi Mémos : Perl / Python / Ruby

Enoncé

A l'aide du client Sympa SOAP fourni, ajouter le code nécessaire pour

  1. lister les listes disponibles
    • utiliser l'appel SOAP à la fonction Sympa « complex_list »
  2. lister les abonnés d'une liste
    • utiliser l'appel SOAP à la fonction Sympa « review »

Savon

main.rb

 1: #
 2: # == Synopsis
 3: #
 4: # Client Sympa SOAP
 5: #
 6: # == Usage
 7: #
 8: # ./main --cookie 0987654321
 9: #
10:
11: %w(sympa/SOAP/client getoptlong rdoc/usage).each do |lib| require lib end
12:
13: opts = GetoptLong.new(
14:         [ '--help',   '-h', GetoptLong::NO_ARGUMENT       ],
15:         [ '--cookie', '-c', GetoptLong::REQUIRED_ARGUMENT ]
16: )
17: begin
18:         opts.each do |opt,arg|
19:                 case opt
20:                 when '--help'  : RDoc::usage
21:                 when '--cookie': @cookie = arg
22:                 end
23:         end
24: rescue
25:         RDoc::usage
26:         exit 1
27: end
28:
29:
30: Sympa::SOAP::Client.new(
31:   :service_uri    => 'https://listes.example.com',
32:   :session_cookie => @cookie
33: ) do
34:     puts lists.inspect
35:     puts complex_lists.inspect
36:     puts which.inspect
37:     puts complex_which.inspect
38:     puts review('anf2012@example.com').inspect
39:   end

sympa/SOAP/client.rb

 1: %w{lists complex_lists which complex_which review}.each do |lib| require "sympa/SOAP/client/#{lib}" end
 2: %w(rubygems savon).each do |lib| require lib end
 3:
 4: Savon.configure do |config|
 5:         config.log = false
 6:         config.raise_errors = false
 7: end
 8:
 9: module Sympa; module SOAP; class Client
10:   def initialize(parameters,&block)
11:     @service_uri    = parameters[:service_uri]
12:     @session_cookie = parameters[:session_cookie]
13:     @soap_client    = Savon::Client.new do |wsdl,http|
14:         http.auth.ssl.verify_mode = :none
15:         wsdl.endpoint             = "#{@service_uri}/sympasoap"
16:         wsdl.document             = "#{@service_uri}/sympa/wsdl"
17:     end
18:     @soap_client.http.headers["Cookie"] = "sympa_session=#{@session_cookie}"
19:     instance_eval(&block)
20:   end
21:   def uri() @service_uri; end
22: end; end; end

sympa/SOAP/client/lists.rb

1: #
2: # hash_result = lists()
3: # puts hash_result.inspect
4: #
5: module Sympa; module SOAP; class Client; def lists()
6:   response = @soap_client.request 'lists', :xmlns => 'urn:sympasoap'
7:   return response.to_hash[:lists_response][:list_info][:item]
8: end; end; end; end

sympa/SOAP/client/complex_lists.rb

 1: #
 2: # hash_result = complex_lists()
 3: # puts hash_result.inspect
 4: #
 5: module Sympa; module SOAP; class Client; def complex_lists()
 6: ###############################################################
 7: #
 8: # DEBUT A COMPLETER
 9: #
10: ###############################################################
11:
12:
13: ###############################################################
14: #
15: # FIN A COMPLETER
16: #
17: ###############################################################
18: end; end; end; end

sympa/SOAP/client/which.rb

1: #
2: # hash_result = which()
3: # puts hash_result.inspect
4: #
5: module Sympa; module SOAP; class Client; def which()
6:   response = @soap_client.request 'which', :xmlns => 'urn:sympasoap'
7:   return response.to_hash[:which_response][:return][:item]
8: end; end; end; end

sympa/SOAP/client/complex_which.rb

1: #
2: # hash_result = complex_which()
3: # puts hash_result.inspect
4: #
5: module Sympa; module SOAP; class Client; def complex_which()
6:   response = @soap_client.request 'complex_which', :xmlns => 'urn:sympasoap'
7:   return response.to_hash[:complex_which_response][:return][:item]
8: end; end; end; end

sympa/SOAP/client/review.rb

 1: #
 2: # hash_result = review('some.list@example.com')
 3: # puts hash_result.inspect
 4: #
 5: module Sympa; module SOAP; class Client; def review(list_name)
 6: ###############################################################
 7: #
 8: # DEBUT A COMPLETER
 9: #
10: ###############################################################
11:
12:
13:
14:
15: ###############################################################
16: #
17: # FIN A COMPLETER
18: #
19: ###############################################################
20: end; end; end; end

Corrigé

sympa/SOAP/client/complex_lists.rb

 1: #
 2: # hash_result = complex_lists()
 3: # puts hash_result.inspect
 4: #
 5: module Sympa; module SOAP; class Client; def complex_lists()
 6: ###############################################################
 7: #
 8: # DEBUT A COMPLETER
 9: #
10: ###############################################################
11:   response = @soap_client.request 'complex_lists', :xmlns => 'urn:sympasoap'
12:   return response.to_hash[:complex_lists_response][:list_info][:item]
13: ###############################################################
14: #
15: # FIN A COMPLETER
16: #
17: ###############################################################
18: end; end; end; end

sympa/SOAP/client/review.rb

 1: #
 2: # hash_result = review('some.list@example.com')
 3: # puts hash_result.inspect
 4: #
 5: module Sympa; module SOAP; class Client; def review(list_name)
 6: ###############################################################
 7: #
 8: # DEBUT A COMPLETER
 9: #
10: ###############################################################
11:   response = @soap_client.request 'review', :xmlns => 'urn:sympasoap' do
12:     soap.body = { :name => list_name }
13:   end
14:   return response.to_hash[:review_response][:return][:item]
15: ###############################################################
16: #
17: # FIN A COMPLETER
18: #
19: ###############################################################
20: end; end; end; end

Version

$Id: jeudi_corrige_ruby_3.txt 567 2012-05-21 07:29:58Z aicardi $

jeudi_corrige_ruby_3.txt · Last modified: 2012/05/21 09:30 (external edit)
 
Except where otherwise noted, content on this wiki is licensed under the following license: CC Attribution-Share Alike 3.0 Unported
Recent changes RSS feed Donate Powered by PHP Valid XHTML 1.0 Valid CSS Driven by DokuWiki