Skip to content

Commit

Permalink
Merge pull request #138 from jefft0/fix/go.mod-update-berty-mobile-ve…
Browse files Browse the repository at this point in the history
…rsion
  • Loading branch information
Antoine Eddi authored Oct 17, 2022
2 parents 6e682fd + a7b8143 commit 95c93ae
Show file tree
Hide file tree
Showing 7 changed files with 27 additions and 16 deletions.
2 changes: 1 addition & 1 deletion ios/Bridge/GomobileIPFS/Sources/Config.swift
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ public class Config {
public func get() throws -> [String: Any] {
do {
let rawJson = try self.goConfig.get()
let json = try JSONSerialization.jsonObject(with: rawJson, options: [])
let json = try JSONSerialization.jsonObject(with: rawJson!, options: [])
return (json as? [String: Any])!
} catch let error as NSError {
throw ConfigError("getting failed", error)
Expand Down
8 changes: 5 additions & 3 deletions ios/Bridge/GomobileIPFS/Sources/RequestBuilder.swift
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ public class RequestBuilder {
/// - Throws: `RequestBuilderError`: If sending the request failed
/// - Returns: A Data object containing the response
/// - seealso: [IPFS API Doc](https://docs.ipfs.io/reference/api/http/)
public func send() throws -> Data {
public func send() throws -> Data? {
do {
return try self.requestBuilder.send()
} catch let error as NSError {
Expand All @@ -113,8 +113,10 @@ public class RequestBuilder {
/// - Throws: `RequestBuilderError`: If sending the request or converting the response failed
/// - Returns: A dict containing the response
/// - seealso: [IPFS API Doc](https://docs.ipfs.io/reference/api/http/)
public func sendToDict() throws -> [String: Any] {
let res = try self.requestBuilder.send()
public func sendToDict() throws -> [String: Any]? {
guard let res = try self.requestBuilder.send() else {
return nil
}

do {
let json = try JSONSerialization.jsonObject(with: res, options: [])
Expand Down
5 changes: 4 additions & 1 deletion ios/Bridge/GomobileIPFSTests/BasicIPFSClassTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,10 @@ class BasicIPFSClassTests: XCTestCase {
}

func makeRequest() throws {
let res = try ipfs.newRequest("id").sendToDict()
guard let res = try ipfs.newRequest("id").sendToDict() else {
XCTFail("error while casting dict for \"id\"")
return
}

// TODO: improve these checks
guard let peerID = res["ID"] as? String else {
Expand Down
18 changes: 12 additions & 6 deletions ios/Bridge/GomobileIPFSTests/RequestIPFSTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,18 @@ class RequestIPFSTests: XCTestCase {
func testDNSRequest() throws {
let domain = "website.ipfs.io"

let resolveResp = try ipfs.newRequest("resolve")
guard let resolveResp = try ipfs.newRequest("resolve")
.with(argument: "/ipns/\(domain)")
.sendToDict()
let dnsResp = try ipfs.newRequest("dns")
.sendToDict() else {
XCTFail("error while casting dict for \"resolve\"")
return
}
guard let dnsResp = try ipfs.newRequest("dns")
.with(argument: domain)
.sendToDict()
.sendToDict() else {
XCTFail("error while casting dict for \"dns\"")
return
}

guard let resolvePath = resolveResp["Path"] as? String else {
XCTFail("error while casting value associated to \"Path\" key")
Expand Down Expand Up @@ -61,9 +67,9 @@ class RequestIPFSTests: XCTestCase {
.send()

do {
try JSONSerialization.jsonObject(with: latestRaw, options: [])
try JSONSerialization.jsonObject(with: latestRaw!, options: [])
} catch _ {
XCTFail("error while parsing fetched JSON: \(String(decoding: latestRaw, as: UTF8.self))")
XCTFail("error while parsing fetched JSON: \(String(decoding: latestRaw! , as: UTF8.self))")
}
}
}
4 changes: 2 additions & 2 deletions ios/Example/Example/ViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ class ViewController: UIViewController {
.send()

title = "IPFS File"
image = UIImage(data: fetchedData)!
image = UIImage(data: fetchedData!)!
} catch let err as IPFSError {
error = err.localizedFullDescription
} catch let err {
Expand Down Expand Up @@ -257,7 +257,7 @@ class ViewController: UIViewController {
.send()

title = "\(randomIndex). \(fetchedInfo["title"] as! String)"
image = UIImage(data: fetchedData)!
image = UIImage(data: fetchedData!)!
} catch let err as IPFSError {
error = err.localizedFullDescription
} catch let err {
Expand Down
2 changes: 1 addition & 1 deletion packages/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -243,5 +243,5 @@ require (
replace (
github.com/ipfs-shipyard/gomobile-ipfs/go => ../go
github.com/lucas-clemente/quic-go => github.com/lucas-clemente/quic-go v0.25.0
golang.org/x/mobile => github.com/berty/mobile v0.0.8 // temporary, see https://github.com/golang/mobile/pull/58 and https://github.com/golang/mobile/pull/82
golang.org/x/mobile => github.com/berty/mobile v0.0.9 // temporary, see https://github.com/golang/mobile/pull/58 and https://github.com/golang/mobile/pull/82
)
4 changes: 2 additions & 2 deletions packages/go.sum

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 95c93ae

Please sign in to comment.