Class: CloudPrint::Client
- Inherits:
-
Object
- Object
- CloudPrint::Client
- Defined in:
- lib/cloudprint/client.rb
Instance Attribute Summary collapse
-
#callback_url ⇒ Object
readonly
Returns the value of attribute callback_url.
-
#client_id ⇒ Object
readonly
Returns the value of attribute client_id.
-
#client_secret ⇒ Object
readonly
Returns the value of attribute client_secret.
-
#connection ⇒ Object
readonly
Returns the value of attribute connection.
-
#print_jobs ⇒ Object
readonly
Returns the value of attribute print_jobs.
-
#printers ⇒ Object
readonly
Returns the value of attribute printers.
-
#refresh_token ⇒ Object
Returns the value of attribute refresh_token.
Instance Method Summary collapse
- #access_token ⇒ Object
- #access_token_valid? ⇒ Boolean
- #auth ⇒ Object
-
#initialize(options = {}) ⇒ Client
constructor
A new instance of Client.
- #oauth_client ⇒ Object
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( = {}) @access_token = nil @refresh_token = [:refresh_token] @client_id = [:client_id] @client_secret = [:client_secret] @callback_url = [:callback_url] @access_type = [:access_type] @connection = Connection.new(self) @printers = PrinterCollection.new(self) @print_jobs = PrintJobCollection.new(self) end |
Instance Attribute Details
#callback_url ⇒ Object (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_id ⇒ Object (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_secret ⇒ Object (readonly)
Returns the value of attribute client_secret.
3 4 5 |
# File 'lib/cloudprint/client.rb', line 3 def client_secret @client_secret end |
#connection ⇒ Object (readonly)
Returns the value of attribute connection.
7 8 9 |
# File 'lib/cloudprint/client.rb', line 7 def connection @connection end |
#print_jobs ⇒ Object (readonly)
Returns the value of attribute print_jobs.
9 10 11 |
# File 'lib/cloudprint/client.rb', line 9 def print_jobs @print_jobs end |
#printers ⇒ Object (readonly)
Returns the value of attribute printers.
8 9 10 |
# File 'lib/cloudprint/client.rb', line 8 def printers @printers end |
#refresh_token ⇒ Object
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_token ⇒ Object
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
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 |
#auth ⇒ Object
23 24 25 |
# File 'lib/cloudprint/client.rb', line 23 def auth @auth ||= CloudPrint::Auth.new(self, access_type: @access_type) end |
#oauth_client ⇒ Object
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 |