Skip to content

Commit a09529f

Browse files
committed
[UPD] JSON v2
1 parent c8adfab commit a09529f

File tree

10 files changed

+447
-196
lines changed

10 files changed

+447
-196
lines changed

CHANGELOG.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,13 @@
22
All notable changes to this project will be documented in this file.
33

44
---
5+
## [3.0.1](https://github.com/RecastAI/SDK-ios/releases/tag/3.0.0)
6+
7+
#### Features
8+
9+
* JSON v2
10+
* Overall redo pod
11+
512
## [2.1.1](https://github.com/RecastAI/SDK-ios/releases/tag/2.1.1)
613

714
#### Features

Example/Pods/Pods.xcodeproj/project.pbxproj

Lines changed: 4 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Example/RecastAI.xcodeproj/project.pbxproj

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -359,6 +359,7 @@
359359
ALWAYS_EMBED_SWIFT_STANDARD_LIBRARIES = YES;
360360
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
361361
INFOPLIST_FILE = RecastAI/Info.plist;
362+
IPHONEOS_DEPLOYMENT_TARGET = 10.0;
362363
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks";
363364
MODULE_NAME = ExampleApp;
364365
PRODUCT_BUNDLE_IDENTIFIER = "org.cocoapods.demo.$(PRODUCT_NAME:rfc1034identifier)";
@@ -374,6 +375,7 @@
374375
ALWAYS_EMBED_SWIFT_STANDARD_LIBRARIES = YES;
375376
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
376377
INFOPLIST_FILE = RecastAI/Info.plist;
378+
IPHONEOS_DEPLOYMENT_TARGET = 10.0;
377379
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks";
378380
MODULE_NAME = ExampleApp;
379381
PRODUCT_BUNDLE_IDENTIFIER = "org.cocoapods.demo.$(PRODUCT_NAME:rfc1034identifier)";

Example/RecastAI/Base.lproj/Main.storyboard

