Skip to content

Commit f2eeabe

Browse files
committed
add basics for search
1 parent 09ce2ae commit f2eeabe

File tree

2 files changed

+20
-10
lines changed

2 files changed

+20
-10
lines changed

README.md

+6-10
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,10 @@ TODO:
2020
- [x] Create Ledger
2121
- [x] Find Ledger
2222
- [x] List Ledgers
23-
- [ ] Search Ledgers
23+
- [x] Search Ledgers
2424
- [x] Create Balances
2525
- [x] Find Balance
26-
- [ ] Search Balances
26+
- [x] Search Balances
2727
- [ ] Create Transaction
2828
- [ ] Find Transaction
2929
- [ ] Search Transactions
@@ -45,14 +45,10 @@ ledger = Blnk::Ledger.create(name: 'foobar')
4545
ledger = Blnk::Ledger.find 'ledger_id'
4646
ledgers = Blnk::Ledger.all
4747

48-
# search not implemented yet
49-
ledgers = Blnk::Ledger.search(
50-
q: 'USD',
51-
filter_by: 'balances > 1400',
52-
sort_by: 'created_at:desc',
53-
page: 1,
54-
per_page: 50
55-
)
48+
ledgers = Blnk::Ledger.search(q: '*')
49+
50+
# for search fields check the documentation
51+
https://docs.blnkledger.com/ledger/tutorial/search/overview
5652

5753

5854
# Balance integrations

lib/blnk/resourceable.rb

+14
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
module Blnk
44
# Resoureable module that bring some tweaks for basic REST api integration
55
class Resourceable < OpenStruct
6+
class SearchResult < OpenStruct; end
7+
68
include Client
79

810
def self.resource_name = raise NotImplementedError
@@ -33,6 +35,18 @@ def self.create(*)
3335
new(response.parse)
3436
end
3537

38+
def self.search(**args)
39+
response = new.post_request(
40+
path: "/search/#{resource_name}",
41+
body: args
42+
)
43+
return response unless response.status.success?
44+
45+
sr = SearchResult.new(response.parse)
46+
sr.resource_name = resource_name
47+
sr
48+
end
49+
3650
def persisted? = raise NotImplementedError
3751
def body_data = raise NotImplementedError
3852
end

0 commit comments

Comments
 (0)