Mardi - Programmation Orientée Objet, Programmation Evènementielle et interactions avec un SGBD

Navigation rapide : Lundi / Mardi / Mercredi / Jeudi / Vendredi Mémos : Perl / Python / Ruby
rakefile.rb
require 'rubygems'
require 'rubygems/package_task'
require 'rdoc/task'
 
require 'sympa-soap-client_gemspec'
 
RDoc::Task.new{|rdoc|
	rdoc.title = 'Sympa::SOAP Documentation'
	rdoc.main  = 'README.rdoc'
	rdoc.rdoc_files.include('README.rdoc','lib/**/*.rb')
}
 
Gem::PackageTask.new(@gemspec){|gem| 
	gem.need_zip = true
	gem.need_tar = true
}
VERSION
1.0.0
sympa-soap-client_gemspec.rb
require	'rubygems'
 
@gemspec = Gem::Specification.new{|s|
	s.name			=	"sympa-soap-client"
	s.version		=	File.open('VERSION'){|f| f.read}
	s.date			=	File.mtime('VERSION')
	s.author		=	'DELAVENNAT, David'
	s.homepage		=	'http://projects.mathrice.org/sympa-soap-client'
	s.email			=	'sympa-soap-client@projetcs.mathrice.org'
	s.platform		=	Gem::Platform::RUBY
	s.summary		=	'An implementation of Sympa SOAP Client for Ruby.'
	s.required_ruby_version	=	'>=1.8.7'
	s.require_path		=	'lib'
	s.has_rdoc		=	true
	s.extra_rdoc_files	=	['README.rdoc']
	s.rdoc_options		= '-SNUF'
	s.files			=	Dir['lib/**/*.rb']
	s.files.reject! { |fn| fn.include? 'CVS' }
}
README.rdoc
= Overview
 
Sympa::SOAP::Client is a pure-Ruby client for programmatically interacting with a Sympa mailing-list server via the SOAP protocol.
 
