Timezone Gem - certificate verify failed - ruby-on-rails

I want to use the Time zone gem to convert lat and long to a time zone;
I have added the gem in to my file
I have created timezone.rb in config/initializers
I enabled the Google Maps Time Zone API, and added a server key
timezone.rb file:
Timezone::Lookup.config(:google) do |c|
c.api_key = 'server_key'
end
When I type to rails console;
> timezone = Timezone['America/Los_Angeles']
=> #<Timezone::Zone name: "America/Los_Angeles">
This works but when I try to use lat and long google gives connection error;
> timezone = Timezone.lookup(-34.92771808058, 138.477041423321)
Timezone::Error::Google: SSL_connect returned=1 errno=0 state=SSLv3 read server certificate B: certificate verify failed

Try to check this Github, it will explain everything to you about Google Time Zone API using ruby.
Just make sure you follow this steps:
Ensure you have a Google API Key, server key
Enable the Google Maps Time Zone API
Configure your lookup. NOTE: in Rails it is recommended that you add this code to an initializer
.
Timezone::Lookup.config(:google) do |c|
c.api_key = 'your_google_api_key_goes_here'
c.client_id = 'your_google_client_id' # if using 'Google for Work'
end
For more information, you can also check this thread and SO question.

Related

Amazon MTurk SDK Ruby gem - RuntimeError: Missing AWSAccessKey

How/where does a rails app specify the MTurk Key & Secret?
The Amazon Mechanical Turk SDK gem docs do not seem to indicate where/how to specify the Access Key and Secret... if you run their sample code in IRB it prompts for the Key and Secret... but where does one specify them in a one-time configuration so an application can run?
For example Amazon gives this code:
require 'mturk'
#mturk = Amazon::WebServices::MechanicalTurkRequester.new
puts "I have $#{#mturk.availableFunds} in Sandbox"
which causes the gem to prompt interactively for the Key and Secret.
Doing this instead:
mturk = Amazon::WebServices::MechanicalTurkRequester.new :AWSAccessKeyId => "xxxx", :AWSSecretAccessKey => "yyyy
gives the error message:
RuntimeError: Missing AWSAccessKey
The key & secret being specified is definitely correct, because I can copy/paste them into the interactive prompt and it works fine.
If this is documented anywhere I fail to find it, but the answer is that unlike every other AWS library I've used they rename the 'secret' to :AWSAccessKey
So this works:
mturk = Amazon::WebServices::MechanicalTurkRequester.new :AWSAccessKeyId => "xxxx", : AWSAccessKey => "yyyy

Invalid scope error

I'm trying to send bitcons using coinbase ruby gem but I'm having a hard time getting it to work. I'm authenticating like this:
c = Coinbase::Wallet::Client.new(api_key: ENV["COINBASE_KEY"], api_secret: ENV["COINBASE_SECRET"])
ca = c.account(User.last.account.account_id)
ca.send(to: ENV["BITCOIN_ADDRESS"], amount: '0.0001', currency: 'BTC')
This is the error I'm getting back.
Coinbase::Wallet::InvalidScopeError: Api::BaseController::InvalidScopeError
To be clear, the API key has the required permission set in the dashboard. what could i be doing wrong?
The new Ruby gem uses API v2 which requires v2 scope, wallet:transactions:send instead of v1's send. Can you check that you have this enabled?

Add support for aws govCloud in rails applicatioin using gem 'aws-sdk'

