ruby-on-railshttpwhere-clauseransackactiveresource

ActiveResource or Flexirest SimplyRets API


I am working on an application where one of its functions is to pull mls/rets real estate listing data from SimplyRets. I'm brand new to API integration and I have ran into some issues:

Using ActiveResource I can't get the app to connect. (end up with 401 Unauthorized.) Here's my Model:

class Listing < ActiveResource::Base

  self.site = "https://api.simplyrets.com/properties"
  user = "simplyrets"
  password = "simplyrets"

end

Using the Flexirest gem I'm more lucky. I can connect and have set up routes and a controller that works quite nicely. Heres that Model:

class Listing < Flexirest::Base
    extend ActiveModel::Naming
    include ActiveModel::Conversion
    include ActiveModel::Validations
    base_url Rails.application.config.api_server_url

    username 'simplyrets'
    password 'simplyrets'

    get :all, "/properties"
    get :where, "/properties"
    get :find, "/properties/:id"

end

But, the problem I'm running into with Flexirest is using Ransack (for searching) or really anytime I try to chain a .where to the danged thing. getting this error:

undefined method `search' for Listing:Class

What do I need to do to be able to search this APIs Array? How can I use that arel .where good good? Will ActiveResource do this for me? Can I convert the data I'm pulling from Flexirest to something I can manipulate with a conditional statement?

I hope I explained myself clearly enough. If anyone wants any other code I can edit.


Solution

  • I found that using ActiveRecord with a Flexirest object to be a mistake, from my searches I've found that for my project I would be better off sending a GET request with a query. If anyone needs some code to show how I did this, I will happily supply it, however, this was just mostly me being a newb. Nevertheless I figured since I was on here I would post this for anyone as lost as I was!