Skip to content
This repository has been archived by the owner on Feb 8, 2021. It is now read-only.

Commit

Permalink
Merge pull request #237 from hkellaway/release/1.1.1
Browse files Browse the repository at this point in the history
Release/1.1.1
  • Loading branch information
Harlan Kellaway authored Nov 27, 2016
2 parents 731d092 + 5cfb987 commit 7389cc9
Show file tree
Hide file tree
Showing 24 changed files with 246 additions and 91 deletions.
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -75,3 +75,7 @@ Carthage/Build
####
# Jazzy
docs

###
# Swift Package Manager
.build
13 changes: 12 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
All notable changes to this project will be documented in this file.
`Gloss` adheres to [Semantic Versioning](http://semver.org/).

- `1.1.x` Releases - [1.1.0](#110)
- `1.1.x` Releases - [1.1.0](#110) | [1.1.1](#111)
- `1.0.x` Releases - [1.0.0](#100)
- `0.8.x` Releases - [0.8.0](#080)
- `0.7.x` Releases - [0.7.0](#070) | [0.7.1](#071) | [0.7.2](#072) | [0.7.3](#073) | [0.7.4](#074)
Expand All @@ -15,6 +15,17 @@ All notable changes to this project will be documented in this file.

---

## [1.1.1](https://github.com/hkellaway/Gloss/releases/tag/1.1.1)
Released on 2016-11-27. All issues associated with this milestone can be found using this [filter](https://github.com/hkellaway/Gloss/issues?utf8=%E2%9C%93&q=milestone%3A1.1.1)

#### Fixed
- Nexted UUID values not being decoded properly [PR [#233](https://github.com/hkellaway/Gloss/pull/233)]

#### Updated
- Tests to be run using `swift test` when loading as a Swift Package [PR [#228](https://github.com/hkellaway/Gloss/pull/228)]

---

## [1.1.0](https://github.com/hkellaway/Gloss/releases/tag/1.1.0)
Released on 2016-10-25. All issues associated with this milestone can be found using this [filter](https://github.com/hkellaway/Gloss/issues?utf8=%E2%9C%93&q=milestone%3A1.1.0)

Expand Down
2 changes: 1 addition & 1 deletion Gloss.podspec
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Pod::Spec.new do |s|
s.name = "Gloss"
s.version = "1.1.0"
s.version = "1.1.1"
s.summary = "A shiny JSON parsing library in Swift"
s.description = "A shiny JSON parsing library in Swift. Features include mapping JSON to objects, mapping objects to JSON, handling of nested objects and custom transformations."
s.homepage = "https://github.com/hkellaway/Gloss"
Expand Down
146 changes: 74 additions & 72 deletions Gloss.xcodeproj/project.pbxproj

Large diffs are not rendered by default.

11 changes: 6 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -350,9 +350,9 @@ Gloss comes with a number of transformations built in for convenience (See: [Glo

Translating from and to JSON is handled via:

`Decoder.decode(dateFromKey:, dateFormatter:)` and `Decode.decode(dateArrayFromKey:, dateFormatter:)` where `key` is the JSON key and `dateFormatter` is the `DateFormatter` used to translate the date(s). e.g. `self.date = Decoder.decode(dateFromKey: "dateKey", dateFormatter: myDateFormatter)(json)`
`Decoder.decode(dateForKey:, dateFormatter:)` and `Decode.decode(dateArrayFromKey:, dateFormatter:)` where `key` is the JSON key and `dateFormatter` is the `DateFormatter` used to translate the date(s). e.g. `self.date = Decoder.decode(dateForKey: "dateKey", dateFormatter: myDateFormatter)(json)`

`Encoder.encode(dateFromKey:, dateFormatter:)` and `Encode.encode(dateFromKey:, dateFormatter:)` where `key` is the JSON key and `dateFormatter` is the `DateFormatter` used to translate the date(s). e.g. `Encoder.encode(dateFromKey: "dateKey", dateFormatter: myDateFormatter)(self.date)`
`Encoder.encode(dateForKey:, dateFormatter:)` and `Encode.encode(dateForKey:, dateFormatter:)` where `key` is the JSON key and `dateFormatter` is the `DateFormatter` used to translate the date(s). e.g. `Encoder.encode(dateForKey: "dateKey", dateFormatter: myDateFormatter)(self.date)`

#### Custom Transformations

Expand Down Expand Up @@ -547,14 +547,15 @@ Check out Gloss in these cool places!
* [Alamofire-Gloss](https://github.com/spxrogers/Alamofire-Gloss)
* [CRUD](https://github.com/MetalheadSanya/CRUD)
* [Moya-Gloss](https://github.com/spxrogers/Moya-Gloss)
* [OctoAPI](http://github.com/ferusinfo/OctoAPI)
* [Restofire-Gloss](https://github.com/Restofire/Restofire-Gloss)

#### SDKs/Products

* [AniList](http://anilist.co) ([iOS SDK](https://github.com/CodeEagle/AniList))
* [AniList](http://anilist.co) ([Unofficial iOS SDK](https://github.com/CodeEagle/AniList))
* [Drift](http://www.drift.com) ([iOS SDK](https://github.com/Driftt/drift-sdk-ios))
* [Phillips Hue](http://www2.meethue.com/en-US) ([iOS SDK](https://github.com/Spriter/SwiftyHue))
* [Skiplagged](http://skiplagged.com) ([iOS SDK] (https://github.com/bulusoy/Skiplagged))
* [Phillips Hue](http://www2.meethue.com/en-US) ([Unofficial iOS SDK](https://github.com/Spriter/SwiftyHue))
* [Skiplagged](http://skiplagged.com) ([Unofficial iOS SDK] (https://github.com/bulusoy/Skiplagged))

#### Apps

Expand Down
8 changes: 4 additions & 4 deletions Sources/Decoder.swift
Original file line number Diff line number Diff line change
Expand Up @@ -488,11 +488,11 @@ public struct Decoder {

- returns: Value decoded from JSON.
*/
public static func decode(uuidForKey key: String) -> (JSON) -> UUID? {
public static func decode(uuidForKey key: String, keyPathDelimiter: String = GlossKeyPathDelimiter) -> (JSON) -> UUID? {
return {
json in

if let uuidString = json[key] as? String {
if let uuidString = json.valueForKeyPath(keyPath: key, withDelimiter: keyPathDelimiter) as? String {
return UUID(uuidString: uuidString)
}

Expand All @@ -507,11 +507,11 @@ public struct Decoder {

- returns: Value decoded from JSON.
*/
public static func decode(uuidArrayForKey key: String) -> (JSON) -> [UUID]? {
public static func decode(uuidArrayForKey key: String, keyPathDelimiter: String = GlossKeyPathDelimiter) -> (JSON) -> [UUID]? {
return {
json in

if let uuidStrings = json[key] as? [String] {
if let uuidStrings = json.valueForKeyPath(keyPath: key, withDelimiter: keyPathDelimiter) as? [String] {
var uuids: [UUID] = []

for uuidString in uuidStrings {
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@
// THE SOFTWARE.
//

import Foundation
import Gloss
import UIKit
import XCTest

class DecoderTests: XCTestCase {
Expand All @@ -36,9 +36,18 @@ class DecoderTests: XCTestCase {
override func setUp() {
super.setUp()

#if SWIFT_PACKAGE

testJSON = TestModel.testJSON
testFailableModelJSONValid = TestFailableModel.testValidJSON
testFailableModelJSONInvalid = TestFailableModel.testInvalidJSON

#else

var testJSONPath: String = Bundle(for: type(of: self)).path(forResource: "TestModel", ofType: "json")!
var testJSONData: Data = try! Data(contentsOf: URL(fileURLWithPath: testJSONPath))


do {
try testJSON = JSONSerialization.jsonObject(with: testJSONData, options: JSONSerialization.ReadingOptions(rawValue: 0)) as? JSON
} catch {
Expand All @@ -62,6 +71,7 @@ class DecoderTests: XCTestCase {
} catch {
print(error)
}
#endif
}

override func tearDown() {
Expand Down Expand Up @@ -140,6 +150,7 @@ class DecoderTests: XCTestCase {

func testDecodeFloatArray() {
let result: [Float]? = Decoder.decode(key: "floatArray")(testJSON!)

let element1: Float = result![0]
let element2: Float = result![1]
let element3: Float = result![2]
Expand Down Expand Up @@ -236,6 +247,8 @@ class DecoderTests: XCTestCase {

XCTAssertTrue((result?.id == 123), "Decode nested model should return correct value")
XCTAssertTrue((result?.name == "nestedModel1"), "Decode nested model should return correct value")
XCTAssertTrue((result?.uuid?.uuidString == "BA34F5F0-E5AA-4ECE-B25C-90195D7AF0D0"), "Decode nested model should return correct value")
XCTAssertTrue((result?.url?.absoluteString == "http://github.com"), "Decode nested model should return correct value")
}

func testDecodeEnumValue() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@
// THE SOFTWARE.
//

import Foundation
import Gloss
import UIKit
import XCTest

class EncoderTests: XCTestCase {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@
// THE SOFTWARE.
//

import Foundation
import Gloss
import UIKit
import XCTest

class FlowObjectCreationTests: XCTestCase {
Expand All @@ -34,6 +34,9 @@ class FlowObjectCreationTests: XCTestCase {
override func setUp() {
super.setUp()

#if SWIFT_PACKAGE
testJSON = TestModel.testJSON
#else
let testJSONPath: String = Bundle(for: type(of: self)).path(forResource: "TestModel", ofType: "json")!
let testJSONData: Data = try! Data(contentsOf: URL(fileURLWithPath: testJSONPath as String))

Expand All @@ -42,6 +45,7 @@ class FlowObjectCreationTests: XCTestCase {
} catch {
print(error)
}
#endif
}

override func tearDown() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@
// THE SOFTWARE.
//

import Foundation
import Gloss
import UIKit
import XCTest

class ObjectToJSONFlowTests: XCTestCase {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@
// THE SOFTWARE.
//

import Foundation
import Gloss
import UIKit
import XCTest

class GlossTests: XCTestCase {
Expand All @@ -37,6 +37,13 @@ class GlossTests: XCTestCase {
super.setUp()

var testJSON: JSON? = [:]

#if SWIFT_PACKAGE

testJSON = TestModel.testJSON

#else

let testJSONPath: String = Bundle(for: type(of: self)).path(forResource: "TestModel", ofType: "json")!
let testJSONData: Data = try! Data(contentsOf: URL(fileURLWithPath: testJSONPath as String))

Expand All @@ -46,6 +53,8 @@ class GlossTests: XCTestCase {
print(error)
}

#endif

testJSONArray = [testJSON!, testJSON!]

testModelsJSON = [
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
// Copyright © 2016 Harlan Kellaway. All rights reserved.
//

import Foundation
import Gloss
import XCTest

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@
// THE SOFTWARE.
//

import Foundation
import Gloss
import UIKit
import XCTest

class OperatorTests: XCTestCase {
Expand All @@ -36,6 +36,11 @@ class OperatorTests: XCTestCase {
override func setUp() {
super.setUp()

#if SWIFT_PACKAGE

testJSON = TestModel.testJSON

#else
let testJSONPath: String = Bundle(for: type(of: self)).path(forResource: "TestModel", ofType: "json")!
let testJSONData: Data = try! Data(contentsOf: URL(fileURLWithPath: testJSONPath as String))

Expand All @@ -44,6 +49,7 @@ class OperatorTests: XCTestCase {
} catch {
print(error)
}
#endif

testNestedModel1 = TestNestedModel(json: [ "id" : 1, "name" : "nestedModel1"])
testNestedModel2 = TestNestedModel(json: ["id" : 2, "name" : "nestedModel2"])
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,3 +46,24 @@ struct TestFailableModel: Glossy {
]
}
}

// Since Swift Package Manager doesn't support fixtures (i.e. stored JSON), we have to access the JSON using this method rather than reading file from Bundle.
#if SWIFT_PACKAGE
extension TestFailableModel {

static var testInvalidJSON: JSON {
return [
"asdf": "dsafhkjdaf",
"asjdkfhl": 203183492749,
"asdfjhkhfsldjghi": 0.12390
]
}

static var testValidJSON: JSON {
return [
"identifier" : "unique",
"value" : 99999
]
}
}
#endif
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,9 @@
"stringArray" : ["def", "ghi", "jkl"],
"nestedModel" : {
"id" : 123,
"name" : "nestedModel1"
"name" : "nestedModel1",
"uuid": "BA34F5F0-E5AA-4ECE-B25C-90195D7AF0D0",
"url": "http://github.com"
},
"nestedModelArray" : [
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
// THE SOFTWARE.
//

import Foundation
import Gloss

struct TestModel: Glossy {
Expand Down Expand Up @@ -154,3 +155,75 @@ struct TestModel: Glossy {
}()

}

// Since Swift Package Manager doesn't support fixtures (i.e. stored JSON), we have to access the JSON using this method rather than reading file from Bundle.
#if SWIFT_PACKAGE
extension TestModel {
static var testJSON: JSON {
return [
"bool" : true,
"boolArray" : [true, false, true],
"integer" : 1,
"integerArray" : [1, 2, 3],
"float" : Float(2.0),
"floatArray" : [Float(1.0), Float(2.0), Float(3.0)],
"double" : Double(6.0),
"doubleArray" : [Double(4.0), Double(5.0), Double(6.0)],
"dictionary" : [
"otherModel" : [
"id" : 789,
"name" : "otherModel1"
]
],
"dictionaryWithArray" : [
"otherModels" : [
[
"id" : 123,
"name" : "otherModel1"
],
[
"id" : 456,
"name" : "otherModel2"
]
]
],
"string" : "abc",
"stringArray" : ["def", "ghi", "jkl"],
"nestedModel" : [
"id" : 123,
"name" : "nestedModel1",
"uuid" : "BA34F5F0-E5AA-4ECE-B25C-90195D7AF0D0",
"url" : "http://github.com"
],
"nestedModelArray" : [
[
"id" : 456,
"name" : "nestedModel2"
],
[
"id" : 789,
"name" : "nestedModel3"
]
],
"enumValue" : "A",
"enumValueArray" : ["A", "B", "C"],
"date" : "2015-08-16T20:51:46.600Z",
"dateArray" : ["2015-08-16T20:51:46.600Z", "2015-08-16T20:51:46.600Z"],
"dateISO8601" : "2015-08-08T21:57:13Z",
"dateISO8601Array" : ["2015-08-08T21:57:13Z", "2015-08-08T21:57:13Z"],
"int32" : 100000000,
"int32Array" : [100000000, -2147483648, 2147483647],
"uInt32" : 4294967295,
"uInt32Array" : [100000000, 2147483648, 4294967295],
"int64" : 300000000,
"int64Array" : [300000000, -9223372036854775808, 9223372036854775807],
"uInt64" : 18446744073709551615 as UInt64,
"uInt64Array" : [300000000, 9223372036854775808 as UInt64, 18446744073709551615 as UInt64],
"url" : "http://github.com",
"urlArray" : ["http://github.com", "http://github.com", "http://github.com"],
"uuid" : "964F2FE2-0F78-4C2D-A291-03058C0B98AB",
"uuidArray" : ["572099C2-B9AA-42AA-8A25-66E3F3056271", "54DB8DCF-F68D-4B55-A3FC-EB8CF4C36B06", "982CED72-743A-45F8-87CF-278386D32EBF"]
]
}
}
#endif
Loading

0 comments on commit 7389cc9

Please sign in to comment.