Skip to content

Commit

Permalink
Initial release 🚀
Browse files Browse the repository at this point in the history
  • Loading branch information
rugaard committed Jul 27, 2019
0 parents commit 18a5b31
Show file tree
Hide file tree
Showing 22 changed files with 1,979 additions and 0 deletions.
18 changes: 18 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
; This file is for unifying the coding style for different editors and IDEs.
; More information at http://editorconfig.org

root = true

[*]
charset = utf-8
indent_size = 4
indent_style = space
end_of_line = lf
insert_final_newline = true
trim_trailing_whitespace = true

[*.{json,yml,yaml}]
indent_size = 2

[*.md]
trim_trailing_whitespace = false
8 changes: 8 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
/build
/vendor
/.idea
index.php
composer.phar
composer.lock
.DS_Store
.phpunit.result.cache
23 changes: 23 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
language: php

cache:
directories:
- $HOME/.composer/cache

php:
- 7.2
- 7.3

install:
- travis_retry composer self-update
- travis_retry composer install --no-interaction --prefer-dist --no-suggest

before_script:
- curl -L https://codeclimate.com/downloads/test-reporter/test-reporter-latest-linux-amd64 > ./cc-test-reporter && chmod +x ./cc-test-reporter
- if [ $(phpenv version-name) = "7.2" ]; then ./cc-test-reporter before-build; fi

script:
- vendor/bin/phpunit --do-not-cache-result --coverage-text --coverage-clover clover.xml

after_success:
- if [ $(phpenv version-name) = "7.2" ] && [ "$TRAVIS_PULL_REQUEST" == "false" ]; then ./cc-test-reporter after-build -t clover --exit-code $TRAVIS_TEST_RESULT; fi
402 changes: 402 additions & 0 deletions LICENSE

Large diffs are not rendered by default.

117 changes: 117 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,117 @@
<div align="center"><img src="https://rugaard.github.io/packages/pollen/logo.jpg"></div>

# 🇩🇰🤧 Pollen measurements from Astma-Allergi Denmark

<a href="https://github.com/rugaard/pollen/releases"><img src="https://img.shields.io/github/release/rugaard/pollen.svg"></a>
<a href="https://travis-ci.org/rugaard/pollen"><img src="https://travis-ci.org/rugaard/pollen.svg?branch=master"></a>
<a href="https://codeclimate.com/github/rugaard/pollen"><img src="https://img.shields.io/codeclimate/coverage/rugaard/pollen.svg"></a>
<a href="https://codeclimate.com/github/rugaard/pollen"><img src="https://img.shields.io/codeclimate/maintainability/rugaard/pollen.svg"></a>
<a href="https://creativecommons.org/licenses/by-nc-nd/4.0/"><img src="https://img.shields.io/static/v1.svg?labelColor=5f5f5f&label=license&color=43897a&message=CC%20BY-NC-ND"></a>

Astma-Allergi Denmark does unfortunately not offer an official API for the latest pollen measurements in Denmark.

This package is (in some form) a workaround for that. It collects the latest measurements from the official Astma-Allergi Denmark website and turns it into structured data objects.

The returned data shows the measured pollen between **13:00** _(1:00 PM)_ yesterday and **13:00** _(1:00 PM)_ present day. Everyday at **16:00** _(4:00 PM)_ the latest measurements are being published.

## ⚠️ Disclaimer
Since Astma-Allergi Denmark is an independent union, with a very little government funding, this package is made available under a very strict license, which prohibits any use other than personal.

If you wish to use the pollen measurements commercially, you should contact Astma-Allergi Denmark directly and support them by buying the data instead. The payment goes directly to the maintenance and further development of their Pollen measurement service.

