foursquare api calls failing in heroku console with quimby gem - ruby-on-rails

I am using the quimby gem to interface with foursquare's venue api. I have an establishment model, I am trying to run a method that looks up an establishment on foursquare so that I can then do stuff with the data 4sq provides.
in my establishment model I've created this method
def find_on_foursquare
Foursquare.verbose = true
foursquare = Foursquare::Base.new(FOURSQUARE_ID, FOURSQUARE_SECRET)
begin
venue = foursquare.venues.search(:ll => "#{self.lat},#{self.long}",
:query => self.name,
:categoryId => '4d4b7105d754a06374d81259')['nearby'][0]
puts venue
rescue
puts 'FAILED!'
end
end
when I execute this from localhost console everything runs smoothly. However, when I push to heroku and try to execute from heroku console it fails with "! Internal server error"
Any ideas what I am doing wrong and/or how to debug this?
Some curious lines from the heroku logs:
2011-12-29T17:09:29+00:00 app[web.1]: [foursquare] GET https://api.foursquare.com/v2/venues/search
2011-12-29T17:09:29+00:00 app[web.1]: [foursquare] PARAMS: {"ll"=>"42.344432,-71.098326", "query"=>"Citizen", "categoryId"=>"4d4b7105d754a06374d81259"}
2011-12-29T17:09:29+00:00 app[web.1]: /app/.bundle/gems/ruby/1.9.1/gems/typhoeus-0.3.3/lib/typhoeus/easy.rb:397: [BUG] Segmentation fault
2011-12-29T17:09:29+00:00 app[web.1]: ruby 1.9.2p180 (2011-02-18 revision 30909) [x86_64-linux]

Solution: I had to downgrade Typhoeus to 0.2.4 to get the Quimby gem to talk to Foursquare when deployed on Heroku. Working perfectly now.

Related

solidus_searchkick - undefined method `deep_symbolize_keys'

I am using Solidus and I want to implement a better search wiht elasticsearch, I'm using solidus_searchkick to do that. But I get the following error:
undefined method 'deep_symbolize_keys' for #<ActionController::Parameters:0x0000556eae99cda8>
At Spree::HomeController#index, that has:
Spree::HomeController.class_eval do
def index
#searcher = build_searcher(params.merge(include_images: true))
#products = #searcher.retrieve_products
#taxonomies = Spree::Taxonomy.includes(root: :children)
end
end
I have NOT changed anything at Solidus' search options.
I get this error right after I run 'bundle install', installs everything just fine.
Then, I run 'rails s' and I get this error when I try to get my home or any other page that shows me any product.
Versions:
Rails: 5.1.6
Ruby: 2.5.1
solidus_searchkick: 0.3.4
Solidus: 2.5.0
This is an issue with the deprecated method deep_symbolize_keys in Rails 5.1. I just submitted a Pull Request for the solidus_searchkick gem. You can find it here https://github.com/elevatorup/solidus_searchkick/pull/6/files
If you point your solidus_searchkick gem to that branch it will work.

Elasticsearch::Transport::Transport::Errors::BadRequest error heroku

I have a rails app which has search system which depends on elasticsearch, i have pushed it on heroku using the bonsai addon, but whenever i try to search something on my app it give me this error in the log.
2017-07-16T04:04:44.083489+00:00 app[web.1]: Completed 500 Internal Server Error in 18ms (ActiveRecord: 1.9ms)
2017-07-16T04:04:44.084229+00:00 app[web.1]: app/controllers/search_controller.rb:7:in `show'
2017-07-16T04:04:44.084222+00:00 app[web.1]: Elasticsearch::Transport::Transport::Errors::BadRequest ([400] {"error":{"root_cause":[{"type":"parsing_exception","reason":"no [query] registered for [filtered]","line":1,"col":22}],"type":"parsing_exception","reason":"no [query] registered for [filtered]","line":1,"col":22},"status":400}):
My Elasticsearch Controller
class SearchController < ApplicationController
before_action :beautify_url
layout "simple"
def show
#post_records = Post.search(query_term).paginate(page: params[:page]).records
#posts = #post_records.to_a.select { |post| post.published? }
#users = User.search(query_term).records.to_a
#tags = Tag.search(query_term).records
end
def users
#users = User.search(query_term).records.to_a
end
private
def beautify_url
if params[:search].present?
case params[:action]
when "show"
redirect_to search_url(q: params[:search][:q])
when "users"
redirect_to search_users_url(q: params[:search][:q])
end
end
end
def query_term
params[:q] || ''
end
end
Please help!!
Bonsai support here. Bonsai clusters are currently being provisioned on Elasticsearch 5.x, and as of Elasticsearch 5.0, the filtered query has been removed. Attempting to use a filtered query in 5.x results in that error message you're seeing.
From what you've shared, I would say the most likely issue is that the client is using a deprecated version of the Query DSL. That would suggest an incompatible gem version.
You can check what version your Elasticsearch gems are by running this from a command line:
bundle show | grep elasticsearch
If they are not 5.x.x, update them in your Gemfile:
gem "elasticsearch", "~> 5"
gem "elasticsearch-rails", "~> 5"
And run bundle update elasticsearch elasticsearch-rails. Push the change to Heroku and try your search again.
If that doesn't help, shoot an email to support#bonsai.io and we'll help you sort it out.

