Skip to content
This repository has been archived by the owner on Jul 2, 2018. It is now read-only.

Commit

Permalink
Merge branch 'release/1.5.0'
Browse files Browse the repository at this point in the history
  • Loading branch information
danthorpe committed Feb 6, 2016
2 parents 4675ae7 + 12bc978 commit eb5d0a8
Show file tree
Hide file tree
Showing 26 changed files with 16 additions and 2,096 deletions.
2 changes: 1 addition & 1 deletion .jazzy.yaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
author_name: Daniel Thorpe
author_url: http://danthorpe.me
module_name: Money
module_version: 1.4.0
module_version: 1.5.0
github_url: https://github.com/danthorpe/Money
readme: README.md
podspec: Money.podspec
Expand Down
2 changes: 0 additions & 2 deletions Cartfile
Original file line number Diff line number Diff line change
@@ -1,3 +1 @@
github "danthorpe/ValueCoding"
github "antitypical/Result" >= 1.0
github "SwiftyJSON/SwiftyJSON"
1 change: 0 additions & 1 deletion Cartfile.private

This file was deleted.

5 changes: 1 addition & 4 deletions Cartfile.resolved
Original file line number Diff line number Diff line change
@@ -1,4 +1 @@
github "venmo/DVR" "v0.2.0"
github "antitypical/Result" "1.0.1"
github "SwiftyJSON/SwiftyJSON" "2.3.3"
github "danthorpe/ValueCoding" "1.1.1"
github "danthorpe/ValueCoding" "1.2.0"
5 changes: 2 additions & 3 deletions Money.podspec
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Pod::Spec.new do |s|
s.name = "Money"
s.version = "1.4.2"
s.version = "1.5.0"
s.summary = "Swift types for working with Money."
s.description = <<-DESC
Expand Down Expand Up @@ -34,7 +34,6 @@ Pod::Spec.new do |s|
s.tvos.exclude_files = [ 'Money/iOS' ]

s.dependency 'ValueCoding'
s.dependency 'Result'
s.dependency 'SwiftyJSON'

end

158 changes: 5 additions & 153 deletions Money.xcodeproj/project.pbxproj

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion Money.xcodeproj/xcshareddata/xcschemes/Money-OSX.xcscheme
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "0710"
LastUpgradeVersion = "0720"
version = "1.3">
<BuildAction
parallelizeBuildables = "YES"
Expand Down
2 changes: 1 addition & 1 deletion Money.xcodeproj/xcshareddata/xcschemes/Money-iOS.xcscheme
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "0710"
LastUpgradeVersion = "0720"
version = "1.3">
<BuildAction
parallelizeBuildables = "YES"
Expand Down
2 changes: 1 addition & 1 deletion Money.xcodeproj/xcshareddata/xcschemes/Money-tvOS.xcscheme
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "0710"
LastUpgradeVersion = "0720"
version = "1.3">
<BuildAction
parallelizeBuildables = "YES"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "0710"
LastUpgradeVersion = "0720"
version = "1.3">
<BuildAction
parallelizeBuildables = "YES"
Expand Down
142 changes: 0 additions & 142 deletions Money/Shared/FX/Bitcoin.swift
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,6 @@
// SOFTWARE.

import Foundation
import Result
import SwiftyJSON


// MARK: - Bitcoin Currency
Expand Down Expand Up @@ -90,143 +88,3 @@ public typealias XBT = _Money<Currency.XBT>
public typealias BTC = _Money<Currency.BTC>


// MARK - cex.io FX

/**
CEX.io Supported fiat currencies

CEX only supports USD, EUR and RUB.

- see: https://cex.io
*/
public protocol CEXSupportedFiatCurrencyType: ISOCurrencyType {

/**
CEX.io charge a percentage based commission with FX transactions.
- returns: a BankersDecimal representing the % commission.
*/
static var cex_commissionPercentage: BankersDecimal { get }
}

extension Currency.USD: CEXSupportedFiatCurrencyType {

/// - returns: the commission charged for USD transactions, a BankersDecimal
public static let cex_commissionPercentage: BankersDecimal = 0.2
}

