Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add reserve model #14

Merged
merged 3 commits into from
Nov 10, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions Source/Client/UpholdClient.swift
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,15 @@ public class UpholdClient: Client {
self.baseUrl(GlobalConfigurations.UPHOLD_API_URL)
}

/**
Gets the reserve object.

- returns: The reserve object.
*/
public func getReserve() -> Reserve {
return Reserve()
}

/**
Gets all the exchange rates for all currency pairs.

Expand Down
59 changes: 59 additions & 0 deletions Source/Model/Reserve.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
import Foundation
import PromiseKit

/// Reserve model.
public class Reserve: BaseModel {

/**
Gets the ledger.

- parameter start: The start position for the range.
- parameter end: The end position for the range.

- returns: A promise with the array of deposits.
*/
public func getLedger(start: Int, end: Int) -> Promise<[Deposit]> {
let request = self.adapter.buildRequest(ReserveService.getLedger(Header.buildRangeHeader(start, end: end)))

return self.adapter.buildResponse(request)
}

/**
Gets the reserve summary of all the obligations and assets within it.

- returns: A promise with the reserve summary of all the obligations and assets within it.
*/
public func getStatistics() -> Promise<[ReserveStatistics]> {
let request = self.adapter.buildRequest(ReserveService.getStatistics())

return self.adapter.buildResponse(request)
}

/**
Gets the information of any transaction.

- parameter transactionId: The id of the transaction.

- returns: A promise with the transaction.
*/
public func getTransactionById(transactionId: String) -> Promise<Transaction> {
let request = self.adapter.buildRequest(ReserveService.getReserveTransactionById(transactionId))

return self.adapter.buildResponse(request)
}

/**
Gets information of all the transactions from the beginning of time.

- parameter start: The start position for the range.
- parameter end: The end position for the range.

- returns: A promise with the array of transactions.
*/
public func getTransactions(start: Int, end: Int) -> Promise<[Transaction]> {
let request = self.adapter.buildRequest(ReserveService.getReserveTransactions(Header.buildRangeHeader(start, end: end)))

return self.adapter.buildResponse(request)
}

}
60 changes: 60 additions & 0 deletions Source/Model/Reserve/Deposit.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
import Foundation
import ObjectMapper

/// Deposit model.
public class Deposit: Mappable {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sort the parameters and the constructor.


/// The date when the transaction was created.
public private(set) var createdAt: String?

/// The deposit in movement.
public private(set) var input: DepositMovement?

/// The deposit out movement.
public private(set) var output: DepositMovement?

/// The id of the transaction.
public private(set) var transactionId: String?

/// The type of the deposit.
public private(set) var type: String?

/**
Constructor.

- parameter createdAt: The date when the transaction was created.
- parameter input: The deposit in movement.
- parameter output: The deposit out movement.
- parameter transactionId: The id of the transaction.
- parameter type: The type of the deposit.
*/
public init(createdAt: String, input: DepositMovement, output: DepositMovement, transactionId: String, type: String) {
self.createdAt = createdAt
self.input = input
self.output = output
self.transactionId = transactionId
self.type = type
}

// MARK: Required by the ObjectMapper.

/**
Constructor.
*/
required public init?(_ map: Map) {
}

/**
Maps the JSON to the Object.

- parameter map: The object to map.
*/
public func mapping(map: Map) {
self.createdAt <- map["createdAt"]
self.input <- map["in"]
self.output <- map["out"]
self.transactionId <- map["TransactionId"]
self.type <- map["type"]
}

}
42 changes: 42 additions & 0 deletions Source/Model/Reserve/DepositMovement.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
import Foundation
import ObjectMapper

/// DepositMovement model.
public class DepositMovement: Mappable {

/// The amount of the deposit movement.
public private(set) var amount: String?

/// The currency of the deposit movement.
public private(set) var currency: String?

/**
Constructor.

- parameter amount: The amount of the deposit movement.
- parameter currency: The currency of the deposit movement.
*/
public init(amount: String, currency: String) {
self.amount = amount
self.currency = currency
}

// MARK: Required by the ObjectMapper.

/**
Constructor.
*/
required public init?(_ map: Map) {
}

/**
Maps the JSON to the Object.

- parameter map: The object to map.
*/
public func mapping(map: Map) {
self.amount <- map["amount"]
self.currency <- map["currency"]
}

}
48 changes: 48 additions & 0 deletions Source/Model/Reserve/ReserveStatistics.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
import Foundation
import ObjectMapper