== For details on the SOAP Protocol, refer to the {Wikipedia SOAP Protocol description}[http://en.wikipedia.org/wiki/SOAP]
 
== For details on the Sympa/SOAP Web-Service, refer to the {Sympa SOAP manual}[http://www.sympa.org/manual/soap]
 
= Requirements
 
- {patron}[http://patron/] for the HTTP handling
- {savon}[http://savonrb.com/] for the SOAP processing
- {yaml}[http://toto/truc.txt] for the YAML parsing
- {nokogiri}[http://nokogiri.org] for the XML parsing
 
= Installation
 
    $ sudo gem install sympa-soap-client
 
= Examples
 
== Simple cases
 
=== Listing lists
 
    require 'rugygems'
    require 'sympa/auth/cas'
    require 'sympa/soap/client'
    require 'pp'
 
    Sympa::SOAP::Client.new(
       :service_uri           => 'https://lists.domain.tld',
       :authentication_helper => Sympa::Auth::Cas.new(
          :credential_file    => File.expand_path('~/.auth_file')
       )
    ) do
      pp lists
    end
 
=== Creating a list
 
    require 'rugygems'
    require 'sympa/auth/cas'
    require 'sympa/soap/client'
 
    Sympa::SOAP::Client.new(
       :service_uri           => 'https://lists.domain.tld',
       :authentication_helper => Sympa::Auth::Cas.new(
          :credential_file    => File.expand_path('~/.auth_file')
       )
    ) do
      pp create_list :list_name   => 'some.list@domain.tld',
                     :subject     => 'shiny.user@domain.tld',
                     :template    => '',
                     :description => 'SHINY User',
                     :topics      => true
    end
 
=== Adding some user to a list
 
    require 'rugygems'
    require 'sympa/auth/cas'
    require 'sympa/soap/client'
 
    Sympa::SOAP::Client.new(
       :service_uri           => 'https://lists.domain.tld',
       :authentication_helper => Sympa::Auth::Cas.new(
          :credential_file    => File.expand_path('~/.auth_file')
       )
    ) do
      pp add :list_name  => 'some.list@domain.tld',
             :user_email => 'shiny.user@domain.tld',
             :gecos      => 'SHINY User',
             :quiet      => true
    end
 
=== Removing some user from a list
 
    require 'rugygems'
    require 'sympa/auth/cas'
    require 'sympa/soap/client'
 
    Sympa::SOAP::Client.new(
       :service_uri           => 'https://lists.domain.tld',
       :authentication_helper => Sympa::Auth::Cas.new(
          :credential_file    => File.expand_path('~/.auth_file')
       )
    ) do
      pp del :list_name  => 'some.list@domain.tld',
             :user_email => 'shiny.user@domain.tld',
             :quiet      => true
    end
 
=== Closing a list
 
    require 'rugygems'
    require 'sympa/auth/cas'
    require 'sympa/soap/client'
 
    Sympa::SOAP::Client.new(
       :service_uri           => 'https://lists.domain.tld',
       :authentication_helper => Sympa::Auth::Cas.new(
          :credential_file    => File.expand_path('~/.auth_file')
       )
    ) do
      pp close_list :list_name  => 'some.list@domain.tld'
    end
 
 
== Complex cases
 
=== Populating some list with users picked-up form a csv-file.
 
    require 'rugygems'
    require 'sympa/auth/cas'
    require 'sympa/soap/client'
 
    Sympa::SOAP::Client.new(
       :service_uri           => 'https://lists.domain.tld',
       :authentication_helper => Sympa::Auth::Cas.new(
          :credential_file    => File.expand_path('~/.auth_file')
       )
    ) do
      list_name = 'some.list@domain.tld'
      File.open('users.csv').each_line do |user|
        user_email,gecos = user.split(';')
        if add :list_name  => list_name,
               :user_email => user_email,
               :gecos      => gecos,
               :quiet      => true
        then
          puts "User '#{gecos}' added successfully to the list '#{list_name}'"
        else
          puts "An error occured adding user '#{gecos}' to the list '#{list_name}'"
        end
      end
    end
 
=== Updating mailing-lists according to users properties
 
    require 'rugygems'
    require 'sympa/auth/cas'
    require 'sympa/soap/client'
    require 'sequel'
 
    # create an in-memory sqlite database
    db = Sequel.sqlite
    db.create_table :lists do
      primary_key :id
      String :name
    end
    db.create_table :subscribers do
      primary_key :id
      Integer :list_id
      String  :email
    end
    mailing_lists     = db[:lists]
    lists_subscribers = db[:subscribers]
 
    # connect to the sympa SOAP service
    Sympa::SOAP::Client.new(
       :service_uri           => 'https://lists.domain.tld',
       :authentication_helper => Sympa::Auth::Cas.new(
          :credential_file    => File.expand_path('~/.auth_file')
       )
    ) do
      complex_lists.each do |complex_list|
        review(:list_name => complex_list[:toto]).each do |subscriber|
 
 
        end
 
        File.open('users.csv').each_line do |user|
          user_email,gecos,status,building,stage, = user.split(';')
          if add :list_name  => list_name,
                 :user_email => user_email,
                 :gecos      => gecos,
                 :quiet      => true
          then
            puts "User '#{gecos}' added successfully to the list '#{list_name}'"
          else
            puts "An error occured while adding user '#{gecos}' to the list '#{list_name}'"
          end
        end
      end
    end
 
 
 
 
 
= Credits
 
Author:: {David Delavennat}[mailto:sympa-soap-client.project@u-psud.fr]
 
= Licence (BSD)
 
 Copyright (c) 2011 David Delavennat
 
 Permission to use, copy, modify, and distribute this software for any
 purpose with or without fee is hereby granted, provided that the above
 copyright notice and this permission notice appear in all copies.
 
 THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
 WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
 MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
 ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
 WHATSOEVER RESULTING FROM LOSS OF MIND, USE, DATA OR PROFITS, WHETHER
 IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING
 OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
--
 $Id$
++
bin/sympa-soap-client.rb
 
lib/sympa/soap/client.rb
 
mardi_corrige_ruby_2.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