Skip to content

Commit

Permalink
Merge pull request #40 from uphold/feature/create-card-with-settings
Browse files Browse the repository at this point in the history
Add card settings to the card request model
  • Loading branch information
ruipenso committed Apr 15, 2016
2 parents 2f2ebe0 + b694e7d commit fd8b4c0
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 0 deletions.
15 changes: 15 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,21 @@ user.getCards().then { (cards: [Card]) -> () in
}
```

### Create a new card for the user

```swift
let cardRequest: CardRequest = CardRequest(currency: "foo", label: "BTC", settings: CardSettings(position: 1, starred: true))

// Or just create a card without specifying the card settings.
// let cardRequest: CardRequest = CardRequest(currency: "foo", label: "BTC")

user.createCard(cardRequest).then { (card: Card) -> () in
/// Do something with the card.
}.error { (error: ErrorType) -> Void in
/// Do something with the error.
}
```

### Get ticker

```swift
Expand Down
17 changes: 17 additions & 0 deletions Source/Model/Card/CardRequest.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@ public class CardRequest: Mappable {
/// The label of the card.
public private(set) final var label: String?

/// The card settings.
public private(set) final var settings: CardSettings?

/**
Constructor.

Expand All @@ -21,6 +24,19 @@ public class CardRequest: Mappable {
self.label = label
}

/**
Constructor.

- parameter currency: The currency of the card.
- parameter label: The label of the card.
- parameter settings: The settings of the card.
*/
public init(currency: String, label: String, settings: CardSettings) {
self.currency = currency
self.label = label
self.settings = settings
}

// MARK: Required by the ObjectMapper.

/**
Expand All @@ -39,6 +55,7 @@ public class CardRequest: Mappable {
public func mapping(map: Map) {
currency <- map["currency"]
label <- map["label"]
settings <- map["settings"]
}

}
15 changes: 15 additions & 0 deletions Tests/Integration/Model/UserTest.swift
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,21 @@ class UserTest: UpholdTestCase {
wait()
}

func testCreateCardWithSettingsShouldReturnTheCard() {
let cardSettings: CardSettings = CardSettings(position: 1, starred: true)
let expectation = expectationWithDescription("User test: create card.")
let user: User = Fixtures.loadUser()
user.adapter = MockRestAdapter(body: Mapper().toJSONString(Fixtures.loadCard(["id": "foobar"]))!)

user.createCard(CardRequest(currency: "foo", label: "BTC", settings: cardSettings)).then { (card: Card) -> () in
XCTAssertEqual(card.id, "foobar", "Failed: Wrong card id.")

expectation.fulfill()
}

wait()
}

func testGetBalancesByCurrencyShouldReturnTheCurrencyBalance() {
let expectation = expectationWithDescription("User test: get balances by currency.")
let json: String = "{" +
Expand Down

0 comments on commit fd8b4c0

Please sign in to comment.