En gros ce que tu cherches a faire c'est de te connecter sur leur page et 
utiliser leur WebServices?

En ruby: (voir doc do httparty pour determiner ou non si tu veux qqch dans la 
hash query)

require 'rubygems'
require 'httparty'

class LoginSomeWhere
  include HTTParty
  base_uri "https://YOURURL.COM";
  headers "content-type" => "application/x-www-form-urlencoded"

  def self.login username, password
    post "/", :query => {  }, :body => { :username => username, :password => 
password }
  end
end

puts LoginSomeWhere.login "username", "password"

Ca

On Nov 21, 2011, at 10:06 AM, Frédérick Sauvage wrote:

> Bonjour,
> 
> Cherchant à créer un sceau d'horodatage via Universign, je me retrouve
> face à 3 codes pour réaliser cela ... évidemment nulle trace de Ruby.
> Je cherche actuellement comment m'adapter au Ruby (en partant du Java
> que je maitrise mieux), mais je rencontre des difficultés.
> 
> Une bonne âme pourrait-elle m'aider ?
> 
> Voici les différents codes :
> 
> En Python :
> 
>      #!/usr/bin/python
> 
>      import urllib;
>      import urllib2;
>      import hashlib;
>      import base64;
> 
>      # first we construct the parameters for the request
>      data = {};
>      data['hashAlgo'] = "SHA256";
>      data['withCert'] = "true";
>      data['hashValue'] = hashlib.sha256(dataToTimestamp).hexdigest();
>      params = urllib.urlencode(data);
> 
>      # basic HTTP authentication is needed to access this service
>      headers = {};
>      auth = base64.encodestring(username + ":" + password);
>      headers["Authorization"] = "Basic " + auth;
> 
>      # then the request itself
>      request = urllib2.Request("https://ws.universign.eu/tsa/post/";,
> params, headers);
> 
>      # all is ready, the request is made
>      response = urllib2.urlopen(request);
>      tsp = response.read();
> 
> 
> 
> En PHP :
> 
>      $hashedDataToTimestamp = hash('sha256', $dataToTimestamp);
>      $dataToSend = array ('hashAlgo' => 'SHA256', 'withCert' =>
> 'true', 'hashValue' => $hashedDataToTimestamp);
>      $dataQuery = http_build_query($dataToSend);
>      $context_options = array (
>              'http' => array (
>                  'method' => 'POST',
>                  'header'=> "Content-type: application/x-www-form-
> urlencoded\r\n"
>                   ."Content-Length: " . strlen($dataQuery) . "\r\n"
>                   ."Authorization: Basic ".base64_encode($login.':'.
> $password)."\r\n",
>                  'content' => $dataQuery
>                )
>            );
> 
>      $context = stream_context_create($context_options);
>      $fp = fopen("https://ws.universign.eu/tsa/post/";, 'r', false,
> $context);
>      $tsp = stream_get_contents($fp);
> 
> 
> 
> En Java :
> 
>      static InputStream doTsp(String login, String pwd, String hash,
> String algo)
>        throws Exception
>      {
>        URLConnection conn = new URL("https://ws.universign.eu/tsa/
> post/").openConnection();
>        conn.setDoOutput(true);
>        conn.setDoInput(true);
>        String authString = login + ":" + pwd;
>        String authStringEnc = Base64.encode(authString);
>        conn.setRequestProperty("Authorization", "Basic " +
> authStringEnc);
> 
>        OutputStream out = conn.getOutputStream();
>        String params = "hashAlgo=" + URLEncoder.encode(algo, "UTF-8")
> + "&hashValue="
>            + URLEncoder.encode(hash, "UTF-8") + "&withCert=" +
> URLEncoder.encode("false", "UTF-8");
>        out.write(params.getBytes("UTF-8"));
>        out.flush();
> 
>        return conn.getInputStream();
>      }
> 
> 
> Merci d'avance,
>    Frédéric
> 
> -- 
> Vous avez reçu ce message, car vous êtes abonné au groupe "Railsfrance" de 
> Google Groups.
> Pour transmettre des messages à ce groupe, envoyez un e-mail à l'adresse 
> [email protected]
> Pour résilier votre abonnement envoyez un e-mail à l'adresse 
> [email protected]

-- 
Vous avez reçu ce message, car vous êtes abonné au groupe "Railsfrance" de 
Google Groups.
Pour transmettre des messages à ce groupe, envoyez un e-mail à l'adresse 
[email protected]
Pour résilier votre abonnement envoyez un e-mail à l'adresse 
[email protected]

Répondre à