URI::InvalidURIError: the scheme http does not accept registry part: :9200 (or bad hostname?)

I am using Elasticsearch / SearchKick / Bonsai to set up search in production on Heroku. This is working beautifully locally, but I am having trouble indexing my objects on Heroku.
in config/initializers/bonsai.rb
require 'elasticsearch/model'
if ENV['BONSAI_URL']
Elasticsearch::Model.client = Elasticsearch::Client.new({url: ENV['BONSAI_URL'], logs: true})
end
in lib/tasks/elasticsearch.rb
require 'elasticsearch/rails/tasks/import'
in user.rb
include Elasticsearch::Model
include Elasticsearch::Model::Callbacks
searchkick
def search_data
attributes.merge(
profile_name: profile.name(&:name),
book_title: books.map(&:title)
)
end
gemfile
gem 'bonsai-elasticsearch-rails' #in the production group
gem 'elasticsearch-model'
gem 'elasticsearch-rails'
gem "searchkick"
I ran: heroku config:add BONSAI_URL=mybonsaiurl
But, when I try to reindex with: heroku run rake searchkick:reindex CLASS=User
I get: URI::InvalidURIError: the scheme http does not accept registry part: :9200 (or bad hostname?)
Or when I do: User.elasticsearch.create_index! force: true
I get: User.elasticsearch.create_index!: command not found
It seems like SearchKick or something is set to 9200 by default but I am not sure how to change it or whether it should look for my app URL or the Bonsai URL -- I am really lost and seem to have missed a step somewhere?
Thanks for any help!
Solved thanks to Heroku support team.
I was trying to use two different clients - the official Elasticsearch rails client, and Searchkick. I went thru and removed all the configuration for the 3 Elasticsearch/Bonsai gems, and edited this file:
config/initializers/bonsai.rb
if ENV['BONSAI_URL']
# Elasticsearch::Model.client = Elasticsearch::Client.new({url: ENV['BONSAI_URL'], logs: true})
Searchkick.client = Elasticsearch::Client.new({url: ENV[‘BONSAI_URL’], logs: true})
end
Now, I can run: heroku run rake searchkick:reindex:all
to index my models.
More here: http://danifankhauser.com/post/104137889438/rails-how-to-index-searchkick-on-heroku-with

send mail using resque-mailer -RAILS 3

