Class: CloudPrint::Client

Inherits:
Object
  • Object
show all
Defined in:
lib/cloudprint/client.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ Client

Returns a new instance of Client.



11
12
13
14
15
16
17
18
19
# File 'lib/cloudprint/client.rb', line 11

def initialize(options = {})
  @refresh_token = options[:refresh_token]
  @client_id = options[:client_id]
  @client_secret = options[:client_secret]
  @callback_url = options[:callback_url]
  @connection = Connection.new(self)
  @printers = PrinterCollection.new(self)
  @print_jobs = PrintJobCollection.new(self)
end

Instance Attribute Details

#callback_urlObject (readonly)

Returns the value of attribute callback_url.



6
7
8
# File 'lib/cloudprint/client.rb', line 6

def callback_url
  @callback_url
end

#client_idObject (readonly)

Returns the value of attribute client_id.



4
5
6
# File 'lib/cloudprint/client.rb', line 4

def client_id
  @client_id
end

#client_secretObject (readonly)

Returns the value of attribute client_secret.



3
4
5
# File 'lib/cloudprint/client.rb', line 3

def client_secret
  @client_secret
end

#connectionObject (readonly)

Returns the value of attribute connection.



7
8
9
# File 'lib/cloudprint/client.rb', line 7

def connection
  @connection
end

Returns the value of attribute print_jobs.



9
10
11
# File 'lib/cloudprint/client.rb', line 9

def print_jobs
  @print_jobs
end

#printersObject (readonly)

Returns the value of attribute printers.



8
9
10
# File 'lib/cloudprint/client.rb', line 8

def printers
  @printers
end

#refresh_tokenObject

Returns the value of attribute refresh_token.



5
6
7
# File 'lib/cloudprint/client.rb', line 5

def refresh_token
  @refresh_token
end

Instance Method Details

#access_tokenObject



21
22
23
# File 'lib/cloudprint/client.rb', line 21

def access_token
  (access_token_valid? && @access_token || renew_access_token!).token
end

#access_token_valid?Boolean

Returns:

  • (Boolean)


30
31
32
# File 'lib/cloudprint/client.rb', line 30

def access_token_valid?
  @access_token.is_a?(OAuth2::AccessToken) && !@access_token.token.to_s.strip.empty? && !@access_token.expired?
end