-
Notifications
You must be signed in to change notification settings - Fork 14
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
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
import Foundation | ||
import ObjectMapper | ||
|
||
/// Deposit model. | ||
public class Deposit: Mappable { | ||
|
||
/// 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"] | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"] | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"] | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"] | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"] | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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 { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. | ||
|
||
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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.