fix url structure and response feedback

pull/11/head
James Sangalli 7 years ago
parent a95c50a587
commit 2b00f64ad3
  1. 26
      Trust/Market/OrdersRequest.swift
  2. 2
      TrustTests/Market/OrderRequestTest.swift

@ -29,10 +29,12 @@ public class OrdersRequest {
}
//only have to give first order to server then pad the signatures
public func giveOrderToServer(signedOrders : [SignedOrder], publicKeyb64: String,
public func giveOrderToServer(signedOrders : [SignedOrder], publicKey: String,
callback: @escaping (_ result: Any) -> Void)
{
let query : String = baseURL + "/public-key/" + publicKeyb64
let query : String = baseURL + "public-key/" + publicKey + "?start=" +
signedOrders[0].order.start.description + ";count="
+ signedOrders[0].order.count.description
var data: [UInt8] = signedOrders[0].message.array
for i in 0...signedOrders.count - 1 {
@ -42,8 +44,6 @@ public class OrdersRequest {
}
let parameters : Parameters = [
"count" : signedOrders[0].order.start.description,
"start" : signedOrders[0].order.count.description,
"data": data
]
@ -52,10 +52,20 @@ public class OrdersRequest {
]
Alamofire.request(query, method: .put, parameters: parameters,
encoding: JSONEncoding.default, headers: headers).response
{
cb in
callback(cb)
encoding: JSONEncoding.default, headers: headers).responseJSON {
response in
print("Request: \(String(describing: response.request))") // original url request
print("Response: \(String(describing: response.response))") // http url response
print("Result: \(response.result)") // response serialization result
if let json = response.result.value {
print("JSON: \(json)") // serialized json response
callback(json)
}
if let data = response.data, let utf8Text = String(data: data, encoding: .utf8) {
print("Data: \(utf8Text)") // original server data as UTF8 string
}
}
}

@ -54,7 +54,7 @@ class OrderRequestTest : XCTestCase {
let publicKey = try! Secp256k1.shared.pubKeyFromPrivateKey(from:
privateKey.dematerialize()).hexString
OrdersRequest.init().giveOrderToServer(signedOrders: signedOrders, publicKeyb64: publicKey, callback: {
OrdersRequest.init().giveOrderToServer(signedOrders: signedOrders, publicKey: publicKey, callback: {
callback in
print(callback)
expectation.fulfill()

Loading…
Cancel
Save