extension Currency.EUR: CEXSupportedFiatCurrencyType {

/// - returns: the commission charged for EUR transactions, a BankersDecimal
public static let cex_commissionPercentage: BankersDecimal = 0.2
}

extension Currency.RUB: CEXSupportedFiatCurrencyType {

/// - returns: the commission charged for RUB transactions, a BankersDecimal
public static let cex_commissionPercentage: BankersDecimal = 0
}

struct _CEXBuy<Base: MoneyType where Base.Currency: CEXSupportedFiatCurrencyType>: CryptoCurrencyMarketTransactionType {
typealias BaseMoney = Base
typealias CounterMoney = BTC
typealias FiatCurrency = Base.Currency
static var transactionKind: CurrencyMarketTransactionKind { return .Buy }
}

struct _CEXSell<Counter: MoneyType where Counter.Currency: CEXSupportedFiatCurrencyType>: CryptoCurrencyMarketTransactionType {
typealias BaseMoney = BTC
typealias CounterMoney = Counter
typealias FiatCurrency = Counter.Currency
static var transactionKind: CurrencyMarketTransactionKind { return .Sell }
}

class _CEX<T: CryptoCurrencyMarketTransactionType where T.FiatCurrency: CEXSupportedFiatCurrencyType>: FXRemoteProvider<T.BaseMoney, T.CounterMoney>, FXRemoteProviderType {

static func name() -> String {
return "CEX.IO \(BaseMoney.Currency.code)\(CounterMoney.Currency.code)"
}

static func request() -> NSURLRequest {
let url = NSURL(string: "https://cex.io/api/convert/\(BTC.Currency.code)/\(T.FiatCurrency.code)")
let request = NSMutableURLRequest(URL: url!)
request.HTTPMethod = "POST"
request.setValue("application/json", forHTTPHeaderField: "Content-Type")
let data = try! JSON(["amnt": Double(1.0)]).rawData()
request.HTTPBody = data
return request
}

static func quoteFromNetworkResult(result: Result<(NSData?, NSURLResponse?), NSError>) -> Result<FXQuote, FXError> {
return result.analysis(

ifSuccess: { data, response in

guard let data = data else {
return Result(error: .NoData)
}

let json = JSON(data: data)

if json.isEmpty {
return Result(error: .InvalidData(data))
}

guard let rateLiteral = json["amnt"].double else {
return Result(error: .RateNotFound(name()))
}

let rate: BankersDecimal

switch T.transactionKind {
case .Buy:
rate = BankersDecimal(floatLiteral: rateLiteral).reciprocal
case .Sell:
rate = BankersDecimal(floatLiteral: rateLiteral)
}

return Result(value: FXQuote(rate: rate, percentage: T.FiatCurrency.cex_commissionPercentage))
},

ifFailure: { error in
return Result(error: .NetworkError(error))
}
)
}
}

/**
Represents the purchase of bitcoin using CEX.io.

Usage is entirely type based - there is nothing to initialize. It is
generic over USD, EUR or RUB, no other currency types. For example.

```swift
CEXBuy<USD>.quote(1_000) { transaction in
// etc.
}
```

The above sample represents buying US$1,000 worth of BTC using CEX.io.
*/
public final class CEXBuy<Base: MoneyType where Base.Currency: CEXSupportedFiatCurrencyType>: _CEX<_CEXBuy<Base>> { }

/**
Represents the sale of bitcoin using CEX.io.

Usage is entirely type based - there is nothing to initialize. It is
generic over USD, EUR or RUB, no other currency types. For example.

```swift
CEXBuy<EUR>.quote(10) { transaction in
// etc.
}
```

The above sample represents selling 10 bitcoins for euros using CEX.io.
*/
public final class CEXSell<Counter: MoneyType where Counter.Currency: CEXSupportedFiatCurrencyType>: _CEX<_CEXSell<Counter>> { }





Loading

0 comments on commit eb5d0a8

Please sign in to comment.