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 card settings to the card request model #40

Merged
merged 2 commits into from
Apr 15, 2016
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
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