class TwentySix::Core

Public Class Methods

authenticate(username, password) click to toggle source
# File lib/twentysix/core.rb, line 8
def self.authenticate(username, password)
  response = post('/oauth/token',
                  body: {
                    'username' => username,
                    'password' => password,
                    'grant_type' => 'password'
                  },
                  headers: {
                    'Authorization' => 'Basic bXktdHJ1c3RlZC13ZHBDbGllbnQ6c2VjcmV0',
                    'User-Agent' => 'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/48.0.2564.109 Safari/537.36'
                  })
  if response['access_token']
    new(response['access_token'])
  else
    response
  end
end
new(access_token) click to toggle source
# File lib/twentysix/core.rb, line 26
def initialize(access_token)
  @access_token = access_token
end

Public Instance Methods

account_summary() click to toggle source
# File lib/twentysix/core.rb, line 34
def account_summary
  get '/api/accounts'
end
addresses() click to toggle source
# File lib/twentysix/core.rb, line 38
def addresses
  get '/api/addresses'
end
barzahlen_summary() click to toggle source
# File lib/twentysix/core.rb, line 124
def barzahlen_summary
  get '/api/barzahlen/check'
end
block_card(card_id) click to toggle source
# File lib/twentysix/core.rb, line 128
def block_card(card_id)
  post "/api/cards/#{card_id}/block"
end
card_limits(card_id) click to toggle source
# File lib/twentysix/core.rb, line 58
def card_limits(card_id)
  get "/api/settings/limits/#{card_id}"
end
card_with_id(id) click to toggle source
# File lib/twentysix/core.rb, line 50
def card_with_id(id)
  get "/api/cards/#{id}"
end
cards() click to toggle source
# File lib/twentysix/core.rb, line 54
def cards
  get '/api/cards'
end
categories() click to toggle source
# File lib/twentysix/core.rb, line 46
def categories
  get '/api/smrt/categories'
end
contacts() click to toggle source
# File lib/twentysix/core.rb, line 42
def contacts
  get '/api/smrt/contacts'
end
create_transfer(pin, name, iban, bic, amount, reference) click to toggle source
# File lib/twentysix/core.rb, line 107
def create_transfer(pin, name, iban, bic, amount, reference)
  post '/api/transactions', options: {
    body: {
      pin: pin,
      transaction: {
        partnerName: name,
        partnerBic: bic,
        partnerIban: iban,
        amount: amount,
        referenceText: reference,
        type: 'DT'
      }
    }.to_json,
    headers: { 'Content-Type' => 'application/json' }
  }
end
statement(id, pdf: false) click to toggle source
# File lib/twentysix/core.rb, line 70
def statement(id, pdf: false)
  prefix = if pdf
             ''
           else
             'json/'
           end
  get "/api/statements/#{prefix}#{id}", options: { headers: { 'Content-Type' => 'application/json' } }
end
statements() click to toggle source
# File lib/twentysix/core.rb, line 66
def statements
  get '/api/statements'
end
transaction(id) click to toggle source
# File lib/twentysix/core.rb, line 99
def transaction(id)
  get "/api/transactions/#{id}"
end
transaction_metadata(smartlink_id) click to toggle source
# File lib/twentysix/core.rb, line 103
def transaction_metadata(smartlink_id)
  get "/api/transactions/#{smartlink_id}/metadata"
end
transactions(count: 50, include_pending: false, text_filter: nil, from_time: nil, to_time: nil) click to toggle source
# File lib/twentysix/core.rb, line 79
def transactions(count: 50,
                 include_pending: false,
                 text_filter: nil,
                 from_time: nil,
                 to_time: nil)
  query = {
    limit: count,
    pending: include_pending
  }

  if from_time && to_time
    query['from'] = from_time.to_i
    query['to'] = to_time.to_i
  end

  query['textFilter'] = text_filter if text_filter

  get '/api/smrt/transactions', options: { query: query }
end
unblock_card(card_id) click to toggle source
# File lib/twentysix/core.rb, line 132
def unblock_card(card_id)
  post "/api/cards/#{card_id}/unblock"
end
update_card_limits(card_id, limits) click to toggle source
# File lib/twentysix/core.rb, line 62
def update_card_limits(card_id, limits)
  post "/api/settings/limits/#{card_id}", options: { body: limits }
end
whoami() click to toggle source
# File lib/twentysix/core.rb, line 30
def whoami
  get '/api/me'
end

Private Instance Methods

default_headers() click to toggle source
# File lib/twentysix/core.rb, line 154
def default_headers
  {
    'Authorization' => "Bearer #{@access_token}"
  }
end
default_options() click to toggle source
# File lib/twentysix/core.rb, line 150
def default_options
  { headers: default_headers }
end
get(uri, options: {}) click to toggle source
# File lib/twentysix/core.rb, line 138
def get(uri, options: {})
  opts = default_options
  opts.deep_merge!(options)
  self.class.get(uri, opts)
end
post(uri, options: {}) click to toggle source
# File lib/twentysix/core.rb, line 144
def post(uri, options: {})
  opts = default_options
  opts.deep_merge!(options)
  self.class.post(uri, opts)
end