Where to put gem configuration - ruby-on-rails

I'm using stw_engine gem to get screenshots of websites. This gem requires to provide own config, but I don't know where it should be put. It gives an error StwEngine error: No api secret defined! if I put it to initializers/stw.rb
StwEngine.config({
# required
:api_key => 'xXXXXXXXXXXXXX',
:private_key => 'xxxx,
#optional use if supported
:size => 'lg',
})
gem page:
https://github.com/sabirmostofa/stw-engin

Try to add this code to initializers/stw_engine.rb. Also, there must be :api_secret => 'xxxxx' instead :private_key

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.

Getting error The AWS Access Key Id you provided does not exist in our records when I try to delete a file

Gemfile :
gem 'aws-sdk', '< 2.0'
in the initializer folder I created a file aws.rb with the following code
AWS.config(access_key_id: '...key id...', secret_access_key: '...secret_key...')
S3_BUCKET = AWS::S3.new.buckets['my_bucket']
I have a file in the path :
my_backet/uploads/391cd178-a64a-4fda-83b6-210430c34a0c/file.png
when I try to delete a file
def delete_file
key = '391cd178-a64a-4fda-83b6-210430c34a0c/file.png'
S3_BUCKET.objects[key].delete
end
I get the error
AWS::S3::Errors::InvalidAccessKeyId in ImagesController#delete_file
The AWS Access Key Id you provided does not exist in our records.
I was able to solve that by providing an s3_endpoint as parameter to my AWS.config :
AWS.config(
:s3_endpoint => '...',
:access_key_id => '....',
:secret_access_key => '....'
)
The source that helped me : https://ruby.awsblog.com/post/TxVOTODBPHAEP9/Working-with-Regions
Double check the credential initialization syntax and format. It is possible you have not specified them there correctly.
The references below indicate different syntax that the one you are using.
AWS.config(:access_key_id => 'KEY', :secret_access_key => 'SECRET')
Please see:
https://ruby.awsblog.com/blog/tag/config
http://docs.aws.amazon.com/AWSRubySDK/latest/AWS/Core/Configuration.html
http://www.rubydoc.info/gems/aws_sdk/3.1.5/AWS/Core/Configuration

uninitialized constant Name_of_controller::Savon

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.

Trouble accessing methods in aws/s3 gem

Hi I'm playing around with the aws/s3 gem so that my rails app can store and then download files from Amazon s3. I'm finding that I can't access the methods contained within the gem.
I followed the instructions in the documentation:
Entered into irb
required 'aws/s3'
entered interactive shell provided by aws/s3: % s3sh
AWS::S3::Base.establish_connection!(
:access_key_id => 'my credentials',
:secret_access_key => 'my credentials'
)
From here I believe I should be able to access my buckets and objects within them but when I call Service.buckets I get an error that states undefined method 'buckets'.
I also tried (not using s3sh):
service = AWS::S3::Base.establish_connection!(
:access_key_id => 'my credentials',
:secret_access_key => 'my credentials'
)
then service.buckets but still I get undefined method 'buckets'. How do I use this gem correctly?
Any help appreciated, thanks a lot.
AWS::S3::Service.buckets listed the buckets.

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