class GoogleSimpleApi::Manager
Attributes
settings[R]
Public Class Methods
new(settings, access_token = nil)
click to toggle source
# File lib/google_simple_api/manager.rb, line 19 def initialize(settings, access_token = nil) @settings = settings @authorizer = GoogleSimpleApi::Authorizer.new(settings) @authorizer.access_token = access_token if access_token end
Public Instance Methods
execute(action, parameters = {})
click to toggle source
Executes call for the loaded api. @param action [String] the resource that will be called. @param parameters [Hash] the parameters associated with the action. @return an object that contains the result of the call.
# File lib/google_simple_api/manager.rb, line 53 def execute(action, parameters = {}) methods = split_method(action) discovered_api = settings.discovered_api api_client = settings.api_client params = { :api_method => chained_method_calls(methods, discovered_api), :parameters => parameters } api_client.execute(params).data end
get_token(code, refresh_token=false)
click to toggle source
Processes code param and returns a valid access_token. @param code [String] the code returned from {#authorize_url} or
a previous stored refresh_token if <tt>refresh_token</tt> was true.
@param refresh_token [Boolean] indicates if code
is a refresh_token or a code from first access. @return [Hash] with all required data for the api access.
# File lib/google_simple_api/manager.rb, line 39 def get_token(code, refresh_token=false) if refresh_token authorizer.refresh_token=(code) else authorizer.code= code end authorizer.authorization.fetch_access_token! end
Private Instance Methods
chained_method_calls(methods, api)
click to toggle source
# File lib/google_simple_api/manager.rb, line 67 def chained_method_calls(methods, api) methods.inject(api) { |e, method| e.send(method.underscore) } end
split_method(method)
click to toggle source
# File lib/google_simple_api/manager.rb, line 71 def split_method(method) method.split(".") end