Skip to content

Commit b2b6549

Browse files
committed
Initial Commit
0 parents  commit b2b6549

File tree

232 files changed

+19235
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

232 files changed

+19235
-0
lines changed

.gitattributes

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
# no binary files in this repo and store all files with LF line endings.
2+
3+
# for windows do the following:
4+
# git config --global core.eol native
5+
# git config --global core.autocrlf true
6+
7+
* text=auto

.gitignore

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
vendor/
2+
.idea/
3+
bin/
4+
src/PHPFUI/PHPUnitSyntaxCoverage
5+
src/PHPFUI/MySQLSlowQuery
6+
src/PHPFUI/HTMLUnitTester
7+
src/PHPFUI/InstaDoc
8+
src/PHPFUI/PayPal/PayPal.md
9+
src/PHPFUI/README.md
10+
composer.lock
11+
.php-cs-fixer.cache
12+
.phpunit.result.cache
13+
phpunit.xml
14+

.php-cs-fixer.dist.php

Lines changed: 288 additions & 0 deletions
Large diffs are not rendered by default.

CODE_OF_CONDUCT.md

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
# Contributor Covenant Code of Conduct
2+
3+
## Our Pledge
4+
5+
In the interest of fostering an open and welcoming environment, we as contributors and maintainers pledge to making participation in our project and our community a harassment-free experience for everyone, regardless of age, body size, disability, ethnicity, gender identity and expression, level of experience, nationality, personal appearance, race, religion, or sexual identity and orientation.
6+
7+
## Our Standards
8+
9+
Examples of behavior that contributes to creating a positive environment include:
10+
11+
* Using welcoming and inclusive language
12+
* Being respectful of differing viewpoints and experiences
13+
* Gracefully accepting constructive criticism
14+
* Focusing on what is best for the community
15+
* Showing empathy towards other community members
16+
17+
Examples of unacceptable behavior by participants include:
18+
19+
* The use of sexualized language or imagery and unwelcome sexual attention or advances
20+
* Trolling, insulting/derogatory comments, and personal or political attacks
21+
* Public or private harassment
22+
* Publishing others' private information, such as a physical or electronic address, without explicit permission
23+
* Other conduct which could reasonably be considered inappropriate in a professional setting
24+
25+
## Our Responsibilities
26+
27+
Project maintainers are responsible for clarifying the standards of acceptable behavior and are expected to take appropriate and fair corrective action in response to any instances of unacceptable behavior.
28+
29+
Project maintainers have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct, or to ban temporarily or permanently any contributor for other behaviors that they deem inappropriate, threatening, offensive, or harmful.
30+
31+
## Scope
32+
33+
This Code of Conduct applies both within project spaces and in public spaces when an individual is representing the project or its community. Examples of representing a project or community include using an official project email address, posting via an official social media account, or acting as an appointed representative at an online or offline event. Representation of a project may be further defined and clarified by project maintainers.
34+
35+
## Enforcement
36+
37+
Instances of abusive, harassing, or otherwise unacceptable behavior may be reported by contacting the project owner. They will review and investigate all complaints, and will respond in a way that it deems appropriate to the circumstances. The project team is obligated to maintain confidentiality with regard to the reporter of an incident. Further details of specific enforcement policies may be posted separately.
38+
39+
Project maintainers who do not follow or enforce the Code of Conduct in good faith may face temporary or permanent repercussions as determined by other members of the project's leadership.
40+
41+
## Attribution
42+
43+
This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4, available at [http://contributor-covenant.org/version/1/4][version]
44+
45+
[homepage]: http://contributor-covenant.org
46+
[version]: http://contributor-covenant.org/version/1/4/

LICENSE

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
Copyright 2021 Bruce K. Wells
2+
3+
Permission is hereby granted, free of charge, to any person obtaining a
4+
copy of this software and associated documentation files (the "Software"),
5+
to deal in the Software without restriction, including without limitation
6+
the rights to use, copy, modify, merge, publish, distribute, sublicense,
7+
and/or sell copies of the Software, and to permit persons to whom the
8+
Software is furnished to do so, subject to the following conditions: The
9+
above copyright notice and this permission notice shall be included in all
10+
copies or substantial portions of the Software.
11+
12+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
13+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
14+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
15+
THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
16+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
17+
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
18+
DEALINGS IN THE SOFTWARE.

README.md

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
# ConstantContact [![Build Status](https://api.travis-ci.com/phpfui/constantcontact.png?branch=master)](https://api.travis-ci.com/phpfui/constantcontact) [![Latest Packagist release](https://img.shields.io/packagist/v/phpfui/constantcontact.svg)](https://packagist.org/packages/phpfui/phpfui)
2+
3+
PHP Object Oriented wrapper for the Constant Contact V3 API.
4+
5+
**PHPFUI/ConstantContact** is a [modern](#php-versions) PHP library that tracks the latest changes to the Constant Contact API.
6+
7+
**PHPFUI/ConstantContact** reads the [YAML](https://api.cc.email/v3/swagger.yaml) file from the Constant Contact documentation and generates PHP classes directly from the YAML file. The library is auto updated nightly. This means the library is always up to date with the latest changes. See the [versioning](#Versioning) section for further details.
8+
9+
## Namespaces
10+
This library normalizes the [Constant Contact API](https://v3.developer.constantcontact.com/api_guide/index.html) to modern PHP class standards. All endpoints are first character capitialized. Underscores are removed and followed by a capital letter. Each end point is a class with methods matching the standard REST methods (ie. put, post, delete, put, etc.). The methods take required and optional parameters matching the name specified in the Constant Contact YAML API. In addition, this library supports all definitions of types in the API. See below.
11+
12+
Due to a mistake in naming conventions by Constant Contact API designers, several end points are duplicated between the end point that returns all objects, and the end point that just works with one object. Normally this is dealt with by using the singular form of the noun for CRUD type operations on a single object, and the plural noun form returns a list of objects. This library follows the correct naming convention (single nouns for CRUD and plural nouns for collections) and not the Constant Contact naming convention.
13+
14+
## Definitions
15+
This Constant Contact API defines all types of objects to interact with the API. They are defined in the **PHPFUI\ConstantContact\Definition** namespace. Only valid fields are allowed to be accessed. Types are fully validated as to the best ability of PHP. Min and max lengths are enforced for strings.
16+
17+
## Usage Once Authorized (see below)
18+
```PHP
19+
// Create a client
20+
$client = new \PHPFUI\ConstantContact\Client($apiKey, $secret, $redirectURI);
21+
// Set access and refresh tokens on client
22+
$client->accessToken = $accessTokenFromDatabase;
23+
$client->refreshToken = $refreshTokenFromDatabase;
24+
// Refresh the tokens. This should be done on a regular (daily) basis so the token does not expire.
25+
$client->refreshToken();
26+
// save $client->accessToken and $client->refreshToken to database.
27+
28+
// $client is now ready to use
29+
$listEndPoint = new \PHPFUI\ConstantContact\V3\ContactLists($client);
30+
$lists = $listEndPoint->get();
31+
print_r($lists);
32+
```
33+
34+
## Constant Contact Setup
35+
In order to use this library, you will need to set up Constant Contact correctly. Go to [Constant Contact API](https://app.constantcontact.com) and create an application. Get an *API Key* and *Secret* and save it off for the **\PHPFUI\ConstantContact\Client** constructor. You will also need to set up and add a *Redirect URI*. You can use https://localhost if you want to authorize manually, but it is recommended to allow your users to authorize directly. The *Redirect URI* will receive a code that you will need to authorize the app, and then store the generated access token and refresh token. You should also provide the URL to your site's App logo. This will be shown to your user when they authenticate the app. They will need to sign into Constant Contact if they have not already done so. Fill out the other information as appropriate, but it is for informational purposes only.
36+
37+
## Authorization Control Flow
38+
You will need to set up a web page where your user can enter the *API Key* and *Secret*. You should also provide an **"Authorize"** button if the API returns an error, meaning it was not authorized. This allows the user to control the authorization process. Authorization needs to be done interactively. The user will have to log in to Constant Contact and then authorize the application. Once this is done, the app can run in the background and refresh the token daily and it should not expire or need to be reauthorized as long as the Secret has not been changed. Change the secret to require reauthorization.
39+
40+
## The Authorization control flow is as follows:
41+
42+
1. Create a Client with the API Key and Secret and specify a Redirect URI which will receive a code from Constant Contact.
43+
2. Redirect to $client->getAuthorizationURL(); User will authorize and redirected back to the $redirectURI you provide.
44+
3. Retrieve the code and save access and refresh tokens for later use. Redirect back to where ever.
45+
46+
### 1. Create A Client
47+
```php
48+
$client = new \PHPFUI\ConstantContact\Client($apiKey, $secret, $tokenURL);
49+
// set any scopes here, defaults to all scopes. Your user will need to accept what ever scopes you specify.
50+
```
51+
### 2. Redirect to Authorization URL
52+
```php
53+
\header('location: ' . $client->getAuthorizationURL());
54+
```
55+
The above will ask the user to authorize the app for the scopes you specified. The default is all scopes, but you can specify different scopes after constructing the client and before you authorize.
56+
57+
### 3. Retrieve the Code sent to the $redirectURI
58+
```php
59+
$client->acquireAccessToken($_GET['code']);
60+
// Save $client->accessToken and $client->refreshToken to the database
61+
// redirect back to where ever
62+
```
63+
64+
You should now be authorized to use the API. Make sure you save and restore the access token and refresh tokens every time you access the API.
65+
66+
## Versioning
67+
Since the [Constant Contact API](https://v3.developer.constantcontact.com/api_guide/index.html) is constantly being updated, this library will track all updates on a calendar based versioning schema. The major version will be the last two digits of the year the update was released. The minor version will be the month it was released. Any bug fixes will be a patch version. So V21.8.0 would be the first August 2021 version, and V21.8.1 would be a bug fix to V21.8. All bug fixes will be included in subsequent versions, so V21.9.0 would include all fixes from the V21.8 version. YAML changes are tracked nightly and a new version will be generated automatically. Multiple YAML changes in a month will be tracked as patch versions.
68+
69+
## Documentation
70+
Via [PHPFUI/InstaDoc](http://www.phpfui.com/?PHPFUI\ConstantContact)
71+
72+
## License
73+
**PHPFUI/ConstantContact** is distributed under the MIT License.
74+
75+
### PHP Versions
76+
This library only supports PHP 8.0 and higher versions of PHP. While we would love to support PHP from the late Ming Dynasty, the advantages of modern PHP versions far out weigh quaint notions of backward compatibility. Time to upgrade.

Tests/DefinitionTest.php

Lines changed: 161 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,161 @@
1+
<?php
2+
3+
/**
4+
* This file is part of the PHPFUI\ConstantContact package
5+
*
6+
* (c) Bruce Wells
7+
*
8+
* For the full copyright and license information, please view
9+
* the LICENSE.md file that was distributed with this source
10+
* code
11+
*/
12+
class DefinitionTest extends \PHPUnit\Framework\TestCase
13+
{
14+
15+
public function testGetSet() : void
16+
{
17+
$fixture = new \Tests\Fixtures\TypeTest();
18+
$integer = 123;
19+
$fixture->integer = $integer;
20+
$this->assertEquals($integer, $fixture->integer);
21+
$this->assertIsInt($fixture->integer);
22+
23+
$string = 'A long string';
24+
$fixture->string = $string;
25+
$this->assertEquals($string, $fixture->string);
26+
$this->assertIsString($fixture->string);
27+
28+
$boolean = true;
29+
$fixture->boolean = $boolean;
30+
$this->assertEquals($boolean, $fixture->boolean);
31+
$this->assertIsBool($fixture->boolean);
32+
33+
$array = [1, 2, 3];
34+
$fixture->array = $array;
35+
$this->assertEquals($array, $fixture->array);
36+
$this->assertIsArray($fixture->array);
37+
38+
$float = 1.23;
39+
$fixture->float = $float;
40+
$this->assertEquals($float, $fixture->float);
41+
$this->assertIsFloat($fixture->float);
42+
43+
$string = 'primary_email';
44+
$fixture->enum = $string;
45+
$this->assertEquals($string, $fixture->enum);
46+
$this->assertIsString($fixture->enum);
47+
48+
$integer = 1;
49+
$fixture->intEnum = $integer;
50+
$this->assertEquals($integer, $fixture->intEnum);
51+
$this->assertIsInt($fixture->intEnum);
52+
53+
$string = 'REMOVED';
54+
$fixture->ucEnum = $string;
55+
$this->assertEquals($string, $fixture->ucEnum);
56+
$this->assertIsString($fixture->ucEnum);
57+
58+
$class = new \Tests\Fixtures\ClassTest();
59+
$fixture->class = $class;
60+
$this->assertEquals($class, $fixture->class);
61+
$this->assertIsObject($fixture->class);
62+
63+
$json = $fixture->getJSON();
64+
$expectedJSON ='{
65+
"class": {},
66+
"integer": 123,
67+
"string": "A long string",
68+
"boolean": true,
69+
"array": [
70+
1,
71+
2,
72+
3
73+
],
74+
"float": 1.23,
75+
"enum": "primary_email",
76+
"intEnum": 1,
77+
"ucEnum": "REMOVED"
78+
}';
79+
// normalize line endings
80+
$expectedJSON = str_replace("\r\n", "\n", $expectedJSON);
81+
$this->assertEquals($expectedJSON, $json);
82+
}
83+
84+
public function testBadField() : void
85+
{
86+
$fixture = new \Tests\Fixtures\TypeTest();
87+
$this->expectException(\PHPFUI\ConstantContact\Exception\InvalidField::class);
88+
$fixture->badField = 'test';
89+
}
90+
91+
public function testBadIntType() : void
92+
{
93+
$fixture = new \Tests\Fixtures\TypeTest();
94+
$this->expectException(\PHPFUI\ConstantContact\Exception\InvalidType::class);
95+
$fixture->integer = 'test';
96+
}
97+
98+
public function testBadStringType() : void
99+
{
100+
$fixture = new \Tests\Fixtures\TypeTest();
101+
$this->expectException(\PHPFUI\ConstantContact\Exception\InvalidType::class);
102+
$fixture->string = 123;
103+
}
104+
105+
public function testBadFloatType() : void
106+
{
107+
$fixture = new \Tests\Fixtures\TypeTest();
108+
$this->expectException(\PHPFUI\ConstantContact\Exception\InvalidType::class);
109+
$fixture->float = 'abc';
110+
}
111+
112+
public function testBadBooleanType() : void
113+
{
114+
$fixture = new \Tests\Fixtures\TypeTest();
115+
$this->expectException(\PHPFUI\ConstantContact\Exception\InvalidType::class);
116+
$fixture->boolean = 0;
117+
}
118+
119+
public function testBadArrayType() : void
120+
{
121+
$fixture = new \Tests\Fixtures\TypeTest();
122+
$this->expectException(\PHPFUI\ConstantContact\Exception\InvalidType::class);
123+
$fixture->array = 0;
124+
}
125+
126+
public function testBadClassType() : void
127+
{
128+
$fixture = new \Tests\Fixtures\TypeTest();
129+
$this->expectException(\PHPFUI\ConstantContact\Exception\InvalidType::class);
130+
$fixture->class = new \DateTime();
131+
}
132+
133+
public function testBadEnum() : void
134+
{
135+
$fixture = new \Tests\Fixtures\TypeTest();
136+
$this->expectException(\PHPFUI\ConstantContact\Exception\InvalidValue::class);
137+
$fixture->enum = 'fred';
138+
}
139+
140+
public function testMinLength() : void
141+
{
142+
$fixture = new \Tests\Fixtures\TypeTest();
143+
$this->expectException(\PHPFUI\ConstantContact\Exception\InvalidLength::class);
144+
$fixture->string = 'fred';
145+
}
146+
147+
public function testMaxLength() : void
148+
{
149+
$fixture = new \Tests\Fixtures\TypeTest();
150+
$this->expectException(\PHPFUI\ConstantContact\Exception\InvalidLength::class);
151+
$fixture->string = str_pad('', 100);
152+
}
153+
154+
public function testGeneratedClass() : void
155+
{
156+
$fixture = new \PHPFUI\ConstantContact\Definition\EmailCampaignActivity();
157+
$this->expectException(\PHPFUI\ConstantContact\Exception\InvalidType::class);
158+
$fixture->physical_address_in_footer = new \DateTime();
159+
}
160+
161+
}

Tests/Fixtures/ClassTest.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
<?php
2+
3+
namespace Tests\Fixtures;
4+
5+
class ClassTest
6+
{
7+
8+
}

Tests/Fixtures/TypeTest.php

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
<?php
2+
3+
namespace Tests\Fixtures;
4+
5+
class TypeTest extends \PHPFUI\ConstantContact\Definition\Base
6+
{
7+
8+
protected static array $fields = [
9+
'boolean' => 'bool',
10+
'integer' => 'int',
11+
'string' => 'string',
12+
'enum' => ['primary_email', 'permalink', 'resend'],
13+
'array' => 'array',
14+
'float' => 'float',
15+
'ucEnum' => ['DRAFT', 'SCHEDULED', 'EXECUTING', 'DONE', 'ERROR', 'REMOVED'],
16+
'intEnum' => [1, 2, 3, 4, 5],
17+
'class' => 'Tests\\Fixtures\\ClassTest',
18+
];
19+
20+
protected static array $minLength = [
21+
'string' => 10,
22+
];
23+
24+
protected static array $maxLength = [
25+
'string' => 50,
26+
];
27+
28+
}

Tests/SyntaxTest.php

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
<?php
2+
3+
/**
4+
* This file is part of the PHPFUI package
5+
*
6+
* (c) Bruce Wells
7+
*
8+
* For the full copyright and license information, please view
9+
* the LICENSE.md file that was distributed with this source
10+
* code
11+
*/
12+
class SyntaxTest extends \PHPFUI\PHPUnitSyntaxCoverage\Extensions
13+
{
14+
public function testDirectory() : void
15+
{
16+
$this->assertValidPHPDirectory(PROJECT_ROOT . '/src', 'src directory has an error');
17+
$this->assertValidPHPDirectory(PROJECT_ROOT . '/Tools', 'Tools directory has an error');
18+
}
19+
}

Tests/bootstrap.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
<?php
2+
3+
\define('PROJECT_ROOT', __DIR__ . '/..');
4+
5+
\error_reporting(E_ALL);
6+
7+
include __DIR__ . '//..//vendor//autoload.php';

0 commit comments

Comments
 (0)