Lines changed: 11 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
1-
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
2-
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="10116" systemVersion="15E65" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" initialViewController="vXZ-lx-hvc">
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="11201" systemVersion="16A323" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" colorMatched="YES" initialViewController="vXZ-lx-hvc">
33
<dependencies>
44
<deployment identifier="iOS"/>
5-
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="10085"/>
5+
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="11161"/>
66
<capability name="Constraints to layout margins" minToolsVersion="6.0"/>
7+
<capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
78
</dependencies>
89
<scenes>
910
<!--View Controller-->
@@ -15,19 +16,18 @@
1516
<viewControllerLayoutGuide type="bottom" id="2fi-mo-0CV"/>
1617
</layoutGuides>
1718
<view key="view" contentMode="scaleToFill" id="kh9-bI-dsS">
18-
<rect key="frame" x="0.0" y="0.0" width="600" height="600"/>
19+
<rect key="frame" x="0.0" y="0.0" width="375" height="667"/>
1920
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMaxY="YES"/>
2021
<subviews>
2122
<button opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" buttonType="roundedRect" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="MWL-OU-tmo">
22-
<rect key="frame" x="225" y="285" width="150" height="30"/>
23-
<color key="backgroundColor" red="1" green="0.70196078429999997" blue="0.0" alpha="1" colorSpace="calibratedRGB"/>
23+
<color key="backgroundColor" red="1" green="0.70196078429999997" blue="0.0" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
2424
<constraints>
2525
<constraint firstAttribute="width" constant="150" id="Ksw-R9-Pjd"/>
2626
<constraint firstAttribute="height" constant="30" id="XEN-jn-NDy"/>
2727
<constraint firstAttribute="width" constant="100" id="ZAD-Ke-7DG"/>
2828
</constraints>
2929
<state key="normal" title="Make Request">
30-
<color key="titleColor" red="1" green="1" blue="1" alpha="1" colorSpace="calibratedRGB"/>
30+
<color key="titleColor" red="1" green="1" blue="1" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
3131
</state>
3232
<variation key="default">
3333
<mask key="constraints">
@@ -39,13 +39,11 @@
3939
</connections>
4040
</button>
4141
<textField opaque="NO" clipsSubviews="YES" contentMode="scaleToFill" contentHorizontalAlignment="left" contentVerticalAlignment="center" borderStyle="roundedRect" textAlignment="natural" minimumFontSize="17" translatesAutoresizingMaskIntoConstraints="NO" id="XzR-fn-OHd">
42-
<rect key="frame" x="225" y="247" width="150" height="30"/>
4342
<fontDescription key="fontDescription" type="system" pointSize="14"/>
4443
<textInputTraits key="textInputTraits"/>
4544
</textField>
4645
<button opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="4oX-sm-DSi">
47-
<rect key="frame" x="275" y="323" width="50" height="50"/>
48-
<color key="backgroundColor" red="1" green="0.70196078431372544" blue="0.0" alpha="1" colorSpace="calibratedRGB"/>
46+
<color key="backgroundColor" red="1" green="0.70196078431372544" blue="0.0" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
4947
<constraints>
5048
<constraint firstAttribute="height" constant="50" id="4BA-m9-asc"/>
5149
<constraint firstAttribute="width" constant="50" id="Sou-Xd-3D4"/>
@@ -55,11 +53,9 @@
5553
<action selector="makeVoiceRequest" destination="vXZ-lx-hvc" eventType="touchUpInside" id="8p4-l5-BW3"/>
5654
</connections>
5755
</button>
58-
<imageView userInteractionEnabled="NO" contentMode="scaleAspectFit" horizontalHuggingPriority="251" verticalHuggingPriority="251" image="logo" translatesAutoresizingMaskIntoConstraints="NO" id="FNJ-0f-7AF">
59-
<rect key="frame" x="20" y="381" width="560" height="211"/>
60-
</imageView>
56+
<imageView userInteractionEnabled="NO" contentMode="scaleAspectFit" horizontalHuggingPriority="251" verticalHuggingPriority="251" image="logo" translatesAutoresizingMaskIntoConstraints="NO" id="FNJ-0f-7AF"/>
6157
</subviews>
62-
<color key="backgroundColor" red="0.38039215686274508" green="0.38039215686274508" blue="0.38039215686274508" alpha="1" colorSpace="calibratedRGB"/>
58+
<color key="backgroundColor" red="0.38039215686274508" green="0.38039215686274508" blue="0.38039215686274508" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
6359
<constraints>
6460
<constraint firstItem="XzR-fn-OHd" firstAttribute="centerX" secondItem="MWL-OU-tmo" secondAttribute="centerX" id="0cC-Fu-OEh"/>
6561
<constraint firstItem="MWL-OU-tmo" firstAttribute="centerX" secondItem="kh9-bI-dsS" secondAttribute="centerX" id="2Zn-sa-hN4"/>
@@ -95,6 +91,6 @@
9591
</scenes>
9692
<resources>
9793
<image name="logo" width="945" height="945"/>
98-
<image name="micro" width="24" height="24"/>
94+
<image name="micro" width="18" height="18"/>
9995
</resources>
10096
</document>

Example/RecastAI/ViewController.swift

Lines changed: 10 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -19,14 +19,13 @@ class ViewController: UIViewController
1919

2020
//Vars
2121
var bot : RecastAIClient?
22-
var recording : Bool = true
2322

2423
override func viewDidLoad()
2524
{
2625
super.viewDidLoad()
2726
// Do any additional setup after loading the view, typically from a nib.
28-
self.bot = RecastAIClient(token : "512f707a5a4af678656255dafa17fd60")
29-
self.bot = RecastAIClient(token : "512f707a5a4af678656255dafa17fd60", language: "en")
27+
self.bot = RecastAIClient(token : "YOUR_TOKEN")
28+
self.bot = RecastAIClient(token : "YOUR_TOKEN", language: "en")
3029
}
3130

