views:

75

answers:

2

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.

+1  A: 

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.

Andy Atkinson
Andy, I am able to pull all the records. The part I think i don really understand is the second part ( I know you have not used the API) Where and how would i use /people/search.xml?criteria[email][email protected] (PART in my controller) THat's the part that i am missing. @person = Highrise::Person.find(:all)The first part was a huge help - Thank you.I cant seem to find any really good information on the subject.Larry
Fresh
You have to generate an HTTP Get request to the Highrise server. Check out [Rest Client](http://github.com/adamwiggins/rest-client) for Ruby. The API looks like it returns XML. That means you'd probably also want an XML parser. I would look at [Nokogiri](http://nokogiri.org/). Generating requests and handling the responses are non-trivial tasks, but it will be worth your while to learn these skills since most APIs work this way, and chances are good you'll be working with more APIs in another project. Maybe you can create a wrapper Ruby library if one does not exist already.
Andy Atkinson
A: 

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
Fresh
Will now i cant seem to figure out how to update a record.I cant use @person.saveLost
Fresh