My application was sending mails in background in development but recently i installed redis and resque to use resque along with resque-mailer and now nothing is working.Everytime i get a message RuntimeError Invalid delivery method :resque.I have been trying hard to figure out whats wrong because earlier i just included resque-mailer in user_mailer.rb and thats it,my mails were running but now i dont know what wrong i did.below are my relevant file AFTER INSTALLING REDIS using Railscasts for resque.I googled alot to find but many times i came across monkey patching devise but i dont think i need to do that as my mailers were working fine without worrying about devise.Using ruby 1.9.3 and rails 3.2
im getting same error when tried with sidekiq :(
my gemfile.
gem 'resque','1.19.0' ,:require => "resque/server"
gem 'resque_mailer'
my user_mailer.rb
class UserMailer < ActionMailer::Base
include Resque::Mailer
default from: "support#mywebsite.com"
def logged_in(user.id)
Rails.logger.info 'sending mail----------registeration mail----------'
#user=User.find(user_id)
p #user
###line number 19 is below
mail(:to => #user.email, :subject => " Hi #{#user.username},You logged-in just now ")
end
app/controllers/users/devise/sessions_controller.rb
##enqueue the mailer using resque and send mail asynchronously
###this was working earlier but now its not so i made use of railscasts above to use redis
###UserMailer.logged_in(resource.id).deliver
#user_id=resource.id
Resque.enqueue(UserMailerWorker,#user_id)
now the changes that i did using Railscasts and mail is not sending giving above error
my worker
class UserMailerWorker
#queue = :user_mailer_job_queue
def self.perform(user_id)
p 'usermailer worker sending logged in mail----'
p user_id
UserMailer.logged_in(user_id).deliver
end
end
backtrace error as seen in resque-web UI---
localhost.localdomain:8119 on mailer at just now
Retry or Remove
Class
UserMailer
Arguments
"logged_in"
7
Exception
RuntimeError
Error
Invalid delivery method :resque
/usr/local/rvm/gems/ruby-1.9.3-head#latest/gems/actionmailer-3.2.0/lib/action_mailer/delivery_methods.rb:71:in `wrap_delivery_behavior'
/usr/local/rvm/gems/ruby-1.9.3-head#latest/gems/actionmailer-3.2.0/lib/action_mailer/delivery_methods.rb:83:in `wrap_delivery_behavior!'
/usr/local/rvm/gems/ruby-1.9.3-head#latest/gems/actionmailer-3.2.0/lib/action_mailer/base.rb:628:in `mail'
/mnt/hgfs/latest-master/latest/app/mailers/user_mailer.rb:19:in `logged_in'
/usr/local/rvm/gems/ruby-1.9.3-head#latest/gems/actionpack-3.2.0/lib/abstract_controller/base.rb:167:in `process_action'
/usr/local/rvm/gems/ruby-1.9.3-head#latest/gems/actionpack-3.2.0/lib/abstract_controller/base.rb:121:in `process'
/usr/local/rvm/gems/ruby-1.9.3-head#latest/gems/actionpack-3.2.0/lib/abstract_controller/rendering.rb:45:in `process'
/usr/local/rvm/gems/ruby-1.9.3-head#latest/gems/actionmailer-3.2.0/lib/action_mailer/base.rb:456:in `process'
/usr/local/rvm/gems/ruby-1.9.3-head#latest/gems/actionmailer-3.2.0/lib/action_mailer/base.rb:451:in `initialize'
/usr/local/rvm/gems/ruby-1.9.3-head#latest/gems/resque_mailer-2.2.6/lib/resque_mailer.rb:48:in `new'
/usr/local/rvm/gems/ruby-1.9.3-head#latest/gems/resque_mailer-2.2.6/lib/resque_mailer.rb:48:in `perform'
well after removing and resetting my application...i came to know why i was getting this error.its because i was not starting the resque job as well as redis.so after starting redis using redis-server and resque using bundle exec rake resque:work QUEUE='*'...my asynchronous mail started working without any problem just by including include Resque::Mailer

Spree Error - Error registering calculator Calculator::PriceBucket

Getting this error locally and in production w/ a clean install. Seed data has been loaded. Rails 3.0.3, ruby 1.87 (development) and ruby 1.8.7 REE in prod.
spree gems
spree (0.30.1)
spree_api (0.30.1)
spree_auth (0.30.1)
spree_core (0.30.1)
spree_dash (0.30.1)
spree_promo (0.30.1)
spree_sample (0.30.1)
Development Error:
=> Booting WEBrick => Rails 3.0.3 application starting in development on http://0.0.0.0:3000
=> Call with -d to detach => Ctrl-C to shutdown server
Error registering calculator Calculator::PriceBucket
[2010-11-27 12:57:49] INFO WEBrick 1.3.1
[2010-11-27 12:57:49] INFO ruby 1.8.7 (2010-08-16) [i686-darwin10.4.3]
[2010-11-27 12:57:49] INFO WEBrick::HTTPServer#start: pid=18146 port=3000
Prod Error:
Error message:
superclass mismatch for class PriceBucket
Exception class:
TypeError
Application root:
/home/deploy/webstores/mystore/current Backtrace:
File Line Location
0 /home/deploy/.bundler/ruby/1.8/spree-e9c3485bf22e/core/app/models/calculator/price_bucket.rb 1
This ended up working for me though its a lot different from your error :
It should also be noted that the way things are calculated in Rails3 Spree is a slight bit different. The object now contains the attributes of item_total, rather than just calling object.length.
In my main extension gem :
def self.activate
Dir.glob(File.join(File.dirname(__FILE__), "../app/**/*_decorator*.rb")) do |c|
Rails.env.production? ? require(c) : load(c)
end
Calculator::PerWeight.register
end
In my custom calculator:
def self.register
super
ShippingMethod.register_calculator(self)
end

Resources