Skip to content

Commit

Permalink
add basics for search
Browse files Browse the repository at this point in the history
  • Loading branch information
devton committed Jun 27, 2024
1 parent 09ce2ae commit f2eeabe
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 10 deletions.
16 changes: 6 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,10 @@ TODO:
- [x] Create Ledger
- [x] Find Ledger
- [x] List Ledgers
- [ ] Search Ledgers
- [x] Search Ledgers
- [x] Create Balances
- [x] Find Balance
- [ ] Search Balances
- [x] Search Balances
- [ ] Create Transaction
- [ ] Find Transaction
- [ ] Search Transactions
Expand All @@ -45,14 +45,10 @@ ledger = Blnk::Ledger.create(name: 'foobar')
ledger = Blnk::Ledger.find 'ledger_id'
ledgers = Blnk::Ledger.all

# search not implemented yet
ledgers = Blnk::Ledger.search(
q: 'USD',
filter_by: 'balances > 1400',
sort_by: 'created_at:desc',
page: 1,
per_page: 50
)
ledgers = Blnk::Ledger.search(q: '*')

# for search fields check the documentation
https://docs.blnkledger.com/ledger/tutorial/search/overview


# Balance integrations
Expand Down
14 changes: 14 additions & 0 deletions lib/blnk/resourceable.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
module Blnk
# Resoureable module that bring some tweaks for basic REST api integration
class Resourceable < OpenStruct
class SearchResult < OpenStruct; end

include Client

def self.resource_name = raise NotImplementedError
Expand Down Expand Up @@ -33,6 +35,18 @@ def self.create(*)
new(response.parse)
end

def self.search(**args)
response = new.post_request(
path: "/search/#{resource_name}",
body: args
)
return response unless response.status.success?

sr = SearchResult.new(response.parse)
sr.resource_name = resource_name
sr
end

def persisted? = raise NotImplementedError
def body_data = raise NotImplementedError
end
Expand Down

0 comments on commit f2eeabe

Please sign in to comment.