Skip to content

Commit

Permalink
imStickered Parameterising query
Browse files Browse the repository at this point in the history
Main.storyboard
- add Search Term field

ViewController.swift
- add outlet searchEntry
- onTest pass searchEntry content to testit

StickerManager
- testit
  - take a non-empty search term & use in hardcoded search
  - take count of items to get back and use in search
  • Loading branch information
AndyDentFree committed Oct 21, 2021
1 parent fa64d0b commit 9c2d3a2
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 7 deletions.
5 changes: 3 additions & 2 deletions imStickered/Common/StickerManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,12 @@ import FoundationNetworking
struct StickerManager {
let token = SnapAuthKeys.SnapKitAPIToken_Staging

func testit() {
func testit(searchTerm: String, numResults: Int = 3) {

var semaphore = DispatchSemaphore (value: 0)

let parameters = "{\"query\":\"query SearchStickerSample {\\r\\n sticker {\\r\\n searchStickers(\\r\\n req:{\\r\\n searchStickersParams:{searchText: \\\"duck\\\", numberResults: 5},\\r\\n stickerUserContext:{countryCode: US, localTimeZoneUTCOffsetMinutes: 2,locale: EN_US}\\r\\n }){\\r\\n stickerResults {\\r\\n items {\\r\\n itemType\\r\\n id\\r\\n pngURL\\r\\n thumbnailURL\\r\\n }\\r\\n }\\r\\n }\\r\\n }\\r\\n}\",\"variables\":{}}"
/// yes this is messy but attempting to use raw strings and multi-line raw strings got a JSON error don't have time to debug.
let parameters = "{\"query\":\"query SearchStickerSample {\\r\\n sticker {\\r\\n searchStickers(\\r\\n req:{\\r\\n searchStickersParams:{searchText: \\\"\(searchTerm)\\\", numberResults: \(numResults)},\\r\\n stickerUserContext:{countryCode: US, localTimeZoneUTCOffsetMinutes: 2,locale: EN_US}\\r\\n }){\\r\\n stickerResults {\\r\\n items {\\r\\n itemType\\r\\n id\\r\\n pngURL\\r\\n thumbnailURL\\r\\n }\\r\\n }\\r\\n }\\r\\n }\\r\\n}\",\"variables\":{}}"
let postData = parameters.data(using: .utf8)

var request = URLRequest(url: URL(string: "https://graph.snapchat.com/graphql")!,timeoutInterval: Double.infinity)
Expand Down
19 changes: 18 additions & 1 deletion imStickered/imStickered Code Change Diary.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ Creation
Created by duplicating the webFromIM and renaming everything.

-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
Integrating plain StickerKit without auth into app - works with hardcoded
Integrating plain StickerKit without auth into app - works with hardcoded query
2021-10-20


Expand All @@ -19,3 +19,20 @@ ViewController.swift

StickerManager
- added to wrap testing initially using the code from Postman

-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
Parameterising query
2021-10-21

Main.storyboard
- add Search Term field

ViewController.swift
- add outlet searchEntry
- onTest pass searchEntry content to testit

StickerManager
- testit
- take a non-empty search term & use in hardcoded search
- take count of items to get back and use in search

23 changes: 20 additions & 3 deletions imStickered/imStickeredapp/Base.lproj/Main.storyboard
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,15 @@
<fontDescription key="fontDescription" type="system" pointSize="14"/>
<textInputTraits key="textInputTraits" autocapitalizationType="sentences"/>
</textView>
<button opaque="NO" contentMode="scaleToFill" misplaced="YES" contentHorizontalAlignment="center" contentVerticalAlignment="center" buttonType="system" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="piO-SP-7sY">
<rect key="frame" x="169" y="145" width="77" height="31"/>
<textField opaque="NO" contentMode="scaleToFill" ambiguous="YES" contentHorizontalAlignment="left" contentVerticalAlignment="center" borderStyle="roundedRect" placeholder="Search term here" textAlignment="natural" minimumFontSize="17" translatesAutoresizingMaskIntoConstraints="NO" id="3Ri-yb-zyA" userLabel="Search term">
<rect key="frame" x="20" y="143.5" width="250" height="34"/>
<color key="backgroundColor" systemColor="systemFillColor"/>
<color key="textColor" systemColor="secondaryLabelColor"/>
<fontDescription key="fontDescription" type="system" pointSize="14"/>
<textInputTraits key="textInputTraits"/>
</textField>
<button opaque="NO" contentMode="scaleToFill" ambiguous="YES" misplaced="YES" contentHorizontalAlignment="center" contentVerticalAlignment="center" buttonType="system" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="piO-SP-7sY">
<rect key="frame" x="278" y="142" width="77" height="31"/>
<state key="normal" title="Button"/>
<buttonConfiguration key="configuration" style="plain" title="Test"/>
<connections>
Expand All @@ -52,15 +59,19 @@
<constraint firstItem="vL5-Az-CjE" firstAttribute="width" secondItem="6Tk-OE-BBY" secondAttribute="width" constant="-24" id="5Sf-MJ-FwS"/>
<constraint firstItem="piO-SP-7sY" firstAttribute="top" secondItem="rDp-VH-9bN" secondAttribute="bottom" constant="23.5" id="5Ur-JM-80K"/>
<constraint firstItem="vL5-Az-CjE" firstAttribute="top" secondItem="6Tk-OE-BBY" secondAttribute="top" constant="12" id="DT7-Mf-RIt"/>
<constraint firstItem="piO-SP-7sY" firstAttribute="centerX" secondItem="6Tk-OE-BBY" secondAttribute="centerX" id="Ddl-iF-dYh"/>
<constraint firstItem="rDp-VH-9bN" firstAttribute="top" secondItem="vL5-Az-CjE" secondAttribute="bottom" constant="8" id="DtS-eu-00i"/>
<constraint firstItem="rDp-VH-9bN" firstAttribute="centerX" secondItem="6Tk-OE-BBY" secondAttribute="centerX" id="Hz0-pC-n0G"/>
<constraint firstItem="vL5-Az-CjE" firstAttribute="centerX" secondItem="6Tk-OE-BBY" secondAttribute="centerX" id="LT2-Yo-du0"/>
<constraint firstItem="6Tk-OE-BBY" firstAttribute="trailing" secondItem="piO-SP-7sY" secondAttribute="trailing" constant="16" id="epg-c5-nlh"/>
<constraint firstItem="piO-SP-7sY" firstAttribute="leading" secondItem="3Ri-yb-zyA" secondAttribute="trailing" constant="8" symbolic="YES" id="kJ8-F9-Qx6"/>
<constraint firstItem="3Ri-yb-zyA" firstAttribute="centerY" secondItem="piO-SP-7sY" secondAttribute="centerY" id="pZs-Kk-Cfi"/>
<constraint firstItem="rDp-VH-9bN" firstAttribute="width" secondItem="vL5-Az-CjE" secondAttribute="width" id="rxo-ru-EWg"/>
<constraint firstItem="3Ri-yb-zyA" firstAttribute="leading" secondItem="6Tk-OE-BBY" secondAttribute="leading" constant="20" id="wEg-ez-eLp"/>
</constraints>
</view>
<connections>
<outlet property="results" destination="eAR-XI-uHe" id="cPh-uR-hub"/>
<outlet property="searchEntry" destination="3Ri-yb-zyA" id="Fnk-9j-BKk"/>
</connections>
</viewController>
<placeholder placeholderIdentifier="IBFirstResponder" id="dkx-z0-nzr" sceneMemberID="firstResponder"/>
Expand All @@ -72,8 +83,14 @@
<systemColor name="labelColor">
<color white="0.0" alpha="1" colorSpace="custom" customColorSpace="genericGamma22GrayColorSpace"/>
</systemColor>
<systemColor name="secondaryLabelColor">
<color red="0.23529411764705882" green="0.23529411764705882" blue="0.2627450980392157" alpha="0.59999999999999998" colorSpace="custom" customColorSpace="sRGB"/>
</systemColor>
<systemColor name="systemBackgroundColor">
<color white="1" alpha="1" colorSpace="custom" customColorSpace="genericGamma22GrayColorSpace"/>
</systemColor>
<systemColor name="systemFillColor">
<color red="0.47058823529411764" green="0.47058823529411764" blue="0.50196078431372548" alpha="0.20000000000000001" colorSpace="custom" customColorSpace="sRGB"/>
</systemColor>
</resources>
</document>
4 changes: 3 additions & 1 deletion imStickered/imStickeredapp/ViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,16 @@ class ViewController: UIViewController {
let mgr = StickerManager()

@IBOutlet weak var results: UITextView!
@IBOutlet weak var searchEntry: UITextField!

override func viewDidLoad() {
super.viewDidLoad()
// setup the webview and load any incoming
}

@IBAction func onTest(_ sender: Any) {
mgr.testit()
guard let searchFor = searchEntry.text, !searchFor.isEmpty else {return}
mgr.testit(searchTerm: searchFor)
}

}
Expand Down

0 comments on commit 9c2d3a2

Please sign in to comment.