3

I have started with this example, I managed to make everything work on sinatra.

But I want to use this in my Rails app so I did the followings:

  1. Create the client, in sinatra they do that in the configure block.

In rails I did: In the config/initializers file I've added the entire block which is in sinatra after that I wrote a class GoogleCalendar::Base where I have:

class GoogleCalendar::Base
  class << self
    attr_accessor :api_client, :calendar_api
  end
  def self.configure
    yield self if block_given?
  end

So like this I replaced the set :api_client, client, set :calendar, calendar

In my application controller then I've added the:

def user_credentials
  ...
  (what i've changed was instead of session i've added `see below`)
  auth.update_token!(access_token: session[:access_token], 
                     refresh_token: session[:refresh_token])
end

Because I wasn't working if passing session maybe someone can tell me why? (conflict between sessions? and it was working with cookies.)

Also I have created other functions in the application controller which I use for callback and get content.

def api_client
  GoogleCalendar::Base.api_client
end

def calendar
  GoogleCalendar::Base.calendar_api
end

In the end I've created the rest of the controllers/views and everything works fine.

My final question is: It is ok creating the Google::APIClient in the initialisers folder because I've notice that every time I change something in my controllers the code brakes, but if I restart the server everything works ok.

Linda Lawton - DaImTo
  • 106,405
  • 32
  • 180
  • 449
RockNinja
  • 2,179
  • 4
  • 16
  • 16

0 Answers0