Skip to content

Commit

Permalink
Added Accounts endpoint functionality
Browse files Browse the repository at this point in the history
  • Loading branch information
jaredsmithse committed Oct 13, 2019
1 parent 459910b commit ce0680b
Show file tree
Hide file tree
Showing 9 changed files with 89 additions and 8 deletions.
2 changes: 1 addition & 1 deletion spec/spec_helper.cr
@@ -1,2 +1,2 @@
require "spec"
require "../src/monzo.cr"
require "../src/monzo"
7 changes: 0 additions & 7 deletions src/client.cr

This file was deleted.

11 changes: 11 additions & 0 deletions src/monzo.cr
@@ -1,5 +1,16 @@
require "http/client"
require "json"
require "habitat"

require "./monzo/client"

require "./monzo/api/accounts"

require "./monzo/models/account"
require "./monzo/models/owner"
require "./monzo/models/payment_details"
require "./monzo/models/locales/us"

# TODO: Write documentation for `Monzo.cr`
module Monzo
VERSION = "0.1.0"
Expand Down
17 changes: 17 additions & 0 deletions src/monzo/api/accounts.cr
@@ -0,0 +1,17 @@
module Monzo
module API
class Accounts
delegate :host, :headers, to: Monzo::Client

def initialize
@base_url = "#{host}/accounts"
end

def list
response = HTTP::Client.get(@base_url, headers: headers)

Array(Account).from_json(response.body, "accounts")
end
end
end
end
24 changes: 24 additions & 0 deletions src/monzo/client.cr
@@ -0,0 +1,24 @@
module Monzo
class Client
Habitat.create do
setting user_id : String
setting account_id : String
setting access_token : String
setting base_url : String
end

def self.headers
@@headers ||= HTTP::Headers {
"Authorization" => "Bearer #{settings.access_token}"
}
end

def self.host
settings.base_url
end

def self.accounts
Monzo::API::Accounts.new
end
end
end
16 changes: 16 additions & 0 deletions src/monzo/models/account.cr
@@ -0,0 +1,16 @@
class Account
include JSON::Serializable

property id : String
property closed : Bool

@[JSON::Field(converter: Time::Format.new("%F"))]
property created : Time

property description : String
property type : String
property currency : String
property country_code : String
property owners : Array(Owner)
property payment_details : PaymentDetails
end
8 changes: 8 additions & 0 deletions src/monzo/models/locales/us.cr
@@ -0,0 +1,8 @@
module Locales
class US
include JSON::Serializable

property account_number : String
property routing_number : String
end
end
7 changes: 7 additions & 0 deletions src/monzo/models/owner.cr
@@ -0,0 +1,7 @@
class Owner
include JSON::Serializable

property user_id : String
property preferred_name : String
property preferred_first_name : String
end
5 changes: 5 additions & 0 deletions src/monzo/models/payment_details.cr
@@ -0,0 +1,5 @@
class PaymentDetails
include JSON::Serializable

property locale_us : Locales::US
end

0 comments on commit ce0680b

Please sign in to comment.