#1
  1. A Change of Season
    Devshed Loyal (3000 - 3499 posts)

    Join Date
    Mar 2004
    Location
    Next Door
    Posts
    3,247
    Rep Power
    220

    Integration with PitchPrint


    Hello I am very surprised. Trying to connect to PitchPrint api and their code has major errors. This is the sample of code they give on Github:


    It has synthx error on line 31 and the libraries don't load.I get access denied for https://s3.amazonaws.com/pitchprint.rsc.

    Is it their buggy system or am I doing something wrong?

    Thanks
    Code:
    <html>
    	<title>PitchPrint Sample SDK</title>
    	<head>
    		
    		<script src="https://code.jquery.com/jquery-3.1.1.min.js"></script>
    		<script src="https://dta8vnpq1ae34.cloudfront.net/app/83/js/app.js"></script>
    
    		<script type="text/javascript">
    			
    			var cdnBase = 'https://dta8vnpq1ae34.cloudfront.net/',			//CDN path to resources
    				rscBase = 'https://s3.amazonaws.com/pitchprint.rsc/',		//Same path as above without the CDN caching.. good for loading design images that will change after customer edits.
    				apiBase = 'https://pitchprint.net/api/front/',				//Application API calls go here.
    				buildPath = 'app/83/',
    				
    				langCode = 'en',											//Language code
    				apiKey = 'f80b84b4eb5cc81a140cb90f52e824f6',				//Sample api key. You can generate one from https://pitchprint.net/admin/domains
    				
    				designId = 'ab73e4cc5b80b05facfca35cca40d318',				//Sample designId. After creating a design (https://pitchprint.net/admin/designs), you can get the ID from the category drop down (more options) > Export design list
    				userId = 'guest',											//This is useful for tracking who created what project against your apiKey
    				mode = 'new',												//"new" or "edit".. obvious
    				version = '8.3.0',
    				lang, designer, projectSource, previews, numPages, projectId, designerShown, config, validationData;
    				
    			function validate() {
    				$.ajax( {
    					url: apiBase + 'validate',
    					type: 'POST',
    					dataType: 'json',
    					xhrFields: { withCredentials: true }
    					data: {
    						userId: userId,
    						apiKey: apiKey,
    						version: version,
    						config: true
    					},
    					success: function(_data) {
    						if (!_data.error) {
    							validationData = _data.validation;
    							config = _data.config;
    							loadLanguage();
    						} else {
    							alert(_data);
    						}
    					},
    					error: function(_e) {
    						console.log(_e);
    					}
    				} );
    			}
    			
    			/** Load the language file as a json data **/
    			function loadLanguage () {
    				$.ajax( {
    					type: 'GET',
    					dataType: 'json',
    					url: cdnBase + buildPath + 'lang/' + (langCode || 'en'),
    					cache: true,
    					success: function(_r) {
    						lang = _r;
    						//Language data loaded, let's initialize the editor next..
    						initEditor();
    					}
    				} );
    			}
    			
    			/** This instantiates the editor object and we store it in the variable designer. **/
    			function initEditor() {
    				designer = new pprint.designer({
    					apiKey: apiKey,
    					apiBase: apiBase,
    					cdnBase: cdnBase,
    					rscBase: rscBase,
    					buildPath: buildPath,
    					parentDiv: '#pp_inline_div',
    					mode: mode,
    					config: config,
    					lang: lang,
    					langCode: langCode,
    					userId: userId,
    					product: { title: 'Sample Card', id: '' },
    					designId: designId,
    					validationData: validationData,
    					autoInitialize: true,
    					isUserproject: false,
    					isAdmin: false,
    					
    					onLibReady: onLibReady,
    					autoShow: false,
    					onSave: onSave,
    					onShown: onShown
    				});
    			}
    			
    			function onShown() {
    				designerShown = true;
    			}
    			
    			function onLibReady() {
    				$('#launch_btn').show();
    				$('#pp_loader_div').hide();
    			}
    			
    			function onSave(_val) {
    				mode = 'edit';
    				projectSource = _val.source;
    				projectId = _val.projectId;
    				numPages = _val.numPages;
    				previews = _val.previews;
    				
    				//Let's show previews
    				var _prevDiv = $('#pp_preview_div');
    				_prevDiv.empty();
    				
    				for (var i=0; i < numPages; i++) {
    					_prevDiv.append('<img style="border: 1px solid #eee; margin: 10px" src="' + rscBase + 'images/previews/' + projectId + '_' + (i+1) + '.jpg" >');		//Please note, previews are stored based on design page number, thus (i+1)... page 1, page 2...
    				}
    				
    				designer.close(true);	//Setting this to true ensures the designer is active but with previews shown.
    				
    				//If you pass in false, you will need to collapse the editor or remove it from DOM.
    				
    				//Now show the launch button again, change the text to edit
    				$('#launch_btn').show().text('Edit Design');
    			}
    			
    			function showDesigner() {
    				/*Here, we check if the designer has not been shown before, then we animage the container div's height, which was initially 0
    					If designer has been shown before, we just call up the resume function on the designer..
    				*/
    				if (!designerShown) {
    					TweenLite.to($('#pp_inline_div'), 0.6, { 'height': ($(window).height() - 150), ease: Power2.easeOut, onComplete: function() {
    						designer.show();
    						$('#launch_btn').hide();
    					} } );
    				} else {
    					designer.resume();
    				}
    			}
    			
    			$(function() {
    				$('#launch_btn').hide();
    				validate();
    			})
    			
    			
    
    		</script>
    	</head>
    	<body>
    		<div id="pp_inline_div" style="width: 1200px; height: 0; margin: 0 auto; position: relative; overflow: hidden;"></div>
    		<div id="pp_loader_div"><img src="//dta8vnpq1ae34.cloudfront.net/images/loaders/anim-ring.svg" ></div>
    		<button id="launch_btn" onclick="showDesigner();" >Launch Designer</button>
    		<div id="pp_preview_div"> </div>
    	</body>
    </html>
  2. #2
  3. Banned (not really)
    Devshed Supreme Being (6500+ posts)

    Join Date
    Dec 1999
    Location
    Caro, Michigan
    Posts
    14,815
    Rep Power
    4554
    What does this have to do with PHP?
    -- Cigars, whiskey and wild, wild women. --
  4. #3
  5. Maddening Moderator
    Devshed Supreme Being (6500+ posts)

    Join Date
    Mar 2007
    Location
    Washington, USA
    Posts
    16,453
    Rep Power
    9645
    Did you get an API key? How about the design ID thing?

    And you know you're not supposed to access /pitchprint.rsc directly, right? They will put files somewhere in there under /pitchprint.psc/images/previews/*_*.jpg that you access after saving the whatever.

    Originally Posted by Sepodati
    What does this have to do with PHP?
    Absolutely nothing. Despite years of warnings about it, Tea has a bad habit of posting everything in PHP regardless whether PHP is part of the question.
  6. #4
  7. A Change of Season
    Devshed Loyal (3000 - 3499 posts)

    Join Date
    Mar 2004
    Location
    Next Door
    Posts
    3,247
    Rep Power
    220
    Originally Posted by requinix
    Did you get an API key? How about the design ID thing?

    And you know you're not supposed to access /pitchprint.rsc directly, right? They will put files somewhere in there under /pitchprint.psc/images/previews/*_*.jpg that you access after saving the whatever.


    Absolutely nothing. Despite years of warnings about it, Tea has a bad habit of posting everything in PHP regardless whether PHP is part of the question.
    Sorry about posting in PHP. I'll be more careful.

    This is their code sample. Isn't their sample supposed to work as a demo? This is what is says.

    Their code has synthax error. What's going on?
  8. #5
  9. Maddening Moderator
    Devshed Supreme Being (6500+ posts)

    Join Date
    Mar 2007
    Location
    Washington, USA
    Posts
    16,453
    Rep Power
    9645
    As you noticed the code is syntactically invalid, so you have to take what they say on that page with a grain of salt.
  10. #6
  11. Wiser? Not exactly.
    Devshed God 2nd Plane (6000 - 6499 posts)

    Join Date
    May 2001
    Location
    Bonita Springs, FL
    Posts
    6,123
    Rep Power
    4103
    Originally Posted by English Breakfast Tea
    This is their code sample. Isn't their sample supposed to work as a demo? This is what is says.
    In theory everyone's examples should work. In practice they may not. You can see from the commit history someone added the xhrFields parameter and forgot to add a comma at the end. Since it was a relatively minor change they probably just added it and committed without testing. I've done that numerous times.

    Many times sample code isn't necessarily guaranteed to work, it's just there as a demonstration to help you get familiar with an API or whatever. If it works then great. If it doesn't then you can usually get the general idea still (though i've seen terrible example code in the past). You could bring up the fact that it doesn't work with their support but ultimately you just fix the problem and move on if it's possible to do so.

    I was recently trying out a library for mobile apps and their demo's didn't work due to what appeared to be a missing file on their CDN. I sent a short message to their support to inform them and they apologized for the inconvenience and had it fixed in a few hours. In the mean time I was able to keep working because a little time looking around at their other documentation allowed me to find the proper URL to the missing file. It had just been renamed on the server but the URL in the demo hadn't been updated.
    Recycle your old CD's



    If I helped you out, show some love with some reputation, or tip with Bitcoins to 1N645HfYf63UbcvxajLKiSKpYHAq2Zxud
  12. #7
  13. A Change of Season
    Devshed Loyal (3000 - 3499 posts)

    Join Date
    Mar 2004
    Location
    Next Door
    Posts
    3,247
    Rep Power
    220
    I am gonna contact support and see what they say.
    Last edited by English Breakfast Tea; July 14th, 2017 at 03:16 AM.

IMN logo majestic logo threadwatch logo seochat tools logo