Class: Pluggy::Client

Inherits:
Object
  • Object
show all
Defined in:
lib/pluggy/client.rb

Overview

The entry point.

client = Pluggy::Client.new(
client_id: ENV["PLUGGY_CLIENT_ID"],
client_secret: ENV["PLUGGY_CLIENT_SECRET"]
)
client.accounts.list(item_id: item_id)

Authentication is handled for you: the apiKey is fetched lazily on the first request, cached until the expiry in its own JWT, and renewed transparently if the API rejects it mid-session.

One client holds one credential set and is safe to share across threads.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(client_id: nil, client_secret: nil, api_key: nil, **options) ⇒ Client

Returns a new instance of Client.



20
21
22
23
24
25
26
27
28
29
# File 'lib/pluggy/client.rb', line 20

def initialize(client_id: nil, client_secret: nil, api_key: nil, **options)
  @config = Pluggy.config.merge(
    client_id: client_id,
    client_secret: client_secret,
    api_key: api_key,
    **options
  )
  @config.validate!
  @requestor = APIRequestor.new(@config)
end

Instance Attribute Details

#configObject (readonly)

Returns the value of attribute config.



18
19
20
# File 'lib/pluggy/client.rb', line 18

def config
  @config
end

#requestorObject (readonly)

Returns the value of attribute requestor.



18
19
20
# File 'lib/pluggy/client.rb', line 18

def requestor
  @requestor
end

Instance Method Details

#accountsObject



31
# File 'lib/pluggy/client.rb', line 31

def accounts = @accounts ||= Services::AccountService.new(self)

#api_keyObject

The current apiKey, authenticating first if needed. Rarely useful directly -- mostly for debugging and for the live smoke test.



46
# File 'lib/pluggy/client.rb', line 46

def api_key = @requestor.credentials.fetch(@requestor).to_s

#billsObject



33
# File 'lib/pluggy/client.rb', line 33

def bills = @bills ||= Services::BillService.new(self)

#categoriesObject



37
# File 'lib/pluggy/client.rb', line 37

def categories = @categories ||= Services::CategoryService.new(self)

#connect_tokensObject



39
# File 'lib/pluggy/client.rb', line 39

def connect_tokens = @connect_tokens ||= Services::ConnectTokenService.new(self)

#connectorsObject



36
# File 'lib/pluggy/client.rb', line 36

def connectors = @connectors ||= Services::ConnectorService.new(self)

#create_connect_token(**kwargs) ⇒ Object

The first call most integrations make.



42
# File 'lib/pluggy/client.rb', line 42

def create_connect_token(**kwargs) = connect_tokens.create(**kwargs)

#delete(path, **params) ⇒ Object



54
# File 'lib/pluggy/client.rb', line 54

def delete(path, **params) = @requestor.request(:delete, path, params: params)

#get(path, **params) ⇒ Object

Escape hatches for the endpoints this gem deliberately does not model (payments, smart transfers, boletos, consents, webhooks, investments, identity). Returns parsed JSON, not resource objects.



51
# File 'lib/pluggy/client.rb', line 51

def get(path, **params) = @requestor.request(:get, path, params: params)

#inspectObject Also known as: to_s



56
57
58
# File 'lib/pluggy/client.rb', line 56

def inspect
  "#<Pluggy::Client client_id=#{@config.client_id.to_s[0, 8]}... api_base=#{@config.api_base}>"
end

#itemsObject



35
# File 'lib/pluggy/client.rb', line 35

def items = @items ||= Services::ItemService.new(self)

#loansObject



34
# File 'lib/pluggy/client.rb', line 34

def loans = @loans ||= Services::LoanService.new(self)

#merchantsObject



38
# File 'lib/pluggy/client.rb', line 38

def merchants = @merchants ||= Services::MerchantService.new(self)

#patch(path, **body) ⇒ Object



53
# File 'lib/pluggy/client.rb', line 53

def patch(path, **body) = @requestor.request(:patch, path, body: body)

#post(path, **body) ⇒ Object



52
# File 'lib/pluggy/client.rb', line 52

def post(path, **body) = @requestor.request(:post, path, body: body)

#transactionsObject



32
# File 'lib/pluggy/client.rb', line 32

def transactions = @transactions ||= Services::TransactionService.new(self)