Skip to content

Commit

Permalink
Merge pull request #25 from IBM-Swift/develop
Browse files Browse the repository at this point in the history
Updated to swift 3.0.1
  • Loading branch information
rolivieri authored Nov 4, 2016
2 parents 54595e5 + a503912 commit a1e20d2
Show file tree
Hide file tree
Showing 5 changed files with 9 additions and 17 deletions.
2 changes: 1 addition & 1 deletion .swift-version
Original file line number Diff line number Diff line change
@@ -1 +1 @@
3.0
3.0.1
2 changes: 1 addition & 1 deletion Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ let package = Package(
],
dependencies: [
//.Package(url: "https://github.com/behrang/YamlSwift.git", majorVersion: 1),
.Package(url: "https://github.com/IBM-Swift/SwiftyJSON.git", majorVersion: 14)
.Package(url: "https://github.com/IBM-Swift/SwiftyJSON.git", majorVersion: 15)
]
//testDependencies: []
)
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ This library determines if you are running your application "locally" or on the
For the implementation of this Swift package, we used as inspiration a similar module that had been developed for Node.js applications, [node-cfenv](https://github.com/cloudfoundry-community/node-cfenv).

## Swift version
The latest version of Swift-cfenv works with the `3.0` version of the Swift binaries. You can download this version of the Swift binaries by following this [link](https://swift.org/download/#snapshots).
The latest version of Swift-cfenv works with the `3.0.1` version of the Swift binaries. You can download this version of the Swift binaries by following this [link](https://swift.org/download/#snapshots).

## Usage
To leverage the Swift-cfenv package in your Swift application, you should specify a dependency for it in your `Package.swift` file:
Expand Down Expand Up @@ -111,7 +111,7 @@ The following are the instance methods for an `AppEnv` object:

- `appEnv.getService(spec: String)`: Returns a [Service](#service) object for the specified Cloud Foundry service. The `spec` parameter should be the name of the service or a regular expression to look up the service. If there is no service that matches the `spec` parameter, this method returns nil.

- `getServiceURL(spec: String, replacements: JSON?)`: Returns a service URL generated from the `VCAP_SERVICES` environment variable for the specified service or nil if service cannot be found. The `spec` parameter should be the name of the service or a regular expression to look up the service. The `replacements` parameter is a JSON object with the properties (e.g. `user`, `password`, `port`, etc.) found in Foundation's [NSURLComponents](https://developer.apple.com/library/ios/documentation/Foundation/Reference/NSURLComponents_class/index.html) class. To generate the service URL, the `url` property in the service credentials is first used to create an instance of the NSURLComponents class. The initial set of properties in the NSURLComponents instance can then be overridden by properties specified in the optional `replacements` JSON parameter. If there is not a `url` property in the service credentials, this method returns nil. Having said this, note that you have the capability to override the `url` property in the service credentials, with a `replacements` property of `url` and a value that specifies the name of the property in the service credentials that contains the base URL. For instance, you may find this useful in the case there is no `url` property in the service credentials.
- `getServiceURL(spec: String, replacements: JSON?)`: Returns a service URL generated from the `VCAP_SERVICES` environment variable for the specified service or nil if service cannot be found. The `spec` parameter should be the name of the service or a regular expression to look up the service. The `replacements` parameter is a JSON object with the properties (e.g. `user`, `password`, `port`, etc.) found in Foundation's [URLComponents](https://developer.apple.com/reference/foundation/urlcomponents) class. To generate the service URL, the `url` property in the service credentials is first used to create an instance of the URLComponents object. The initial set of properties in the URLComponents instance can then be overridden by properties specified in the optional `replacements` JSON parameter. If there is not a `url` property in the service credentials, this method returns nil. Having said this, note that you have the capability to override the `url` property in the service credentials, with a `replacements` property of `url` and a value that specifies the name of the property in the service credentials that contains the base URL. For instance, you may find this useful in the case there is no `url` property in the service credentials.

- `appEnv.getServiceCreds(spec: String)`: Returns a JSON object that contains the credentials for the specified service. The `spec` parameter should be the name of the service or a regular expression to look up the service. If there is no service that matches the `spec` parameter, this method returns nil. In the case there is no credentials property for the specified service, an empty JSON object is returned.

Expand Down
12 changes: 4 additions & 8 deletions Sources/CloudFoundryEnv/AppEnv.swift
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,7 @@ public struct AppEnv {
*/
public init(options: JSON) throws {
// NSProcessInfo.processInfo().environment returns [String : String]
#if os(Linux)
let environmentVars = ProcessInfo.processInfo.environment
#else
let environmentVars = ProcessInfo.processInfo.environment
#endif
let environmentVars = ProcessInfo.processInfo.environment
let vcapApplication = environmentVars["VCAP_APPLICATION"]
isLocal = (vcapApplication == nil)

Expand Down Expand Up @@ -162,7 +158,7 @@ public struct AppEnv {
* service or a regex to look up the service.
*
* The replacements parameter is a JSON object with the properties found in
* Foundation's NSURLComponents class.
* Foundation's URLComponents class.
*/
public func getServiceURL(spec: String, replacements: JSON?) -> String? {
var substitutions: JSON = replacements ?? [:]
Expand All @@ -178,7 +174,7 @@ public struct AppEnv {
}

substitutions.dictionaryObject?["url"] = nil
guard let parsedURL = NSURLComponents(string: url) else {
guard var parsedURL = URLComponents(string: url) else {
return nil
}

Expand All @@ -192,7 +188,7 @@ public struct AppEnv {
if let password = substitutions["password"].string {
parsedURL.password = password
}
if let port = substitutions["port"].number {
if let port = substitutions["port"].int {
parsedURL.port = port
}
if let host = substitutions["host"].string {
Expand Down
6 changes: 1 addition & 5 deletions Sources/CloudFoundryEnv/DateUtils.swift
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,7 @@ public struct DateUtils {
dateFormatter = DateFormatter()
// Example: 2016-03-04 02:43:07 +0000
dateFormatter.dateFormat = "yyyy-MM-dd HH:mm:ss ZZZ"
#if os(Linux)
let timeZone = TimeZone(abbreviation: "UTC")
#else
let timeZone = TimeZone(identifier: "UTC")
#endif
let timeZone = TimeZone(identifier: "UTC")
dateFormatter.timeZone = timeZone
}

Expand Down

0 comments on commit a1e20d2

Please sign in to comment.