Class: SatMx::DownloadRequest

Inherits:
Object
  • Object
show all
Defined in:
lib/sat_mx/download_request.rb

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(download_request_body:, client:) ⇒ DownloadRequest

Returns a new instance of DownloadRequest.



26
27
28
29
# File 'lib/sat_mx/download_request.rb', line 26

def initialize(download_request_body:, client:)
  @download_request_body = download_request_body
  @client = client
end

Class Method Details

.call(start_date:, end_date:, request_type:, issuing_rfc:, recipient_rfcs:, requester_rfc:, access_token:, certificate:, private_key:) ⇒ Object



3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/sat_mx/download_request.rb', line 3

def self.call(start_date:,
  end_date:,
  request_type:,
  issuing_rfc:,
  recipient_rfcs:,
  requester_rfc:,
  access_token:,
  certificate:,
  private_key:)
  new(
    download_request_body: DownloadRequestBody.new(
      start_date:,
      end_date:,
      request_type:,
      issuing_rfc:,
      recipient_rfcs:,
      requester_rfc:,
      certificate:
    ),
    client: Client.new(private_key:, access_token:)
  ).call
end

Instance Method Details

#callObject



31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/sat_mx/download_request.rb', line 31

def call
  response = client.download_request(download_request_body.generate)

  case response.status
  when 200..299
    check_body_status response.xml
  when 400..599
    Result.new(success?: false, value: nil, xml: response.xml)
  else
    SatMx::Error
  end
end