Handling returning error

const imgRequest = new XMLHttpRequest();
imgRequest.onload = addImage;
imgRequest.open('GET', 'https://api.unsplash.com/photos?page=1&query=${searchedForText}');
imgRequest.setRequestHeader('Authorization', 'Client-ID <client-id-here>');
imgRequest.send();
function addImage(){
	const data = JSON.parse(this.responseText);
	const firstImage = datat.results[0];

	responseContainer.insertAdjacementHTML('afterbegin', <figure>
		<img src="${firstImage.urls.small}" alt="${searchedForText}">
		<figcaption>${searchedForText} by ${firstImage.user.name}</figcaption>
		</figure>
		);
}

jQuery ajax()

$.ajax(<url-to-fetch>,<a-configuration-object>);
$.ajax(<just a configuration object>);

var settings = {
	frosting: 'buttercream',
	colors: ['orange', 'blue'],
	layers: 2,
	isRound: true
};

const myDeliciousCake = MakeCake({
	frosting: 'buttercream',
	colors: ['orange', 'blue'],
	layers: 2,
	isRound: true
});

$.ajax({
	url: 'http://swapi.co/api/people/1/'
});
function handleResponse(data){
	console.log('the ajax request has finished!');
	console.log(data);
}

$.ajax({
	url: 'http://swapi.co/api/people/1/'
}).done(handleResponse);

A request

function handleSuccess(){
	const data = JSON.parse(this.responseText);
	const.log(data);
}
asyncRequestObject.onload = handleSuccess;

unsplash for developer
https://unsplash.com/developers
create an application
https://unsplash.com/oauth/applications

The New York Times for developers
https://developer.nytimes.com/

function addImage(){}
const searchedForText = 'hippos';
const unsplashRequest = new XMLHttpRequest();

unsplashRequest.open('GET', 'https://api.unsplash.com/search/photos?page=1&query=${searchedForText}');
unsplashRequest.onload = addImage;

unsplashRequest.send()
function addArticles(){}
const articleRequest = new XMLHttpRequest();
articleRequest.onload = addArticles;
articleRequest.open('GET', 'http://api.nytimes.com/svc/search/v2/articlesearch.json?q=${searchedForText}&api-key=<API-key-goes-here>');
articleRequest.send();

APIs

What’s an API?
The acronym “API” stands for:

Application
Programming
Interface

google API
https://developers.google.com/apis-explorer/#p/
ProgrammableWeb
https://www.programmableweb.com/apis/directory

const asyncRequestObject = new XMLHttpRequest();
asyncRequestObject.open('GET', 'https://unsplash.com');
const req = new XMLHttpRequest();
undefined
req.open('GET', 'https://www.google.com/');
undefined
VM453:1 [Deprecation] Synchronous XMLHttpRequest on the main thread is deprecated because of its detrimental effects to the end user's experience. For more help, check https://xhr.spec.whatwg.org/.
function handleSuccess(){
	console.log(this.responseText);
}
asyncRequestObject.onload = handleSuccess;

function handleError(){
	// in the function, the 'this' value is the XHR object
	console.log('An error occured');
}
asyncRequestOjbect.onerror = handleError;
function handleSuccess (){
	console.log(this.responseText);
}
function handleError(){
	console.log('An error occurred')
}

const asyncRequestObject = new XMLHttpRequest();

asyncRequestObject.open('GET', 'https://unsplash.com');
asyncRequestObject.onload = handleSuccess;
asyncRequestOjbect.onerror = handleError;

asyncRequestObject.send();

Ajax with XHR

GET Request: An internet request for data. Sent from a client to a server.
Response: A server’s response to a request. Sent from a server to a client. A response to a GET request will usually include data that the client needs to load the page’s content.

-Ajax Definition
Asynchronous
JavaScript
And
XML
request

Get request and response
Data: XML, JSON, HTML

xhr(XMLHttpRequest (XHR)) is Asynchronous

Technical Documentation

OSS, JOB
documentation for you, coworkers, or your users!

