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
20
21
# 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

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



27
28
29
# File 'lib/cloudprint/client.rb', line 27

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

#access_token_valid?Boolean

Returns:

  • (Boolean)


36
37
38
# 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

#authObject



23
24
25
# File 'lib/cloudprint/client.rb', line 23

def auth
  @auth ||= CloudPrint::Auth.new(self, access_type: @access_type)
end

#oauth_clientObject



40
41
42
43
44
45
46
47
48
# 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