Skip to content

Commit

Permalink
A couple Object fixes (#29)
Browse files Browse the repository at this point in the history
* Fixed an issue that hardcoded the subscribe key used by membership calls and 

* Fixed JSONCodableScalarType encoding issue
  • Loading branch information
Craig Lane committed Nov 6, 2019
1 parent 1108f6e commit fd54525
Show file tree
Hide file tree
Showing 6 changed files with 27 additions and 12 deletions.
10 changes: 9 additions & 1 deletion .pubnub.yml
Original file line number Diff line number Diff line change
@@ -1,9 +1,17 @@
---
name: swift
scm: github.com/pubnub/swift
version: "2.1.0"
version: "2.1.1"
schema: 1
changelog:
-
changes:
- test: "Encoding `JSONCodableScalar` values will now properly encode to a single value"
type: bug
- test: "Membership APIs no longer use hardcoded subscribe key"
type: bug
date: 2019-11-06
version: v2.1.1
-
changes:
- test: "Added support for Message Action Subscription Listener"
Expand Down
2 changes: 1 addition & 1 deletion PubNubSwift.podspec
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Pod::Spec.new do |s|
s.name = 'PubNubSwift'
s.version = '2.1.0'
s.version = '2.1.1'
s.homepage = 'https://github.com/pubnub/swift'
s.documentation_url = 'https://www.pubnub.com/docs/swift-native/pubnub-swift-sdk'
s.authors = { 'PubNub, Inc.' => 'support@pubnub.com' }
Expand Down
11 changes: 9 additions & 2 deletions Sources/PubNub/Helpers/JSONCodable.swift
Original file line number Diff line number Diff line change
Expand Up @@ -210,11 +210,18 @@ public struct JSONCodableScalarType: Codable, Hashable {
underlying = .string(DateFormatter.iso8601.string(from: dateValue))
}

// Note: Research why decoding collections containing this object fails when using the synthesized
// decoder method
// Note: Research why decoding collections containing this object
// fails when using the synthesized decoder method
public init(from decoder: Decoder) throws {
let container = try decoder.singleValueContainer()

underlying = try container.decode(AnyJSONType.self)
}

// Required or this will default to encoding the `underlying` key
// instead of a `singleValueContainer` of the underlying value
public func encode(to encoder: Encoder) throws {
var container = encoder.singleValueContainer()
try container.encode(underlying)
}
}
8 changes: 4 additions & 4 deletions Sources/PubNub/Networking/Endpoints/PubNubRouter.swift
Original file line number Diff line number Diff line change
Expand Up @@ -306,13 +306,13 @@ extension PubNubRouter: Router {
path = "/v1/objects/\(subscribeKey)/spaces/\(spaceID)"

case let .objectsUserMemberships(parameters):
path = "/v1/objects/demo/users/\(parameters.userID)/spaces"
path = "/v1/objects/\(subscribeKey)/users/\(parameters.userID)/spaces"
case let .objectsUserMembershipsUpdate(parameters):
path = "/v1/objects/demo/users/\(parameters.userID)/spaces"
path = "/v1/objects/\(subscribeKey)/users/\(parameters.userID)/spaces"
case let .objectsSpaceMemberships(parameters):
path = "/v1/objects/demo/spaces/\(parameters.spaceID)/users"
path = "/v1/objects/\(subscribeKey)/spaces/\(parameters.spaceID)/users"
case let .objectsSpaceMembershipsUpdate(parameters):
path = "/v1/objects/demo/spaces/\(parameters.spaceID)/users"
path = "/v1/objects/\(subscribeKey)/spaces/\(parameters.spaceID)/users"

case let .fetchMessageActions(channel, _, _, _):
path = "/v1/message-actions/\(subscribeKey)/channel/\(channel)"
Expand Down
4 changes: 2 additions & 2 deletions Tests/PubNubTests/Integration/OnboardingSnippets.swift
Original file line number Diff line number Diff line change
Expand Up @@ -115,11 +115,11 @@ class OnboardingSnippets: XCTestCase {
let listener = SubscriptionListener()
listener.didReceiveSubscription = { event in
switch event {
case .messageReceived(let message):
case let .messageReceived(message):
if message.publisher == configuration.uuid {
performMessageFetch()
}
case .connectionStatusChanged(let connection):
case let .connectionStatusChanged(connection):
if connection == .connected {
client.publish(channel: "pubnub_onboarding_channel",
message: ["sender": configuration.uuid,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ class SpaceObjectsEndpointIntegrationTests: XCTestCase {
let configuration = PubNubConfiguration(from: testsBundle)
let client = PubNub(configuration: configuration)

let user = UserObject(name: "Swift ITest", id: "SwiftITest")
let user = UserObject(name: "Swift ITest", id: "SwiftITest", custom: ["age": 12])
let space = SpaceObject(name: "Swift Membership ITest", id: "SwiftMembershipITest")

client.create(user: user, include: .custom) { _ in
Expand All @@ -174,7 +174,7 @@ class SpaceObjectsEndpointIntegrationTests: XCTestCase {
let configuration = PubNubConfiguration(from: testsBundle)
let client = PubNub(configuration: configuration)

let user = UserObject(name: "Swift ITest", id: "SwiftITest")
let user = UserObject(name: "Swift ITest", id: "SwiftITest", custom: ["age": 12])
let space = SpaceObject(name: "Swift Membership ITest", id: "SwiftMembershipITest")

client.create(user: user, include: .custom) { _ in
Expand Down

0 comments on commit fd54525

Please sign in to comment.