Ruby on Rails Net HTTP or HTTPParty - ruby-on-rails

I've been at this for awhile. I've tried using net http to connect to a https url with no luck. I've tried http party and getting uninitialized constant httpparty. I am running rails 3.2.7. I have httpparty add to gem file.
Can someone please provide an example with either problem sending params to a https url and receiving a response.
code:
options = {:id => params[:id], :code => params[:code]}
response = HTTPParty.post('https://test.com', options)
gem file:
gem "httparty", "~> 0.9.0"

HTTParty.get('https://google.com', :query => {:q => 'stack overflow'})
If this doesn't work for you, please show the code you're using. It you're getting an uninitialized constant error, you've done something wrong. Did you run bundle after adding to your Gemfile?
Also, it's HTTParty, not HTTPParty.

Related

How to o properly run Pagination with Ajax in ruby on rails

Am trying to implement pagination in ruby on rails.So I reference solution found here link by mmrobins .
I have tried will_paginate options and its working fine.
Now am trying to implement the second options which ajax pagination by following railcasts pagination with ajax. here is the source link
My Issues with Ajax Pagination:
I have configured all the steps as required but when I restart my server,it shows error undefine local variable or method config for main:Object (NameError)
I believe this error was caused by setting the following code at config/environment.rb
config.gem "mislav-will_paginate", :lib => "will_paginate", :source => "http://gems.github.com"
any idea on ow to resolve the issue. Am running ruby on rails version
Here is the screenshot of how I save that line of code above at config/environment.rb
Wrap your configuration code under 'Rails.application.configure do .. end' in development.rb
Rails.application.configure do
# your code here
config.gem "mislav-will_paginate", :lib => "will_paginate", :source => "http://gems.github.com"
end

Error when trying to use ruby gem- NameError (uninitialized constant RightScraper::Scraper)

I am trying to use a ruby gem called right_scraper. I have added the gem to my gem file and it installs fine. I used the example code from the gems github page (https://github.com/rightscale/right_scraper)
require 'rubygems'
require 'right_scraper'
scraper = RightScraper::Scraper.new(:basedir => '/tmp', :kind => :cookbook)
scraper.scrape(:type => :git, :url => 'git://github.com/rightscale/right_scraper.git')
running this code returns the following error:
NameError (uninitialized constant RightScraper::Scraper)
Does anyone know whats going wrong?
Looks like the README is out of date; that class does indeed not exist.
In cases like this, it is often a good idea to look at the specs to see what the correct usage should be. For example, based on this spec, I found the following works:
RightScraper::Main.new(:basedir => '/tmp', :kind => :cookbook)
It would also be a good idea to raise this as an issue with the author. You could even provide a pull request with some up-to-date documentation.

how to retrieve data from Bigcommerce using Rails application?

I am trying to connect a Rails application with the Bigcommerce API but I can't and I don't know why.
I made the next:
Add 'gem bigcommerce' to my gem file
Execute 'bundle install'
Put the code behind in the ApplicationController index
def index
api = Bigcommerce::Api.new({
:store_url => "http://mystore.mybigcommerce.com",
:username => "user",
:api_key => "3a0ce...[my api key]"
})
puts api.time
end
Stop and Start Rails server
I received an error saying 'undefined method `time' for #'
Does any body could tell me what I am doing wrong and how to configure Bigcommerce in a Rails app? I found the official documentation, but it's not very clear for me.
Thanks in advance
Have you added require at the beggining of your ApplicationController file?
require 'bigcommerce'

Using actionwebservice and Rails 3

We want to use actionwebservice for some SOAP integration. We were able to install it however using it causes an error. Here's my code:
class HelloMessageApi < ActionWebService::Base
api_method :hello_message,
:expects => [{:firstname=>:string},
{:lastname=>:string}],
:returns => [:string]
end
The error returned is
uninitialized constant
ActionWebService
When I do a gem list I can see the gem installed, what am I missing? Please help.

Empty Session after Omniauth Twitter Callback

I'm trying to build an Application that is using the OmniAuth gem, so that Twitter users can login.
I followed the steps in the tutorials and i'm pretty sure, that i've done everything right.
But on the callback from Twitter i get this infamous error message:
NoMethodError
You have a nil object when you didn't expect it!
You might have expected an instance of ActiveRecord::Base.
The error occurred while evaluating nil.[]
After digging deeper in the omniauth gem, i figured out, that in the OAuth#callback_phase the session does not contain any oauth information
def callback_phase
::Rails.logger.info "session: #{session.inspect}"
::Rails.logger.info "consumer: #{consumer.inspect}"
request_token = ::OAuth::RequestToken.new(consumer, session['oauth'][name.to_s].delete('request_token'), session['oauth'][name.to_s].delete('request_secret'))
...
end
Log after callback
session: {"session_id"=>"190523311f7a63fe796558691b1d4fff"}
consumer: #<OAuth::Consumer:0x103735b50 #secret="...", #http=#<Net::HTTP api.twitter.com:443 open=false>, #key="...", #options={:access_token_path=>"/oauth/access_token", :proxy=>nil, :http_method=>:post, :site=>"https://api.twitter.com", :request_token_path=>"/oauth/request_token", :scheme=>:header, :oauth_version=>"1.0", :signature_method=>"HMAC-SHA1", :authorize_path=>"/oauth/authenticate"}>
So it looks like the Session content is not filled or gets lost on the way from twitter to omniauth.
Does anyone have a idea, what can cause the behavior?
My Gemfile:
gem 'mongrel', '1.2.0.pre2'
gem "rails", "~> 3.0.6"
gem "mysql"
gem 'omniauth'
gem 'settingslogic' # config/application.yml
gem 'will_paginate', '~> 3.0.beta'
Thanks for your help in advance.
In my session_store.rb I had something like this:
# Be sure to restart your server when you modify this file.
PersonalAccount::Application.config.session_store :cookie_store, :key => '_app_session', :secure => true
But in my development environment I did not use SSL, so OmniAuth could not store its session.
Removing the :secure => true resolved my problem.

Resources