Analytics API integration rails failing on heroku production - ruby-on-rails

I am currently developing a ruby on rails application which includes the gattica gem to fetch Google Analytics data. When I fetch my data:
https://github.com/activenetwork/gattica
gs = Gattica.new({:email => 'johndoe#google.com', :password => 'password', :profile_id => 123456})
results = gs.get({ :start_date => '2008-01-01',
:end_date => '2008-02-01',
:dimensions => 'browser',
:metrics => 'pageviews',
:sort => '-pageviews'})
on development I will simply receive a response which I can parse to my application.
However on production the page returns a 500 error and in my Gmail inbox I receive a message about a suspicious login being caught.
Is there any way I can fix this issue?
PS: my application is hosted on Heroku.
With kind regards,
Dennis

You're getting the 500 error because Google is blocking your heroku ip from accessing your account. They aren't sure it's you.
You need to change your activity settings to authorize that ip/domain.
Read this: https://support.google.com/accounts/answer/1144110?hl=en&ref_topic=2401957
Also, its a good idea to read your logs when debugging these kinds of errors. Rails.logger.debug results could shed some light.

Related

Authorize.net in Rails - User Authentication failed due to invalid authentication values

I am building a client's ecommerce website. I'm at the latest stages, where I have to integrate the payment system. I signed up for a developer account for Authorize.net in order to test the system. I've ran into a roadblock here
I submitted my payment form, and found the following in my Development Logs
User authentication failed due to invalid authentication values
I set up my gateway as followed, based on my login information to Authorize.net
gateway = ActiveMerchant::Billing::AuthorizeNetGateway.new(
:login => "mylogin",
:password => "mypassword",
:test => false
)
Apparently, I'm missing something, but I'm not sure what it is. I watched the RailsCasts videos 144 and 145. I just substituted the gateway to AuthorizeNetGateWay.
Where am I going wrong here?
Here is my development.rb file
config.after_initialize do
ActiveMerchant::Billing::Base.mode = :test
::GATEWAY = ActiveMerchant::Billing::AuthorizeNetGateway.new(
:login => "mylogin",
:password => "mypassword",
#:signature => "AGjv6SW.mTiKxtkm6L9DcSUCUgePAUDQ3L-kTdszkPG8mRfjaRZDYtSu"
:test_requests => false
)
end
Could the problem be ActiveMerchant::Billing::Base.mode = :test considering this is my Development Environment file?
If you're using a developer account set test to true to use the developer server:
:test => true

salesforce sandbox integration in rails, error expired access

I am using the Ruby Gem "databascdotcom" to integrate Salesforce in a Rails app and all works fine until i try it with sandbox account type "Configuration Only".
The following code work fine when i used with salesforce product account.
Here is my code
def SalesForceFeed
#oppID = params[:oppid]
client = Databasedotcom::Client.new client.client_id #=> foo client.client_secret #=> bar
client.authenticate :username => "foo#bar.com", :password => "ThePasswordTheSecurityToken" #=> "the-oauth-token"
client.materialize("Opportunity")
begin
#client=SalesForce::Connection.new.client
#opp = Opportunity.find_by_Id(#oppID)
rescue Exception=>e
end
But when i try to use it with salesforce sandbox account with username like "foo#bar.com.sandbox"
I m getting following error "expired access/refresh token"
Any ideas?
Got the issue.
Just need to add
host= "test.salesforce.com"
Thanks All

how to get oauth access token for facebook using ruby

