Class: Gslide::Models::Presentation
- Includes:
- Concerns::Requests
- Defined in:
- lib/gslide/models/presentation.rb
Constant Summary collapse
- PRESENTATION_PATTERN =
%r[/presentation/d/([a-zA-Z0-9\-_]+)?]
Instance Attribute Summary collapse
-
#id ⇒ Object
readonly
Returns the value of attribute id.
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.
12 13 14 15 |
# File 'lib/gslide/models/presentation.rb', line 12 def initialize(id_or_url, auth: nil) @id = (url_id = id_or_url.match(PRESENTATION_PATTERN)) ? url_id[1] : 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 |
Instance Method Details
#batch_update(options = {}) ⇒ Object
Returns True when update successful.
33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/gslide/models/presentation.rb', line 33 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.
19 20 21 22 23 24 |
# File 'lib/gslide/models/presentation.rb', line 19 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
51 52 53 54 |
# File 'lib/gslide/models/presentation.rb', line 51 def parsed_body = get parsed_body[:slides].collect { || [:object_id] } end |
#link_url ⇒ Object
26 27 28 |
# File 'lib/gslide/models/presentation.rb', line 26 def link_url "https://docs.google.com/presentation/d/#{@id}/edit" end |