-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
navibyte
committed
Feb 22, 2020
0 parents
commit 2f400b1
Showing
126 changed files
with
6,015 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
# Auto detect text files and perform LF normalization | ||
* text=auto |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
.DS_Store | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
MIT License | ||
|
||
Copyright (c) 2020 Navibyte (https://navibyte.com). | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy | ||
of this software and associated documentation files (the "Software"), to deal | ||
in the Software without restriction, including without limitation the rights | ||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the Software is | ||
furnished to do so, subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in all | ||
copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
SOFTWARE. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
Sub projects "core" and "mobile" contains also code snippets or adapted code | ||
originating from the "flutter_weather" sample app by Felix Angelov | ||
|
||
Source for the sample app mentioned: | ||
https://github.com/felangel/bloc/tree/master/examples/flutter_weather | ||
|
||
Below the original license for these copied or adapted parts. | ||
|
||
------------------------------------------------------------------------------ | ||
MIT License | ||
|
||
Copyright (c) 2018 Felix Angelov | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy | ||
of this software and associated documentation files (the "Software"), to deal | ||
in the Software without restriction, including without limitation the rights | ||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the Software is | ||
furnished to do so, subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in all | ||
copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
SOFTWARE. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
# Quake Monitor - Flutter app to monitor earthquakes | ||
|
||
This is an experimental sample app based on | ||
[Flutter](https://flutter.dev/) | ||
and [Dart](https://dart.dev/). | ||
|
||
The purpose is to learn Dart and Flutter, to experiment with Flutter's | ||
[support for the web platform](https://flutter.dev/web) and to test different API-technologies for | ||
implementing communication between a mobile (or web) app and backend services. | ||
|
||
This app has backend service integrations based on either | ||
[RESTful APIs](https://en.wikipedia.org/wiki/Representational_state_transfer) | ||
or [gRPC](https://grpc.io/) services. | ||
|
||
For example the related repository | ||
[quake](https://github.com/navibyte/quake) implements a gRPC service | ||
providing earthquake data. | ||
|
||
## Screenshot | ||
|
||
Quake Monitor sample app running on Chrome based on the [Flutter web](https://flutter.dev/web) platform. Locally tested also on iOS simulator. | ||
|
||
<img src="assets/screenshots/quake-monitor.jpg" width="60%" title="Quake Monitor - Earthquake Alerts" /> | ||
|
||
## Projects | ||
|
||
This repository contains three separate Dart or Flutter projects with | ||
each having their own `pubspec.yaml` dependency file. | ||
|
||
<img src="assets/diagrams/project-structure.png" width="60%" title="Quake Monitor - Project Structure" /> | ||
|
||
Please open | ||
each project separately on an IDE. Each project has also own README | ||
describing the code and dependencies for a project. | ||
|
||
Project | SDK | Description | ||
------- | --- | ----------- | ||
[api](api) | Dart & gRPC | API client and generated stub for gRPC service providing earthquake data. | ||
[core](core) | Dart | Platform independent domain models, data providers (API clients), repositories, i18 and other shared utilities. | ||
[mobile](mobile) | Flutter | Blocs (state management), widgets, pages and UI related utilities. | ||
|
||
## Dependencies | ||
|
||
See code projects introduced above for Dart and Flutter libraries linked. | ||
|
||
## Authors | ||
|
||
This project is authored by **[Navibyte](https://navibyte.com)**. | ||
|
||
## License | ||
|
||
This project is licensed under the MIT License - see the [LICENSE](LICENSE). | ||
|
||
## Links | ||
|
||
The app is based on SDKs: | ||
* [Dart](https://dart.dev/) | ||
* [Flutter](https://flutter.dev/) | ||
* [gRPC](https://grpc.io/) | ||
|
||
Other key libraries used by the app: | ||
* [Bloc](https://bloclibrary.dev/) | ||
* [Equatable](https://pub.dev/packages/equatable) | ||
* [Circular Bottom Navigation](https://pub.dev/packages/circular_bottom_navigation) | ||
|
||
Data sources: | ||
* earthquakes from the [GeoJSON service](https://earthquake.usgs.gov/earthquakes/feed/v1.0/geojson.php) of the USGS | ||
* place searches from the [GeoNames.org](https://www.geonames.org/) service | ||
|
||
Other assets: | ||
* App bar images by [Marcello Migliosi](https://pixabay.com/users/marcellomigliosi1956-1650894/?utm_source=link-attribution&utm_medium=referral&utm_campaign=image&utm_content=1790896) via [Pixabay](https://pixabay.com/) | ||
|
||
Inspiration for how to handle state using the | ||
[Bloc](https://bloclibrary.dev/) library | ||
and how to structure model, repository, | ||
bloc and widget layers originates from | ||
[Flutter Weather Tutorial](https://bloclibrary.dev/#/flutterweathertutorial) | ||
by [Felix Angelov](https://twitter.com/felangelov) | ||
(see also related example [repository](https://github.com/felangel/bloc/tree/master/examples/flutter_weather)). | ||
|
||
Inspiration for the sub-project structure originates from | ||
[inKino](https://github.com/roughike/inKino) app by | ||
[Iiro Krankka](https://twitter.com/koorankka). | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
# Files and directories created by pub | ||
.dart_tool/ | ||
.packages | ||
# Remove the following pattern if you wish to check in your lock file | ||
pubspec.lock | ||
|
||
# Conventional directory for build outputs | ||
build/ | ||
|
||
# Directory created by dartdoc | ||
doc/api/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
# Copyright 2020 Navibyte (https://navibyte.com). All rights reserved. | ||
# Use of this source code is governed by a MIT-style license, see the LICENSE. | ||
|
||
# Makefile to init project and generate gRPC stub for QuakeService. | ||
|
||
# Dependencies (tools must be available on the path): | ||
# - protoc (Protocol Buffer v3) | ||
# - protoc-gen-dart (protoc compiler extension for Dart) | ||
# | ||
# That is install Dart 2.0 or higher, gRPC, Protocol Buffers v3 and protoc plugin | ||
# for Dart according to: https://grpc.io/docs/quickstart/dart/ | ||
# Dart package protoc_plugin must be installed using pub. | ||
# See also: https://github.com/protocolbuffers/protobuf/releases | ||
|
||
# Please note also that this Makefiles assumes that you | ||
# have following repositories locally under the same root: | ||
# * quake (=> https://github.com/navibyte/quake) | ||
# * api/v1 (proto files here) | ||
# * quake_monitor (=> https://github.com/navibyte/quake_monitor) | ||
# * api (this project) | ||
# * Makefile (use this to *make* code generation) | ||
# * lib/src/quake/api/v1 (dart code is generated here) | ||
|
||
# This is parent folder for quake and quake_monitor repositories locally | ||
PROTOS=../.. | ||
|
||
# Input protos from the quake repository | ||
INPUT=$(PROTOS)/quake/api/v1 | ||
PROTO_FILES=$(INPUT)/quake.proto $(INPUT)/quake_api.proto | ||
|
||
# Dart output on the quake_monitor repository | ||
DART_OUT=$(PROTOS)/quake_monitor/api/lib/src | ||
DART_OUTFILE=$(DART_OUT)/quake/api/v1/quake.pb.dart | ||
|
||
# default target | ||
all: stub | ||
|
||
# Generate Dart stubs | ||
# (more about Dart plugin => https://pub.dev/packages/protoc_plugin) | ||
stub: $(DART_OUTFILE) | ||
$(DART_OUTFILE): $(PROTO_FILES) | ||
mkdir -p $(DART_OUT) | ||
protoc -I$(PROTOS) $(INPUT)/*.proto --dart_out=grpc:$(DART_OUT) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,113 @@ | ||
# API - the gRPC client for earthquakes | ||
|
||
A [gRPC](https://grpc.io/) client (written in Dart) for accessing earthquake | ||
data from the [quake](https://github.com/navibyte/quake) gRPC service (written in Go). | ||
|
||
This is a [Dart](https://dart.dev/) code project named `api` under the | ||
[quake_monitor](https://github.com/navibyte/quake_monitor) repository. The | ||
repository contains also other Dart and Flutter projects. | ||
|
||
## Dependencies | ||
|
||
gRPC message and service definitions as | ||
[Protocol Buffers](https://developers.google.com/protocol-buffers) schema: | ||
* under the [quake](https://github.com/navibyte/quake) repository | ||
* [api/v1/quake.proto](https://github.com/navibyte/quake/blob/master/api/v1/quake.proto) for message definitions | ||
* [api/v1/quake_api.proto](https://github.com/navibyte/quake/blob/master/api/v1/quake_api.proto) for the service definition | ||
|
||
The client containing both generated and written [Dart](https://dart.dev/) code depends also on following external packages: | ||
* [fixnum](https://pub.dev/packages/fixnum) | ||
* [protobuf](https://pub.dev/packages/protobuf) | ||
* [grpc](https://pub.dev/packages/grpc) | ||
|
||
Please see `pubscec.yaml` for more details and versions used. | ||
|
||
## Usage | ||
|
||
`EarthquakeApiClient` class in the `api/lib/src/helper/api_client.dart` source | ||
file wraps setting up a gRPC channel for the server and calling it. | ||
|
||
A basic example for using the class to get earthquake list from a local server: | ||
|
||
```dart | ||
// setup API client and open a channel to gRPC service | ||
final client = EarthquakeApiClient( | ||
address: "localhost", port: 50051, isSecure: false); | ||
final channel = await client.open(); | ||
try { | ||
// call gRPC service | ||
final col = await channel.listEarthquakes( | ||
magnitude: Magnitude.MAGNITUDE_SIGNIFICANT, | ||
past: Past.PAST_7DAYS, | ||
limit: 10, | ||
details: false); | ||
if (col != null) { | ||
for (Earthquake eq in col.features) { | ||
// do something with an earthquake iterated from a resulting collection | ||
} | ||
} | ||
} finally { | ||
// ensure resources are closed | ||
await channel.shutdown(); | ||
} | ||
``` | ||
|
||
## Testing | ||
|
||
The quake_client is a simple CLI command to test a gRPC service and it has | ||
a main() function in the `api/bin/quake_client.dart` source file. This uses also | ||
the `EarthquakeApiClient` class introduced above. | ||
|
||
Please ensure you have [Dart](https://dart.dev/) SDK (minimum version 2.7) | ||
installed on your system. | ||
|
||
Then under a local repository clone you can run the test client: | ||
``` | ||
$ dart api/bin/quake_client.dart help | ||
``` | ||
|
||
By default the client accesses `localhost` server address at the port | ||
`50051`. This can be modified by setting a QUAKE_SERVICE environment variable | ||
for a server address and port (ie. `myserver.example.org:443`). | ||
|
||
Some examples for requesting earthquakes from a gRPC service using command line: | ||
``` | ||
$ dart api/bin/quake_client.dart ListEarthquakes significant 7days | ||
$ dart api/bin/quake_client.dart ListEarthquakes 2.5 day 5 | ||
``` | ||
|
||
## Code generation | ||
|
||
This project contains generated .dart files for server interface code and | ||
client side stubs related to the gRPC service defined on the | ||
[quake](https://github.com/navibyte/quake) repository introduced earlier. | ||
|
||
If you like or need to regenerate server interfaces and client stubs for Dart | ||
then you need a development environment with following command line tools: | ||
* protoc (Protocol Buffer v3) | ||
* protoc-gen-dart (protoc compiler extension for Dart) | ||
|
||
Please consult following quick start quide to setup your environment first: | ||
* [Dart Quick Start for gRPC](https://grpc.io/docs/quickstart/dart/) | ||
|
||
When needing regeneration then on your development enviroment cd to the `api` | ||
folder and run `make` command to generate Dart code. Generated code is stored on | ||
the the `api/lib/src/quake/api/v1` folder. | ||
|
||
This process is defined on the Makefile. Please note that it assumes that you | ||
have following repositories locally under the same root: | ||
* [quake](https://github.com/navibyte/quake) | ||
* `api/v1` (proto files here) | ||
* [quake_monitor](https://github.com/navibyte/quake_monitor) | ||
* `api` (this project) | ||
* `Makefile` (use this to *make* code generation) | ||
* `lib/src/quake/api/v1` (dart code is generated here) | ||
|
||
## Authors | ||
|
||
This project is authored by **[Navibyte](https://navibyte.com)**. | ||
|
||
## License | ||
|
||
This project is licensed under the MIT License - see the [LICENSE](../LICENSE). |
Oops, something went wrong.