Class: Gslide::Models::Presentation

Inherits:
Object
  • Object
show all
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

Instance Method Summary collapse

Methods included from Concerns::Requests

#get_request, #post_request

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

#idObject (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.

Parameters:

  • options (Hash) (defaults to: {})

    the request body.

Returns:

  • True when update successful.

See Also:



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(options = {})
  retries ||= 0

  uri = URI(GOOGLE_SLIDES + "/#{@id}:batchUpdate")
  request_body = options.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

#getHash

Returns data from a Google Slides presentation.

Returns:

  • (Hash)

    data from a Google Slides presentation.

See Also:



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_idsObject



51
52
53
54
# File 'lib/gslide/models/presentation.rb', line 51

def get_slide_ids
  parsed_body = get
  parsed_body[:slides].collect { |slide| slide[:object_id] }
end


26
27
28
# File 'lib/gslide/models/presentation.rb', line 26

def link_url
  "https://docs.google.com/presentation/d/#{@id}/edit"
end