lib/acme/client/resources/challenges/base.rb in acme-client-0.4.1 vs lib/acme/client/resources/challenges/base.rb in acme-client-0.5.0
- old
+ new
@@ -1,28 +1,32 @@
class Acme::Client::Resources::Challenges::Base
- attr_reader :client, :status, :uri, :token, :error
+ attr_reader :authorization, :status, :uri, :token, :error
- def initialize(client, attributes)
- @client = client
- assign_attributes(attributes)
+ def initialize(authorization)
+ @authorization = authorization
end
+ def client
+ authorization.client
+ end
+
def verify_status
- response = @client.connection.get(@uri)
+ authorization.verify_status
- assign_attributes(response.body)
- @error = response.body['error']
status
end
def request_verification
- response = @client.connection.post(@uri, resource: 'challenge', type: challenge_type, keyAuthorization: authorization_key)
+ response = client.connection.post(@uri, resource: 'challenge', type: challenge_type, keyAuthorization: authorization_key)
response.success?
end
- def to_h
- { 'token' => token, 'uri' => uri, 'type' => challenge_type }
+ def assign_attributes(attributes)
+ @status = attributes.fetch('status', 'pending')
+ @uri = attributes.fetch('uri')
+ @token = attributes.fetch('token')
+ @error = attributes['error']
end
private
def challenge_type
@@ -31,15 +35,9 @@
def authorization_key
"#{token}.#{crypto.thumbprint}"
end
- def assign_attributes(attributes)
- @status = attributes.fetch('status', 'pending')
- @uri = attributes.fetch('uri')
- @token = attributes.fetch('token')
- end
-
def crypto
- @crypto ||= Acme::Client::Crypto.new(@client.private_key)
+ @crypto ||= Acme::Client::Crypto.new(client.private_key)
end
end