All Projects → PerfectExamples → Perfect-Weather

PerfectExamples / Perfect-Weather

Licence: other
Demonstrate using URL Routes & variables, Fetching of remote data from API's as JSON, reading and transforming to data more appropriately consumable by an API client.

Programming Languages

swift
15916 projects

Projects that are alternatives of or similar to Perfect-Weather

Perfect-XML
XML support for Perfect.
Stars: ✭ 16 (-50%)
Mutual labels:  perfect, server-side-swift
Perfect-Zip
Perfect Zip compression utility.
Stars: ✭ 20 (-37.5%)
Mutual labels:  perfect, server-side-swift
Perfect-URLRouting
Perfect Example Module: URL Routing
Stars: ✭ 20 (-37.5%)
Mutual labels:  perfect, server-side-swift
Perfect-SMTP
SMTP Client for Perfect.
Stars: ✭ 19 (-40.62%)
Mutual labels:  perfect, server-side-swift
Perfect
Server-side Swift. The Perfect core toolset and framework for Swift Developers. (For mobile back-end development, website and API development, and more…)
Stars: ✭ 13,890 (+43306.25%)
Mutual labels:  perfect, server-side-swift
Perfect-Thread
Core threading library for Perfect Server Side Swift. Includes support for serial and concurrent thread queues, locks, read/write locks and events.
Stars: ✭ 17 (-46.87%)
Mutual labels:  perfect, server-side-swift
Perfect-HTTPServer
HTTP server for Perfect.
Stars: ✭ 104 (+225%)
Mutual labels:  perfect, server-side-swift
SwiftString
A comprehensive, lightweight string extension for Swift 3.x & 4.0
Stars: ✭ 117 (+265.63%)
Mutual labels:  perfect, server-side-swift
Perfect-JSON-API
An Example JSON API for Perfect
Stars: ✭ 43 (+34.38%)
Mutual labels:  perfect, server-side-swift
Perfect-Authentication
OAuth2 Implementations with Facebook, Google, LinkedIn, Slack, SalesForce and GitHub providers.
Stars: ✭ 14 (-56.25%)
Mutual labels:  perfect, server-side-swift
Perfect-WebSocketsServer
Perfect Example Module: WebSockets Server
Stars: ✭ 34 (+6.25%)
Mutual labels:  perfect, server-side-swift
Perfect-URL-Shortener
An Example URL Shortener System for Perfect
Stars: ✭ 37 (+15.63%)
Mutual labels:  perfect, server-side-swift
Perfect-HTTP
Base HTTP Support for Perfect.
Stars: ✭ 29 (-9.37%)
Mutual labels:  perfect, server-side-swift
descent
Elegant now playing display for Last.fm showing song metadata and local weather.
Stars: ✭ 97 (+203.13%)
Mutual labels:  weather
PerfectLearnGuide
Are you eager to get programming with Swift and Perfect? This PerfectLearnGuide will help you.
Stars: ✭ 19 (-40.62%)
Mutual labels:  perfect
verif
Software for verifying weather forecasts
Stars: ✭ 70 (+118.75%)
Mutual labels:  weather
Lumpik
[experimental] Lumpik is a job queue system for general purpose.
Stars: ✭ 21 (-34.37%)
Mutual labels:  server-side-swift
model
Swift Kubernetes API objects
Stars: ✭ 18 (-43.75%)
Mutual labels:  server-side-swift
open-earth-compiler
development repository for the open earth compiler
Stars: ✭ 50 (+56.25%)
Mutual labels:  weather
pluvia weather flutter
A weather app with beautiful animations, built with Flutter. Uses the OpenWeatherMap API and MapBox API.
Stars: ✭ 114 (+256.25%)
Mutual labels:  weather

Perfect Weather App Example简体中文

Get Involed with Perfect!

Star Perfect On Github Stack Overflow Follow Perfect on Twitter Join the Perfect Slack

Swift 3.0 Platforms OS X | Linux License Apache PerfectlySoft Twitter Slack Status

An Example Weather App Backend for Perfect

The purpose of this example is to demonstrate using URL Routes & variables, Fetching of remote data from API's as JSON, reading and transforming to data more appropriately consumable by an API client.

Packages demonstrated:

  • PerfectLib (JSON)
  • HTTPServer
  • CURL
  • JSONConfig (3rd party library for reading configurations)

This package builds with Swift Package Manager and is part of the Perfect project.

Ensure you have installed Xcode 8.0 or later.

Obtaining an API Key

This example project requires a valid API key from https://www.wunderground.com/weather/api/ to function. Use this link to sign up for a developer account, and obtain an API key.

This key will be added to the ApplicationConfiguration.json file as described below.

Setup - Xcode 8

  • Check out or download the project;
  • In terminal, navigate to the directory and execute
swift package generate-xcodeproj
  • Open Perfect-Weather.xcodeproj
  • Add to the "Library Search Paths" in "Project Settings" $(PROJECT_DIR), recursive. (This step will be unneeded in a future release of Xcode 8.)
  • Rename the ApplicationConfiguration.json.example file to ApplicationConfiguration.json.
  • Open this file and change the token value to the WeatherUnderground token obtained above.
  • Add the file to a new "Copy Files" build phase as shown:

