Class: Passkit::Api::V1::PassesController

Inherits:
ActionController::API
  • Object
show all
Defined in:
app/controllers/passkit/api/v1/passes_controller.rb

Instance Method Summary collapse

Instance Method Details

#createObject



7
8
9
10
11
12
13
14
15
16
17
18
19
20
# File 'app/controllers/passkit/api/v1/passes_controller.rb', line 7

def create
  set_generator

  if @generator && @payload[:collection_name].present?
    files = @generator.public_send(@payload[:collection_name]).collect do |collection_item|
      Passkit::Factory.create_pass(@payload[:pass_class], collection_item)
    end
    file = Passkit::Generator.compress_passes_files(files)
    send_file(file, type: 'application/vnd.apple.pkpasses', disposition: 'attachment')
  else
    file = Passkit::Factory.create_pass(@payload[:pass_class], @generator)
    send_file(file, type: 'application/vnd.apple.pkpass', disposition: 'attachment')
  end
end

#showObject

Returns:

  • If request is authorized, returns HTTP status 200 with a payload of the pass data.

  • If the request is not authorized, returns HTTP status 401.

  • Otherwise, returns the appropriate standard HTTP status.



25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'app/controllers/passkit/api/v1/passes_controller.rb', line 25

def show
  authentication_token = request.headers["Authorization"]&.split(" ")&.last
  unless authentication_token.present?
    render json: {}, status: :unauthorized
    return
  end

  pass = Pass.find_by(serial_number: params[:serial_number], authentication_token: authentication_token)
  unless pass
    render json: {}, status: :unauthorized
    return
  end

  pass_output_path = Passkit::Generator.new(pass).generate_and_sign

  response.headers["last-modified"] = pass.last_update.httpdate
  if request.headers["If-Modified-Since"].nil? ||
      (pass.last_update.to_i > Time.zone.parse(request.headers["If-Modified-Since"]).to_i)
    send_file(pass_output_path, type: "application/vnd.apple.pkpass", disposition: "attachment")
  else
    head :not_modified
  end
end