Skip to content

Commit 68dd53c

Browse files
committed
Updated Google SpreadSheet implementation.
Work in progress.
1 parent c476185 commit 68dd53c

18 files changed

+822
-15
lines changed

sheets/src/json/eg_sheets_json.e

Lines changed: 49 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,24 +40,71 @@ 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

5359
feature -- 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+
5977
end
6078

79+
feature {NONE} -- JSON To Eiffel
80+
81+
eg_spreadsheet_properties (a_json: JSON_VALUE): EG_SPREADSHEET_PROPERTIES
82+
--
83+
do
84+
create Result
85+
if attached {JSON_OBJECT} json_value (a_json, "properties") as l_properties then
86+
if attached string_value_from_json (l_properties, "title") as l_title then
87+
Result.set_title (l_title)
88+
end
89+
if attached string_value_from_json (l_properties, "locale") as l_locale then
90+
Result.set_locale (l_locale)
91+
end
92+
if attached string_value_from_json (l_properties, "autoRecalc") as l_auto_recalc then
93+
if l_auto_recalc.is_case_insensitive_equal ("ON_CHANGE") then
94+
Result.auto_recalc.set_on_change
95+
end
96+
if l_auto_recalc.is_case_insensitive_equal ("MINUTE") then
97+
Result.auto_recalc.set_minute
98+
end
99+
if l_auto_recalc.is_case_insensitive_equal ("HOUR") then
100+
Result.auto_recalc.set_hour
101+
end
102+
end
103+
if attached string_value_from_json (l_properties, "timeZone") as l_time_zone then
104+
Result.set_time_zone (l_time_zone)
105+
end
106+
end
107+
end
61108

62109

63110
feature {NONE} -- Implementation

sheets/src/objects/eg_border.e

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
note
2+
description: "Summary description for {EG_BORDER}."
3+
author: ""
4+
date: "$Date$"
5+
revision: "$Revision$"
6+
7+
class
8+
EG_BORDER
9+
10+
end

sheets/src/objects/eg_borders.e

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
note
2+
description: "[
3+
Object rerpesenting the borders of the cell
4+
5+
{
6+
"top": {
7+
object (Border)
8+
},
9+
"bottom": {
10+
object (Border)
11+
},
12+
"left": {
13+
object (Border)
14+
},
15+
"right": {
16+
object (Border)
17+
}
18+
}
19+
20+
21+
]"
22+
date: "$Date$"
23+
revision: "$Revision$"
24+
EIS: "name=borders", "src=https://developers.google.com/sheets/api/reference/rest/v4/spreadsheets/cells#Borders", "protocol=uri"
25+
26+
class
27+
EG_BORDERS
28+
29+
inherit
30+
31+
ANY
32+
redefine
33+
default_create
34+
end
35+
36+
create
37+
default_create
38+
39+
feature {NONE} -- Initialization
40+
41+
default_create
42+
do
43+
create top
44+
create bottom
45+
create left
46+
create right
47+
end
48+
49+
feature -- Access
50+
51+
top: EG_BORDER
52+
-- The top border of the cell.
53+
54+
bottom: EG_BORDER
55+
-- The bottom border of the cell.
56+
57+
left: EG_BORDER
58+
-- The left border of the cell.
59+
60+
right: EG_BORDER
61+
-- The right border of the cell.
62+
63+
64+
end
Lines changed: 89 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,97 @@
11
note
2-
description: "Summary description for {EG_CELL_FORMAT}."
3-
author: ""
2+
description: "[
3+
Object representing the format of a cell.
4+
5+
{
6+
"numberFormat": {
7+
object (NumberFormat)
8+
},
9+
"backgroundColor": {
10+
object (Color)
11+
},
12+
"backgroundColorStyle": {
13+
object (ColorStyle)
14+
},
15+
"borders": {
16+
object (Borders)
17+
},
18+
"padding": {
19+
object (Padding)
20+
},
21+
"horizontalAlignment": enum (HorizontalAlign),
22+
"verticalAlignment": enum (VerticalAlign),
23+
"wrapStrategy": enum (WrapStrategy),
24+
"textDirection": enum (TextDirection),
25+
"textFormat": {
26+
object (TextFormat)
27+
},
28+
"hyperlinkDisplayType": enum (HyperlinkDisplayType),
29+
"textRotation": {
30+
object (TextRotation)
31+
}
32+
}
33+
]"
434
date: "$Date$"
535
revision: "$Revision$"
36+
EIS: "name=Cell Format", "src=https://developers.google.com/sheets/api/reference/rest/v4/spreadsheets/cells#CellFormat", "protocol=uri"
637

738
class
839
EG_CELL_FORMAT
940

