uninitialized constant Name_of_controller::Savon - ruby-on-rails

I am using savon gem to interact with a SOAP API.
client = Savon.client(wsdl: "http://karvymfs.com/CP_STP_SERVICE/STPService.svc?singleWsdl")
xmlkarvy = "<file>...........</file>"
#response = client.call(:stp_upload, message: {"FundCode" =>"AXF","UserID" => ".............", "Password"=> "..................", "ARNCode" => "..........", "IPAddress" => "..............", "XMLFile" => xmlkarvy , "Branch" => "?"})
Works absolutely fine in IRB but when the same code is used in a controller I get the error.
uninitialized constant ControllerName::Savon

write following before controller class
require 'savon'
This is mentioned in the gem documentation too.

Related

When attempting to retrieve Google Contacts via PeopleV1 API in Ruby Rails, why do I get "ArgumentError: unknown keyword: person_fields"?

I'm having a hard time integrating Google Contacts into my Ruby (version 2.2.10) on Rails 5 (version 5.1.5) App.
When I execute the following code block, I receive "ArgumentError: unknown keyword: person_fields".
people = Google::Apis::PeopleV1::PeopleService.new
people.authorization = auth_client
response = people.list_person_connections('people/me', page_size: 10,
person_fields: 'names,emailAddresses')
To rectify the problem, I tried using the following gem versions:
gem 'google-api-client', '~> 0.11'
gem 'google-api-client', '~> 0.8'
gem 'google-api-client'
I still receive the error no matter which version of the gem I use.
Below is the code in its entirety:
require 'google/apis/people_v1'
require 'google/api_client/client_secrets'
client_secrets = Google::APIClient::ClientSecrets.load 'client_secret_1088824912015-f8asojku302s0mvcijgj7takse8pg8rg.apps.googleusercontent.com.json'
auth_client = client_secrets.to_authorization
auth_client.update!( :scope => 'https://www.googleapis.com/auth/contacts.readonly', :redirect_uri => 'http://localhost:3000/oauth2callback', :additional_parameters => { "access_type" => "offline", "include_granted_scopes" => "true" } )
auth_uri = auth_client.authorization_uri.to_s
# To exchange an authorization code for an access token, use the fetch_access_token! method:
auth_client.code = #auth_code#
auth_client.fetch_access_token!
people = Google::Apis::PeopleV1::PeopleService.new
people.authorization = auth_client
response = people.list_person_connections('people/me', page_size: 10, person_fields: 'names,emailAddresses')
Any assistance would be greatly appreciated.
Just to clarify for any future readers, Ray Baxte linked to docs corresponding to version 0.9.19 of the google-api-client gem - the current version is 0.27.1
I'm using 0.26.0 and the correct argument is person_fields - this obviously changed somewhere between 0.9.19 and 0.26.0
I follow the documentation in the generated API method definitions:
https://github.com/googleapis/google-api-ruby-client/blob/0.27.1/generated/google/apis/people_v1/service.rb#L591
The correct attribute is fields not person_fields. See docs here.

keep getting 'client' method undefined when running rails app

trying to add this to my rails project https://github.com/adelevie/parse-ruby-client
so i first obviously bundle installed the gem, then i created a parse.rb file in config/initializers with this code :
require 'parse-ruby-client'
client = Parse.create :application_id => 'API_KEY',
:api_key => 'API_KEY',
when i call client anywhere i get a error that its undefined
In your example client is a local variable. By the time you try to access it, it has already left the scope. What you should do is create or use a globally visible object. One example:
require 'parse-ruby-client'
::MyParse = Parse.create :application_id => 'APP_ID',
:api_key => 'API_KEY',
You can access such object as MyParse in the code.
Another example:
require 'parse-ruby-client'
MyApp::Application.configure do
config.parse = Parse.create :application_id => 'APP_ID',
:api_key => 'API_KEY',
end
And use it like this:
MyApp::Application.config.parse

Get HTTP error RestClient::Unauthorized (401 Unauthorized): Using 'rest-client' gem in rails

i have use the Ruby Gem rest-client for request on a url of a website. and i get the following error...
RestClient::Unauthorized (401 Unauthorized):
app/controllers/api/v1/channels_controller.rb:199:in `streaming_link'
help me to fix it.
my controller method is bellow
def streaming_link
url = URI.encode("http://eboundservices.com/hash/hash_app.php?code=orientplay")
result = RestClient::Request.new({:user => "hashapp", :password => "PlayFair00",:method => :post, :url => url}).execute
return render :json =>{:success=>true,:result=>result}
end
I was also struggling with rest-client and a 401 until I recognised, that it was because of the digest authentication the service needed. Rest-Client currently did not support digest auth.
Instead I switched to httparty, which supports it and with this it worked. Maybe it's the same with your 401.
#auth = {:username => 'hashapp', :password => 'PlayFair00'}
options = { :digest_auth => #auth }
response = HTTParty.get('http://eboundservices.com/hash/hash_app.php?code=orientplay', options)

Searching location by IP using Geocoder gem not working properly with rails 4

I have added geocoder gem in my rails application but it is not responding properly when i am searching location by IP.
The problem is that it's returning nil array.
Geocoding API's response was not valid JSON.
[]
But sometimes it's working, I don't know why.
What I have done:
Gemfile
gem 'geocoder'
initializers/geocoder.rb
Geocoder.configure(
:timeout => 20,
:lookup => :google,
#:ip_lookup => :google,
#:api_key => "xxxx-xxx",
:units => :km
)
application_controller.rb
def current_location
if Rails.env.development?
geo_data = Geocoder.search('50.131.44.114')
else
geo_data = Geocoder.search(request.remote_ip)
end
[geo_data[0].city, geo_data[0].country_code ].compact.join(', ')
end
was getting the same error
used this
" Geocoder.configure(ip_lookup: :telize) " it solved the problem.
source - https://github.com/alexreisner/geocoder/issues/770

rails twitter_oauth library uninitialized constant

I'm trying to use the twitter_oauth gem : http://github.com/moomerman/twitter_oauth
In my model I have:
require 'twitter_oauth'
And within a function I have:
def example
client = TwitterOAuth::Client.new(
:consumer_key => 'xxxx',
:consumer_secret => 'xxxx',
:token => "xxxx",
:secret => "xxxx")
return client
end
This seems fairly straight forward, but I can't seem to find out why I'm getting this error:
(Event being the name of the model)
uninitialized constant Event::TwitterOAuth
I can't seem to locate any conflicts with the TwitterOAuth namespace, any other thoughts?
Decided to use Grackle instead, seems to work fine

Resources