Class: SatMx::DownloadPetition

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

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(body:, client:) ⇒ DownloadPetition

Returns a new instance of DownloadPetition.



14
15
16
17
# File 'lib/sat_mx/download_petition.rb', line 14

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

Class Method Details

.call(package_id:, requester_rfc:, access_token:, certificate:, private_key:) ⇒ Object



3
4
5
6
7
8
9
10
11
12
# File 'lib/sat_mx/download_petition.rb', line 3

def self.call(package_id:, requester_rfc:, access_token:, certificate:, private_key:)
  new(
    body: DownloadPetitionBody.new(
      package_id:,
      requester_rfc:,
      certificate:
    ),
    client: Client.new(private_key:, access_token:)
  ).call
end

Instance Method Details

#callObject



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
46
47
48
49
50
51
52
53
54
55
56
57
58
# File 'lib/sat_mx/download_petition.rb', line 19

def call
  response = client.download_petition(body.generate)

  case response.status
  when 200..299
    xml = response.xml
    response_tag = xml.xpath(
      "//xmlns:respuesta",
      xmlns: "http://DescargaMasivaTerceros.sat.gob.mx"
    )[0]

    if response_tag["CodEstatus"] == "5000"
      Result.new(
        success?: true,
        xml: response.xml,
        value: response.xml.xpath(
          "//xmlns:Paquete",
          xmlns: "http://DescargaMasivaTerceros.sat.gob.mx"
        ).inner_text
      )
    else
      Result.new(
        success?: false,
        xml: response.xml,
        value: {
          CodEstatus: response_tag["CodEstatus"],
          Mensaje: response_tag["Mensaje"]
        }
      )
    end
  when 400..599
    Result.new(
      success?: false,
      xml: nil,
      value: nil
    )
  else
    SatMx::Error
  end
end