Class: Passkit::BasePass

Inherits:
Object
  • Object
show all
Defined in:
lib/passkit/base_pass.rb

Direct Known Subclasses

ExampleStoreCard

Instance Method Summary collapse

Constructor Details

#initialize(generator = nil) ⇒ BasePass

Returns a new instance of BasePass.



3
4
5
# File 'lib/passkit/base_pass.rb', line 3

def initialize(generator = nil)
  @generator = generator
end

Instance Method Details

#add_other_files(path) ⇒ Object

After base files are copied this is called to allow for adding custom images



85
86
# File 'lib/passkit/base_pass.rb', line 85

def add_other_files(path)
end

#app_launch_urlObject

URL to launch the associated app (nil by default) Returns a String



94
95
# File 'lib/passkit/base_pass.rb', line 94

def app_launch_url
end

#apple_team_identifierObject



11
12
13
# File 'lib/passkit/base_pass.rb', line 11

def apple_team_identifier
  ENV["PASSKIT_APPLE_TEAM_IDENTIFIER"] || raise(Error.new("Missing environment variable: PASSKIT_APPLE_TEAM_IDENTIFIER"))
end

#associated_store_identifiersObject

A list of Apple App Store identifiers for apps associated with the pass. The first one that is compatible with the device is picked. Returns an array of numbers



101
102
103
# File 'lib/passkit/base_pass.rb', line 101

def associated_store_identifiers
  []
end

#auxiliary_fieldsObject



223
224
225
# File 'lib/passkit/base_pass.rb', line 223

def auxiliary_fields
  []
end

#back_fieldsObject



227
228
229
# File 'lib/passkit/base_pass.rb', line 227

def back_fields
  []
end

#background_colorObject



55
56
57
58
# File 'lib/passkit/base_pass.rb', line 55

def background_color
  # white
  "rgb(255, 255, 255)"
end

#barcodeObject

QRCode by default



192
193
194
195
196
197
# File 'lib/passkit/base_pass.rb', line 192

def barcode
  { messageEncoding: "iso-8859-1",
    format: "PKBarcodeFormatQR",
    message: "https://github.com/coorasse/passkit",
    altText: "https://github.com/coorasse/passkit" }
end

#barcodesObject

An array of barcodes, the first one that can be displayed on the device is picked. Returns an array of hashes representing Pass.Barcodes



108
109
110
# File 'lib/passkit/base_pass.rb', line 108

def barcodes
  []
end

#beaconsObject

List of iBeacon identifiers to identify when the pass should be displayed. Returns an array of hashes representing Pass.Beacons



115
116
117
# File 'lib/passkit/base_pass.rb', line 115

def beacons
  []
end

#boarding_passObject

Information specific to a boarding pass Returns a hash representing Pass.BoardingPass



121
122
# File 'lib/passkit/base_pass.rb', line 121

def boarding_pass
end

#couponObject

Information specific to a coupon Returns a hash representing Pass.Coupon



126
127
# File 'lib/passkit/base_pass.rb', line 126

def coupon
end

#descriptionObject



69
70
71
# File 'lib/passkit/base_pass.rb', line 69

def description
  "A basic description for a pass"
end

#event_ticketObject

Information specific to an event ticket Returns a hash representing Pass.EventTicket



131
132
# File 'lib/passkit/base_pass.rb', line 131

def event_ticket
end

#expiration_dateObject

Date and time the pass expires, must include days, hours and minutes (seconds are optional) Returns a String representing the date and time in W3C format



137
138
# File 'lib/passkit/base_pass.rb', line 137

def expiration_date
end

#file_nameObject



187
188
189
# File 'lib/passkit/base_pass.rb', line 187

def file_name
  @file_name ||= SecureRandom.uuid
end

#foreground_colorObject



50
51
52
53
# File 'lib/passkit/base_pass.rb', line 50

def foreground_color
  # black
  "rgb(0, 0, 0)"
end

#format_versionObject



7
8
9
# File 'lib/passkit/base_pass.rb', line 7

def format_version
  ENV["PASSKIT_FORMAT_VERSION"] || 1
end

#genericObject

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



142
143
# File 'lib/passkit/base_pass.rb', line 142

def generic
end

#grouping_identifierObject

A key to identify group multiple passes together (e.g. a number of boarding passes for the same trip) Returns a String



148
149
# File 'lib/passkit/base_pass.rb', line 148

def grouping_identifier
end

#header_fieldsObject



