Skip to content

Commit

Permalink
fix Pass object additional feilds (#31)
Browse files Browse the repository at this point in the history
* fix Pass object additional feilds

Pass.Coupon, Pass.EventTicket, Pass.EventTicket, and Pass.Generic don't have any additional feilds availabe so we don't need to provide methods for additional feilds.  boardingPass was being overwritten by the additonal feild method, now fixed.

resolves #29

* Update lib/passkit/generator.rb

Co-authored-by: Alessandro Rodi <[email protected]>

---------

Co-authored-by: Alessandro Rodi <[email protected]>
  • Loading branch information
annaswims and coorasse authored May 28, 2024
1 parent a698506 commit 3522c16
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 30 deletions.
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 @@ -129,17 +129,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 @@ -149,11 +142,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 @@ -179,11 +167,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 @@ -88,20 +88,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] = {
Expand All @@ -112,6 +106,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

0 comments on commit 3522c16

Please sign in to comment.