Class: Gslide::Models::Presentation
- Includes:
- Concerns::Requests
- Defined in:
- lib/gslide/models/presentation.rb
Constant Summary collapse
- PRESENTATION_ID_PATTERN =
/[a-zA-Z0-9\-_]+/- PRESENTATION_PATTERN =
%r[/presentation/d/(#{PRESENTATION_ID_PATTERN})?]
Instance Attribute Summary collapse
-
#id ⇒ Object
readonly
Returns the value of attribute id.
Class Method Summary collapse
-
.file_id_in(id_or_url) ⇒ String
The presentation id, or the argument when it is not a url.
Instance Method Summary collapse
-
#batch_update(options = {}) ⇒ Object
True when update successful.
-
#get ⇒ Hash
Data from a Google Slides presentation.
- #get_slide_ids ⇒ Object
-
#initialize(id_or_url, auth: nil) ⇒ Presentation
constructor
A new instance of Presentation.
- #link_url ⇒ Object
Methods included from Concerns::Requests
Constructor Details
#initialize(id_or_url, auth: nil) ⇒ Presentation
Returns a new instance of Presentation.
19 20 21 22 |
# File 'lib/gslide/models/presentation.rb', line 19 def initialize(id_or_url, auth: nil) @id = self.class.file_id_in(id_or_url) @auth = auth end |
Instance Attribute Details
#id ⇒ Object (readonly)
Returns the value of attribute id.
8 9 10 |
# File 'lib/gslide/models/presentation.rb', line 8 def id @id end |
Class Method Details
.file_id_in(id_or_url) ⇒ String
Returns the presentation id, or the argument when it is not a url.
15 16 17 |
# File 'lib/gslide/models/presentation.rb', line 15 def self.file_id_in(id_or_url) (url_id = id_or_url.match(PRESENTATION_PATTERN)) ? url_id[1] : id_or_url end |
Instance Method Details
#batch_update(options = {}) ⇒ Object
Returns True when update successful.
40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 |
# File 'lib/gslide/models/presentation.rb', line 40 def batch_update( = {}) retries ||= 0 uri = URI(GOOGLE_SLIDES + "/#{@id}:batchUpdate") request_body = .convert_keys { |k| k.to_s.lower_camel_case }.to_json response_body = post_request(uri, auth_token: @auth.token, body: request_body) response_body["presentationId"] == @id rescue Gslide::QuotaExceededError if (retries += 1) < 3 sleep 10 + retries * retries * 10 retry end # all retries failed, raise exception raise end |
#get ⇒ Hash
Returns data from a Google Slides presentation.
26 27 28 29 30 31 |
# File 'lib/gslide/models/presentation.rb', line 26 def get uri = URI(GOOGLE_SLIDES + "/#{@id}") response_body = get_request(uri, auth_token: @auth.token) response_body.convert_keys {|k| k.snake_case.to_sym } end |
#get_slide_ids ⇒ Object
58 59 60 61 |
# File 'lib/gslide/models/presentation.rb', line 58 def parsed_body = get parsed_body[:slides].collect { || [:object_id] } end |
#link_url ⇒ Object
33 34 35 |
# File 'lib/gslide/models/presentation.rb', line 33 def link_url "https://docs.google.com/presentation/d/#{@id}/edit" end |