Class: Rack::PassbookRack
- Inherits:
-
Object
- Object
- Rack::PassbookRack
- Defined in:
- lib/rack/passbook_rack.rb
Instance Method Summary collapse
- #append_parameter_separator(url) ⇒ Object
- #call(env) ⇒ Object
- #each(&block) ⇒ Object
- #find_method(path) ⇒ Object
-
#initialize(app) ⇒ PassbookRack
constructor
A new instance of PassbookRack.
Constructor Details
#initialize(app) ⇒ PassbookRack
Returns a new instance of PassbookRack.
4 5 6 |
# File 'lib/rack/passbook_rack.rb', line 4 def initialize(app) @app = app end |
Instance Method Details
#append_parameter_separator(url) ⇒ Object
42 43 |
# File 'lib/rack/passbook_rack.rb', line 42 def append_parameter_separator url end |
#call(env) ⇒ Object
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/rack/passbook_rack.rb', line 8 def call(env) method_and_params = find_method env['PATH_INFO'] if method_and_params case method_and_params[:method] when 'device_register_delete' if env['REQUEST_METHOD'] == 'POST' [Passbook::PassbookNotification. register_pass(method_and_params[:params].merge! JSON.parse(env['rack.input'].read 1000))[:status], {}, ['']] elsif env['REQUEST_METHOD'] == 'DELETE' [Passbook::PassbookNotification.unregister_pass(method_and_params[:params])[:status], {}, {}] end when 'passes_for_device' response = Passbook::PassbookNotification.passes_for_device(method_and_params[:params]) [response ? 200 : 204, {}, [response.to_json]] when 'latest_pass' response = Passbook::PassbookNotification.latest_pass(method_and_params[:params]) if response [200, {'Content-Type' => 'application/vnd.apple.pkpass', 'Content-Disposition' => 'attachment', 'filename' => "#{method_and_params[:params]['serialNumber']}.pkpass"}, [response]] else [204, {}, {}] end when 'log' Passbook::PassbookNotification.log JSON.parse(env['rack.input'].read 10000) [200, {}, {}] else end else @app.call env end end |
#each(&block) ⇒ Object
45 46 |
# File 'lib/rack/passbook_rack.rb', line 45 def each(&block) end |
#find_method(path) ⇒ Object
49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 |
# File 'lib/rack/passbook_rack.rb', line 49 def find_method(path) parsed_path = path.split '/' url_beginning = parsed_path.index 'v1' if url_beginning args_length = parsed_path.size - url_beginning if (parsed_path[url_beginning + 1 ] == 'devices') and (parsed_path[url_beginning + 3 ] == 'registrations') if args_length == 6 return method_and_params_hash 'device_register_delete', path elsif args_length == 5 return method_and_params_hash 'passes_for_device', path end elsif parsed_path[url_beginning + 1] == 'passes' and args_length == 4 return method_and_params_hash 'latest_pass', path elsif parsed_path[url_beginning + 1] == 'log' and args_length == 2 return {:method => 'log'} end end return nil end |