registration.rb 897 Bytes
Newer Older
1
2
3
4
5
6
7
8
9
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
class Acme::Client::Resources::Registration
  attr_reader :id, :key, :contact, :uri, :next_uri, :recover_uri, :term_of_service_uri

  def initialize(client, response)
    @client = client
    @uri = response.headers['location']
    assign_links(response.headers['Link'])
    assign_attributes(response.body)
  end

  def get_terms
    return unless @term_of_service_uri

    @client.connection.get(@term_of_service_uri).body
  end

  def agree_terms
    return true unless @term_of_service_uri

    response = @client.connection.post(@uri, resource: 'reg', agreement: @term_of_service_uri)
    response.success?
  end

  private

  def assign_links(links)
    @next_uri = links['next']
    @recover_uri = links['recover']
    @term_of_service_uri = links['terms-of-service']
  end

  def assign_attributes(body)
    @id = body['id']
    @key = body['key']
    @contact = body['contact']
  end
end