Skip to content
This repository has been archived by the owner on Jul 21, 2020. It is now read-only.

Commit

Permalink
Added a method to update the session's user object
Browse files Browse the repository at this point in the history
  • Loading branch information
jackcook committed Dec 14, 2016
1 parent ac4d876 commit e42b02c
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 3 deletions.
4 changes: 2 additions & 2 deletions BeamAPI.podspec
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
Pod::Spec.new do |s|
s.name = "BeamAPI"
s.version = "1.4.2"
s.version = "1.4.3"
s.summary = "An interface to communicate with Beam's backend."
s.homepage = "https://github.com/WatchBeam/beam-client-swift"
s.license = "MIT"
s.author = { "Jack Cook" => "jack@beam.pro" }

s.requires_arc = true
s.ios.deployment_target = "8.2"
s.source = { :git => "https://github.com/WatchBeam/beam-client-swift.git", :tag => "1.4.2" }
s.source = { :git => "https://github.com/WatchBeam/beam-client-swift.git", :tag => "1.4.3" }
s.source_files = "Pod/Classes/**/*"

s.dependency "Starscream", "~> 2.0"
Expand Down
18 changes: 17 additions & 1 deletion Pod/Classes/Clients/BeamSession.swift
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,29 @@ public class BeamSession {
}

/// The authenticated user's data.
public var user: BeamUser!
public var user: BeamUser

/// Initializes a session given a user. Won't do anything on its own unless BeamSession.sharedSession is set to it.
public init(user: BeamUser) {
self.user = user
}

/**
Updates the stored user model.

:param: completion An optional completion block, called when the new user object has been retrieved.
*/
public func updateStoredUser(completion: ((_ user: BeamUser?, _ error: BeamRequestError?) -> Void)?) {
BeamClient.sharedClient.users.getUserWithId(self.user.id) { user, error in
if let user = user {
self.user = user
UserDefaults.standard.set(user.encoded, forKey: "UserData")
}

completion?(user, error)
}
}

/**
Authenticates a user given a username, password, and optional 2FA code.

Expand Down

0 comments on commit e42b02c

Please sign in to comment.