Class: Sphragis::Providers::ItsmeProvider

Inherits:
BaseProvider show all
Defined in:
lib/sphragis/providers/itsme_provider.rb

Overview

Itsme.free Provider Free e-signature service (hypothetical - adjust based on actual service)

Note: This is a template implementation. Adjust based on actual Itsme.free API

Constant Summary collapse

ITSME_API_BASE =
"https://api.itsme.free/v1"

Instance Attribute Summary

Attributes inherited from BaseProvider

#config

Instance Method Summary collapse

Methods inherited from BaseProvider

#connected?, #provider_name

Constructor Details

#initialize(config = {}) ⇒ ItsmeProvider

Initialize Itsme.free provider

Parameters:

  • config (Hash) (defaults to: {})

    Configuration options

    • client_id: Itsme client ID

    • client_secret: Itsme client secret

    • user_email: User email for identification

    • environment: ‘production’ or ‘sandbox’ (default: ‘production’)



23
24
25
26
27
28
29
30
31
32
# File 'lib/sphragis/providers/itsme_provider.rb', line 23

def initialize(config = {})
  super
  @config = {
    client_id: config[:client_id],
    client_secret: config[:client_secret],
    user_email: config[:user_email],
    environment: config[:environment] || "production"
  }
  @api_base = @config[:environment] == "sandbox" ? "#{ITSME_API_BASE}/sandbox" : ITSME_API_BASE
end

Instance Method Details

#certificateObject

Raises:



76
77
78
79
80
81
# File 'lib/sphragis/providers/itsme_provider.rb', line 76

def certificate
  raise ProviderError, "Not connected to Itsme" unless connected?

  # In a real implementation, fetch user's certificate from Itsme
  simulate_itsme_certificate
end

#check_signing_status(session_id) ⇒ Hash

Check signing status

Parameters:

  • session_id (String)

    Signing session ID

Returns:

  • (Hash)

    Status information



105
106
107
108
109
110
111
112
# File 'lib/sphragis/providers/itsme_provider.rb', line 105

def check_signing_status(session_id)
  # Real implementation: GET #{@api_base}/sign/#{session_id}/status
  {
    session_id: session_id,
    status: "completed", # or 'pending', 'expired', 'rejected'
    signature: simulate_itsme_signing("data")
  }
end

#connectObject



34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
# File 'lib/sphragis/providers/itsme_provider.rb', line 34

def connect
  validate_configuration!

  # Authenticate with Itsme API
  # In a real implementation, this would use OAuth2 flow
  response = authenticate_with_itsme

  @session = {
    connected: true,
    provider: "itsme",
    access_token: response[:access_token],
    refresh_token: response[:refresh_token],
    token_expires_at: Time.now + response[:expires_in],
    user_email: @config[:user_email]
  }
  true
rescue StandardError => e
  raise ProviderError, "Failed to connect to Itsme: #{e.message}"
end

#disconnectObject



54
55
56
57
58
59
# File 'lib/sphragis/providers/itsme_provider.rb', line 54

def disconnect
  # Revoke OAuth token
  # In real implementation: POST #{@api_base}/oauth/revoke
  @session = nil
  true
end

#initiate_signing(data) ⇒ Hash

Initiate signing with user interaction

Parameters:

  • data (String)

    Data to sign

Returns:

  • (Hash)

    Signing session information



92
93
94
95
96
97
98
99
100
# File 'lib/sphragis/providers/itsme_provider.rb', line 92

def initiate_signing(data)
  # Real implementation might return a URL for user to confirm on mobile
  {
    session_id: SecureRandom.uuid,
    confirmation_url: "#{@api_base}/sign/#{SecureRandom.uuid}",
    expires_at: Time.now + 300, # 5 minutes to confirm
    status: "pending"
  }
end

#sign(data) ⇒ Object



61
62
63
64
65
66
67
68
69
70
71
72
73
74
# File 'lib/sphragis/providers/itsme_provider.rb', line 61

def sign(data)
  raise ProviderError, "Not connected to Itsme" unless connected?

  refresh_token_if_needed

  # In a real implementation, this would:
  # 1. Send data to Itsme signing endpoint
  # 2. May require user interaction (mobile app confirmation)
  # 3. Return the signature with timestamp

  simulate_itsme_signing(data)
rescue StandardError => e
  raise ProviderError, "Failed to sign with Itsme: #{e.message}"
end

#validate_configuration!Object

Raises:



83
84
85
86
87
# File 'lib/sphragis/providers/itsme_provider.rb', line 83

def validate_configuration!
  raise ProviderError, "Itsme client ID not configured" if @config[:client_id].nil?
  raise ProviderError, "Itsme client secret not configured" if @config[:client_secret].nil?
  raise ProviderError, "User email not configured" if @config[:user_email].nil?
end