Crea Developer logo

Crea Developer Portal

RB: Search Accounts

Performing a search on account by names starting with a given input.

Full, runnable src of Search Accounts can be downloaded as part of the RB tutorials repository.

This tutorial will return account names matching the input given, up to a specified limit.

Sections

  1. Making the api call - performing the lookup
    1. Example api call - make the call in code
    2. Example api call using script - using our tutorial script
    3. Example Output - output from a successful call
  2. To Run - Running the example.

Making the api call

To request the a list of accounts starting with a particular lookup pattern, we can use the lookup_accounts method:

api = Radiator::Api.new

api.lookup_accounts(lower_bound_name, limit) do |accounts|
  puts accounts.join(' ')
end

Notice, the above example can request up to 1000 accounts as an array.

Example api call

If we want to get the accounts starting with “alice” …

api.lookup_accounts("alice", 10) do |content| ...

Example api call using script

And to do the same with our tutorial script, which has its own default limit of 10:

ruby search_accounts.rb alice

Example Output

From the example we get the following output from our script:

alice alice-22 alice-is alice-labardo alice-mikhaylova alice-n-chains alice-radster alice-sandra alice-thuigh alice-way

To Run

First, set up your workstation using the steps provided in Getting Started. Then you can create and execute the script (or clone from this repository):

git clone git@github.com:creary/devportal-tutorials-rb.git
cd devportal-tutorials-rb/tutorials/15_search_accounts
bundle install
ruby search_accounts.rb <lower-bound-name> [limit]