Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix Pass object additional feilds #31

Merged
merged 2 commits into from
May 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 0 additions & 4 deletions app/models/passkit/pass.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,11 @@ class Pass < ActiveRecord::Base
:barcodes,
:beacons,
:boarding_pass,
:coupon,
:description,
:event_ticket,
:expiration_date,
:file_name,
:foreground_color,
:format_version,
:generic,
:grouping_identifier,
:header_fields,
:label_color,
Expand All @@ -42,7 +39,6 @@ class Pass < ActiveRecord::Base
:secondary_fields,
:semantics,
:sharing_prohibited,
:store_card,
:suppress_strip_shine,
:user_info,
:voided,
Expand Down
23 changes: 3 additions & 20 deletions lib/passkit/base_pass.rb
Original file line number Diff line number Diff line change
Expand Up @@ -128,17 +128,10 @@ def beacons

# Information specific to a boarding pass
# Returns a hash representing Pass.BoardingPass
# https://developer.apple.com/documentation/walletpasses/pass/boardingpass
# i.e {transitType: 'PKTransitTypeGeneric'}
def boarding_pass
end

# Information specific to a coupon
# Returns a hash representing Pass.Coupon
def coupon
end

# Information specific to an event ticket
# Returns a hash representing Pass.EventTicket
def event_ticket
{}
end

# Date and time the pass expires, must include
Expand All @@ -148,11 +141,6 @@ def event_ticket
def expiration_date
end

# Information specific to a generic pass
# Returns a hash representing Pass.Generic
def generic
end

# A key to identify group multiple passes together
# (e.g. a number of boarding passes for the same trip)
# Returns a String
Expand All @@ -178,11 +166,6 @@ def relevant_date
def semantics
end

# Information specific to a store card
# Returns a hash representing Pass.StoreCard
def store_card
end

# Display the strip image without a shine effect
# Returns a boolean
def suppress_strip_shine
Expand Down
8 changes: 2 additions & 6 deletions lib/passkit/generator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -75,20 +75,14 @@ def generate_json_pass
else
pass[:barcodes] = @pass.barcodes
end

pass[:appLaunchURL] = @pass.app_launch_url if @pass.app_launch_url
pass[:associatedStoreIdentifiers] = @pass.associated_store_identifiers unless @pass.associated_store_identifiers.empty?
pass[:beacons] = @pass.beacons unless @pass.beacons.empty?
pass[:boardingPass] = @pass.boarding_pass if @pass.boarding_pass
pass[:coupon] = @pass.coupon if @pass.coupon
pass[:eventTicket] = @pass.event_ticket if @pass.event_ticket
pass[:expirationDate] = @pass.expiration_date if @pass.expiration_date
pass[:generic] = @pass.generic if @pass.generic
pass[:groupingIdentifier] = @pass.grouping_identifier if @pass.grouping_identifier
pass[:nfc] = @pass.nfc if @pass.nfc
pass[:relevantDate] = @pass.relevant_date if @pass.relevant_date
pass[:semantics] = @pass.semantics if @pass.semantics
pass[:store_card] = @pass.store_card if @pass.store_card
pass[:userInfo] = @pass.user_info if @pass.user_info

pass[@pass.pass_type] = {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can be confident that this does not cause any new problems, because

pass[:coupon], pass[:eventTicket], and pass[:generic] were being overwritten by pass[@pass.pass_type] here.

pass[:store_card] should've been pass[:storeCard], so it never did anything useful.

Expand All @@ -99,6 +93,8 @@ def generate_json_pass
backFields: @pass.back_fields
}

pass[:boardingPass].merge(@pass.boarding_pass) if @pass.pass_type == :boardingPass && @pass.boarding_pass

File.write(@temporary_path.join("pass.json"), pass.to_json)
end

Expand Down