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
7eb54a69
Commit
7eb54a69
authored
Sep 24, 2021
by
Dmitry Stepanets
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Started implementing GraphQL integration
parent
ce28bbd2
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
10 changed files
with
256 additions
and
0 deletions
+256
-0
1Weather.xcworkspace/contents.xcworkspacedata
+3
-0
InMobiGraphQLSource/InMobiGraphQLSource.xcodeproj/project.pbxproj
+0
-0
InMobiGraphQLSource/InMobiGraphQLSource/InMobiGraphQLSource.h
+18
-0
InMobiGraphQLSource/InMobiGraphQLSource/InMobiGraphQLSource.swift
+119
-0
InMobiGraphQLSource/InMobiGraphQLSource/Models/GraphQLResponse.swift
+23
-0
InMobiGraphQLSource/InMobiGraphQLSource/Models/MediaArrayObjectCollection.swift
+12
-0
InMobiGraphQLSource/InMobiGraphQLSource/Models/MediaObjectImage.swift
+18
-0
InMobiGraphQLSource/InMobiGraphQLSource/Models/MediaObjectItem.swift
+14
-0
InMobiGraphQLSource/InMobiGraphQLSource/Models/WeatherCardItem.swift
+16
-0
InMobiGraphQLSource/InMobiGraphQLSourceTests/InMobiGraphQLSourceTests.swift
+33
-0
No files found.
1Weather.xcworkspace/contents.xcworkspacedata
View file @
7eb54a69
...
...
@@ -2,6 +2,9 @@
<Workspace
version =
"1.0"
>
<FileRef
location =
"group:InMobiGraphQLSource/InMobiGraphQLSource.xcodeproj"
>
</FileRef>
<FileRef
location =
"group:InMobiShortsSource/InMobiShortsSource.xcodeproj"
>
</FileRef>
<FileRef
...
...
InMobiGraphQLSource/InMobiGraphQLSource.xcodeproj/project.pbxproj
0 → 100644
View file @
7eb54a69
This diff is collapsed.
Click to expand it.
InMobiGraphQLSource/InMobiGraphQLSource/InMobiGraphQLSource.h
0 → 100644
View file @
7eb54a69
//
// InMobiGraphQLSource.h
// InMobiGraphQLSource
//
// Created by Dmitry Stepanets on 24.09.2021.
//
#import <Foundation/Foundation.h>
//! Project version number for InMobiGraphQLSource.
FOUNDATION_EXPORT
double
InMobiGraphQLSourceVersionNumber
;
//! Project version string for InMobiGraphQLSource.
FOUNDATION_EXPORT
const
unsigned
char
InMobiGraphQLSourceVersionString
[];
// In this header, you should import all the public headers of your framework using statements like #import <InMobiGraphQLSource/PublicHeader.h>
InMobiGraphQLSource/InMobiGraphQLSource/InMobiGraphQLSource.swift
0 → 100644
View file @
7eb54a69
//
// InMobiGraphQLSource.swift
// InMobiGraphQLSource
//
// Created by Dmitry Stepanets on 24.09.2021.
//
import
Foundation
import
OneWeatherCore
import
OneWeatherAnalytics
public
enum
InMobiGraphQLSourceError
:
Error
{
case
badUrl
case
invalidIds
case
networkError
(
Error
?)
case
badServerResponse
(
Error
?)
case
dataEncodingError
(
String
)
}
public
class
InMobiGraphQLSource
:
ShortSource
{
private
let
log
=
Logger
(
componentName
:
"InMobiGraphQLSource"
)
private
let
baseURL
=
"https://graphql.contentful.com/content/v1/spaces/f2vk0k553nc3/environments/master"
private
let
token
=
"oxH_tXQAzlST37BSR_IGFZUNht65YUZEYLsiFl8OXJQ"
private
let
formatter
:
DateFormatter
=
{
let
fmt
=
DateFormatter
()
fmt
.
dateFormat
=
"yyyy-MM-dd'T'hh:mm:ss.sssZ"
return
fmt
}()
public
init
()
{}
public
func
updateShorts
(
completion
:
@escaping
ShortsSourceCompletion
)
{
guard
let
url
=
URL
(
string
:
baseURL
)
else
{
completion
(
nil
,
InMobiGraphQLSourceError
.
badUrl
)
return
}
var
request
=
URLRequest
(
url
:
url
)
request
.
httpMethod
=
"POST"
request
.
addValue
(
"Bearer
\(
token
)
"
,
forHTTPHeaderField
:
"Authorization"
)
let
dateString
=
formatter
.
string
(
from
:
Date
())
let
graphQLString
=
"""
{"
query
{
weatherCardObjectCollection
(
where
:
{
AND
:
[
{
expiredAt_gte
:
"
\(
dateString
)
"
}
],
})
{
items
{
shortsCategories
,
sourceUrl
,
buttonText
,
publishedAt
mediaArrayObjectCollection
{
items
{
...
on
WImageObject
{
title
,
summary
image
}
}
}
sys
{
id
}
}
}
}
"""
guard let bodyData = graphQLString.data(using: .utf8) else {
completion(nil, InMobiGraphQLSourceError.dataEncodingError("
Invalid
GraphQL
body
"))
return
}
request.httpBody = bodyData
let dataTask = URLSession.shared.dataTask(with: request) { data, response, error in
guard error == nil else {
self.log.debug("
Network
response
:
error
\
(
String
(
describing
:
error
))
")
completion(nil, InMobiGraphQLSourceError.networkError(error))
return
}
guard let data = data else {
self.log.debug("
Network
response
:
error
Invalid
data
")
completion(nil, InMobiGraphQLSourceError.dataEncodingError("
Invalid
data
"))
return
}
let decoder = JSONDecoder()
decoder.keyDecodingStrategy = .useDefaultKeys
do {
let graphQLResponse = try decoder.decode(GrapQLResponse.self, from: data)
}
catch {
}
}
dataTask.resume()
}
private func toAppModel(item: WeatherCardItem) -> ShortsItem {
ShortsItem(id: UUID().uuidString,
images: <#T##[ShortsItemImage]#>,
overlayImages: <#T##[ShortsItemImage]#>,
updatedAtInSecs: <#T##TimeInterval#>,
startsAtInSecs: <#T##TimeInterval#>,
endsAtInSecs: <#T##TimeInterval#>,
shareURL: <#T##URL?#>,
title: <#T##String#>,
summaryText: <#T##String#>,
sourceName: <#T##String#>,
heartCount: <#T##Int#>,
shortURL: <#T##URL?#>,
ctaText: <#T##String#>,
ctaURL: <#T##URL?#>,
likeCount: <#T##Int#>,
shareCount: <#T##Int#>)
}
}
InMobiGraphQLSource/InMobiGraphQLSource/Models/GraphQLResponse.swift
0 → 100644
View file @
7eb54a69
//
// GraphQLResponse.swift
// InMobiGraphQLSource
//
// Created by Dmitry Stepanets on 24.09.2021.
//
import
Foundation
private
struct
Data
:
Codable
{
let
weatherCardObjectCollection
:
WeatherCardObjectCollection
}
private
struct
WeatherCardObjectCollection
:
Codable
{
let
items
:
[
WeatherCardItem
]
}
struct
GrapQLResponse
:
Codable
{
private
let
data
:
Data
var
weatherItems
:
[
WeatherCardItem
]
{
return
data
.
weatherCardObjectCollection
.
items
}
}
InMobiGraphQLSource/InMobiGraphQLSource/Models/MediaArrayObjectCollection.swift
0 → 100644
View file @
7eb54a69
//
// MediaArrayObjectCollection.swift
// InMobiGraphQLSource
//
// Created by Dmitry Stepanets on 24.09.2021.
//
import
Foundation
struct
MediaArrayObjectCollection
:
Codable
{
}
InMobiGraphQLSource/InMobiGraphQLSource/Models/MediaObjectImage.swift
0 → 100644
View file @
7eb54a69
//
// MediaObjectImage.swift
// InMobiGraphQLSource
//
// Created by Dmitry Stepanets on 24.09.2021.
//
import
Foundation
struct
MediaObjectImageItem
:
Codable
{
let
lowresolution
:
URL
let
highresolution
:
URL
}
struct
MediaObjectImage
:
Codable
{
let
baseImage
:
[
MediaObjectImageItem
]
let
overlayImage
:
[
MediaObjectImageItem
]
}
InMobiGraphQLSource/InMobiGraphQLSource/Models/MediaObjectItem.swift
0 → 100644
View file @
7eb54a69
//
// MediaObjectItem.swift
// InMobiGraphQLSource
//
// Created by Dmitry Stepanets on 24.09.2021.
//
import
Foundation
struct
MediaObjectItem
:
Codable
{
let
title
:
String
let
summary
:
String
let
image
:
MediaObjectImage
}
InMobiGraphQLSource/InMobiGraphQLSource/Models/WeatherCardItem.swift
0 → 100644
View file @
7eb54a69
//
// WeatherCardItem.swift
// InMobiGraphQLSource
//
// Created by Dmitry Stepanets on 24.09.2021.
//
import
Foundation
struct
WeatherCardItem
:
Codable
{
let
shortsCategores
:
String
let
sourceUrl
:
URL
let
buttonText
:
String
let
publishedAt
:
Date
let
mediaArrayObjectCollection
:
MediaArrayObjectCollection
}
InMobiGraphQLSource/InMobiGraphQLSourceTests/InMobiGraphQLSourceTests.swift
0 → 100644
View file @
7eb54a69
//
// InMobiGraphQLSourceTests.swift
// InMobiGraphQLSourceTests
//
// Created by Dmitry Stepanets on 24.09.2021.
//
import
XCTest
@testable
import
InMobiGraphQLSource
class
InMobiGraphQLSourceTests
:
XCTestCase
{
override
func
setUpWithError
()
throws
{
// Put setup code here. This method is called before the invocation of each test method in the class.
}
override
func
tearDownWithError
()
throws
{
// Put teardown code here. This method is called after the invocation of each test method in the class.
}
func
testExample
()
throws
{
// This is an example of a functional test case.
// Use XCTAssert and related functions to verify your tests produce the correct results.
}
func
testPerformanceExample
()
throws
{
// This is an example of a performance test case.
self
.
measure
{
// Put the code you want to measure the time of here.
}
}
}
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