Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Realtime updates #110

Open
wants to merge 119 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 90 commits
Commits
Show all changes
119 commits
Select commit Hold shift + click to select a range
f651263
Added mac os x demo app.
Oct 27, 2017
7d6ef56
Swift 4 fixes.
Oct 30, 2017
2c15600
Serve netfox models over http.
Oct 30, 2017
0a6211c
Removed harcoded values.
Oct 31, 2017
25e31f5
Connect to different apps on different devices..
Nov 1, 2017
7877f11
Changed how discover service is configured.
Nov 3, 2017
525bc90
Test runloop
Jan 30, 2018
377ed2b
Client communications using input / output stream.
Feb 1, 2018
39bb1d2
A working model :)
Feb 1, 2018
ab129b4
Some bugfixing.
Feb 1, 2018
3f8da9f
Removed swifter dependency.
Feb 1, 2018
552f92d
More improvements on error handling and retry when app goes into back…
Feb 2, 2018
0cdd676
accessed string directly instead of characters to remove deprecated w…
StefanSuciu Feb 2, 2018
61a7135
added a new data structure to handle directory like structure of requ…
StefanSuciu Feb 5, 2018
f8b7c29
added a NFXHTTPModel property to NFXPathNode leaves and a method to r…
StefanSuciu Feb 6, 2018
431a74a
add an array of NFXHTTPModel to a NFXPathNode
StefanSuciu Feb 6, 2018
e80fad4
used NFXPathNodeManager inside the NFSHTTPModelManager
StefanSuciu Feb 6, 2018
3115a45
added cell controller files for PathNode and replaced the NFXListCont…
StefanSuciu Feb 6, 2018
f670668
removed a bad assignment at node creation
StefanSuciu Feb 6, 2018
f8623eb
printTree change
StefanSuciu Feb 6, 2018
b84ccf0
removed NFXPathNodeManager dependency in NFXHTTPModelManger getModels…
StefanSuciu Feb 6, 2018
a592d01
overloaded configForObject to work with NFXPathNode as well
StefanSuciu Feb 6, 2018
07204ba
use two local models in NFXPathNodeListController instead of the defa…
StefanSuciu Feb 6, 2018
0715615
getModels returns root's children
StefanSuciu Feb 6, 2018
595faa5
insert node's children to pathNodeTableData when a node is selected
StefanSuciu Feb 6, 2018
c4dbf86
added a method to compute a node's depth
StefanSuciu Feb 6, 2018
be90707
added a leading constraint to the cell, which is computed based on no…
StefanSuciu Feb 6, 2018
ae7a970
insert after current index in pathNodeTableData
StefanSuciu Feb 6, 2018
4cb7863
added expanded logic
StefanSuciu Feb 6, 2018
8c34f57
Added app dummy icon.
Feb 6, 2018
b370ab3
Merge branch 'realtime_updates' of https://github.com/alextud/netfox …
Feb 6, 2018
f2f635c
Fix a bug.
Feb 6, 2018
d9b8301
Runloop fixes.
Feb 7, 2018
1775cb4
Search filtering.
Feb 7, 2018
5306c3f
Refresh earlier netservice.
Feb 7, 2018
82c448c
Added sequence / structure mode.
Feb 7, 2018
bfa0c5b
Removed first item.
Feb 7, 2018
3b29dea
Structured content - filter by string.
Feb 7, 2018
75f3f20
Expanded state.
Feb 7, 2018
4c2e4cf
Structured list mode improvement.
Feb 7, 2018
7cdc1b4
Bugfixes.
Feb 7, 2018
185f486
retrieve http models
StefanSuciu Feb 8, 2018
77d51ad
use NFXPathManager to retrieve http models
StefanSuciu Feb 8, 2018
1321663
added assets for some images
StefanSuciu Feb 8, 2018
ca86931
display an image accordingly to response status
StefanSuciu Feb 8, 2018
d742a18
depth + isExpanded update
StefanSuciu Feb 8, 2018
2115bac
added support for loading request
StefanSuciu Feb 8, 2018
ec48433
comment update code which is not ready to execute
StefanSuciu Feb 8, 2018
d05fc38
fixed a bug which occurred when inserting a folder when a resource wi…
StefanSuciu Feb 8, 2018
f23fec5
fixed a force unwrap crash
StefanSuciu Feb 8, 2018
1b05881
removed a print
StefanSuciu Feb 8, 2018
89f4b77
added json2codable
StefanSuciu Feb 12, 2018
ae14311
added CodableClass + coding keys
StefanSuciu Feb 12, 2018
17f0f66
code refactoring
StefanSuciu Feb 12, 2018
c221f94
added exclamation mark
StefanSuciu Feb 13, 2018
b76b96b
added new tab for codable
StefanSuciu Feb 13, 2018
ab5ea18
added Json2Codable code + changed the print to return String
StefanSuciu Feb 13, 2018
f6afff9
display an error message if can't serialize response to dictionary
StefanSuciu Feb 13, 2018
6f94d0b
added a method to retrieve resource class name from url
StefanSuciu Feb 13, 2018
6e4d6bf
support for converting first element of array to codable
StefanSuciu Feb 13, 2018
e3850c1
moved arround some classes
StefanSuciu Feb 13, 2018
5850255
arrays with first item different than dictionary will return the type
StefanSuciu Feb 13, 2018
644e6a6
remove some garbage from class name
StefanSuciu Feb 13, 2018
e2afeec
lowercase bug fix
StefanSuciu Feb 14, 2018
3962ba6
crash fix when property of type array is empty
StefanSuciu Feb 14, 2018
02d03d1
added a character in camelCase components
StefanSuciu Feb 14, 2018
aa81276
infer Any if field value is empty dictionary or nil + infer [Any] if …
StefanSuciu Feb 14, 2018
dcf4ae4
display empty body in codable tab
StefanSuciu Feb 14, 2018
bf2e3d1
code changes
StefanSuciu Feb 14, 2018
d9b8194
some code refactoring + replacing last occurence
StefanSuciu Feb 14, 2018
5115865
added url parser
StefanSuciu Feb 16, 2018
df7c104
added a date parser
StefanSuciu Feb 19, 2018
fa10f66
only check the key since any Int can be cast to a Date
StefanSuciu Feb 21, 2018
a6bf27b
added changes to readme.md
StefanSuciu Feb 21, 2018
15e555b
don't try to parse empty arrays
StefanSuciu Feb 21, 2018
f988096
Copy netfox framework.
Feb 23, 2018
c8ad2ec
Merge pull request #1 from rajanbalana/request_body_issue_fix
alextud Feb 23, 2018
c593cae
borken outlet fix
StefanSuciu Feb 23, 2018
147748b
added .gif to readme
StefanSuciu Feb 23, 2018
a77fdd2
use actual .gif
StefanSuciu Feb 23, 2018
d58bb30
removed some characters
StefanSuciu Feb 23, 2018
1a19875
used another gif
StefanSuciu Feb 23, 2018
b3450d6
Keep all found services in the popup list.
Feb 23, 2018
ab58a02
Merge branch 'realtime_updates' of https://github.com/alextud/netfox …
Feb 23, 2018
ffc1fee
disabled auto enable items
StefanSuciu Feb 23, 2018
8537d3f
Connected service.
Feb 23, 2018
b6e51d2
Export objc methods.
Feb 23, 2018
89aad8c
Removed cocoapods dependecy.
Feb 23, 2018
81d39ab
take into account all occurrences of a class in a json array to predi…
StefanSuciu Mar 5, 2018
2f81a67
Merge remote-tracking branch 'origin/realtime_updates' into realtime_…
Mar 5, 2018
7219fd4
if an array is found while parsing, apply convertToCodable to go deep…
StefanSuciu Mar 6, 2018
705c497
fix
StefanSuciu Mar 6, 2018
511558f
refactored NFXCodableClass properties to a class + started to handle …
StefanSuciu Mar 6, 2018
7d80af6
small fix for "?"
StefanSuciu Mar 6, 2018
5ffb418
show in coding keys only properties which have different name than th…
StefanSuciu Mar 8, 2018
0ef518a
if no coding keys, dont display the enum
StefanSuciu Mar 8, 2018
836439b
started to work on enum detection
StefanSuciu Mar 8, 2018
c9f35fa
Integrated Code review changes.
Mar 12, 2018
55c016f
Merge master branch.
Mar 12, 2018
39d80a1
NFXImage - code refactoring.
Mar 12, 2018
9910ef1
Merge remote-tracking branch 'origin/realtime_updates' into realtime_…
Mar 12, 2018
1e824f0
User property name instead of index.
Mar 12, 2018
9b06f79
commented alerts
StefanSuciu Mar 12, 2018
5c31131
Fixed integration issues
Mar 15, 2018
a0ea910
Didn't mean to edit the project file
Mar 15, 2018
e14097d
Fixed the pod lib lint failure
Mar 15, 2018
35321c2
Merge pull request #2 from kasketis/realtime_updates_integration_fix
alextud Mar 15, 2018
7784601
Update README.md
alextud Mar 15, 2018
0f6565a
multipart post fix
StefanSuciu Mar 23, 2018
a76cf97
readme changes
StefanSuciu Mar 23, 2018
b0c7a25
Merge branch 'realtime_updates' of https://github.com/alextud/netfox …
Mar 23, 2018
1fd9bab
workaround for multipart/from-data
StefanSuciu Mar 27, 2018
eb74da9
added a bool parser
StefanSuciu Mar 28, 2018
5aadaa0
avoid concurrent read from httpBodyStream
StefanSuciu Mar 28, 2018
ae5e77f
swift 4 conversion
StefanSuciu Apr 26, 2018
1234229
Merge master
Sep 15, 2018
44e1515
added demo gif locally, updated readme
StefanSuciu Sep 18, 2018
726444e
added alt
StefanSuciu Sep 18, 2018
45b8748
removed a broken image
StefanSuciu Sep 18, 2018
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
131 changes: 67 additions & 64 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,65 +1,68 @@
.DS_Store
*.xcuserdatad

