mirror of
https://github.com/zerotier/ZeroTierOne.git
synced 2024-12-22 14:22:23 +00:00
beginning of communicating with the zero tier service
This commit is contained in:
parent
40198d6c13
commit
da30d2898e
@ -7,6 +7,7 @@
|
||||
objects = {
|
||||
|
||||
/* Begin PBXBuildFile section */
|
||||
9330F1351CEAB4C400687EC8 /* ServiceCom.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9330F1341CEAB4C400687EC8 /* ServiceCom.swift */; };
|
||||
93326BDC1CE7C816005CA2AC /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 93326BDB1CE7C816005CA2AC /* AppDelegate.swift */; };
|
||||
93326BDE1CE7C816005CA2AC /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 93326BDD1CE7C816005CA2AC /* Assets.xcassets */; };
|
||||
93326BE11CE7C816005CA2AC /* MainMenu.xib in Resources */ = {isa = PBXBuildFile; fileRef = 93326BDF1CE7C816005CA2AC /* MainMenu.xib */; };
|
||||
@ -17,6 +18,7 @@
|
||||
/* End PBXBuildFile section */
|
||||
|
||||
/* Begin PBXFileReference section */
|
||||
9330F1341CEAB4C400687EC8 /* ServiceCom.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ServiceCom.swift; sourceTree = "<group>"; };
|
||||
93326BD81CE7C816005CA2AC /* ZeroTier One.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = "ZeroTier One.app"; sourceTree = BUILT_PRODUCTS_DIR; };
|
||||
93326BDB1CE7C816005CA2AC /* AppDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppDelegate.swift; sourceTree = "<group>"; };
|
||||
93326BDD1CE7C816005CA2AC /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = "<group>"; };
|
||||
@ -61,6 +63,7 @@
|
||||
93326BDB1CE7C816005CA2AC /* AppDelegate.swift */,
|
||||
93326BE81CE7D9B9005CA2AC /* JoinNetworkViewController.swift */,
|
||||
93326BEC1CE7DA30005CA2AC /* ShowNetworksViewController.swift */,
|
||||
9330F1341CEAB4C400687EC8 /* ServiceCom.swift */,
|
||||
93326BDD1CE7C816005CA2AC /* Assets.xcassets */,
|
||||
93326BDF1CE7C816005CA2AC /* MainMenu.xib */,
|
||||
93326BE21CE7C816005CA2AC /* Info.plist */,
|
||||
@ -145,6 +148,7 @@
|
||||
93326BDC1CE7C816005CA2AC /* AppDelegate.swift in Sources */,
|
||||
93326BEA1CE7D9B9005CA2AC /* JoinNetworkViewController.swift in Sources */,
|
||||
93326BEE1CE7DA30005CA2AC /* ShowNetworksViewController.swift in Sources */,
|
||||
9330F1351CEAB4C400687EC8 /* ServiceCom.swift in Sources */,
|
||||
);
|
||||
runOnlyForDeploymentPostprocessing = 0;
|
||||
};
|
||||
|
@ -2,6 +2,11 @@
|
||||
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
|
||||
<plist version="1.0">
|
||||
<dict>
|
||||
<key>NSAppTransportSecurity</key>
|
||||
<dict>
|
||||
<key>NSAllowsArbitraryLoads</key>
|
||||
<true/>
|
||||
</dict>
|
||||
<key>LSUIElement</key>
|
||||
<true/>
|
||||
<key>CFBundleDevelopmentRegion</key>
|
||||
|
97
ZeroTier One/ServiceCom.swift
Normal file
97
ZeroTier One/ServiceCom.swift
Normal file
@ -0,0 +1,97 @@
|
||||
//
|
||||
// ServiceCom.swift
|
||||
// ZeroTier One
|
||||
//
|
||||
// Created by Grant Limberg on 5/16/16.
|
||||
// Copyright © 2016 ZeroTier, Inc. All rights reserved.
|
||||
//
|
||||
|
||||
import Cocoa
|
||||
|
||||
class ServiceCom: NSObject {
|
||||
static let baseURL = "http://localhost:9993"
|
||||
static var key: NSString? = "ddeb3b1e6996b6b4f2d12d10"
|
||||
|
||||
static func getNetworkList() {
|
||||
|
||||
let urlString = baseURL + "/network?auth=\(ServiceCom.key!)"
|
||||
|
||||
let url = NSURL(string: urlString)
|
||||
|
||||
if let u = url {
|
||||
let request = NSMutableURLRequest(URL: u)
|
||||
let session = NSURLSession.sharedSession()
|
||||
let task = session.dataTaskWithRequest(request) { (data, response, error) in
|
||||
let httpResponse = response as! NSHTTPURLResponse
|
||||
let status = httpResponse.statusCode
|
||||
|
||||
if status == 200 {
|
||||
do {
|
||||
let json = try NSJSONSerialization.JSONObjectWithData(data!, options: NSJSONReadingOptions())
|
||||
print("\(json)")
|
||||
}
|
||||
catch {
|
||||
print("JSON Error: \(error)")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
task.resume()
|
||||
}
|
||||
else {
|
||||
print("bad URL")
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
static func joinNetwork(network: String) {
|
||||
let urlString = baseURL + "/network/\(network)?auth=\(ServiceCom.key!)"
|
||||
let url = NSURL(string: urlString)
|
||||
|
||||
if let u = url {
|
||||
let request = NSMutableURLRequest(URL: u)
|
||||
request.HTTPMethod = "POST"
|
||||
|
||||
let session = NSURLSession.sharedSession()
|
||||
let task = session.dataTaskWithRequest(request) { (data, response, error) in
|
||||
let httpResponse = response as! NSHTTPURLResponse
|
||||
let status = httpResponse.statusCode
|
||||
|
||||
if status == 200 {
|
||||
print("join ok")
|
||||
}
|
||||
else {
|
||||
print("join error: \(status)")
|
||||
}
|
||||
}
|
||||
|
||||
task.resume()
|
||||
}
|
||||
}
|
||||
|
||||
static func leaveNetwork(network: String) {
|
||||
let urlString = baseURL + "/network/\(network)?auth=\(ServiceCom.key!)"
|
||||
let url = NSURL(string: urlString)
|
||||
|
||||
if let u = url {
|
||||
let request = NSMutableURLRequest(URL: u)
|
||||
request.HTTPMethod = "DELETE"
|
||||
|
||||
let session = NSURLSession.sharedSession()
|
||||
let task = session.dataTaskWithRequest(request) { (data, response, error) in
|
||||
let httpResponse = response as! NSHTTPURLResponse
|
||||
let status = httpResponse.statusCode
|
||||
|
||||
if status == 200 {
|
||||
print("leave ok")
|
||||
}
|
||||
else {
|
||||
print("leave error: \(status)")
|
||||
}
|
||||
}
|
||||
|
||||
task.resume()
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@ -16,5 +16,11 @@ class ShowNetworksViewController: NSViewController {
|
||||
super.viewDidLoad()
|
||||
// Do view setup here.
|
||||
}
|
||||
|
||||
override func viewWillAppear() {
|
||||
super.viewWillAppear()
|
||||
|
||||
ServiceCom.getNetworkList()
|
||||
}
|
||||
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user