I am working on AWS api based application where is working fine for all regions ,now i want to add the support aws govCloud(http://docs.aws.amazon.com/govcloud-us/latest/UserGuide/welcome.html)using aws-sdk api.
But when i try to call api using access key and secret token i am getting error "The security token included in the request is invalid" How can i access the govCloud using aws-sdk.
You have to pass the region 'us-gov-west-1' while accessing the API of govCloud.
#ec2 = AWS::EC2.new(access_key_id: 'Your Access Key', secret_access_key: 'Your S', region: 'us-gov-west-1')
response = #ec2.client.describe_instances
#instances = response.reservation_set.map(&:instances_set).flatten!
Using this code you can access the govCloud.

Does Geocoder gem work with google API key?

I am using ruby geocoder gem for my project and as the project is growing I am starting to look into connecting to the Google API key. After adding this to the project:
Geocoder.configure do |config|
# geocoding service (see below for supported options):
config.lookup = :google
# to use an API key:
config.api_key = 'my_key'
# geocoding service request timeout, in seconds (default 3):
config.timeout = 5
end
I get Google Geocoding API error: request denied. when I start the application. From reading around, it seems like others switch over to yahoo if they choose to continue using the gem. Can I configure the gem to work with google api key? Mainly, I would like to keep an eye out for the amount of daily queries to avoid going over the limit.
Geocoder supports Google api keys for Google Premier accounts only.
Its found here in the readme on github: https://github.com/alexreisner/geocoder#google-google-google_premier
If you have a Google Premier api key you just need to put this in an intializer:
# config/initializers/geocoder.rb
Geocoder.configure(:lookup => :google_premier, :api_key => "...")
And your Geocoder will use your premier key.
I had this issue today and managed to solve it by setting use_https e.g.
Geocoder.configure(
timeout: 15,
api_key: "YOUR_KEY",
use_https: true
)
create a file: config/initializers/geocoder.rb and setup like this:
Geocoder.configure(
lookup: :google_premier,
api_key: ['api_key', 'client_id', 'client_id_type'],
)
Geocoder works fine with the free tier of their Map API. However, to make it work I had to register a key using this page specifically.
https://console.developers.google.com/flows/enableapi?apiid=geocoding_backend&keyType=SERVER_SIDE
And set up the configuration
# config/initializers/geocoder.rb
Geocoder.configure(
api_key: 'KEY_HERE',
use_https: true
)
By default Geocoder uses Google's geocoding API to fetch coordinates and street addresses. So, I think that a Google API key should work on the initializer.
I hope this work for you.
Geocoder.configure(
# geocoding service
lookup: :google,
# geocoding service request timeout (in seconds)
timeout: 3,
# default units
units: :km
)
This work for me. You can call API from rails console with geocoder doc at http://www.rubygeocoder.com/ than call it from view /my_map/show.html.erb replace address or city etc with <%= #place.address %>
If anyone is still looking at this, for some reason the Google API changed and Geocoder no longer works with the standard config file. However, you can simply not use the Geocoder gem for geocoding and reverse geocoding (don't use Geocoder.search) and use any http request gem to directly call the google api, as of this moment using RestClient the api call would be
response = RestClient.get 'https://maps.googleapis.com/maps/api/geocode/json?address=' + sanitized_query + '&key=' + your_key
where sanitized query can be either an address like Cupertino, CA or a lat=x, lng=y string for geocoding or reverse geocoding. It is not necessary to get a Google premier account.

Trouble with authlogic_rpx

I'm trying to run http://github.com/tardate/rails-authlogic-rpx-sample (only rails version was changed) but get error message http://gist.github.com/385696, when RPX returns information after successful authentication via Google Account. What is wrong here? And how I can fix it?
The code was successfully tested with rails 2.3.3 by its author: http://rails-authlogic-rpx-sample.heroku.com/
I run on Windows with cygwin and rails (2.3.5), rpx_now (0.6.20), authlogic_rpx (1.1.1).
Update
In several hours RPX rejected my app http://img96.imageshack.us/img96/2508/14128362.png
Update2
The same error message ( http://gist.github.com/386124) appears with http://github.com/grosser/rpx_now_example , but in this case RPX allows me to sign in (so far).
Solved
See below
Got error: Invalid parameter: apiKey (code: 1), HTTP status: 200
You have to first register your RPX app at http://www.RPXnow.com and set its name. You'll be assigned an API key which you should set in the config/environment.rb file:
RPX_API_KEY = ENV["RPX_API_KEY"]
RPX_APP_NAME = "your_app_name_here!"
Or: Read slide 35: http://www.slideshare.net/tardate/srbauthlogicrpx
You shouldn't have any constraints enforced at the database level.
The reason was trailing \r character in my API key. Apparently, non of the steps did key trimming and the exception was not processed in a good way.

Resources