Quotes help make search much faster. Example: "Practice Makes Perfect"

Showing posts with label APIs. Show all posts
Showing posts with label APIs. Show all posts

Sunday, January 13, 2013

Codecademy Sample Solution: Parsing XML


#sample solution for Code tab

require "rexml/document"

file = File.open("pets.txt")
doc = REXML::Document.new file
file.close

doc.elements.each("pets/pet/name") do |element|
  puts element
end

puts ''

doc.elements.each("pets/pet/species") do |element|
  puts element
end

Codecademy Sample Solution: HTTP Status Codes


require 'open-uri'

placekitten = open('http://placekitten.com/')

# Add your code below!
puts(placekitten.status())

Codecademy Sample Solution: Making a Request


require 'open-uri'

# Open http://placekitten.com/ for reading on line 4!
kittens = open('http://placekitten.com')
body = kittens.read[559, 441]

# Add your puts statement below!
puts(body)

Codecademy Sample Solution: Adding data to your Parse Object

//sample solution to my_parse_app.js

$(window).on("html_loaded", function(e) {
    $(".submit_button").click(function(e) {
     
        // This creates our new Post object
        var Post = Parse.Object.extend("Post");
        var myPost = new Post();
     
        // 1. Let's add some data for the key 'text'
        myPost.set("text", "any string");
     
    });
});

Codecademy Sample Solution: XML & JSON


// What data format is shown below? Set answer
// equal to 'XML' for XML and 'JSON' for JSON.

// {
//   "Cartoon Foxes": {
//     {
//       "Name": "Fox Tall",
//       "Job": "Bein' tall"
//     },
//     {
//       "Name": "Fox Small",
//       "Job": "Bein' small"
//     }
//   }
// }

var answer = "JSON";

Codecademy Sample Solution: Authentication and API Keys


// What's an API key?

// A: An alphanumeric string used to identify you to an API
// B: An OAuth token
// C: An All-Purpose Internet key
// D: The tool used to unlock an API gate

var answer = "A";

Codecademy Sample Solution: Requests


// Add your code below this line!
var xhr = new XMLHttpRequest();
xhr.open("GET","http://www.codecademy.com/",false);
xhr.send();

// Add your code above this line!

console.log(xhr.status);
console.log(xhr.statusText);

Codecademy Sample Solution: REST Constraints and Requirements


// 1. HTTP is a protocol that connects clients and ______.
var answer1 = "servers";

// 2. The four HTTP methods are GET, POST, ___, and DELETE.
var answer2 = "PUT";

// 3. A ___ error means the server goofed up. (200, 300, 400, or 500)
var answer3 = "500";

Saturday, January 12, 2013

Codecademy Sample Solution: HTTP Status Codes


var xhr = new XMLHttpRequest();
xhr.open("GET", "http://www.codecademy.com/doesnt_exist", false);
xhr.send();
// Add your code below!
console.log(xhr.status);

Codecademy Sample Solution: Endpoints


// What are the four commonly used HTTP methods ("verbs")?

// A: FIND, SEND, UPDATE, REMOVE
// B: CREATE, READ, UPDATE, DELETE
// C: GET, SEND, PUT, DELETE
// D: GET, POST, PUT, DELETE

var answer = "D";

Codecademy Sample Solution: Making a Request


var xhr = new XMLHttpRequest();
xhr.open("GET", "http://www.codecademy.com/", false);
// Add your code below!
xhr.send();
console.log(xhr.status);
console.log(xhr.statusText);

Codecademy Sample Solution: No REST for the Wicked


// You (the client) make an HTTP request. What sends the response?

// A: The Internet
// B: The World Wide Web
// C: The server
// D: The waiter

var answer = "C";

This is an example of scrolling text using Javascript.

Popular Posts