/// ReserveStatistics model.
public class ReserveStatistics: Mappable {

/// The currency from the reserve.
public private(set) var currency: String?

/// The commissions, transaction volume, assets and liabilities.
public private(set) var totals: Total?

/// The value of held in the associated currency in all supported forms.
public private(set) var values: [Value]?

/**
Constructor.

- parameter currency: The currency from the reserve.
- parameter totals: The commissions, transaction volume, assets and liabilities.
- parameter values: The value of held in the associated currency in all supported forms.
*/
public init(currency: String, totals: Total, values: [Value]) {
self.currency = currency
self.totals = totals
self.values = values
}

// MARK: Required by the ObjectMapper.

/**
Constructor.
*/
required public init?(_ map: Map) {
}

/**
Maps the JSON to the Object.

- parameter map: The object to map.
*/
public func mapping(map: Map) {
self.currency <- map["currency"]
self.totals <- map["totals"]
self.values <- map["values"]
}

}
54 changes: 54 additions & 0 deletions Source/Model/Reserve/Total.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
import Foundation
import ObjectMapper

/// Total model.
public class Total: Mappable {

/// The assets from the corresponding holding.
public private(set) var assets: String?

/// The commission from the corresponding holding.
public private(set) var commissions: String?

/// The liabilities from the corresponding holding.
public private(set) var liabilities: String?

/// The transactions from the corresponding holding.
public private(set) var transactions: String?

/**
Constructor.

- parameter assets: The assets from the corresponding holding.
- parameter commissions: The commission from the corresponding holding.
- parameter liabilities: The liabilities from the corresponding holding.
- parameter transactions: The transactions from the corresponding holding.
*/
public init(assets: String, commissions: String, liabilities: String, transactions: String) {
self.assets = assets
self.commissions = commissions
self.liabilities = liabilities
self.transactions = transactions
}

// MARK: Required by the ObjectMapper.

/**
Constructor.
*/
required public init?(_ map: Map) {
}

/**
Maps the JSON to the Object.

- parameter map: The object to map.
*/
public func mapping(map: Map) {
self.assets <- map["assets"]
self.commissions <- map["commissions"]
self.liabilities <- map["liabilities"]
self.transactions <- map["transactions"]
}

}
54 changes: 54 additions & 0 deletions Source/Model/Reserve/Value.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
import Foundation
import ObjectMapper

/// Value model.
public class Value: Mappable {

/// The quantity of assets held for the corresponding holding, but converted to a different currency.
public private(set) var assets: String?

/// The currency we are computing the current holding in.
public private(set) var currency: String?

/// The quantity of liabilities for the corresponding holding, but converted to a different currency.
public private(set) var liabilities: String?

/// The rate we used when computing the holding to the corresponding currency.
public private(set) var rate: String?

/**
Constructor.

- parameter assets: The quantity of assets held for the corresponding holding, but converted to a different currency.
- parameter currency: The currency we are computing the current holding in.
- parameter liabilities: The quantity of liabilities for the corresponding holding, but converted to a different currency.
- parameter rate: The rate we used when computing the holding to the corresponding currency.
*/
public init(assets: String, currency: String, liabilities: String, rate: String) {
self.assets = assets
self.currency = currency
self.liabilities = liabilities
self.rate = rate
}

// MARK: Required by the ObjectMapper.

/**
Constructor.
*/
required public init?(_ map: Map) {
}

/**
Maps the JSON to the Object.

- parameter map: The object to map.
*/
public func mapping(map: Map) {
self.assets <- map["assets"]
self.currency <- map["currency"]
self.liabilities <- map["liabilities"]
self.rate <- map["rate"]
}

}
12 changes: 12 additions & 0 deletions Source/Util/Header.swift
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,18 @@ import SwiftClient
/// Header util class.
public class Header {

/**
Builds a string with the range header.

- parameter start: The position of the first element.
- parameter end: The position of the last element.

- returns: The string with the header value.
*/
public static func buildRangeHeader(start: Int, end: Int) -> String {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please add a test to this function.

return String(format: "items=%i-%i", start, end)
}

/**
Gets the default headers.

Expand Down
Loading