Fresh
Fresh

Reputation: 767

Highrise API Example. help

I am trying to get the highrise api working with my project. total noob.

I have an account, have my api key, added to my rails project like so in my controller.

require 'highrise' Highrise::Base.site = 'http://MYACCOUNT.highrisehq.com' Highrise::Base.user = 'MYAPI KEY'
@person = Highrise::Person.find(:all)

in my view i can get all of rthe people in my contacts list, but cant figure out how to narrow down that list.

so if @person = Highrise::Person.find(:all) fetchs all of them, what will only fetch, say , your with the name "larry"?

I have tried and just cant wrap my head around this.

Upvotes: 2

Views: 1804

Answers (2)

Fresh
Fresh

Reputation: 767

So i got my answer
in my controller

@tag = params[:tag]
@person = Highrise::Person.find(:all, :from => "/people/search.xml?term=#{@tag}")  


THanks Andy for your help .   set me on the right path

Upvotes: 4

Andrew Atkinson
Andrew Atkinson

Reputation: 1165

I'd use @people for an instance variable for what you have, since your query returns multiple records. You can loop over these records and print the fields on a person as follows:

<% @people.each do |person| %>
  <%= "Got a person: #{person.inspect}" %>
<% end %>

Instead of printing each person, you could check for the value you care about, maybe puts person if person.name == "larry", but if you know you want "larry" up front, then you want to query Highrise for just one record. Check out List by search criteria on the Highrise API docs. I haven't used it, but I'd try searching with your criteria /people/search.xml?criteria[email][email protected] which should return a collection of results, then if you find the specific larry you want, you have the user ID, and you can use the "show" action of the API, e.g. /people/#{id}.xml (pass in larry's ID here) to query for the single record.

Upvotes: 3

Related Questions