File tree Expand file tree Collapse file tree 5 files changed +50
-14
lines changed
Expand file tree Collapse file tree 5 files changed +50
-14
lines changed Original file line number Diff line number Diff line change @@ -20,7 +20,7 @@ bundle install
2020
2121``` rb
2222token = " ya29.a0AXeO8..."
23- id = " 113Xmx0YQc... "
23+ id = " 1nNv3fyCIrvAs754Zd5c6klCjMhP7D2rmX3T9nFpjW4Q "
2424editor = Gslide ::Editor .new (token)
2525pres = Gslide ::Presentation .new (id, auth: editor)
2626pres.get
@@ -32,39 +32,42 @@ editor = Gslide::Editor.new(token)
3232editor.insert_presentation(title: " Once upon a time" )
3333# => <Gslide::Models::Presentation:0x000000013e6d4108
3434# @id="1itXwmlLbyTRa1QKhrsO16OhJPEJUK6eh2d1nqsQfuqY">
35-
3635pres = _
36+ ```
37+
38+ ``` rb
3739pres.batch_update({
3840 requests: [
3941 {
40- createSlide : {
41- slideLayoutReference : {
42- predefinedLayout : " BLANK"
42+ create_slide : {
43+ slide_layout_reference : {
44+ predefined_layout : " BLANK"
4345 }
4446 }
4547 }
4648 ]
4749})
50+ # => true
4851
4952pres.get_slide_ids
50- # => ["p", "SLIDES_API1463300837_0 "]
53+ # => ["p", "SLIDES_API778986045_0 "]
5154
5255pres.batch_update({
5356 requests: [
5457 {
55- createImage : {
58+ create_image : {
5659 url: " https://drive.usercontent.google.com/download?id=1fus5psRLzIJjG3A5GAfbqu22cdEczNZQ&authuser=0" ,
57- elementProperties : {
58- pageObjectId : " SLIDES_API1463300837_0 " ,
60+ element_properties : {
61+ page_object_id : " SLIDES_API778986045_0 " ,
5962 size: {
6063 height: { magnitude: 200 , unit: " PT" },
6164 width: { magnitude: 300 , unit: " PT" }
6265 },
6366 transform: {
64- scaleX : 1 ,
65- scaleY : 1 ,
66- translateX : 100 ,
67- translateY : 100 ,
67+ scale_x : 1 ,
68+ scale_y : 1 ,
69+ translate_x : 100 ,
70+ translate_y : 100 ,
6871 unit: " PT"
6972 }
7073 }
Original file line number Diff line number Diff line change 11# frozen_string_literal: true
22
33require_relative "gslide/version"
4+ require_relative "string"
45
56require "gslide/models/models"
67
Original file line number Diff line number Diff line change @@ -22,6 +22,7 @@ def initialize(token)
2222 def insert_presentation ( options = { } )
2323 uri = URI ( GOOGLE_SLIDES + "" )
2424
25+ # "title" is the only allowed field in the request body
2526 res = post_request ( uri , auth_token : @token , body : options . to_json )
2627 response_body = JSON ( res . body )
2728
Original file line number Diff line number Diff line change @@ -30,8 +30,9 @@ def link_url
3030 # @see https://developers.google.com/slides/api/reference/rest/v1/presentations/batchUpdate#request-body
3131 def batch_update ( options = { } )
3232 uri = URI ( GOOGLE_SLIDES + "/#{ @id } :batchUpdate" )
33+ request_body = options . convert_keys { |k | k . to_s . lower_camel_case } . to_json
3334
34- res = post_request ( uri , auth_token : @auth . token , body : options . to_json )
35+ res = post_request ( uri , auth_token : @auth . token , body : request_body )
3536 response_body = JSON ( res . body )
3637
3738 if response_body [ "error" ]
Original file line number Diff line number Diff line change 1+ # frozen_string_literal: true
2+
3+ class String
4+ def snake_case
5+ gsub ( /::/ , '/' ) .
6+ gsub ( /([A-Z]+)([A-Z][a-z])/ , '\1_\2' ) .
7+ gsub ( /([a-z\d ])([A-Z])/ , '\1_\2' ) .
8+ tr ( "-" , "_" ) .
9+ downcase
10+ end
11+
12+ def lower_camel_case
13+ split ( '_' ) . inject { |m , p | m + p . capitalize }
14+ end
15+ end
16+
17+ class Object
18+ def convert_keys ( &blk )
19+ case self
20+ when Array
21+ self . map { |v | v . convert_keys ( &blk ) }
22+ when Hash
23+ self . map { |k , v | [ blk . call ( k ) , v . convert_keys ( &blk ) ] } . to_h
24+ else
25+ self
26+ end
27+ end
28+ end
29+
30+ # Now, you can do options.convert_keys { |k| k.lower_camel_case }
You can’t perform that action at this time.
0 commit comments