Skip to content

Commit 16545b9

Browse files
committed
Merge branch 'release/0.2.0'
2 parents 865d0c2 + 3f32bbc commit 16545b9

18 files changed

Lines changed: 697 additions & 221 deletions

Example/Example/AppDelegate.swift

Lines changed: 54 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,43 @@ import Quartz
1313
@NSApplicationMain
1414
class AppDelegate: NSObject, NSApplicationDelegate {
1515

16+
let keyPairName = "My Test Keypair"
1617
let fileURL = Bundle.main.url(forResource: "The Cathedral and the Bazaar", withExtension: ".pdf")!
1718

1819
func applicationDidFinishLaunching(_ aNotification: Notification) {
19-
testUpload(of: fileURL)
20+
testKeyPairCreation()
21+
}
22+
23+
private func testKeyPairCreation() {
24+
print("Creating IPNS keypair...\n")
25+
26+
DefaultAPI.keygen(arg: keyPairName, type: .rsa, size: 2048) { (response, error) in
27+
if let error = error {
28+
fatalError("\(error)")
29+
} else if let response = response {
30+
print("Keypair created.\n")
31+
print(" Type: rsa\n Size: 2048 bits\n Name: \(response.name!)\n ID: \(response.id!)\n")
32+
self.testKeyPairRetrieval()
33+
}
34+
}
35+
}
36+
37+
private func testKeyPairRetrieval() {
38+
print("Retrieving list of local keypairs...\n")
39+
40+
DefaultAPI.listKeys { (response, error) in
41+
if let error = error {
42+
fatalError("\(error)")
43+
} else if let response = response {
44+
print("Keypairs found.")
45+
for key in response.keys! {
46+
print(" \"\(key.name!)\": \(key.id!)")
47+
}
48+
print("")
49+
50+
self.testUpload(of: self.fileURL)
51+
}
52+
}
2053
}
2154

2255
private func testUpload(of file: URL) {
@@ -33,9 +66,9 @@ class AppDelegate: NSObject, NSApplicationDelegate {
3366
}
3467

3568
private func testPublish(of hash: String) {
36-
print("Publishing file...\n")
69+
print("Publishing file under key \"\(keyPairName)\"...\n")
3770

38-
DefaultAPI.publish(arg: hash) { (response, error) in
71+
DefaultAPI.publish(arg: hash, key: keyPairName) { (response, error) in
3972
if let error = error {
4073
fatalError("\(error)")
4174
} else if let response = response {
@@ -85,6 +118,24 @@ class AppDelegate: NSObject, NSApplicationDelegate {
85118
} else {
86119
print("File compared to local counterpart.\n Is PDF with same number of pages: ❌\n")
87120
}
121+
122+
testKeyPairRemoval()
123+
}
124+
125+
private func testKeyPairRemoval() {
126+
print("Removing keypair \"\(keyPairName)\"...\n")
127+
128+
DefaultAPI.removeKey(arg: keyPairName) { (response, error) in
129+
if let error = error {
130+
fatalError("\(error)")
131+
} else if let response = response {
132+
print("Keypair removed.")
133+
for key in response.keys! {
134+
print(" \"\(key.name!)\": \(key.id!)")
135+
}
136+
print("")
137+
}
138+
}
88139
}
89140

90141
}

Example/Podfile.lock

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
PODS:
22
- Alamofire (4.5.1)
3-
- IPFSWebService (0.0.1):
3+
- IPFSWebService (0.1.0):
44
- Alamofire (~> 4.5)
55

66
DEPENDENCIES:
@@ -13,7 +13,7 @@ EXTERNAL SOURCES:
1313

1414
SPEC CHECKSUMS:
1515
Alamofire: 2d95912bf4c34f164fdfc335872e8c312acaea4a
16-
IPFSWebService: 071512e3f63435706f5a56c19576d67962a4a157
16+
IPFSWebService: 0854391521e5f506aa2b716a54fb0cc0a6a357ed
1717

1818
PODFILE CHECKSUM: 61ed0b4ea744697cba534ae39b8006c4b4575530
1919

Example/Pods/Local Podspecs/IPFSWebService.podspec.json

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

Example/Pods/Manifest.lock

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

Example/Pods/Pods.xcodeproj/project.pbxproj

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

Example/Pods/Target Support Files/IPFSWebService/Info.plist

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

IPFSWebService.podspec

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
Pod::Spec.new do |s|
22
s.name = 'IPFSWebService'
3-
s.version = '0.1.0'
3+
s.version = '0.2.0'
44
s.summary = 'Defines and versions the HTTP based IPFS interface.'
55
s.description = <<-DESC
66
The API for communication with an IPFS server is defined and versioned by

SwaggerClient/Classes/Swaggers/APIs/DefaultAPI.swift

Lines changed: 122 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,90 @@ open class DefaultAPI: APIBase {
9393
return requestBuilder.init(method: "GET", URLString: (url?.string ?? URLString), parameters: parameters, isBody: false)
9494
}
9595

96+
/**
97+
* enum for parameter type
98+
*/
99+
public enum ModelType_keygen: String {
100+
case rsa = "rsa"
101+
case ed25519 = "ed25519"
102+
}
103+
104+
/**
105+
Create a new keypair
106+
107+
- parameter arg: (query) Name of key to create.
108+
- parameter type: (query) Type of the key to create.
109+
- parameter size: (query) Size of the key to generate
110+
- parameter completion: completion handler to receive the data and the error objects
111+
*/
112+
open class func keygen(arg: String, type: ModelType_keygen, size: Int32, completion: @escaping ((_ data: KeygenResponse?,_ error: Error?) -> Void)) {
113+
keygenWithRequestBuilder(arg: arg, type: type, size: size).execute { (response, error) -> Void in
114+
completion(response?.body, error);
115+
}
116+
}
117+
118+
119+
/**
120+
Create a new keypair
121+
- GET /key/gen
122+
- examples: [{contentType=application/json, example=""}]
123+
124+
- parameter arg: (query) Name of key to create.
125+
- parameter type: (query) Type of the key to create.
126+
- parameter size: (query) Size of the key to generate
127+
128+
- returns: RequestBuilder<KeygenResponse>
129+
*/
130+
open class func keygenWithRequestBuilder(arg: String, type: ModelType_keygen, size: Int32) -> RequestBuilder<KeygenResponse> {
131+
let path = "/key/gen"
132+
let URLString = SwaggerClientAPI.basePath + path
133+
let parameters: [String:Any]? = nil
134+
135+
let url = NSURLComponents(string: URLString)
136+
url?.queryItems = APIHelper.mapValuesToQueryItems(values:[
137+
"arg": arg,
138+
"type": type.rawValue,
139+
"size": size.encodeToJSON()
140+
])
141+
142+
143+
let requestBuilder: RequestBuilder<KeygenResponse>.Type = SwaggerClientAPI.requestBuilderFactory.getBuilder()
144+
145+
return requestBuilder.init(method: "GET", URLString: (url?.string ?? URLString), parameters: parameters, isBody: false)
146+
}
147+
148+
/**
149+
List all local keypairs
150+
151+
- parameter completion: completion handler to receive the data and the error objects
152+
*/
153+
open class func listKeys(completion: @escaping ((_ data: ListKeysResponse?,_ error: Error?) -> Void)) {
154+
listKeysWithRequestBuilder().execute { (response, error) -> Void in
155+
completion(response?.body, error);
156+
}
157+
}
158+
159+
160+
/**
161+
List all local keypairs
162+
- GET /key/list
163+
- examples: [{contentType=application/json, example=""}]
164+
165+
- returns: RequestBuilder<ListKeysResponse>
166+
*/
167+
open class func listKeysWithRequestBuilder() -> RequestBuilder<ListKeysResponse> {
168+
let path = "/key/list"
169+
let URLString = SwaggerClientAPI.basePath + path
170+
let parameters: [String:Any]? = nil
171+
172+
let url = NSURLComponents(string: URLString)
173+
174+
175+
let requestBuilder: RequestBuilder<ListKeysResponse>.Type = SwaggerClientAPI.requestBuilderFactory.getBuilder()
176+
177+
return requestBuilder.init(method: "GET", URLString: (url?.string ?? URLString), parameters: parameters, isBody: false)
178+
}
179+
96180
/**
97181
IPNS is a PKI namespace, where names are the hashes of public keys, and the private key enables publishing new (signed) values. In both publish and resolve, the default name used is the node's own PeerID, which is the hash of its public key.
98182

@@ -137,6 +221,44 @@ open class DefaultAPI: APIBase {
137221
return requestBuilder.init(method: "GET", URLString: (url?.string ?? URLString), parameters: parameters, isBody: false)
138222
}
139223

224+
/**
225+
List all local keypairs
226+
227+
- parameter arg: (query) Name of key to remove.
228+
- parameter completion: completion handler to receive the data and the error objects
229+
*/
230+
open class func removeKey(arg: String, completion: @escaping ((_ data: RemoveKeyResponse?,_ error: Error?) -> Void)) {
231+
removeKeyWithRequestBuilder(arg: arg).execute { (response, error) -> Void in
232+
completion(response?.body, error);
233+
}
234+
}
235+
236+
237+
/**
238+
List all local keypairs
239+
- GET /key/rm
240+
- examples: [{contentType=application/json, example=""}]
241+
242+
- parameter arg: (query) Name of key to remove.
243+
244+
- returns: RequestBuilder<RemoveKeyResponse>
245+
*/
246+
open class func removeKeyWithRequestBuilder(arg: String) -> RequestBuilder<RemoveKeyResponse> {
247+
let path = "/key/rm"
248+
let URLString = SwaggerClientAPI.basePath + path
249+
let parameters: [String:Any]? = nil
250+
251+
let url = NSURLComponents(string: URLString)
252+
url?.queryItems = APIHelper.mapValuesToQueryItems(values:[
253+
"arg": arg
254+
])
255+
256+
257+
let requestBuilder: RequestBuilder<RemoveKeyResponse>.Type = SwaggerClientAPI.requestBuilderFactory.getBuilder()
258+
259+
return requestBuilder.init(method: "GET", URLString: (url?.string ?? URLString), parameters: parameters, isBody: false)
260+
}
261+
140262
/**
141263
IPNS is a PKI namespace, where names are the hashes of public keys, and the private key enables publishing new (signed) values. In both publish and resolve, the default name used is the node's own PeerID, which is the hash of its public key.
142264

SwaggerClient/Classes/Swaggers/Models.swift

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,35 @@ class Decoders {
166166
}
167167

168168

169+
// Decoder for [Key]
170+
Decoders.addDecoder(clazz: [Key].self) { (source: AnyObject, instance: AnyObject?) -> [Key] in
171+
return Decoders.decode(clazz: [Key].self, source: source)
172+
}
173+
// Decoder for Key
174+
Decoders.addDecoder(clazz: Key.self) { (source: AnyObject, instance: AnyObject?) -> Key in
175+
let sourceDictionary = source as! [AnyHashable: Any]
176+
let result = instance == nil ? Key() : instance as! Key
177+
178+
result.name = Decoders.decodeOptional(clazz: String.self, source: sourceDictionary["Name"] as AnyObject?)
179+
result.id = Decoders.decodeOptional(clazz: String.self, source: sourceDictionary["Id"] as AnyObject?)
180+
return result
181+
}
182+
183+
184+
// Decoder for [KeyList]
185+
Decoders.addDecoder(clazz: [KeyList].self) { (source: AnyObject, instance: AnyObject?) -> [KeyList] in
186+
return Decoders.decode(clazz: [KeyList].self, source: source)
187+
}
188+
// Decoder for KeyList
189+
Decoders.addDecoder(clazz: KeyList.self) { (source: AnyObject, instance: AnyObject?) -> KeyList in
190+
let sourceDictionary = source as! [AnyHashable: Any]
191+
let result = instance == nil ? KeyList() : instance as! KeyList
192+
193+
result.keys = Decoders.decodeOptional(clazz: Array.self, source: sourceDictionary["Keys"] as AnyObject?)
194+
return result
195+
}
196+
197+
169198
// Decoder for [PublishResponse]
170199
Decoders.addDecoder(clazz: [PublishResponse].self) { (source: AnyObject, instance: AnyObject?) -> [PublishResponse] in
171200
return Decoders.decode(clazz: [PublishResponse].self, source: source)
@@ -193,6 +222,49 @@ class Decoders {
193222
result.path = Decoders.decodeOptional(clazz: String.self, source: sourceDictionary["Path"] as AnyObject?)
194223
return result
195224
}
225+
226+
227+
// Decoder for [KeygenResponse]
228+
Decoders.addDecoder(clazz: [KeygenResponse].self) { (source: AnyObject, instance: AnyObject?) -> [KeygenResponse] in
229+
return Decoders.decode(clazz: [KeygenResponse].self, source: source)
230+
}
231+
// Decoder for KeygenResponse
232+
Decoders.addDecoder(clazz: KeygenResponse.self) { (source: AnyObject, instance: AnyObject?) -> KeygenResponse in
233+
let sourceDictionary = source as! [AnyHashable: Any]
234+
let result = instance == nil ? KeygenResponse() : instance as! KeygenResponse
235+
236+
result.name = Decoders.decodeOptional(clazz: String.self, source: sourceDictionary["Name"] as AnyObject?)
237+
result.id = Decoders.decodeOptional(clazz: String.self, source: sourceDictionary["Id"] as AnyObject?)
238+
return result
239+
}
240+
241+
242+
// Decoder for [ListKeysResponse]
243+
Decoders.addDecoder(clazz: [ListKeysResponse].self) { (source: AnyObject, instance: AnyObject?) -> [ListKeysResponse] in
244+
return Decoders.decode(clazz: [ListKeysResponse].self, source: source)
245+
}
246+
// Decoder for ListKeysResponse
247+
Decoders.addDecoder(clazz: ListKeysResponse.self) { (source: AnyObject, instance: AnyObject?) -> ListKeysResponse in
248+
let sourceDictionary = source as! [AnyHashable: Any]
249+
let result = instance == nil ? ListKeysResponse() : instance as! ListKeysResponse
250+
251+
result.keys = Decoders.decodeOptional(clazz: Array.self, source: sourceDictionary["Keys"] as AnyObject?)
252+
return result
253+
}
254+
255+
256+
// Decoder for [RemoveKeyResponse]
257+
Decoders.addDecoder(clazz: [RemoveKeyResponse].self) { (source: AnyObject, instance: AnyObject?) -> [RemoveKeyResponse] in
258+
return Decoders.decode(clazz: [RemoveKeyResponse].self, source: source)
259+
}
260+
// Decoder for RemoveKeyResponse
261+
Decoders.addDecoder(clazz: RemoveKeyResponse.self) { (source: AnyObject, instance: AnyObject?) -> RemoveKeyResponse in
262+
let sourceDictionary = source as! [AnyHashable: Any]
263+
let result = instance == nil ? RemoveKeyResponse() : instance as! RemoveKeyResponse
264+
265+
result.keys = Decoders.decodeOptional(clazz: Array.self, source: sourceDictionary["Keys"] as AnyObject?)
266+
return result
267+
}
196268
}()
197269

198270
static fileprivate func initialize() {

SwaggerClient/Classes/Swaggers/Models/AddResponse.swift

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
import Foundation
99

1010

11-
/** The object which represents a response from the server. */
1211
open class AddResponse: JSONEncodable {
1312

1413
public var name: String?

0 commit comments

Comments
 (0)