Class: GlobeSSL::DomainControlValidation

Inherits:
Base
  • Object
show all
Defined in:
lib/globessl/domain_control_validation.rb

Constant Summary collapse

METHODS =
["email", "http", "https"].freeze

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Base

#inspect

Class Method Details

.write_file(sha1, md5, location) ⇒ Object



114
115
116
117
118
119
# File 'lib/globessl/domain_control_validation.rb', line 114

def self.write_file(sha1, md5, location)
  File.open(File.join(location, "#{md5}.txt"), 'w') do |file|
    file.puts sha1
    file.puts "comodoca.com"
  end
end

Instance Method Details

#change!Object



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/globessl/domain_control_validation.rb', line 10

def change!
  @errors.clear
  
  return false unless valid?
  
  params = { 
    "id"         => @certificate.id,
    "dcv_method" => @dcv_method
  }
  
  if @dcv_method == "email" && @certificate.product.validation == "dv"
    email_params = {
      "approver_email" => @approver_email
    }
    params.merge!(email_params)
    
    if @certificate.product.multi_domain
      multi_domain_params = {
        "approver_emails" => @approver_emails
      }
      params.merge!(multi_domain_params)
    end
  end
        
  request = Client.post('/dcv/change', params)
  
  case response.code
  when '200'  
    return true
  when '400', '401', '403'
    set_errors(response)
    return false
  else
    return false
  end
end

#resend!Object



47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
# File 'lib/globessl/domain_control_validation.rb', line 47

def resend!
  @errors.clear
  
  unless @certificate
    @errors << "certificate is required"
    return false
  end
  
  params = { 
    "id" => @certificate.id
  }
  
  request = Client.post('/dcv/resend', params)
  
  case response.code
  when '200'  
    return true
  when '400', '401', '403'
    set_errors(response)
    return false
  else
    return false
  end
end

#set_errors(response) ⇒ Object



72
73
74
75
76
# File 'lib/globessl/domain_control_validation.rb', line 72

def set_errors(response)
  json = response.body
  hash = JSON.parse(json)
  @errors << hash["message"]
end

#valid?Boolean

Returns:

  • (Boolean)


78
79
80
# File 'lib/globessl/domain_control_validation.rb', line 78

def valid?
  validate
end

#validateObject



82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
# File 'lib/globessl/domain_control_validation.rb', line 82

def validate
  unless @certificate
    @errors << "certificate is required"
  end
  
  unless @dcv_method
    @errors << "dcv_method is required"
  else
    unless METHODS.include?(@dcv_method)
      @errors << "dcv_method must be one of 'email', 'http' or 'https'"
    end
  end
  
  if @dcv_method == "email"
    unless @approver_email
      @errors << "approver_email is required"
    end
    
    if @certificate.product.multi_domain
      unless @approver_emails
        @errors << "approver_emails are required"
      end
    end
  end
  
  if @errors.any?
    return false
  else
    return true
  end
end