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

Commit

Permalink
Added methods for channel hosting
Browse files Browse the repository at this point in the history
  • Loading branch information
jackcook committed Aug 9, 2016
1 parent 905f5ea commit 204f38a
Show file tree
Hide file tree
Showing 3 changed files with 59 additions and 2 deletions.
4 changes: 2 additions & 2 deletions BeamAPI.podspec
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Pod::Spec.new do |s|
s.name = "BeamAPI"
s.version = "1.0.7"
s.version = "1.0.8"
s.summary = "An interface to communicate with Beam's backend."
s.homepage = "https://github.com/WatchBeam/beam-client-swift"
s.license = "MIT"
Expand All @@ -9,7 +9,7 @@ Pod::Spec.new do |s|
s.requires_arc = true
s.ios.deployment_target = "8.2"
s.tvos.deployment_target = "9.0"
s.source = { :git => "https://github.com/WatchBeam/beam-client-swift.git", :tag => "1.0.7" }
s.source = { :git => "https://github.com/WatchBeam/beam-client-swift.git", :tag => "1.0.8" }
s.source_files = "Pod/Classes/**/*"

s.dependency "Starscream", "~> 1.1"
Expand Down
22 changes: 22 additions & 0 deletions Example/Tests/ChannelsTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,28 @@ class ChannelsTests: XCTestCase {
waitForExpectationsWithTimeout(10, handler: nil)
}

func testHostChannel() {
let expectation = expectationWithDescription("tests hosting a channel")

BeamClient.sharedClient.channels.hostChannel(channelId) { (error) in
XCTAssert(error == .NotAuthenticated)
expectation.fulfill()
}

waitForExpectationsWithTimeout(10, handler: nil)
}

func testStopHosting() {
let expectation = expectationWithDescription("tests stopping hosting")

BeamClient.sharedClient.channels.stopHosting { (error) in
XCTAssert(error == .NotAuthenticated)
expectation.fulfill()
}

waitForExpectationsWithTimeout(10, handler: nil)
}

func testChannelWithId() {
let expectation = expectationWithDescription("tests retrieving a channel by id")

Expand Down
35 changes: 35 additions & 0 deletions Pod/Classes/Routes/ChannelsRoutes.swift
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,41 @@ public class ChannelsRoutes {
}
}

/**
Hosts a channel from the currently authenticated user's channel.

:param: channelId The id of the channel being hosted.
:param: completion An optional completion block with response data.
*/
public func hostChannel(channelId: Int, completion: ((error: BeamRequestError?) -> Void)?) {
guard let id = BeamSession.sharedSession?.user.channel?.id else {
completion?(error: .NotAuthenticated)
return
}

let body = ["id": channelId]

BeamRequest.request("/channels/\(id)/hostee", requestType: "PUT", body: body) { (json, error) in
completion?(error: error)
}
}

/**
Stops hosting a channel on the currently authenticated user's channel.

:param: completion An optional completion block with response data.
*/
public func stopHosting(completion: ((error: BeamRequestError?) -> Void)?) {
guard let id = BeamSession.sharedSession?.user.channel?.id else {
completion?(error: .NotAuthenticated)
return
}

BeamRequest.request("/channels/\(id)/hostee", requestType: "DELETE") { (json, error) in
completion?(error: error)
}
}

// MARK: Retrieving Channels

/**
Expand Down

0 comments on commit 204f38a

Please sign in to comment.