$ git clone https://github.com/riyadshauk/coupon-retailer-shopper-app.git \
&& cd coupon-retailer-shopper-app && git submodule init && git submodule update
I've used two 3rd-party libraries when building the mobile apps (a QR Code reading library, and form-creating library, Eureka – to easily write a clean login form). To get them working properly for this project, we utilize git submodules, as shown above. Alternatively, Cocoa Pods or Carthage could have been used.
- ClientAPI
- Setup
- Table of contents
- Brief Description
- Project Notes (Getting Situated with the Project Structure))
- Building and Running the webserver & demo apps
- Common Build Errors
This project consists of an authenticated REST API + DB (written in Swift 4 + Vapor, can build on both Linux and macOS), which also contains a ClientAPI/db_scripts/populator.ts to populate the database associated with this REST API via a client-side JavaScript wrapper API.
This project also consists of two client-side applications (both written in Swift 4): A Retailer app, RetailerQRReader, and a Shopper app, ShopperQRCodeCouponClient.
I made these for a demo POC project. The two iOS applications were initially just hacked together over a couple days, so I didn't spend nearly as much time on code quality and design as I did on the authenticated REST API + DB I built.
- Shopper/Retailer login with basic authentication (assume account already created)
- Shopper screen contains QR codes representing relevant coupons for him (assume he already saved his preferences)
- Retailer scans a QR code displayed on the Shopper app and POSTs the coupon info to the backend using a bearer token (supplied on login)
- Shopper GETs relevant coupons using bearer token (supplied on login)
- When Shopper logs out and logs back in, he will see that a
timesProcessed
variable associated with the coupon that was scanned has increased by one
- Not Fully Implemented: In practice, another backend, possibly part of some larger system, would POST relevant coupons to the database based on a set of rules which would be initialized, in part, from the Retailer. These would be sent to the Shopper when he polls for relevant coupons.
For the iPhone apps built in Swift 4, after properly cloning this repo, you will just need to open their corresponding .xcodeproj files to launch each app's Xcode project.
Note that in order to run these apps, you will need to modify the URL of the webserver to wherever you run your webserver (which will probably be localhost:8080). However, connecting to an iPhone app on localhost:8080 doesn't really work too well. For that, a simple solution is to download the Ngrok tool, then run ngrok http 8080
in your terminal, for example; this will open up your localhost webserver running on port 8080 at a specified temporary ngrok URL (with an 8 hour lifetime). Use that URL (outputted in your Terminal) as the webserver URL used in the Retailer and Shopper client apps (search for http
or ngrok
to find those locations, and do a simple find-replace).
Alternatively, you could run your webserver using a free tier account with vapor.cloud, made by the developers who built the Vapor web framework that this project's backend webserver is running on (the webserver is actually an adaptation of the project generated from the following scaffolding command: vapor new WebServer --template=auth-template
, as documented on vapor.codes).
Go ahead and follow these directions for how to test an iPhone app on a real device using Xcode, or something similar, for more info.
- Sometimes Xcode 10 acts strange when two projects that depend on the same git submodule are open in the Xcode editor at the same time, so close the one you're not currently trying to build. Also quit Xcode and relaunch Xcode with the project you want to build.
- The next step is to change the active scheme to Eureka, then build, then change the active scheme back to the main app we want to build, and run the application. In more details, ie:
- Select
Product > Scheme > Eureka
- Select
Product > Build
(make sure to have your device selected, similar to how you normally would) - Select
Product > Scheme > ShopperQRCodeCouponClient
- Select
Product > Run
(as you normally would)
- Select
- Click on the blue application icon named
ShopperQRCodeCouponClient
in the Project Navigator pane. - Select
General
for the targetShopperQRCodeCouponClient
. - Under
Embedded Binaries
, click the plus-symbol, and selectEureka.frameworkiOS
- Stop and Run the application (as you normally would)