Class: GlobalSign::Client

Inherits:
Object
  • Object
show all
Defined in:
lib/global_sign/client.rb

Instance Method Summary collapse

Constructor Details

#initialize(options: {}) ⇒ Client

Returns a new instance of Client.



5
6
7
8
9
10
11
12
13
# File 'lib/global_sign/client.rb', line 5

def initialize(options: {})
  @configuration = GlobalSign.configuration

  @connection = Faraday::Connection.new(url: @configuration.endpoint) do |conn|
    conn.request :url_encoded
    conn.adapter Faraday.default_adapter
    conn.options[:timeout] = options[:timeout] if options[:timeout].present?
  end
end

Instance Method Details

#find_response_class_for(request) ⇒ Object



27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
# File 'lib/global_sign/client.rb', line 27

def find_response_class_for(request)
  case request
  when GlobalSign::CsrDecoder::Request
    GlobalSign::CsrDecoder::Response
  when GlobalSign::DnsVerification::Request
    GlobalSign::DnsVerification::Response
  when GlobalSign::DnsVerificationForIssue::Request
    GlobalSign::DnsVerificationForIssue::Response
  when GlobalSign::UrlVerification::Request
    GlobalSign::UrlVerification::Response
  when GlobalSign::UrlVerificationForIssue::Request
    GlobalSign::UrlVerificationForIssue::Response
  when GlobalSign::OrderGetterByOrderId::Request
    GlobalSign::OrderGetterByOrderId::Response
  when GlobalSign::DVApproverList::Request
    GlobalSign::DVApproverList::Response
  when GlobalSign::DVOrder::Request
    GlobalSign::DVOrder::Response
  when GlobalSign::OVOrder::Request
    GlobalSign::OVOrder::Response
  when GlobalSign::EVOrder::Request
    GlobalSign::EVOrder::Response
  else
    raise ArgumentError, 'invalid request argument'
  end
end

#process(request) ⇒ Object



15
16
17
18
19
20
21
22
23
24
25
# File 'lib/global_sign/client.rb', line 15

def process(request)
  response_class = find_response_class_for(request)

  response = @connection.post do |req|
    req.url request.path
    req.headers['Content-Type'] = 'text/xml'
    req.body = request.to_xml
  end

  response_class.new(response.body)
end