class CloudPrint::Client
Attributes
callback_url[R]
client_id[R]
client_secret[R]
connection[R]
print_jobs[R]
printers[R]
refresh_token[R]
Public Class Methods
new(options = {})
click to toggle source
# File lib/cloudprint/client.rb, line 11 def initialize(options = {}) @access_token = nil @refresh_token = options[:refresh_token] @client_id = options[:client_id] @client_secret = options[:client_secret] @callback_url = options[:callback_url] @access_type = options[:access_type] @connection = Connection.new(self) @printers = PrinterCollection.new(self) @print_jobs = PrintJobCollection.new(self) end
Public Instance Methods
access_token()
click to toggle source
# File lib/cloudprint/client.rb, line 27 def access_token (access_token_valid? && @access_token || renew_access_token!).token end
access_token_valid?()
click to toggle source
# File lib/cloudprint/client.rb, line 36 def access_token_valid? @access_token.is_a?(OAuth2::AccessToken) && !@access_token.token.to_s.strip.empty? && !@access_token.expired? end
auth()
click to toggle source
# File lib/cloudprint/client.rb, line 23 def auth @auth ||= CloudPrint::Auth.new(self, access_type: @access_type) end
oauth_client()
click to toggle source
# File lib/cloudprint/client.rb, line 40 def oauth_client @oauth_client ||= OAuth2::Client.new( client_id, client_secret, :authorize_url => "/o/oauth2/auth", :token_url => "/o/oauth2/token", :access_token_url => "/o/oauth2/token", :site => 'https://accounts.google.com/' ) end
refresh_token=(new_token)
click to toggle source
# File lib/cloudprint/client.rb, line 31 def refresh_token=(new_token) @refresh_token = new_token renew_access_token! end
Private Instance Methods
renew_access_token!()
click to toggle source
# File lib/cloudprint/client.rb, line 52 def renew_access_token! @access_token = OAuth2::AccessToken.new(oauth_client, "", :refresh_token => refresh_token).refresh! end