https://github.com/PerfectExamples/Perfect-Weather/raw/master/Resource/CopyFilesPhase.png

  • Select the Executable build target from the build targets dropdown in Xcode
  • Run (cmd-R) to build & run in Xcode.

In Xcode's console output pane you will see:

[INFO] Starting HTTP server on 0.0.0.0:8181 with document root ./webroot

Setup - Terminal

  • Check out or download the project;
  • In terminal, navigate to the directory
    • Rename the ApplicationConfiguration.json.example file to ApplicationConfiguration.json.
  • Open this file and change the token value to the WeatherUnderground token obtained above.
  • Execute swift build
  • Once the project has compiled, execute ./.build/debug/Perfect-Weather

The output you will see:

[INFO] Starting HTTP server on 0.0.0.0:8181 with document root ./webroot

Included Routes

The following routes are included in this API for demonstration purposes:

Current conditions sample response:

{
  "observation_time": "Last Updated on September 27, 12:00 PM ADT",
  "weather": "Light Rain Showers",
  "temperature_string": "54 F (12 C)"
}

Forecast sample response:

[
	{
		"icon": "rain",
		"icon_url": "http://icons.wxug.com/i/c/k/rain.gif",
		"pop": "100",
		"title": "Tuesday",
		"period": 0,
		"fcttext": "Rain likely. High 54F. Winds SE at 5 to 10 mph. Chance of rain 100%. Rainfall near a half an inch.",
		"fcttext_metric": "Rain likely. High 12C. Winds SE at 10 to 15 km/h. Chance of rain 100%. Rainfall near 12mm."
	},
	{
		"icon": "nt_rain",
		"icon_url": "http://icons.wxug.com/i/c/k/nt_rain.gif",
		"pop": "100",
		"title": "Tuesday Night",
		"period": 1,
		"fcttext": "Rain early...then remaining cloudy with showers overnight. Low 48F. Winds NE at 10 to 15 mph. Chance of rain 100%. Rainfall near a quarter of an inch.",
		"fcttext_metric": "Rain early...then remaining cloudy with showers overnight. Low 9C. Winds NE at 15 to 25 km/h. Chance of rain 100%. Rainfall around 6mm."
	},
	{
		"icon": "cloudy",
		"icon_url": "http://icons.wxug.com/i/c/k/cloudy.gif",
		"pop": "20",
		"title": "Wednesday",
		"period": 2,
		"fcttext": "Overcast. High 59F. Winds NNE at 10 to 15 mph.",
		"fcttext_metric": "Cloudy. High near 15C. Winds NNE at 15 to 25 km/h."
	},
	{
		"icon": "nt_chancerain",
		"icon_url": "http://icons.wxug.com/i/c/k/nt_chancerain.gif",
		"pop": "40",
		"title": "Wednesday Night",
		"period": 3,
		"fcttext": "Considerable cloudiness. Occasional rain showers later at night. Low 52F. Winds NNE at 10 to 15 mph. Chance of rain 40%.",
		"fcttext_metric": "Cloudy with occasional showers late at night. Low 11C. Winds NNE at 10 to 15 km/h. Chance of rain 40%."
	},
	{
		"icon": "cloudy",
		"icon_url": "http://icons.wxug.com/i/c/k/cloudy.gif",
		"pop": "20",
		"title": "Thursday",
		"period": 4,
		"fcttext": "Cloudy. High around 60F. Winds N at 10 to 20 mph.",
		"fcttext_metric": "Cloudy. High 16C. Winds N at 15 to 30 km/h."
	},
	{
		"icon": "nt_mostlycloudy",
		"icon_url": "http://icons.wxug.com/i/c/k/nt_mostlycloudy.gif",
		"pop": "10",
		"title": "Thursday Night",
		"period": 5,
		"fcttext": "Mostly cloudy skies. Low around 45F. Winds N at 10 to 20 mph.",
		"fcttext_metric": "Mostly cloudy. Low 7C. Winds N at 15 to 30 km/h."
	},
	{
		"icon": "partlycloudy",
		"icon_url": "http://icons.wxug.com/i/c/k/partlycloudy.gif",
		"pop": "20",
		"title": "Friday",
		"period": 6,
		"fcttext": "Intervals of clouds and sunshine. High 63F. Winds NNE at 10 to 15 mph.",
		"fcttext_metric": "Intervals of clouds and sunshine. High 17C. Winds NNE at 10 to 15 km/h."
	},
	{
		"icon": "nt_partlycloudy",
		"icon_url": "http://icons.wxug.com/i/c/k/nt_partlycloudy.gif",
		"pop": "10",
		"title": "Friday Night",
		"period": 7,
		"fcttext": "Partly cloudy skies. Low 47F. Winds NNE at 5 to 10 mph.",
		"fcttext_metric": "A few clouds. Low 8C. Winds NNE at 10 to 15 km/h."
	}
]

Postman Collection

The repo includes a file Example-WeatherAPI.postman_collection which is a Postman URL collection.

With Postman installed, import and use to easily query the routes.

Further Information

For more information on the Perfect project, please visit perfect.org.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].