# Created by https://www.gitignore.io/api/xcode,osx

### OSX ###
*.DS_Store
.AppleDouble
.LSOverride

# Icon must end with two \r
.DS_Store
*.xcuserdatad
# Created by https://www.gitignore.io/api/xcode,osx
### OSX ###
*.DS_Store
.AppleDouble
.LSOverride
# Icon must end with two \r
Icon

# Thumbnails
._*

# Files that might appear in the root of a volume
.DocumentRevisions-V100
.fseventsd
.Spotlight-V100
.TemporaryItems
.Trashes
.VolumeIcon.icns
.com.apple.timemachine.donotpresent

# Directories potentially created on remote AFP share
.AppleDB
.AppleDesktop
Network Trash Folder
Temporary Items
.apdisk

### Xcode ###
# Xcode
#
# gitignore contributors: remember to update Global/Xcode.gitignore, Objective-C.gitignore & Swift.gitignore

## Build generated
build/
DerivedData/

## Various settings
*.pbxuser
!default.pbxuser
*.mode1v3
!default.mode1v3
*.mode2v3
!default.mode2v3
*.perspectivev3
!default.perspectivev3
xcuserdata/

## Other
*.moved-aside
*.xccheckout
*.xcscmblueprint

### Xcode Patch ###
*.xcodeproj/*
!*.xcodeproj/project.pbxproj
!*.xcodeproj/xcshareddata/
!*.xcworkspace/contents.xcworkspacedata
/*.gcno

# End of https://www.gitignore.io/api/xcode,osx

# Thumbnails
._*

# Files that might appear in the root of a volume
.DocumentRevisions-V100
.fseventsd
.Spotlight-V100
.TemporaryItems
.Trashes
.VolumeIcon.icns
.com.apple.timemachine.donotpresent

# Directories potentially created on remote AFP share
.AppleDB
.AppleDesktop
Network Trash Folder
Temporary Items
.apdisk

### Xcode ###
# Xcode
#
# gitignore contributors: remember to update Global/Xcode.gitignore, Objective-C.gitignore & Swift.gitignore

## Build generated
build/
DerivedData/

## Various settings
*.pbxuser
!default.pbxuser
*.mode1v3
!default.mode1v3
*.mode2v3
!default.mode2v3
*.perspectivev3
!default.perspectivev3
xcuserdata/

## Other
*.moved-aside
*.xccheckout
*.xcscmblueprint

### Xcode Patch ###
*.xcodeproj/*
!*.xcodeproj/project.pbxproj
!*.xcodeproj/xcshareddata/
!*.xcworkspace/contents.xcworkspacedata
/*.gcno

# End of https://www.gitignore.io/api/xcode,osx

Pods/
*.xcworkspace/
184 changes: 184 additions & 0 deletions JsonToCodable.playground/Contents.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,184 @@
//: Playground - noun: a place where people can play
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lol did you mean to include your playground?


import Foundation
import PlaygroundSupport




extension String {

func uppercaseFirstLetter() -> String {
let paranthesisCount = components(separatedBy: "]").count - 1
let stringWithoutParanthesis = dropFirst(paranthesisCount)

return String(repeating: "[", count: paranthesisCount) + stringWithoutParanthesis.capitalized
}

func lowercaseFirstLetter() -> String {
return prefix(1).lowercased() + dropFirst()
}

var camelCasedString: String {
return components(separatedBy: CharacterSet(charactersIn: "_ ")).map{ $0.lowercased().uppercaseFirstLetter() }.joined()
}

var singular: String {
let paranthesisCount = components(separatedBy: "]").count - 1
let stringWithoutParanthesis = dropLast(paranthesisCount)

if stringWithoutParanthesis.last == "s" {
return stringWithoutParanthesis.dropLast() + String(repeating: "]", count: paranthesisCount)
}

return self
}
}




class Parser<T> {

func canParse(_ value: Any) -> Bool {
return value is T
}

func getPropertyType() -> String {
return "\(T.self)"
}
}

extension Parser where T == [String: Any] {

func parse(_ value: Any) -> T {
return value as! T
}

func getPropertyType(name: String) -> String {
return "\(name)"
}
}

extension Parser where T == [Any] {

func parse(_ value: Any) -> T {
return value as! T
}
}



class CodableClass: CustomStringConvertible {

var className: String
var properties: [(String, String)] = []

init(className: String) {
self.className = className
}

func addProperty(name: String, type: String) {
properties.append((name, type))
}

var description: String {
var str = "class \(className.camelCasedString.singular): Codable {\n\n"
str += properties.map{ "\tvar \($0.0.camelCasedString.lowercaseFirstLetter()): \($0.1.camelCasedString.singular)!" }.joined(separator: "\n")
str += "\n\n\tenum CodingKeys: String, CodingKey {\n"
str += properties.map{"\t\tcase \($0.0.camelCasedString.lowercaseFirstLetter()) = \"\($0.0)\""}.joined(separator: "\n")
str += "\n\t}"
str += "\n}\n\n"
return str
}
}



class Json2Codable {

private let intParser = Parser<Int>()
private let stringParser = Parser<String>()
private let doubleParser = Parser<Double>()
private let dictionaryParser = Parser<[String: Any]>()
private let arrayParser = Parser<[Any]>()

private var codableClasses: [CodableClass] = []

func convertToCodable(name: String, from dictionary: [String: Any]) -> CodableClass {
let codableClass = getCodableClass(name: name)

dictionary.keys.forEach { key in
codableClass.addProperty(
name: key,
type: convertToProperty(key: key, value: dictionary[key]!)
)
}

return codableClass
}

private func convertToProperty(key: String, value: Any) -> String {
if intParser.canParse(value) {
return intParser.getPropertyType()
} else if doubleParser.canParse(value) {
return doubleParser.getPropertyType()
} else if stringParser.canParse(value) {
return stringParser.getPropertyType()
} else if dictionaryParser.canParse(value) {
convertToCodable(name: key, from: dictionaryParser.parse(value))
return dictionaryParser.getPropertyType(name: key)
} else if arrayParser.canParse(value) {
return "[\(convertToProperty(key: key, value: arrayParser.parse(value).first!))]"
}

return ""
}

private func getCodableClass(name: String) -> CodableClass {
var codableClass: CodableClass

if let foundClass = codableClasses.first(where: { $0.className == name }) {
codableClass = foundClass
} else {
codableClass = CodableClass(className: name)
codableClasses.append(codableClass)
}

return codableClass
}

func getResourceName(from url: String?) -> String {
guard let url = url else {
return "ClassName"
}

var components = url.split(separator: "/")
if let _ = Int(components.last ?? "") {
components = Array(components.dropLast())
}

return String(components.last ?? "").singular
}

func printClasses() {
codableClasses.forEach{ print($0) }
}
}




do {
let str = "{\n \"greeting\": \"Welcome to quicktype!\",\n \"some_url\": \"https://facebook.com\",\n \"instructions\": {\n \"tests\": [\n [\n {\"name\": \"Type or paste JSON here\"},\n {\"name\": \"Or choose a sample above\"},\n {\"name\": \"quicktype will generate code in your\"},\n {\"name\": \"chosen language to parse the sample data\"}\n ]\n ]\n }\n}"
let data = str.data(using: .utf8)!
let dictionary = try JSONSerialization.jsonObject(with: data) as! [String: Any]
let converter = Json2Codable()
print(converter.getResourceName(from: "https://jsonplaceholder.typicode.com/posts/1/comments"))
// converter.convertToCodable(name: "welcome", from: dictionary)
// converter.printClasses()
} catch {

}


4 changes: 4 additions & 0 deletions JsonToCodable.playground/contents.xcplayground
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<playground version='5.0' target-platform='ios'>
<timeline fileName='timeline.xctimeline'/>
</playground>
18 changes: 18 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@ Feel free to contribute :)
| ![](https://raw.githubusercontent.com/kasketis/netfox/master/assets/overview1_5_3.gif) | ![](https://cloud.githubusercontent.com/assets/1402212/12893260/78f90916-ce90-11e5-830a-d1a1b91b2ac4.png) |
|---|---|

### netfox_mac app working in parallel with iOS app
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure this should be at the top of the README. It's really cool, but I think the primary functionality of Netfox should be showcased first.

![](https://d2ffutrenqvap3.cloudfront.net/items/2S0C1j2e3D3A3H2P020E/Screen%20Recording%202018-02-23%20at%2001.45%20PM.gif)

## Installation

### CocoaPods
Expand Down Expand Up @@ -99,6 +102,18 @@ to prevent library’s execution on your production app.

You can add the DEBUG symbol with the -DDEBUG entry. Set it in the "Swift Compiler - Custom Flags" section -> "Other Swift Flags" line in project’s "Build Settings"

If you want to use netfox with the netfox_mac application, you should start netfox in the following way:

#### Swift
<pre>
NFX.sharedInstance().startServer()
</pre>

#### Obj-C
<pre>
[[NFX sharedInstance] startServer];
</pre>

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same

## Usage

Just shake your device and check what's going right or wrong!
Expand Down Expand Up @@ -154,6 +169,9 @@ Tip: You can use the url of the host (for example "https://www.github.com") to i
- Clear data within the app
- Statistics: Check cool things like average response time, total response size and more for your selected types of responses
- Info: Check your IP address, your app version and build number and other things within the app
- Live updates between apps running netfox with NFX.sharedInstance.startServer() and netfox_mac application
- Directory-like structure of requests
- Conversion from JSON to Codable class
- More to come.. ;)

## Other
Expand Down
3 changes: 3 additions & 0 deletions netfox.podspec
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,7 @@ DESC
s.source_files = "netfox/Core/*.{swift,h,m}"
s.ios.source_files = "netfox/iOS/*.swift"
s.osx.source_files = "netfox/OSX/*.{swift,xib}"

# s.dependency "Swifter"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we don't depend on Swifter, we can probably remove this.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removed.


end
Loading