2.2.7 • Published 7 years ago

ng2-cdf v2.2.7

Weekly downloads
5
License
MIT
Repository
github
Last release
7 years ago

ng2-cdf

Angular2 Content Delivery Framework (CDF)

The purpose of cdf-data-island component is to surface JSON data to the caller.

FEATURES:

  • Supports caching of results using ng2-cache (https://github.com/Jackson88/ng2-cache)
  • Supports ability to combine multiple GETs and POSTs URLS into a single Observable block
  • Supports ability to combine requests from multiple domains into a single Observable block

TODOS:

  • test multiple domains
  • need ability to surface errors to caller of cdf-data-island
  • ability to supoort PUTs
  • ability to support DELETEs
  • placing cdf-data-island in GitHub so it can be used in multiple projects

CdfRequestModel:

CdfRequestModel is the class used for gathering the GETs and POSTs http requests that will be called as a single Observable block

export class CdfRequestModel
{
	GetList: string[]; 
	PostList: CdfPostModel[];

	constructor()
	{
	}
}
  • GetList is an array of GET requests
  • PostList is an array of POST models

CdfPostModel:

CdfPostModel is the class describing the data elements needed for a proper POST

export class CdfPostModel
{
	URL: string;
	Body: Object;

	constructor(url: string, body: Object)
	{
		this.URL = url;
		this.Body = body;
	}
}
  • URL is the POST URL request
  • Body is the body of the POST request

IMPLEMENTATION EXAMPLES:

	import { Component, OnInit } 				from '@angular/core';
	import { CdfPostModel, CdfRequestModel } 	from '../../../cdf-data-island/index';	

	@Component({
		selector: 'some-cool-custom-tag',
		templateUrl: './some-cool-custom-tag.component.html',
		styleUrls: [ './some-cool-custom-tag.component.less' ],
		providers: []
	})
	export class SomeCoolCustomComponent implements OnInit
	{
		RequestModel = new CdfRequestModel();

		ngOnInit() 
		{		
			//LIST OF GETS FOR DATA ISLAND		
			this.RequestModel.GetList =
				[
					'http://your-domain.com/something/something/1',
					'http://your-domain.com/something/something/2',
					'http://your-domain.com/something/something/3',
					'http://your-domain.com/something/something/4',
					'http://your-domain.com/something/something/5'
				];


			//POST FOR DATA ISLAND
			this.RequestModel.PostList = 
			[
				new CdfPostModel
				(
					//POST URL:
					'http://your-domain.com/something/something/5?limit=3&metadata=false&full=true',
				
					//POST BODY:
					{
						"_type": "stm:media-production-show",
						"mediaProduction.id": 34
					}
				)
			];
		}			

		/*
		rawJson will be an array where each item in array is the results of a GET or POST in RequestModel
		*/
		onContentReceived(rawJson: any) 
		{
			console.log('CONTENT RECEIVED:', rawJson);
		};	
	}
	/* some-cool-custom-tag.component.html: */
	<cdf-data-island [RequestData]="RequestModel" 
				(onContentReceived)="onContentReceived($event)"
				(onContentError)="onContentError($event)"></cdf-data-island>

	<section>
		/* DISPLAY HTML HERE CONSUMING JSON RESULTS FROM CDF-DATA-ISLAND */
	</section>

CDF-DATA-ISLAND ATTRIBUTES:

  • RequestData is RequestModel data type (see below) containing GETs and POSTs that are called as a single Observable block
  • (onContentReceived) is the event binding that is called when results are returned for each call in Observable block
  • (onContentError) is the event binding that is called when an error happens

MULTIPLE HTTP REQUESTS:

CDF supports the ability to group multiple requests into a single Observable block. Observables are part of new Angular2 RXJS implementation

CDF combines multiple requests using ForkJoin

The order that HTTP requests are added to the ForkJoin is the exact same order the results are returned.

CDF allows you to add HTTP requests in multiple ways:

  • GetList is an array of GET requests
  • PostList is an array of POST models

CDF adds requests to the ForkJoin observable in the following oreder:

  • GetList
  • PostList

Again, the results returned to your return event handler (onContentReceived) are in the same order the requests are added to the ForkJoin (see above).


MULTIPLE DOMAINS:

CDF supports multiple domains in combining requests into a single Observable block

CDF sees content as the results of making HTTP requests. It does not care where you get your data for your app. CDF cares about REST.

You can combine requests to different domains in a given CDF Observable block.

Fork Join Observable is successful if ALL requests are successful. If one of the requests receives a 401 unauthorized response, CDF will attempt to recreate a valid token 3 times before quiting.

So, in the event a call fails, CDF will take the domain from the URL that failed and lookup the corresponding credentials and attempt to re-establish a valid authentication token.

If a successful token can be established, then CDF will attept to resubmit each URL in the request.

CDF will attempt the resubmission three times before giving up.


CONFIGURING CDF

cdf-settings.service (/src/cdf-data-island/services/cdf-settings.service.ts) is how you configure ng2-cdf. It's constructor accepts an array of CdfConfigModel (one for each domain that will be supported).

CdfConfigModel contains the following data elements. When a request is made to a REST service, CDF uses the domain of the REST request and looks through the CdfConfigModel array based on Domain name to retrieve the credentials necessary to maintain a connection.

	export class CdfConfigModel
	{
		Domain: string;
		EncodedCredentials: string;
		OAuthURL: string;
		Body: string
	}

cdf-settings.service's constructor accepts an array of CdfConfigModel. The calling application must provide the configuration for cdf-settings.service when the calling app is loaded. Here's an example:

		//ENVIRONMENTAL SETTINGS IN ANGULAR2 (environment.ts)
		export const environment =
		{
			production: false,
			cachePrefix: 'my-site-dev',	
			name: 'My Site - Development',
			version: '2.2.0',
			Domain_Credentials:
			[
				{
					"domain": "api.cloudcms.com",
					"encodedCredentials": "XXXXXXXXXXXXXXXXXXXXX",
					"oAuthURL": "https://api.cloudcms.com/oauth/token/oauth/token",
					"body": "grant_type=password&scope=api&username=XXXXXXXXXXXXXXXXXXXXX&password=XXXXXXXXXXXXXXXXXXXXX"
				},
				{
					"domain": "api.twitter.com",
					"encodedCredentials": "XXXXXXXXXXXXXXXXXXXXX",
					"oAuthURL": "https://api.twitter.com/oauth2/token",
					"body": "grant_type=client_credentials"
				}				
			]	
		};	 


		-------------------------------  config.service.ts:

		import
		{
			CdfConfigModel
		} 								from 'ng2-cdf/lib';

		@Injectable()
		export class ConfigService 
		{		
			/*
			CREATE PROPER CONFIGURATION FOR CONTENT DELIVERY FRAMEWORK (CDF)
			BASED ON REGISTERED DOMAIN'S IN ENVIRONMENT'S Domain_Credentials NODE
			*/
			public static GetDomainCredentials() : CdfConfigModel[]
			{ 
				let configArray: CdfConfigModel[] = [];

				//FIND CONFIG IN LIST WITH SAME DOMAIN NAME
				for (let entry of environment.Domain_Credentials) 
				{
					let domainRootUrl = (entry.domain) ? entry.domain : undefined;

					if (domainRootUrl)
					{ 
						let domainModel = new CdfConfigModel();
						domainModel.Domain = domainRootUrl;
						domainModel.EncodedCredentials = (entry.encodedCredentials) ? entry.encodedCredentials : undefined;
						domainModel.OAuthURL = (entry.oAuthURL) ? entry.oAuthURL : undefined;
						domainModel.Body = (entry.body) ? entry.body : undefined;

						configArray.push(domainModel);
					}	
				}

				//console.log('configArray:', configArray);
				
				return configArray;
			}
		}

		-------------------------------  shared.module.ts:

		//3RD PARTY...
		import { CdfModule } 				from 'ng2-cdf/lib';
		
		//BUILD DOMAIN CONFIGURATION ARRAY NEEDED FOR CDF MODULE...
		let configArray = ConfigService.GetDomainCredentials();

		@NgModule({
			imports:
			[
				CommonModule,
				RouterModule,

				//CONFIGURE CONTENT DELIVERY FRAMEWORK (CDF) WITH CREDENTIALS FOR DIFFERENT REST SOURCES		
				CdfModule.forRoot(configArray)
			],
			declarations:
			[
				//COMPONENTS
			],
			exports:
			[		
				//COMPONENTS

				//MODULES

				//APPLICATION MODULES

				//3RD PARTY...
				CdfModule		
			]
		})
		export class SharedModule
		{
			static forRoot(): ModuleWithProviders
			{
				return {
					ngModule: SharedModule,
					providers:
					[
						.... 
					]
				};
			}
		} 
2.2.7

7 years ago

2.2.6

7 years ago

2.2.5

7 years ago

2.2.4

7 years ago

2.2.3

7 years ago

2.2.2

7 years ago

2.2.1

7 years ago

2.2.0

7 years ago

2.1.0

7 years ago

2.0.3

7 years ago

2.0.2

7 years ago

2.0.1

7 years ago

2.0.0

7 years ago

1.1.11

7 years ago

1.1.10

7 years ago

1.1.9

7 years ago

1.1.8

7 years ago

1.1.7

7 years ago

1.1.5

7 years ago

1.1.4

7 years ago

1.1.3

7 years ago

1.1.2

7 years ago

1.1.1

7 years ago

1.1.0

7 years ago

1.0.28

7 years ago

1.0.27

7 years ago

1.0.26

7 years ago

1.0.25

7 years ago

1.0.24

7 years ago

1.0.23

7 years ago

1.0.22

7 years ago

1.0.21

7 years ago

1.0.20

7 years ago

1.0.19

7 years ago

1.0.18

7 years ago

1.0.17

7 years ago

1.0.16

7 years ago

1.0.15

7 years ago

1.0.14

7 years ago

1.0.13

7 years ago

1.0.12

7 years ago

1.0.11

7 years ago

1.0.10

7 years ago

1.0.9

7 years ago

1.0.8

7 years ago

1.0.7

7 years ago

1.0.6

7 years ago

1.0.5

7 years ago

1.0.4

7 years ago

1.0.3

7 years ago

1.0.2

7 years ago

1.0.1

7 years ago

0.10.11

7 years ago

0.10.10

7 years ago

0.10.9

7 years ago

0.10.8

7 years ago

0.10.7

7 years ago

0.10.5

7 years ago

0.10.4

7 years ago

0.10.3

7 years ago

0.10.2

7 years ago

0.10.1

7 years ago

0.10.0

7 years ago

0.9.17

7 years ago

0.9.16

7 years ago

0.9.15

7 years ago

0.9.13

7 years ago

0.9.12

7 years ago

0.9.11

7 years ago

0.9.10

7 years ago

0.9.9

7 years ago

0.9.8

7 years ago

0.9.7

7 years ago

0.9.6

7 years ago

0.9.5

7 years ago

0.9.4

7 years ago

0.9.3

7 years ago

0.9.2

7 years ago

0.9.1

7 years ago

0.9.0

7 years ago

0.8.32

7 years ago

0.8.31

7 years ago

0.8.30

7 years ago

0.8.29

7 years ago

0.8.28

7 years ago

0.8.27

7 years ago

0.8.26

7 years ago

0.8.25

7 years ago

0.8.24

7 years ago

0.8.23

7 years ago

0.8.22

7 years ago

0.8.21

7 years ago

0.8.20

7 years ago

0.8.19

7 years ago

0.8.18

7 years ago

0.8.17

7 years ago

0.8.16

7 years ago

0.8.15

7 years ago

0.8.14

7 years ago

0.8.13

7 years ago

0.8.12

7 years ago

0.8.11

7 years ago

0.8.10

7 years ago

0.8.9

7 years ago

0.8.8

7 years ago

0.8.7

7 years ago

0.8.6

7 years ago

0.8.5

7 years ago

0.8.4

7 years ago

0.8.3

7 years ago

0.8.2

7 years ago

0.8.1

7 years ago

0.8.0

7 years ago

0.7.5

7 years ago

0.7.4

7 years ago

0.7.3

7 years ago

0.7.2

7 years ago

0.7.1

7 years ago

0.7.0

7 years ago

0.6.5

7 years ago

0.6.4

7 years ago

0.6.3

7 years ago

0.6.2

7 years ago

0.6.1

7 years ago

0.6.0

7 years ago

0.5.27

7 years ago

0.5.26

7 years ago

0.5.25

7 years ago

0.5.23

7 years ago

0.5.22

7 years ago

0.5.21

7 years ago

0.5.20

7 years ago

0.5.15

7 years ago

0.5.14

7 years ago

0.5.13

7 years ago

0.5.12

7 years ago

0.5.11

7 years ago

0.5.10

7 years ago

0.5.9

7 years ago

0.5.8

7 years ago

0.5.7

7 years ago

0.5.6

7 years ago

0.5.5

7 years ago

0.5.4

7 years ago

0.5.3

7 years ago

0.5.2

7 years ago

0.5.1

7 years ago

0.5.0

7 years ago

0.4.5

7 years ago

0.4.4

7 years ago

0.4.3

7 years ago

0.4.2

7 years ago

0.4.1

7 years ago

0.4.0

7 years ago

0.3.22

7 years ago

0.3.21

7 years ago

0.3.20

7 years ago

0.3.13

7 years ago

0.3.12

7 years ago

0.3.11

7 years ago

0.3.10

7 years ago

0.3.9

7 years ago

0.3.8

7 years ago

0.3.7

7 years ago

0.3.6

7 years ago

0.3.5

7 years ago

0.3.4

7 years ago

0.3.3

7 years ago

0.3.2

7 years ago

0.3.1

7 years ago

0.3.0

8 years ago

0.2.35

8 years ago

0.2.34

8 years ago

0.2.33

8 years ago

0.2.32

8 years ago

0.2.31

8 years ago

0.2.30

8 years ago

0.2.29

8 years ago

0.2.28

8 years ago

0.2.27

8 years ago

0.2.26

8 years ago

0.2.25

8 years ago

0.2.24

8 years ago

0.2.23

8 years ago

0.2.22

8 years ago

0.2.21

8 years ago

0.2.20

8 years ago

0.2.19

8 years ago

0.2.18

8 years ago

0.2.17

8 years ago

0.2.16

8 years ago

0.2.15

8 years ago

0.2.14

8 years ago

0.2.13

8 years ago

0.2.12

8 years ago

0.2.11

8 years ago

0.2.10

8 years ago

0.2.9

8 years ago

0.2.8

8 years ago

0.2.7

8 years ago

0.2.6

8 years ago

0.2.5

8 years ago

0.2.4

8 years ago

0.2.3

8 years ago

0.2.2

8 years ago

0.2.1

8 years ago

0.2.0

8 years ago

0.1.41

8 years ago

0.1.40

8 years ago

0.1.38

8 years ago

0.1.37

8 years ago

0.1.36

8 years ago

0.1.35

8 years ago

0.1.34

8 years ago

0.1.33

8 years ago

0.1.32

8 years ago

0.1.31

8 years ago

0.1.30

8 years ago

1.0.0

8 years ago

0.1.25

8 years ago

0.1.24

8 years ago

0.1.23

8 years ago

0.1.22

8 years ago

0.1.21

8 years ago

0.1.20

8 years ago

0.1.19

8 years ago

0.1.18

8 years ago

0.1.17

8 years ago

0.1.16

8 years ago

0.1.15

8 years ago

0.1.12

8 years ago

0.1.10

8 years ago

0.1.6

8 years ago

0.1.5

8 years ago

0.1.4

8 years ago

0.1.3

8 years ago

0.1.2

8 years ago

0.1.1

8 years ago

0.1.0

8 years ago