Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
1
1weather
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Dmitriy Stepanets
1weather
Commits
040ee70b
Commit
040ee70b
authored
Oct 08, 2021
by
Dmitry Stepanets
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Updated GraphQL parsing logic
parent
7fd8fd00
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
43 additions
and
33 deletions
+43
-33
InMobiGraphQLSource/InMobiGraphQLSource/InMobiGraphQLSource.swift
+43
-33
No files found.
InMobiGraphQLSource/InMobiGraphQLSource/InMobiGraphQLSource.swift
View file @
040ee70b
...
...
@@ -72,8 +72,8 @@ public class InMobiGraphQLSource: ShortSource {
decoder
.
keyDecodingStrategy
=
.
useDefaultKeys
do
{
let
graphQLResponse
=
try
decoder
.
decode
(
GrapQLResponse
.
self
,
from
:
data
)
let
items
=
graphQLResponse
.
weatherItems
.
map
{
self
.
toAppModel
(
item
:
$0
)
}
completion
(
item
s
,
nil
)
let
shorts
=
self
.
toAppModel
(
items
:
graphQLResponse
.
weatherItems
)
completion
(
short
s
,
nil
)
}
catch
{
self
.
log
.
error
(
"Parsing error:
\(
error
)
"
)
...
...
@@ -83,44 +83,54 @@ public class InMobiGraphQLSource: ShortSource {
dataTask
.
resume
()
}
private
func
toAppModel
(
item
:
WeatherCardItem
)
->
ShortsItem
{
private
func
toAppModel
(
item
s
:
[
WeatherCardItem
])
->
[
ShortsItem
]
{
let
lowImageSize
=
CGSize
(
width
:
440
,
height
:
783
)
let
highImageSize
=
CGSize
(
width
:
783
,
height
:
1701
)
var
overlayImages
=
[
ShortsItemImage
]()
var
baseImages
=
[
ShortsItemImage
]()
for
mediaObjectCollectionItem
in
item
.
mediaArrayObjectCollection
.
items
{
let
image
=
mediaObjectCollectionItem
.
image
for
overlayImage
in
image
.
overlayImage
{
overlayImages
.
append
(
ShortsItemImage
(
width
:
Int
(
lowImageSize
.
width
),
height
:
Int
(
lowImageSize
.
height
),
url
:
overlayImage
.
lowresolution
))
overlayImages
.
append
(
ShortsItemImage
(
width
:
Int
(
highImageSize
.
width
),
height
:
Int
(
highImageSize
.
height
),
url
:
overlayImage
.
highresolution
))
var
shortItems
=
[
ShortsItem
]()
for
cardItem
in
items
{
guard
cardItem
.
mediaArrayObjectCollection
.
items
.
count
==
1
else
{
continue
}
for
baseImage
in
image
.
baseImage
{
baseImages
.
append
(
ShortsItemImage
(
width
:
Int
(
lowImageSize
.
width
),
height
:
Int
(
lowImageSize
.
height
),
url
:
baseImage
.
lowresolution
))
baseImages
.
append
(
ShortsItemImage
(
width
:
Int
(
highImageSize
.
width
),
height
:
Int
(
highImageSize
.
height
),
url
:
baseImage
.
highresolution
))
for
mediaObjectCollectionItem
in
cardItem
.
mediaArrayObjectCollection
.
items
{
let
image
=
mediaObjectCollectionItem
.
image
var
overlayImages
=
[
ShortsItemImage
]()
var
baseImages
=
[
ShortsItemImage
]()
for
overlayImage
in
image
.
overlayImage
{
overlayImages
.
append
(
ShortsItemImage
(
width
:
Int
(
lowImageSize
.
width
),
height
:
Int
(
lowImageSize
.
height
),
url
:
overlayImage
.
lowresolution
))
overlayImages
.
append
(
ShortsItemImage
(
width
:
Int
(
highImageSize
.
width
),
height
:
Int
(
highImageSize
.
height
),
url
:
overlayImage
.
highresolution
))
}
for
baseImage
in
image
.
baseImage
{
baseImages
.
append
(
ShortsItemImage
(
width
:
Int
(
lowImageSize
.
width
),
height
:
Int
(
lowImageSize
.
height
),
url
:
baseImage
.
lowresolution
))
baseImages
.
append
(
ShortsItemImage
(
width
:
Int
(
highImageSize
.
width
),
height
:
Int
(
highImageSize
.
height
),
url
:
baseImage
.
highresolution
))
}
let
shortItem
=
ShortsItem
(
id
:
cardItem
.
id
,
images
:
baseImages
,
overlayImages
:
overlayImages
,
shareURL
:
cardItem
.
sourceUrl
,
title
:
mediaObjectCollectionItem
.
title
,
summaryText
:
mediaObjectCollectionItem
.
summary
,
sourceName
:
""
,
shortURL
:
cardItem
.
sourceUrl
,
ctaText
:
cardItem
.
buttonText
,
ctaURL
:
cardItem
.
sourceUrl
)
shortItems
.
append
(
shortItem
)
}
}
return
ShortsItem
(
id
:
item
.
id
,
images
:
baseImages
,
overlayImages
:
overlayImages
,
shareURL
:
item
.
sourceUrl
,
title
:
item
.
mediaArrayObjectCollection
.
items
.
first
?
.
title
??
""
,
summaryText
:
item
.
mediaArrayObjectCollection
.
items
.
first
?
.
summary
??
""
,
sourceName
:
""
,
shortURL
:
item
.
sourceUrl
,
ctaText
:
item
.
buttonText
,
ctaURL
:
item
.
sourceUrl
)
return
shortItems
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment