Skip to content

Commit

Permalink
Merge pull request #32 from sebinsua/fix/changes-to-teller-api
Browse files Browse the repository at this point in the history
Changes in response to changes within the Teller API
  • Loading branch information
sebinsua authored Mar 30, 2017
2 parents 10a367c + 6424d93 commit fd9ff05
Show file tree
Hide file tree
Showing 8 changed files with 253 additions and 166 deletions.
61 changes: 60 additions & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "teller_cli"
version = "0.0.8"
version = "0.0.9"
authors = ["Seb Insua <me@sebinsua.com>"]

[[bin]]
Expand Down
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -181,3 +181,9 @@ This relates to the following error:
src/openssl_shim.c:1:10: fatal error: 'openssl/hmac.h' file not found
#include <openssl/hmac.h>
```

If `brew` complains about not being able to force-link `openssl` then you could try building like this:

```sh
OPENSSL_INCLUDE_DIR=/usr/local/opt/openssl/include DEP_OPENSSL_INCLUDE=/usr/local/opt/openssl/include cargo build
```
47 changes: 21 additions & 26 deletions src/api/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,38 +9,33 @@ use api::error::TellerClientError;

pub type ApiServiceResult<T> = Result<T, TellerClientError>;

#[derive(Debug, RustcDecodable)]
struct AccountResponse {
data: Account,
}
type AccountResponse = Account;

#[derive(Debug, RustcDecodable)]
struct AccountsResponse {
data: Vec<Account>,
}
type AccountsResponse = Vec<Account>;

#[derive(Debug, RustcDecodable)]
struct TransactionsResponse {
data: Vec<Transaction>,
}
type TransactionsResponse = Vec<Transaction>;

#[derive(Debug, RustcDecodable, Clone)]
pub struct Account {
pub name: String,
pub institution: String,
pub id: String,
pub currency: String,
pub bank_code: String,
pub account_number: String,
pub balance: String,
pub account_number_last_4: String,
pub bank_code: String,
pub currency: String,
// pub enrollment_id: String,
pub id: String,
pub institution: String,
pub name: String,
}

#[derive(Debug, RustcDecodable, Clone)]
pub struct Transaction {
pub description: String,
pub date: String,
pub counterparty: String,
pub amount: String,
pub counterparty: String,
pub date: String,
pub description: String,
// pub id: String,
// pub running_balance: String,
// pub type: String,
}

pub fn parse_utc_date_from_transaction(t: &Transaction) -> Date<UTC> {
Expand Down Expand Up @@ -100,14 +95,14 @@ impl<'a> TellerClient<'a> {
let body = try!(self.get_body(&format!("{}/accounts", TELLER_API_SERVER_URL)));
let accounts_response: AccountsResponse = try!(json::decode(&body));

Ok(accounts_response.data)
Ok(accounts_response)
}

pub fn get_account(&self, account_id: &str) -> ApiServiceResult<Account> {
let body = try!(self.get_body(&format!("{}/accounts/{}", TELLER_API_SERVER_URL, account_id)));
let account_response: AccountResponse = try!(json::decode(&body));

Ok(account_response.data)
Ok(account_response)
}

pub fn raw_transactions(&self,
Expand All @@ -127,7 +122,7 @@ impl<'a> TellerClient<'a> {
let body = try!(self.get_body(&url.as_str()));
let transactions_response: TransactionsResponse = try!(json::decode(&body));

Ok(transactions_response.data)
Ok(transactions_response)
}

#[allow(unused_variables)]
Expand Down Expand Up @@ -215,7 +210,7 @@ mod tests {
currency: "GBP".to_string(),
bank_code: "00000000".to_string(),
balance: "1000.00".to_string(),
account_number_last_4: "0000".to_string(),
account_number: "00000000".to_string(),
};
assert!(true);
}
Expand Down Expand Up @@ -256,7 +251,7 @@ mod tests {
assert_eq!("1000.00", account.balance);
assert_eq!("GBP", account.currency);
assert_eq!("000000", account.bank_code);
assert_eq!("0000", account.account_number_last_4);
assert_eq!("00000000", account.account_number);
}

#[test]
Expand Down
30 changes: 15 additions & 15 deletions src/api/mocks/get-account.http
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,19 @@ server: Teller API
Connection: keep-alive

{
"data":{
"refreshed_at":"2016-01-28T02:19:22Z",
"name":"current",
"links":{
"transactions":"https://api.teller.io/accounts/123/transactions",
"self":"https://api.teller.io/accounts/123",
"direct_debits":"https://api.teller.io/accounts/123/direct_debits"
},
"institution":"natwest",
"id":"123",
"currency":"GBP",
"bank_code":"000000",
"balance":"1000.00",
"account_number_last_4":"0000"
}
"account_number":"00000000",
"balance":"1000.00",
"bank_code":"000000",
"currency":"GBP",
"enrollment_id":"123",
"id":"123",
"institution":"natwest",
"links":{
"direct_debits":"https://api.teller.io/accounts/123/direct_debits",
"payees": "https://api.teller.io/accounts/123/payees",
"self":"https://api.teller.io/accounts/123",
"standing_orders":"https://api.teller.io/accounts/123/standing_orders",
"transactions":"https://api.teller.io/accounts/123/transactions"
},
"name":"current"
}
81 changes: 36 additions & 45 deletions src/api/mocks/get-accounts.http
Original file line number Diff line number Diff line change
Expand Up @@ -5,48 +5,39 @@ date: Thu, 28 Jan 2016 13:00:51 GMT
server: Teller API
Connection: keep-alive

{
"meta":{
"pagination":{
"prev":null,
"next":null,
"last":"https://api.teller.io/accounts?page=1&page_size=250",
"first":"https://api.teller.io/accounts?page=1&page_size=250"
}
},
"links":{
"self":"https://api.teller.io/accounts?page=1&page_size=250"
},
"data":[
{
"refreshed_at":"2016-01-10T01:09:12Z",
"name":"Savings",
"links":{
"transactions":"https://api.teller.io/accounts/123/transactions",
"self":"https://api.teller.io/accounts/123",
"direct_debits":"https://api.teller.io/accounts/123/direct_debits"
},
"institution":"natwest",
"id":"123",
"currency":"GBP",
"bank_code":"000000",
"balance":"10000.00",
"account_number_last_4":"0000"
},
{
"refreshed_at":"2016-01-10T01:09:13Z",
"name":"Current",
"links":{
"transactions":"https://api.teller.io/accounts/456/transactions",
"self":"https://api.teller.io/accounts/456",
"direct_debits":"https://api.teller.io/accounts/456/direct_debits"
},
"institution":"natwest",
"id":"456",
"currency":"GBP",
"bank_code":"000001",
"balance":"1000.00",
"account_number_last_4":"0001"
}
]
}
[
{
"account_number":"00000000",
"balance":"10000.00",
"bank_code":"000000",
"currency":"GBP",
"enrollment_id":"123",
"id":"123",
"institution":"natwest",
"links":{
"direct_debits":"https://api.teller.io/accounts/123/direct_debits",
"payees": "https://api.teller.io/accounts/123/payees",
"self":"https://api.teller.io/accounts/123",
"standing_orders":"https://api.teller.io/accounts/123/standing_orders",
"transactions":"https://api.teller.io/accounts/123/transactions"
},
"name":"Savings"
},
{
"account_number":"00000000",
"balance":"1000.00",
"bank_code":"000000",
"currency":"GBP",
"enrollment_id":"456",
"id":"456",
"institution":"natwest",
"links":{
"direct_debits":"https://api.teller.io/accounts/456/direct_debits",
"payees": "https://api.teller.io/accounts/456/payees",
"self":"https://api.teller.io/accounts/456",
"standing_orders":"https://api.teller.io/accounts/456/standing_orders",
"transactions":"https://api.teller.io/accounts/456/transactions"
},
"name":"Current"
}
]
Loading

0 comments on commit fd9ff05

Please sign in to comment.