Skip to content

Commit 2afa2b1

Browse files
Merge pull request #24 from ScalaInc/fix/update-readme
Fix/update readme
2 parents d67316d + 4ee4667 commit 2afa2b1

File tree

10 files changed

+542
-380
lines changed

10 files changed

+542
-380
lines changed

Example/ExpSwift/ViewController.swift

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -16,21 +16,26 @@ class ViewController: UIViewController {
1616
// Do any additional setup after loading the view, typically from a nib.
1717
// let host = "http://api.develop.exp.scala.com:9000"
1818
// let host = "http://develop.exp.scala.com:9000"
19-
let host = "http://localhost:9000"
20-
21-
// let host = "https://api.goexp.io"
19+
// let host = "http://localhost:9000"
20+
let host = "https://api-staging.goexp.io"
21+
// let host = "https://api.goexp.io"
2222

23-
ExpSwift.start(host,user: "[email protected]",password: "5715031Com",organization: "").then{ result -> Void in
24-
23+
ExpSwift.start(host,user: "[email protected]",password: "5715031Com@",organization: "").then{ result -> Void in
24+
debugPrint("test")
2525
let channel1 = ExpSwift.getChannel("channel1",system: false,consumerApp: true)
26-
let payload1:Dictionary<String,String> = ["boog":"pro"]
26+
let flingMsg:Dictionary<String,AnyObject> = ["uuid":"myUuid"]
27+
channel1.fling(flingMsg)
28+
let payload1:Dictionary<String,AnyObject> = ["boog":"pro"]
2729
channel1.listen("hi", callback: { (resultListen) -> Void in
2830
debugPrint(resultListen)
29-
ExpSwift.respond(resultListen)
31+
ExpSwift.respond(["text":"hi to you too"])
3032
}).then { result -> Void in
31-
channel1.broadcast("hi", payload: payload1, timeout: "2000")
33+
ExpSwift.getContentNode("")
34+
3235
}
3336

37+
38+
3439
// let channel2 = ExpSwift.getChannel("channel2",system: 0,consumerApp: 1)
3540
// let payload2:Dictionary<String,String> = ["cesar":"hello"]
3641
// channel2.listen("hello", callback: { (resultListen) -> Void in
@@ -43,7 +48,9 @@ class ViewController: UIViewController {
4348
for location in locations.getResults()
4449
{
4550
debugPrint(location.get("name"))
46-
location.fling(channel1,payload: payload1)
51+
// location.fling(channel1,payload: payload1)
52+
let zones = location.getZones()
53+
debugPrint(zones)
4754
}
4855
// debugPrint(devices)
4956
}.error { error in

Example/Podfile.lock

Lines changed: 0 additions & 48 deletions
This file was deleted.

ExpSwift.podspec

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
Pod::Spec.new do |s|
1010
s.name = "ExpSwift"
11-
s.version = "0.0.1"
11+
s.version = "1.0.0"
1212
s.summary = "Exp IOS SDK library. Native IOS library for EXP platform."
1313

1414
# This description is used to generate tags and improve search results.
@@ -22,7 +22,7 @@ Pod::Spec.new do |s|
2222
# s.screenshots = "www.example.com/screenshots_1", "www.example.com/screenshots_2"
2323
s.license = 'MIT'
2424
s.author = { "Cesar Oyarzun" => "[email protected]" }
25-
s.source = { :git => "https://github.com/ScalaInc/exp-ios-sdk.git", :tag => s.version.to_s }
25+
s.source = { :git => "https://github.com/ScalaInc/exp-ios-sdk.git", :tag => 'v1.0.0' }
2626
# s.social_media_url = 'https://twitter.com/<TWITTER_USERNAME>'
2727

2828
s.platform = :ios, '8.0'

Pod/Classes/Content.swift

Lines changed: 135 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,135 @@
1+
//
2+
// Content.swift
3+
// Pods
4+
//
5+
// Created by Cesar on 9/23/15.
6+
//
7+
//
8+
9+
import Foundation
10+
import PromiseKit
11+
import Alamofire
12+
13+
public final class Content: Model,ResponseObject,ResponseCollection {
14+
15+
var children: [Content] = []
16+
public let uuid: String
17+
public let subtype: CONTENT_TYPES
18+
19+
public enum CONTENT_TYPES : String {
20+
case APP = "scala:content:app"
21+
case FILE = "scala:content:file"
22+
case FOLDER = "scala:content:folder"
23+
case URL = "scala:content:url"
24+
case UNKNOWN = ""
25+
}
26+
27+
required public init?(response: NSHTTPURLResponse, representation: AnyObject) {
28+
if let representation = representation as? [String: AnyObject] {
29+
self.uuid = representation["uuid"] as! String
30+
self.subtype = CONTENT_TYPES(rawValue: representation["subtype"] as! String)!
31+
} else {
32+
self.uuid = ""
33+
self.subtype = CONTENT_TYPES.UNKNOWN
34+
}
35+
36+
if let childrenPath = representation.valueForKeyPath("children") as? [[String: AnyObject]] {
37+
self.children = Content.collection(response:response, representation: childrenPath)
38+
}
39+
40+
super.init(response: response, representation: representation)
41+
42+
// remove children from document
43+
document["children"] = nil
44+
}
45+
46+
public static func collection(response response: NSHTTPURLResponse, representation: AnyObject) -> [Content] {
47+
var contents: [Content] = []
48+
if let representation = representation as? [[String: AnyObject]] {
49+
for contentRepresentation in representation {
50+
if let content = Content(response: response, representation: contentRepresentation) {
51+
contents.append(content)
52+
}
53+
}
54+
}
55+
return contents
56+
}
57+
58+
/**
59+
Get Children from Node
60+
@return Promise<[Content]>.
61+
*/
62+
public func getChildren() ->Promise<[Content]>{
63+
if (!children.isEmpty) {
64+
return Promise<[Content]> { fulfill, reject in
65+
fulfill(children)
66+
}
67+
} else {
68+
return Promise { fulfill, reject in
69+
Alamofire.request(Router.getContent(uuid) )
70+
.responseObject { (response: Response<Content, NSError>) in
71+
switch response.result{
72+
case .Success(let data):
73+
self.children = data.children
74+
75+
fulfill(self.children)
76+
case .Failure(let error):
77+
return reject(error)
78+
}
79+
}
80+
}
81+
}
82+
}
83+
84+
/**
85+
Get Url
86+
@return String.
87+
*/
88+
89+
public func getUrl () -> String? {
90+
91+
let rt = auth?.get("restrictedToken") as! String
92+
93+
switch(self.subtype) {
94+
case .FILE:
95+
let escapeUrl = self.document["path"]!.stringByAddingPercentEscapesUsingEncoding(NSUTF8StringEncoding)!
96+
return "\(hostUrl)/api/delivery\(escapeUrl)?_rt=\(rt)"
97+
case .APP:
98+
let escapeUrl = self.document["path"]!.stringByAddingPercentEscapesUsingEncoding(NSUTF8StringEncoding)!
99+
return "\(hostUrl)/api/delivery\(escapeUrl)/index.html?_rt=\(rt)"
100+
case .URL:
101+
return self.document["url"] as? String
102+
default:
103+
return nil
104+
}
105+
}
106+
107+
/**
108+
Get Url to a file variant
109+
@return String.
110+
*/
111+
public func getVariantUrl (name: String) -> String? {
112+
113+
if(CONTENT_TYPES.FILE == self.subtype && hasVariant(name)){
114+
if let url = getUrl() {
115+
let rt = auth?.get("restrictedToken") as! String
116+
let variant = name.stringByAddingPercentEscapesUsingEncoding(NSUTF8StringEncoding)!
117+
return "\(url)?variant=\(variant)&_rt=\(rt)"
118+
}
119+
}
120+
121+
return nil
122+
}
123+
124+
public func hasVariant(name: String) -> Bool {
125+
if let variants = self.document["variants"] as? [[String:AnyObject]] {
126+
for variant in variants {
127+
if(variant["name"] as! String == name){
128+
return true
129+
}
130+
}
131+
}
132+
return false;
133+
}
134+
135+
}

Pod/Classes/ContentNode.swift

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
//
2-
// Content.swift
2+
// ContentNode.swift
33
// Pods
44
//
55
// Created by Cesar on 9/23/15.
@@ -10,6 +10,7 @@ import Foundation
1010
import PromiseKit
1111
import Alamofire
1212

13+
1314
public final class ContentNode: Model,ResponseObject,ResponseCollection {
1415

1516
var children: [ContentNode] = []
@@ -66,7 +67,7 @@ public final class ContentNode: Model,ResponseObject,ResponseCollection {
6667
}
6768
} else {
6869
return Promise { fulfill, reject in
69-
Alamofire.request(Router.getContentNode(uuid) )
70+
Alamofire.request(Router.getContent(uuid) )
7071
.responseObject { (response: Response<ContentNode, NSError>) in
7172
switch response.result{
7273
case .Success(let data):

0 commit comments

Comments
 (0)