41+
inherit
42+
43+
ANY
44+
redefine
45+
default_create
46+
end
47+
48+
feature {NONE} -- Initialization
49+
50+
default_create
51+
do
52+
create background_color
53+
create background_color_style
54+
create padding
55+
create vertical_alignment
56+
create text_format
57+
create wrap_strategy
58+
end
59+
60+
feature -- Access
61+
62+
number_format: detachable EG_NUMBER_FORMAT
63+
-- A format describing how number values should be represented to the user.
64+
65+
background_color: EG_COLOR
66+
-- The background color of the cell.
67+
68+
background_color_style: EG_COLOR_STYLE
69+
-- The background color of the cell. If backgroundColor is also set, this field takes precedence.
70+
71+
borders: detachable EG_BORDERS
72+
-- The borders of the cell.
73+
74+
padding: EG_PADDING
75+
-- The padding of the cell.
76+
77+
horizontal_alignment: detachable EG_HORIZONTAL_ALIGN
78+
-- The horizontal alignment of the value in the cell.
79+
80+
vertical_alignment: EG_VERTICAL_ALIGN
81+
-- The vertical alignment of the value in the cell.
82+
83+
wrap_strategy: EG_WRAP_STRATEGY
84+
-- The wrap strategy for the value in the cell.
85+
86+
text_direction: detachable EG_TEXT_DIRECTION
87+
-- The direction of the text in the cell.
88+
89+
text_format: EG_TEXT_FORMAT
90+
-- The format of the text in the cell (unless overridden by a format run).
91+
92+
hyperlinkDisplayType: detachable EG_HYPERLINK_DISPLAY_TYPE
93+
-- How a hyperlink, if it exists, should be displayed in the cell.
94+
95+
text_rotation: detachable EG_TEXT_ROTATION
96+
-- The rotation applied to text in a cell
1097
end

sheets/src/objects/eg_color.e

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
note
2+
description: "Summary description for {EG_COLOR}."
3+
author: ""
4+
date: "$Date$"
5+
revision: "$Revision$"
6+
7+
class
8+
EG_COLOR
9+
10+
inherit
11+
12+
ANY
13+
redefine
14+
default_create
15+
end
16+
create
17+
default_create
18+
19+
feature {NONE} -- Access
20+
21+
default_create
22+
do
23+
red := 1.0
24+
green := 1.0
25+
blue := 1.0
26+
alpha := 1.0
27+
end
28+
29+
feature -- Access
30+
31+
red: REAL
32+
-- The amount of red in the color as a value in the interval [0, 1].
33+
34+
green: REAL
35+
-- The amount of green in the color as a value in the interval [0, 1].
36+
37+
blue: REAL
38+
-- The amount of blue in the color as a value in the interval [0, 1].
39+
40+
alpha: REAL
41+
-- The fraction of this color that should be applied to the pixel. That is, the final pixel color is defined by the equation:
42+
-- pixel color = alpha * (this color) + (1.0 - alpha) * (background color)
43+
-- This means that a value of 1.0 corresponds to a solid color, whereas a value of 0.0 corresponds to a completely transparent color.
44+
-- This uses a wrapper message rather than a simple float scalar so that it is possible to distinguish between a default value and the value being unset.
45+
-- If omitted, this color object is to be rendered as a solid color (as if the alpha value had been explicitly given with a value of 1.0).
46+
47+
invariant
48+
red_invariant: red >= 0.0 and then red <= 1.0
49+
green_invariant: green >= 0.0 and then green <= 1.0
50+
blue_invariant: blue >= 0.0 and then blue <= 1.0
51+
alpha_invariant: alpha >= 0.0 and then alpha <= 1.0
52+
end
Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
note
2+
description: "[
3+
Object representing a Color value
4+
5+
{
6+
7+
// Union field kind can be only one of the following:
8+
"rgbColor": {
9+
object (Color)
10+
},
11+
"themeColor": enum (ThemeColorType)
12+
// End of list of possible types for union field kind.
13+
}
14+
15+
]"
16+
date: "$Date$"
17+
revision: "$Revision$"
18+
EIS: "name=Color Style", "src=https://developers.google.com/sheets/api/reference/rest/v4/spreadsheets/other#ColorStyle", "protocol=uri"
19+
20+
class
21+
EG_COLOR_STYLE
22+
23+
inherit
24+
ANY
25+
redefine
26+
default_create
27+
end
28+
29+
create
30+
default_create
31+
32+
33+
feature {NONE} -- Initialization
34+
35+
default_create
36+
do
37+
create rgb_color
38+
end
39+
40+
feature -- Access
41+
42+
rgb_color: detachable EG_COLOR
43+
-- RGB color.
44+
45+
theme_color: detachable EG_THEME_COLOR
46+
-- Theme color.
47+
48+
feature -- Change Element
49+
50+
set_theme_color (a_theme: EG_THEME_COLOR)
51+
-- Set color kind to theme with a_theme
52+
-- mark rgb as Void
53+
do
54+
theme_color := a_theme
55+
rgb_color := Void
56+
ensure
57+
theme_set: theme_color = a_theme
58+
rgb_unset: rgb_color = Void
59+
end
60+
61+
set_rgb (a_rgb: EG_COLOR)
62+
-- Set color kind to rgb
63+
-- unset theme
64+
do
65+
rgb_color := a_rgb
66+
theme_color := void
67+
ensure
68+
theme_unset: theme_color= Void
69+
rgb_set: rgb_color = a_rgb
70+
end
71+
72+
invariant
73+
kind_of_rgba: attached rgb_color implies theme_color = Void
74+
kind_of_theme: attached theme_color implies rgb_color = Void
75+
end
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
note
2+
description: "Summary description for {EG_HORIZONTAL_ALIGN}."
3+
author: ""
4+
date: "$Date$"
5+
revision: "$Revision$"
6+
7+
class
8+
EG_HORIZONTAL_ALIGN
9+
10+
11+
end

0 commit comments

Comments
 (0)