require 'restclient'

module Tapfinder
  class Search
    def find(params)
      response = client.post search_terms_for(params)
      case response.code
      when 200
        json_response = JSON.parse(response.body)
        bars = Tapfinder::Bar.load(json_response['bars'])
        beers = Tapfinder::Beer.load(json_response['beers'])
        { bars: bars, beers: beers }
      else
        puts "Failed to search #{client} for #{search_terms_for(params)}"
      end
    end

    def client
      @client ||= RestClient::Resource.new("#{Tapfinder.host}#{Tapfinder.search_path}")
    end

    def search_terms_for(params)
      {
        class: 'Search',
        process: 'searchAll',
        searchTerm: params[:text]
      }
    end
  end
end

require 'restclient'

module Tapfinder
  class Search
    def find(params)
      response = client.post search_terms_for(params)
      case response.code
      when 200
        json_response = JSON.parse(response.body)
        bars = Tapfinder::Bar.load(json_response['bars'])
        beers = Tapfinder::Beer.load(json_response['beers'])
        { bars: bars, beers: beers }
      else
        puts "Failed to search #{client} for #{search_terms_for(params)}"
      end
    end

    def client
      @client ||= RestClient::Resource.new("https://#{Tapfinder.host}#{Tapfinder.search_path}")
    end

    def search_terms_for(params)
      {
        class: 'Search',
        process: 'searchAll',
        searchTerm: params[:text]
      }
    end
  end
end

Connect to Philly Tapfinder via https
Connect to Philly Tapfinder via https

At some point recently, Philly Tapfinder rolled out https support
and added 301s to redirect http => https, which caused errors in
beer_bot.  This updates to connect via https now that we can.
