@@ -40,25 +40,234 @@ feature -- Post
4040 note
4141 EIS :" name=create.spreedsheets" , " src=https://developers.google.com/sheets/api/reference/rest/v4/spreadsheets/create" , " protocol=uri"
4242 do
43- create Result . make ( " " , " " )
43+ create Result
4444 if attached eg_sheets_api .create_spreedsheet as s then
4545 if attached parsed_json (s ) as j then
46+ Result := eg_spreadsheet (Void , j )
4647 else
4748 -- set error
4849 end
4950 end
5051 end
5152
53+ feature -- Error
54+
55+ last_error : detachable STRING
56+ -- Last error message.
57+ -- maybe we can create an specific EG_ERROR.
5258
5359feature -- Implementation Factory
5460
5561 eg_spreadsheet (a_spreadsheet : detachable like eg_spreadsheet ; a_json : JSON_VALUE ): EG_SPREEDSHEET
5662 --
5763 do
58- create Result .make (" " , " " )
64+ if a_spreadsheet /= Void then
65+ Result := a_spreadsheet
66+ else
67+ create Result
68+ end
69+ if attached string_value_from_json (a_json , " spreadsheetId" ) as l_id then
70+ Result .set_id (l_id )
71+ end
72+ if attached string_value_from_json (a_json , " spreadsheetUrl" ) as l_url then
73+ Result .set_url (l_url )
74+ end
75+ Result .set_protperty (eg_spreadsheet_properties (a_json ))
76+ if attached {JSON_ARRAY } json_value (a_json , " sheets" ) as l_sheets then
77+ across l_sheets as ic loop
78+ end
79+ end
80+ if attached {JSON_ARRAY } json_value (a_json , " namedRanges" ) as l_named_ranges then
81+ end
82+ if attached {JSON_ARRAY } json_value (a_json , " developerMetadata" ) as l_developer_metadata then
83+ -- TODO
84+ end
85+
86+
87+ end
88+
89+ feature {NONE } -- JSON To Eiffel
90+
91+ eg_spreadsheet_properties (a_json : JSON_VALUE ): EG_SPREADSHEET_PROPERTIES
92+ --
93+ local
94+ l_cell_format : EG_CELL_FORMAT
95+ do
96+ create Result
97+ if attached {JSON_OBJECT } json_value (a_json , " properties" ) as l_properties then
98+ if attached string_value_from_json (l_properties , " title" ) as l_title then
99+ Result .set_title (l_title )
100+ end
101+ if attached string_value_from_json (l_properties , " locale" ) as l_locale then
102+ Result .set_locale (l_locale )
103+ end
104+ if attached string_value_from_json (l_properties , " autoRecalc" ) as l_auto_recalc then
105+ if l_auto_recalc .is_case_insensitive_equal (" ON_CHANGE" ) then
106+ Result .auto_recalc .set_on_change
107+ elseif l_auto_recalc .is_case_insensitive_equal (" MINUTE" ) then
108+ Result .auto_recalc .set_minute
109+ elseif l_auto_recalc .is_case_insensitive_equal (" HOUR" ) then
110+ Result .auto_recalc .set_hour
111+ end
112+ end
113+ if attached string_value_from_json (l_properties , " timeZone" ) as l_time_zone then
114+ Result .set_time_zone (l_time_zone )
115+ end
116+ if attached {JSON_OBJECT } json_value (l_properties , " defaultFormat" ) as l_default_format then
117+ end
118+ end
59119 end
60120
61121
122+ default_format (a_json : JSON_OBJECT ): EG_CELL_FORMAT
123+ do
124+ create Result
125+
126+ if attached {JSON_OBJECT } json_value (a_json , " backgroundColor" ) as l_background_color then
127+ Result .set_background_color (eg_color (l_background_color ))
128+ end
129+ if attached {JSON_OBJECT } json_value (a_json , " padding" ) as l_padding then
130+ Result .set_padding (padding (l_padding ))
131+ end
132+ if attached string_value_from_json (a_json , " verticalAlignment" ) as l_alignment then
133+ if l_alignment .is_case_insensitive_equal (" BOTTOM" ) then
134+ Result .vertical_alignment .set_bottom
135+ elseif l_alignment .is_case_insensitive_equal (" MIDDLE" ) then
136+ Result .vertical_alignment .set_middle
137+ elseif l_alignment .is_case_insensitive_equal (" TOP" ) then
138+ Result .vertical_alignment .set_top
139+ end
140+ end
141+ if attached string_value_from_json (a_json , " wrapStrategy" ) as l_wrap_strategy then
142+ if l_wrap_strategy .is_case_insensitive_equal (" OVERFLOW_CELL" ) then
143+ Result .wrap_strategy .set_overflow_cell
144+ end
145+ if l_wrap_strategy .is_case_insensitive_equal (" LEGACY_WRAP" ) then
146+ Result .wrap_strategy .set_legacy_wrap
147+ elseif l_wrap_strategy .is_case_insensitive_equal (" CLIP" ) then
148+ Result .wrap_strategy .set_clip
149+ elseif l_wrap_strategy .is_case_insensitive_equal (" WRAP" ) then
150+ Result .wrap_strategy .set_wrap
151+ end
152+ end
153+ if attached {JSON_OBJECT } json_value (a_json , " textFormat" ) as l_text_format then
154+ Result .set_text_format (text_format (l_text_format ))
155+ end
156+ if attached {JSON_OBJECT } json_value (a_json , " backgroundColorStyle" ) as l_background_color_style then
157+ Result .set_background_color_style (eg_color_style (l_background_color_style ))
158+ end
159+ end
160+
161+ eg_color (a_json : JSON_OBJECT ): EG_COLOR
162+ do
163+ create Result
164+ if attached integer_value_from_json (a_json , " red" ) as l_val then
165+ Result .set_red (l_val )
166+ elseif attached real_value_from_json (a_json , " red" ) as l_val then
167+ Result .set_red (l_val )
168+ end
169+ if attached integer_value_from_json (a_json , " green" ) as l_val then
170+ Result .set_green (l_val )
171+ elseif attached real_value_from_json (a_json , " green" ) as l_val then
172+ Result .set_green (l_val )
173+ end
174+ if attached integer_value_from_json (a_json , " blue" ) as l_val then
175+ Result .set_blue (l_val )
176+ elseif attached real_value_from_json (a_json , " blue" ) as l_val then
177+ Result .set_blue (l_val )
178+ end
179+ if attached integer_value_from_json (a_json , " alpha" ) as l_val then
180+ Result .set_alpha (l_val )
181+ elseif attached real_value_from_json (a_json , " alpha" ) as l_val then
182+ Result .set_alpha (l_val )
183+ end
184+ end
185+
186+ padding (a_json : JSON_OBJECT ): EG_PADDING
187+ do
188+ create Result
189+ if attached integer_value_from_json (a_json , " top" ) as l_val then
190+ Result .set_top (l_val )
191+ end
192+ if attached integer_value_from_json (a_json , " right" ) as l_val then
193+ Result .set_right (l_val )
194+ end
195+ if attached integer_value_from_json (a_json , " bottom" ) as l_val then
196+ Result .set_bottom (l_val )
197+ end
198+ if attached integer_value_from_json (a_json , " left" ) as l_val then
199+ Result .set_left (l_val )
200+ end
201+ end
202+
203+ text_format (a_json : JSON_OBJECT ): EG_TEXT_FORMAT
204+ do
205+ create Result
206+ if attached {JSON_OBJECT } json_value (a_json , " foregroundColor" ) as l_foreground_color then
207+ Result .set_foreground_color (eg_color (l_foreground_color ))
208+ end
209+ if attached {JSON_OBJECT } json_value (a_json , " foregroundColorStyle" ) as l_foreground_color_style then
210+ Result .set_foreground_color_style (eg_color_style (l_foreground_color_style ))
211+ end
212+ if attached string_value_from_json (a_json , " fontFamily" ) as l_font_family then
213+ Result .set_font_family (l_font_family )
214+ end
215+ if attached integer_value_from_json (a_json , " fontSize" ) as l_font_size then
216+ Result .set_font_size (l_font_size )
217+ end
218+ if attached boolean_value_from_json (a_json , " bold" ) as l_bold then
219+ Result .set_bold (l_bold )
220+ end
221+ if attached boolean_value_from_json (a_json , " italic" ) as l_italic then
222+ Result .set_italic (l_italic )
223+ end
224+ if attached boolean_value_from_json (a_json , " strikethrough" ) as l_strikethrough then
225+ Result .set_strikethrough (l_strikethrough )
226+ end
227+ if attached boolean_value_from_json (a_json , " underline" ) as l_underline then
228+ Result .set_strikethrough (l_underline )
229+ end
230+ end
231+
232+ eg_color_style (a_json : JSON_OBJECT ): EG_COLOR_STYLE
233+ local
234+ l_tc : EG_THEME_COLOR
235+ do
236+ create Result
237+ if attached {JSON_OBJECT } json_value (a_json , " rgbColor" ) as l_rgbcolor then
238+ Result .set_rgb (eg_color (l_rgbcolor ))
239+ elseif
240+ attached string_value_from_json (a_json , " themeColor" ) as l_theme_color
241+ then
242+ create l_tc
243+ if l_theme_color .is_case_insensitive_equal (" TEXT" ) then
244+ l_tc .set_text
245+ elseif l_theme_color .is_case_insensitive_equal (" BACKGROUND" ) then
246+ l_tc .set_background
247+ elseif l_theme_color .is_case_insensitive_equal (" ACCENT1" ) then
248+ l_tc .set_accent 1
249+ elseif l_theme_color .is_case_insensitive_equal (" ACCENT2" ) then
250+ l_tc .set_accent 2
251+ elseif l_theme_color .is_case_insensitive_equal (" ACCENT3" ) then
252+ l_tc .set_accent 3
253+ elseif l_theme_color .is_case_insensitive_equal (" ACCENT4" ) then
254+ l_tc .set_accent 4
255+ elseif l_theme_color .is_case_insensitive_equal (" ACCENT5" ) then
256+ l_tc .set_accent 5
257+ elseif l_theme_color .is_case_insensitive_equal (" ACCENT6" ) then
258+ l_tc .set_accent 6
259+ elseif l_theme_color .is_case_insensitive_equal (" LINK" ) then
260+ l_tc .set_link
261+ end
262+ Result .set_theme_color (l_tc )
263+ end
264+ end
265+
266+ eg_sheets (a_json : JSON_VALUE ): EG_SHEET
267+ do
268+ create Result
269+ end
270+
62271
63272feature {NONE } -- Implementation
64273
0 commit comments