For more info about a commercial license, [visit their official website](https://hoefeber.astma-allergi.dk/pollenfeed).

## 📖 Table of contents

* [Installation](#-installation)
* [Laravel](#laravel)
* [Usage](#%EF%B8%8F-usage)
* [Pollen Client](#pollen-client)
* [Methods](#methods)
* [Get measurements](#get-measurements)
* [Pollen stations](#-pollen-stations)
* [Frequently Asked Questions (FAQ)](#-frequently-asked-questions-faq)
* [What is this `Tightenco\Collect\Support\Collection` class and how does it work?](#what-is-this-tightencocollectsupportcollection-class-and-how-does-it-work)
* [License](#-license)

## 📦 Installation
You can install the package via [Composer](https://getcomposer.org/), by using the following command:
```shell
composer require rugaard/pollen
```

### Laravel
This package comes with a out-of-the-box Service Provider for the [Laravel](http://laravel.com) framework.
If you're using a newer version of Laravel (`>= 5.5`) then the service provider will be loaded automatically.

Are you using an older version, then you need to manually add the service provider to the `config/app.php` file:
```php
'providers' => [
Rugaard\Pollen\Providers\Laravel\ServiceProvider::class,
]
```

## ⚙️ Usage

First thing you need to do, is to instantiate the `Pollen` client
```php
# Instantiate the Pollen client.
$pollen = new \Rugaard\Pollen\Pollen;
```

Once you've done that, you're able to request the latest measurements from one of the [supported pollen stations](#-pollen-stations):
```php
# Copenhagen pollen station.
$measurements = $pollen->get('copenhagen');
```

### Pollen client

The Pollen client which handles the requests to Astma-Allergi Denmark.

```php
new Pollen(?Client $httpClient);
```

| Parameter | Type | Default | Description |
| :--- | :--- | :---: | :--- |
| `$httpClient` | `\GuzzleHttp\ClientInterface` | `null` | Replace the default underlying HTTP Client |

### Methods

#### Get measurements.

Get latest pollen measurements from a specific pollen station.

```php
get(string $stationCode);
```

| Parameter | Type | Description |
| :--- | :--- | :---: | :--- |
| `$stationCode` | `string` | Code of station. [Supported pollen stations.](#-pollen-stations) |

_**Note**: The returned data shows the measured pollen between 13:00 (1:00 PM) yesterday and 13:00 (1:00 PM) present day. The measurements are updated everyday at 16:00 (4:00 PM)._

## 🏛 Pollen stations

Currently there only exists two Pollen stations in Denmark.

| ID | Name | Code | Region |
| :---: | :--- | :--- | :---: |
| 48 | København | `copenhagen` | East |
| 49 | Viborg | `viborg` | West |

## 🗣 Frequently Asked Questions (FAQ)

#### What is this `Tightenco\Collect\Support\Collection` class and how does it work?

All data is returned within a `Tightenco\Collect\Support\Collection` class. The class is a port of the popular `Collection` class from [Laravel](https://laravel.com).

Please refer to [Laravel](https://laravel.com)'s detailed documentation, to learn more about how you work with a `Collection`:<br>
[https://laravel.com/docs/master/collections](https://laravel.com/docs/master/collections)

## 🚓 License
This package is licensed under a [Creative Commons Attribution-NonCommercial-NoDerivatives 4.0 (CC BY-NC-ND 4.0)](https://creativecommons.org/licenses/by-nc-nd/4.0/).

<a rel="license" href="https://creativecommons.org/licenses/by-nc-nd/4.0/"><img alt="Creative Commons License" style="border-width:0" src="https://i.creativecommons.org/l/by-nc-nd/4.0/88x31.png" /></a>
67 changes: 67 additions & 0 deletions composer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
{
"name": "rugaard/pollen",
"type": "library",
"description": "Fetch latest Pollen measurements from Astma-Allergi Denmark.",
"keywords": [
"morten",
"rugaard",
"morten rugaard",
"pollen",
"measurements",
"pollen measurements",
"hay fever",
"allergic hay fever",
"asthma",
"allergies"
],
"authors": [
{
"name": "Morten Rugaard",
"email": "[email protected]",
"homepage": "https://github.com/rugaard",
"role": "Developer"
}
],
"license": "MIT",
"homepage": "https://github.com/rugaard",
"support": {
"issues": "https://github.com/rugaard/pollen/issues",
"source": "https://github.com/rugaard/pollen"
},
"require": {
"php": "^7.2",
"ext-json": "*",
"guzzlehttp/guzzle": "~6.0",
"tightenco/collect": "^5.8"
},
"require-dev": {
"mockery/mockery": "^1.0",
"phpunit/phpunit": "^8.0"
},
"autoload": {
"psr-4": {
"Rugaard\\Pollen\\": "src"
}
},
"autoload-dev": {
"psr-4": {
"Rugaard\\Pollen\\Tests\\": "tests"
}
},
"extra": {
"laravel": {
"providers": [
"Rugaard\\Pollen\\Providers\\Laravel\\ServiceProvider"
]
}
},
"scripts": {
"test": "./vendor/bin/phpunit --colors=always"
},
"prefer-stable": true,
"config": {
"optimize-autoloader": true,
"preferred-install": "dist",
"sort-packages": true
}
}
26 changes: 26 additions & 0 deletions phpunit.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<?xml version="1.0" encoding="UTF-8"?>
<phpunit backupGlobals="false"
backupStaticAttributes="false"
bootstrap="vendor/autoload.php"
colors="true"
convertErrorsToExceptions="true"
convertNoticesToExceptions="true"
convertWarningsToExceptions="true"
processIsolation="false"
stopOnFailure="false"
>
<testsuites>
<testsuite name="Pollen">
<directory suffix="Test.php">./tests</directory>
</testsuite>
</testsuites>
<filter>
<whitelist>
<directory suffix=".php">./src</directory>
<exclude>
<directory>./src/Exceptions</directory>
<directory>./src/Providers</directory>
</exclude>
</whitelist>
</filter>
</phpunit>
15 changes: 15 additions & 0 deletions src/Exceptions/FailedSessionIdException.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<?php
declare(strict_types=1);

namespace Rugaard\Pollen\Exceptions;

use Exception;

/**
* Class FailedSessionIdException.
*
* @package Rugaard\Pollen\Exceptions
*/
class FailedSessionIdException extends Exception
{
}
15 changes: 15 additions & 0 deletions src/Exceptions/InvalidStationException.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<?php
declare(strict_types=1);

namespace Rugaard\Pollen\Exceptions;

use Exception;

/**
* Class InvalidStationException.
*
* @package Rugaard\Pollen\Exceptions
*/
class InvalidStationException extends Exception
{
}
15 changes: 15 additions & 0 deletions src/Exceptions/ParsingFailedException.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<?php
declare(strict_types=1);

namespace Rugaard\Pollen\Exceptions;

use Exception;

/**
* Class ParsingFailedException.
*
* @package Rugaard\DarkSky\Exceptions
*/
class ParsingFailedException extends Exception
{
}
15 changes: 15 additions & 0 deletions src/Exceptions/RequestFailedException.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<?php
declare(strict_types=1);

namespace Rugaard\Pollen\Exceptions;

use Exception;

/**
* Class RequestFailedException.
*
* @package Rugaard\Pollen\Exceptions
*/
class RequestFailedException extends Exception
{
}
15 changes: 15 additions & 0 deletions src/Exceptions/SessionIdNotFoundException.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<?php
declare(strict_types=1);

namespace Rugaard\Pollen\Exceptions;

use Exception;

/**
* Class SessionIdNotFoundException.
*
* @package Rugaard\Pollen\Exceptions
*/
class SessionIdNotFoundException extends Exception
{
}
Loading

0 comments on commit 18a5b31

Please sign in to comment.