Class: Passkit::Api::V1::RegistrationsController

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

Overview

TODO: check with authentication_token This Class Implements the Apple PassKit API

See Also:

  • https://developer.apple.com/library/archive/documentation/PassKit/Reference/PassKit_WebService/WebService.html
  • https://walletpasses.io/developer/

Instance Method Summary collapse

Instance Method Details

#createObject

Returns:

  • If the serial number is already registered for this device, returns HTTP status 200.

  • If registration succeeds, returns HTTP status 201.

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

  • Otherwise, returns the appropriate standard HTTP status.



16
17
18
19
20
21
22
23
24
# File 'app/controllers/passkit/api/v1/registrations_controller.rb', line 16

def create
  if @pass.devices.find_by(identifier: params[:device_id])
    render json: {}, status: :ok
    return
  end

  register_device
  render json: {}, status: :created
end

#destroyObject

Returns:

  • If disassociation succeeds, returns HTTP status 200.

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

  • Otherwise, returns the appropriate standard HTTP status.



50
51
52
53
54
# File 'app/controllers/passkit/api/v1/registrations_controller.rb', line 50

def destroy
  registrations = @pass.registrations.where(passkit_device_id: params[:device_id])
  registrations.delete_all
  render json: {}, status: :ok
end

#showObject

Returns:

  • If there are matching passes, returns HTTP status 200 with a JSON dictionary with the following keys and values: lastUpdated (string): The current modification tag. serialNumbers (array of strings): The serial numbers of the matching passes.

  • If there are no matching passes, returns HTTP status 204.

  • Otherwise, returns the appropriate standard HTTP status



32
33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'app/controllers/passkit/api/v1/registrations_controller.rb', line 32

def show
  if @device.nil?
    render json: {}, status: :not_found
    return
  end

  passes = fetch_registered_passes
  if passes.none?
    render json: {}, status: :no_content
    return
  end

  render json: updatable_passes(passes).to_json
end