README
app, bin, config, db, lib, log, public, test, vendor/assets, gitignore, README, Gemfile, Gemfile.lock

What happens if I don’t choose a license?
It’s super important to choose License.

Choose an open source license
which of the following best describes your situation?
https://choosealicense.com/

-add to README
known bugs
frequently asked questions
table of contents

Readable READMEs with Markdown
-> easily readable

Markdown is a light markup language often used for READMEs. It is fairly straightforward, and much of the syntax is intuitive.

#Here is your task
‘code’
**Here**
_there_

Markdown files should be saved with a .md extension.

<h1>My Fabulous Recipe</h1>
<p>This recipe for <strong>cereal and milk</strong> has been passed down my family for months.</p>
<h2>Ingredients</h2>
<ul>
	<li>Cereal (you can find cool cereals <a href="www.example.com/coolcereals">here</a>)</li>
	<li>Milk</li>
</ul>

<h2>Directions</h2>
<p>If I were writing these out as <em>code</em>, it might look something like this:</p>

<pre><code>if bowl is empty:
	add cereal
	if bowl only has cereal in it:
	add milk
</code></pre>
</body>

Breakpoints and Visual Tools

override func viewDidLoad(){
	super.viewDidLoad()
	let singleTapRecognizer = UITapGestureRecognizer
	(target: self, action: "handleSingleTap:")
	view.addGestureRecognizer(singleTapRecognizer)
}
@IBAction func popToMasterView(){
	self.navigationController?.popToRootViewControllerAnimated(true)
}

LLDB and Breakpoint Actions

override func motionEnded(motion: UIEventSubtype,
	withEvent event: UIEvent){
		if motion == .MotionShake
		{
			disperseBugsAnimation()
		}
	}
	func handleSignleTap(recognizer:
		UITapGestureRecognizer){
		addBugToView()
		addButToView()
		}

thread backtrace all

Apple’s LLDB Quick Start Guide
https://developer.apple.com/library/content/documentation/IDEs/Conceptual/gdb_to_lldb_transition_guide/document/lldb-command-examples.html#//apple_ref/doc/uid/TP40012917-CH3-SW1

The Debug Bar

func addBugToView(){
if bugs.count < maxBugs { let newBug = bugFactory.createBug() bug.append(newBug) moveBugsAnimation() } } func emptyBugsFromView(){ for bug in self.bugs { bug.removeFromSuperview() } self.bugs.removeAll(keepCapacity: true) } [/code] Getting Help with Bugs Stack Overflow
-be specific as possible
-provides steps leading to the problems
– can use text, code, images, gifts…

No More Crash!

Pay attention to any information provided when the application crashes!

@IBAction func dismissSettingsTouched(sender:
	AnyObject){
		self.dismissViewControllerAnimated(true, completion: nil)
	}

@IBAction func bugTypeSelected(sender: UIButton){
	bugFactory.currentBugType = BugFactory.BugType
	(rawValue: sender.currentTitle!.toInt()!)!
	self.dismissViewControllerAnimated(true, completion: nil)
}
println("starting bug work")
for bug in bugs {
	println("done with \(bug)")
}
println("ending bug work")
let log = XCGLogger()
log.setup(logLevel: .Debug, showLineNumbers: true)
log.debug("starting bug work")
for bug in bugs {
	log.verbose("done with \(bug)")
}
log.debug("ending bug work")
import UIKit
class BreakpointBugViewController: UIViewController {
	// MARK: Properties

	let bugFactory = BugFactory.sharedInstance()
	let maxBugs = 0
	let moveDuration = 3.0
	let disperseDuration = 1.0

	var bugs = [UIImageView]()
}
extension BreakpointBugViewController {
	override func canBecomeFirstResponder() ->
		Bool { return true }
	override func motionEnded(motion: UIEventSubtype, withEvent evnt: UIEvent)
	{
		if motion == .MotionShake {
			disperseBugsAnimation()
		}
	}
	func handleSingleTap(recognizer:
		UITapGestureRecognizer){
		addBugToView()
		addBugToView()
		}
}