Class: Financo::N26::Client
- Inherits:
-
Object
- Object
- Financo::N26::Client
- Defined in:
- lib/financo/n26/client.rb
Overview
Client
Constant Summary collapse
- DEFAULT_ENDPOINT =
'https://api.tech26.de'
Instance Method Summary collapse
-
#initialize(endpoint: DEFAULT_ENDPOINT, access_token: nil) ⇒ Client
constructor
A new instance of Client.
- #login(username, password) ⇒ Object
- #me ⇒ Object
- #transactions(from: nil, to: Time.now.to_i, limit: 10_000, text_filter: nil, pending: false) ⇒ Object
Constructor Details
#initialize(endpoint: DEFAULT_ENDPOINT, access_token: nil) ⇒ Client
Returns a new instance of Client.
12 13 14 15 16 17 18 |
# File 'lib/financo/n26/client.rb', line 12 def initialize(endpoint: DEFAULT_ENDPOINT, access_token: nil) @base_uri = URI.parse(endpoint) @access_token = access_token @http = Net::HTTP.new(@base_uri.host, @base_uri.port) @http.use_ssl = @base_uri.scheme == 'https' end |
Instance Method Details
#login(username, password) ⇒ Object
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/financo/n26/client.rb', line 20 def login(username, password) data = post('/oauth/token') do |r| r['User-Agent'] = 'Mozilla/5.0 (X11; Linux x86_64) ' \ 'AppleWebKit/537.36 (KHTML, like Gecko) ' \ 'Chrome/48.0.2564.109 Safari/537.36' r.basic_auth('my-trusted-wdpClient', 'secret') r.set_form_data( username: username, password: password, grant_type: 'password' ) end @access_token = data['access_token'] end |
#me ⇒ Object
58 59 60 |
# File 'lib/financo/n26/client.rb', line 58 def me get('/api/me') end |
#transactions(from: nil, to: Time.now.to_i, limit: 10_000, text_filter: nil, pending: false) ⇒ Object
36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 |
# File 'lib/financo/n26/client.rb', line 36 def transactions( from: nil, to: Time.now.to_i, limit: 10_000, text_filter: nil, pending: false ) query = { limit: limit, pending: pending } unless from.nil? || to.nil? query[:from] = from * 1000 query[:to] = to * 1000 end query[:textFilter] = text_filter unless text_filter.nil? get('/api/smrt/transactions', query) end |