3231
/**
@@ -39,11 +38,9 @@ class ViewController: UIViewController
3938
func recastRequestDone(_ response : Response)
4039
{
4140
print(response)
42-
let flower = response.get(entity: "flower-type")
43-
print(response.get(entity: "flower-type"))
44-
print(response.get(entity: "flower-type"))
4541
print(response.language)
46-
print(response.intents)
42+
print(response.intent())
43+
print(response.entities)
4744
}
4845

4946
/**
@@ -67,26 +64,19 @@ class ViewController: UIViewController
6764
{
6865
//Call makeRequest with string parameter to make a text request
6966
self.bot?.textRequest(self.requestTextField.text!, successHandler: recastRequestDone, failureHandle: recastRequestError)
70-
// self.bot?.textRequest(self.requestTextField.text!, lang: "en")
7167
}
7268
}
7369

7470
/**
75-
Make Voice request to Recast.AI API
71+
Make File request to Recast.AI API
7672
*/
77-
@IBAction func makeVoiceRequest()
73+
func makeFileRequest()
7874
{
79-
if (self.recording)
80-
{
81-
self.recording = !self.recording
82-
//Call startStreamRequest to start recording your voice
83-
// self.bot!.startStreamRequest()
84-
}
85-
else
75+
if (!(self.requestTextField.text?.isEmpty)!)
8676
{
87-
self.recording = !self.recording
88-
//Call stopStreamRequest to stop recording your voice and launch the request to the Recast.AI API
89-
// self.bot!.stopStreamRequest()
77+
let url = URL(string: self.requestTextField.text!)!
78+
//Call makeRequest with string parameter to make a text request
79+
self.bot?.fileRequest(url, successHandler: recastRequestDone, failureHandle: recastRequestError)
9080
}
9181
}
9282
}

Pod/Classes/Intent.swift

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
//
2+
// Intent.swift
3+
// Pods
4+
//
5+
// Created by PE on 29/09/2016.
6+
//
7+
//
8+
9+
import Foundation
10+
11+
/**
12+
Class Response
13+
14+
Return from the Recast API call
15+
*/
16+
public class Intent : CustomStringConvertible
17+
{
18+
public var confidence : Float?
19+
public var slug : String?
20+
21+
/**
22+
Init class with JSON
23+
24+
- parameter raw : JSON object to init with
25+
*/
26+
init (intent: [String : AnyObject])
27+
{
28+
confidence = intent["confidence"] as? Float
29+
slug = intent["slug"] as? String
30+
31+
}
32+
33+
public var description: String {
34+
return slug!
35+
}
36+
}

Pod/Classes/RecastAI.swift

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,9 @@ RecastAIClient class handling request to the API
1414
*/
1515
public class RecastAIClient
1616
{
17-
static fileprivate let url : String = "https://api.recast.ai/v1/request"
18-
static fileprivate let url_voice : String = "ws://api.recast.ai/v1/request"
19-
fileprivate let token : String
17+
static fileprivate let url : String = "https://api.recast.ai/v2/request"
18+
static fileprivate let url_voice : String = "ws://api.recast.ai/v2/request"
19+
fileprivate var token : String
2020
fileprivate let language : String?
2121

2222
/**
@@ -43,8 +43,12 @@ public class RecastAIClient
4343

4444
- returns: void
4545
*/
46-
public func textRequest(_ request : String, lang: String? = nil, successHandler: @escaping (Response) -> Void, failureHandle: @escaping (Error) -> Void)
46+
public func textRequest(_ request : String, token : String? = nil, lang: String? = nil, successHandler: @escaping (Response) -> Void, failureHandle: @escaping (Error) -> Void)
4747
{
48+
if let tkn = token
49+
{
50+
self.token = token!
51+
}
4852
let headers = ["Authorization" : "Token " + self.token]
4953
var param = ["text" : request]
5054
if let ln = lang
@@ -77,7 +81,11 @@ public class RecastAIClient
7781

7882
- returns: void
7983
*/
80-
public func voiceRequest(_ audioFileURL: URL, lang: String? = nil, successHandler: @escaping (Response) -> Void, failureHandle: @escaping (Error) -> Void) {
84+
public func fileRequest(_ audioFileURL: URL, token : String? = nil, lang: String? = nil, successHandler: @escaping (Response) -> Void, failureHandle: @escaping (Error) -> Void) {
85+
if let tkn = token
86+
{
87+
self.token = token!
88+
}
8189
let headers = ["Authorization": "Token " + self.token]
8290
Alamofire.upload(multipartFormData: { multipartFormData in
8391
multipartFormData.append(audioFileURL, withName: "voice")

0 commit comments

Comments
 (0)