Am trying to get oauth access token for facebook programmatically in ruby.
My code is as follows:
client = OAuth2::Client.new(
APP_ID,
SECRET_ID,
:authorize_url => "/dialog/oauth",
:token_url => "/oauth/access_token",
:site => "https://www.facebook.com/"
)
code = client.auth_code.authorize_url(:redirect_uri => "http://www.facebook.com/")
token = client.auth_code.get_token(code, :redirect_uri => "https://graph.facebook.com/")
OAuth2::AccessToken.new(client, token.token, {:mode => :query, :param_name =>"oauth_token"})
When i try to run the above ruby code, i'm getting the following exception
https://www.facebook.com/dialog/oauth?response_type=code&client_id=APP_ID
51&redirect_uri=http%3A%2F%2Fwww.facebook.com%2F
/home/ec2-user/.rvm/gems/ruby-1.9.3-p0#samples/gems/oauth2-0.5.2/lib/oauth2/clie
nt.rb:129:in `get_token': OAuth2::Error (OAuth2::Error)
from /home/ec2-user/.rvm/gems/ruby-1.9.3-p0#samples/gems/oauth2-0.5.2/li
b/oauth2/strategy/auth_code.rb:29:in `get_token'
from oauth.rb:16:in `<main>'
Any help is greatly appreciated as I have spent more than a day while trying to sort this out.
Have you tried to put as redirect_uri instead of localhost:3000 your real IP address ex. 231.61.233.57:3000? Additionally you could try to use ssh tunneling for testing purposes so your localhost application will be available worldwide. Check this out http://progrium.com/localtunnel/ .
When you will get ip address from this tool try to set redirect_uri param to it.

Twitter User Hash for Sorcery Authentication

I'm using the Sorcery gem and their external module to authenticate with Twitter. I've got the authentication working, but I want to store the user's Twitter profile image URL in my database after a successful log in. Sorcery seems to have a configuration option that's meant to do exactly what I want:
config.twitter.user_info_mapping = {:nickname => "screen_name"}
Maybe I've missed something in the Sorcery documentation, but I can't find any information about what "keys" are available. I tried this to no avail:
config.twitter.user_info_mapping = {:nickname => "screen_name", :avatar_url => "profile_image_url"}
Has anyone found documentation about this?
That is just what you get from twitter in json format.
Here is a twitter documentation about it https://dev.twitter.com/docs/api/1/get/account/verify_credentials
config.twitter.user_info_mapping = {:username => "screen_name",
:realname => "name",
:location => "place",
:web => "url",
:bio => "description"}

Rails 3: SMTP Settings for Google Apps / Heroku

Here are my smtp settings for Google Apps in setup_mail.rb.
:address => "smtp.gmail.com",
:port => 587,
:domain => 'mysite.co',
:user_name => 'noreply#mysite.co',
:password => 'password',
:authentication => 'plain',
:enable_starttls_auto => true
My development logs show in detail the e-mails being generated and sent to the right e-mail address... but they are not arriving. I can only think that there must be something wrong with the settings above. Can you see what the problem is?
Once this is solved, would I have any issue getting it to work on Heroku?
Note: the above is logging a deprecation warning:
DEPRECATION WARNING: Giving a hash to body is deprecated, please use instance va
riables instead. (called from process at C:/Sanj/Ruby192/lib/ruby/gems/1.9.1/gem
s/actionmailer-3.0.0/lib/action_mailer/old_api.rb:77)
I think if you are using rails 3, the correct approach to setup mail would be to follow this railscasts tutorial on action mailer.
in your user controller don't forget to add the .deliver
UserMailer.registration_confirmation(#user).deliver
that is what stumped me
Turned out that the issue was elsewhere - an old AuthLogic tutorial had put me in the right direction on sending out activation codes but the wrong direction on sending out the e-mails themselves. Rails was generating the e-mail but not sending it because the mail_helper's code wasn't going the final step.
If you're reading this in retrospect, what I learned: make sure your Rails 3.0 user_mailer has (or similar):
mail(:to => "#{user.login} <#{user.email}>", :subject => "Registered" )
I haven't used rails3 but I remember reading that sent emails in development are sent to the sender. Your deprecation warning is because you're defining variables for the email template in the previous hash format. Rails 3 works differently. In my experience deploying to heroku works flawlessly but you will need to define mx records.

Resources