I'm using flickr-fu gem within a rails application for flickr api integration. I'm following the sample code for setting up a web app shown below:
def flickr_create
flickr = Flickr.new(File.join(RAILS_ROOT, 'config', 'flickr.yml'))
redirect_to flickr.auth.url(:read)
end
def flickr_callback
flickr = Flickr.new(File.join(RAILS_ROOT, 'config', 'flickr.yml'))
flickr.auth.frob = params[:frob]
current_user.update_attribute :flickr_token, flickr.auth.token.token
flash[:notice] = "Succesfully authenticated with Flickr"
redirect_to :flickr_stream
end
I've registered flickr_callback as the callback method that flickr calls after the authorization process.
The problem is with the line in flickr_callback when I try and assign params[:frob] to flickr.auth.frob. I get the following error:
undefined method `frob=' for Flickr::Auth:0x24b3640
Even if I just require 'flickr_fu' from within console, create a new flickr instance, and attempt to assign to frob, I get the same error. I took a look at the gem source on github, and the setter frob= is set within the Flickr::Auth module, so I'm clueless as to where the error is. The API calls work successfully and the flickr object is initialized fine.
The issue is that the flickr-fu gem from gemcutter or github is at version 0.1.4, and the frob setter method wasn't implemented until subsequent version. Instead install the gem commonthread-flickr_fu v0.3.0 from github, and the frob is writeable.
Related
I am learning payment gateway integration in rails.
I chose insta mojo and was working but the documentation they provide is very inconvenient and hard to understand..
https://github.com/AnkurGel/Instamojo-rb#usage
I have no idea where to Set my API keys
require 'Instamojo-rb'
api = Instamojo::API.new do |app|
app.api_key = "api_key-you-received-from-api#instamojo.com"
app.auth_token = "auth_token-you-received-from-api#instamojo.com"
end`
I tried instamojo.rb in initializers and tries to run console but it gives error that no such method exists.
You can put require statement in application.rb or anywhere else so that file is loaded while application is loading.
You can make 'Payment' model in which you can make methods like verify and get details.
Internally in those methods, you will be making API object and using the above code.
class Payment < ActiveRecord::Base
def verify
client = get_intamojo_client
#Some code
end
def get_details
client = get_intamojo_client
#Some code
end
private
def get_instamojo_client
api = Instamojo::API.new(ENV["INSTAMOJO_KEY"],{auth_token: ENV["INSTAMOJO_TOKEN"], endpoint:"https://test.instamojo.com/api/1.1/"})
return api.client
end
end
And to explore what you can do using client object, just use rails console and make a client object there, and use client.public_methods and start exploring.
EDIT:
I think you are using older version of gem i.e 0.1, their documentation is for version > 1.0. To update, use this gem 'Instamojo-rb', '~> 1.1' in gem file and use bundle update.
So for version 0.1, use
api = Instamojo::API.new(ENV["INSTAMOJO_KEY"],{auth_token: ENV["INSTAMOJO_TOKEN"], endpoint:"https://test.instamojo.com/api/1.1/"})
And for versino >= 1.0, use
api = Instamojo::API.new(ENV["INSTAMOJO_KEY"], ENV["INSTAMOJO_TOKEN"], "https://test.instamojo.com/api/1.1/")
I've been using the gem LinkedIn OAuth 2.0. Right now I can get it to generate the linkedin signin page. However, the next thing that is supposed to happen is it sends to my callback link a code which I use to generate an access token. The problem is that the variable 'oauth' is generated in the authenticate action but then needs to be used again in the callback action. I've tried generating the oauth variable again using the exact same parameters, but when I do that I get an SSL certificate error. It seems like the exact same oauth instance needs to be used in both cases. Let me know if you have any thoughts. My code is below:
def authenticate
require "linkedin-oauth2"
LinkedIn.configure do |config|
config.client_id = "Mycode"
config.client_secret = "Mysecret"
# This must exactly match the redirect URI you set on your application's
# settings page. If your redirect_uri is dynamic, pass it into
# `auth_code_url` instead.
config.redirect_uri = "http://localhost:3000/auth/linkedin/callback"
end
oauth = LinkedIn::OAuth2.new()
url = oauth.auth_code_url
redirect_to url
end
def callback
require "linkedin-oauth2"
code = params[:code]
access_token = oauth.get_access_token(code)
api = LinkedIn::API.new(access_token)
my_job_titles = api.profile(fields: ["id", {"positions" => ["title"]}])
puts my_job_titles
redirect_to("/")
end
end
Getting an SSL certificate error doesn't mean that the instantiation is wrong. I don't know that gem, but I can't see why would that be a problem.
The require and the configuration block should not be inside the method (maybe you forgot the configuration from the second method?); the best place for those is in config/initializers/linkedin_oauth2.rb.
If you don't want to load it at startup, then you can put those in a private method oauth with memoization:
def oauth
#oauth ||=
begin
require "linkedin-oauth2"
LinkedIn.configure do |config|
...
end
LinkedIn::OAuth2.new()
end
end
If the SSL error still occurs, you should investigate that. You can try creating a simple Ruby script with some example from the gem's readme, just to test the connection to LinkedIn.
Looks like the gem is using the faraday gem for HTTP, you can also try using that directly to make a simple call to LinkedIn.
I am attempting to extend one of the helper modules which Spree Commerce offers. I came across the following file: spree/frontend/app/helpers/frontend_helper.rb
Ultimately what I am trying to do is add a simple helper method to this module. I plan to call this helper method for use with the single product page. My implementation seems to be working fine with a couple exceptions, which has led me to believe that I have screwed up somewhere. Here is what I have done:
I have the file app/helpers/spree/frontend_helper_decorator.rb. The contents of this file:
Spree::FrontendHelper.module_eval do
# Create Variant Matrix
def create_variant_matrix( variants )
#valid_variants = {}
...
#valid_variants
end
end
The next thing I have done is extended the Products Controller for the purpose of overwriting one of the methods. I created app/controllers/spree/products_controller_decorator.rb. The content of this file:
Spree::ProductsController.class_eval do
include Spree::FrontendHelper
# Overwrite Show to include variant matrix
def show
#variants = #product.variants_including_master.active(current_currency).includes([:option_values, :images])
#product_properties = #product.product_properties.includes(:property)
#taxon = Spree::Taxon.find(params[:taxon_id]) if params[:taxon_id]
#vMatrix = create_variant_matrix( #variants )
end
end
As you can see here, I have overwritten the show method, copied the code from the default spree method and added my custom call. I have also included the FrontendHelper module in the controller.
This works without any errors with few exceptions. When I run bundle for the purpose of installing a new gem for instance, I typically get an error which requires me to remove my custom FrontendHelper method completly before I can successfully install the gem. Once the gem is installed, I add the code back in and it works fine. The error I receive is:
/fake/path/app/controllers/spree/product_controller_decorator.rb:2:in `block in <top (required)>': uninitialized constant Spree::FrontendHelper (NameError)
I have tried searching for this error with no luck. I am fairly new to Ruby (background is in PHP), but based on the tutorials I followed, I feel that it is correct. It also seems to be working properly in most scenarios.
Any help is appreciated.
I am currently using the google_places gem to try to access the places API. I am using the following code to get results:
class PlacesController < ApplicationController
def index
if params[:search]
#client = ::GooglePlaces::Client.new(Rails.application.secrets.places_api_key)
#places = #client.spots_by_query(params[:search])
end
end
end
I am running into an error of uninitialized constant GooglePlaces, which is replaced with PlacesController::GooglePlaces if I don't scope out. I believe this is a scoping issue, but nothing that I have tried fixes the issue. I am following the directions in the repo's readme and assuming that I don't have to include the source in the lib directory of my site. I can use the gem correctly from the rails console.
To use this API in rails application you need to use google_places gem.
add in gem file and run bundle install and restart the server once
gem 'google_places'
Next Create a project in google console and generate secret key .
https://code.google.com/apis/console
https://developers.google.com/places/documentation/
Finally restart the server
The docs said the API auth call should be:
#client = GooglePlaces::Client.new(Rails.application.secrets.places_api_key)
I am using devise/omniauth-foursquare and have recently run into difficulties now that foursquare is requesting the version parameter with every request. I get this error on everything:
Foursquare::Error (A required parameter was missing or a parameter was malformed. This is also used if the resource ID in the path is incorrect.):
I know with the recent foursquare update I need to add the v=20131016 parameter to all my requests, but I am not sure how to add it.
My devise configuration looks like this:
require 'omniauth-foursquare'
config.omniauth :foursquare, "[MY_APP_ID]", "[MY_SECRET_ID]"
I also access foursquare like this:
def foursquare
#foursquare ||= Foursquare::Base.new(fs_app_id, fs_secret)
end
Any help would be appreciated!
you need to add the newest omniauth-foursquare version to your gemfile. The branch was just updated a few days ago with:
#raw_info ||= access_token.get('https://api.foursquare.com/v2/. users/self?v=20140128').parsed['response']. ['user']
Then everything should be working like a charm again.