211
212
213
# File 'lib/passkit/base_pass.rb', line 211

def header_fields
  []
end

#label_colorObject



60
61
62
63
# File 'lib/passkit/base_pass.rb', line 60

def label_color
  # black
  "rgb(0, 0, 0)"
end

#languageObject



19
20
21
# File 'lib/passkit/base_pass.rb', line 19

def language
  nil
end

#last_updateObject



23
24
25
# File 'lib/passkit/base_pass.rb', line 23

def last_update
  @generator&.updated_at
end

#locationsObject

A pass can have up to ten relevant locations



76
77
78
# File 'lib/passkit/base_pass.rb', line 76

def locations
  []
end

#logo_textObject

Barcode example def barcode

{ messageEncoding: 'iso-8859-1',
  format: 'PKBarcodeFormatCode128',
  message: '12345',
  altText: '12345' }

end



207
208
209
# File 'lib/passkit/base_pass.rb', line 207

def logo_text
  "Logo text"
end

#max_distanceObject

Distance in meters from locations; if blank uses pass default



89
90
# File 'lib/passkit/base_pass.rb', line 89

def max_distance
end

#nfcObject

Information specific to Value Added Service Protocol transactions Returns a hash representing Pass.NFC



154
155
# File 'lib/passkit/base_pass.rb', line 154

def nfc
end

#organization_nameObject



65
66
67
# File 'lib/passkit/base_pass.rb', line 65

def organization_name
  "Passkit"
end

#pass_pathObject



27
28
29
30
31
32
33
34
35
# File 'lib/passkit/base_pass.rb', line 27

def pass_path
  rails_folder = Rails.root.join("private/passkit/#{folder_name}")
  # if folder exists, otherwise is in the gem itself under lib/passkit/base_pass
  if File.directory?(rails_folder)
    rails_folder
  else
    File.join(File.dirname(__FILE__), folder_name)
  end
end

#pass_typeObject



37
38
39
40
41
42
43
# File 'lib/passkit/base_pass.rb', line 37

def pass_type
  :storeCard
  # :coupon
  # :eventTicket
  # :generic
  # :boardingPass
end

#pass_type_identifierObject



15
16
17
# File 'lib/passkit/base_pass.rb', line 15

def pass_type_identifier
  ENV["PASSKIT_PASS_TYPE_IDENTIFIER"] || raise(Error.new("Missing environment variable: PASSKIT_PASS_TYPE_IDENTIFIER"))
end

#primary_fieldsObject



215
216
217
# File 'lib/passkit/base_pass.rb', line 215

def primary_fields
  []
end

#relevant_dateObject

Date and time when the pass becomes relevant and should be displayed, must include days, hours and minutes (seconds are optional) Returns a String representing the date and time in W3C format



161
162
# File 'lib/passkit/base_pass.rb', line 161

def relevant_date
end

#secondary_fieldsObject



219
220
221
# File 'lib/passkit/base_pass.rb', line 219

def secondary_fields
  []
end

#semanticsObject

Machine readable metadata that the device can use to suggest actions Returns a hash representing SemanticTags



167
168
# File 'lib/passkit/base_pass.rb', line 167

def semantics
end

#sharing_prohibitedObject



231
232
233
# File 'lib/passkit/base_pass.rb', line 231

def sharing_prohibited
  false
end

#store_cardObject

Information specific to a store card Returns a hash representing Pass.StoreCard



172
173
# File 'lib/passkit/base_pass.rb', line 172

def store_card
end

#suppress_strip_shineObject

Display the strip image without a shine effect Returns a boolean



177
178
179
# File 'lib/passkit/base_pass.rb', line 177

def suppress_strip_shine
  true
end

#user_infoObject

JSON dictionary to display custom information for companion apps. Data isn’t displayed to the user. e.g. a machine readable version of the user’s favourite coffee



184
185
# File 'lib/passkit/base_pass.rb', line 184

def 
end

#voidedObject



80
81
82
# File 'lib/passkit/base_pass.rb', line 80

def voided
  false
end

#web_service_urlObject

Raises:



45
46
47
48
# File 'lib/passkit/base_pass.rb', line 45

def web_service_url
  raise Error.new("Missing environment variable: PASSKIT_WEB_SERVICE_HOST") unless ENV["PASSKIT_WEB_SERVICE_HOST"]
  "#{ENV["PASSKIT_WEB_SERVICE_HOST"]}/passkit/api"
end