This repository was archived by the owner on Mar 16, 2025. It is now read-only.
-
Couldn't load subscription status.
- Fork 41
Matt's mashup #44
Open
afeld
wants to merge
6
commits into
advanced-js:gh-pages
Choose a base branch
from
iamakimmer:gh-pages
base: gh-pages
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Matt's mashup #44
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,44 +1,10 @@ | ||
| # Mashup project | ||
|
|
||
| This project is open-ended! Requirements: | ||
| This app pulls the latest release of an album and then looks for images on instagram that are tagged with the album name | ||
|
|
||
| * Build a site that uses data from at least one external API in an interesting, interactive way. | ||
| * Replace this README with a description of the project. | ||
| * You are welcome to use any 3rd-party libraries/frameworks – just load them from a CDN (e.g. [cdnjs](http://cdnjs.com)), or put them under the [`vendor/`](vendor/) folder. | ||
| * **Do not commit the `client_secret` (or anything else from an API that says "token" or "secret")**, as a hacker could use this to make requests on behalf of you. | ||
| APIs Used: | ||
|
|
||
| The JS code should be **non-trivial**. That being said... start simple! (Just get the data to show up on the page.) No server-side coding is required, but feel free to create a backend in whatever language if you like, if you need one. | ||
| Spotify: https://developer.spotify.com/ | ||
| Instgram: https://www.instagram.com/developer/endpoints/tags/ | ||
|
|
||
| * [AJAX demos](https://github.com/advanced-js/deck/tree/gh-pages/demos/ajax) | ||
| * [inspiration?](http://www.programmableweb.com/mashups) | ||
|
|
||
| ## Finding an API | ||
|
|
||
| A couple things to look for in an API (or at least the endpoints you're using) for this project: | ||
|
|
||
| * Make sure it doesn't require authentication/authorization (e.g. [OAuth](http://oauth.net/)) - at least for the endpoints that you want to use - so that you don't need a server. | ||
| * If the API doesn't support cross-domain requests (JSONP or CORS), you will need to use [JSONProxy](https://jsonp.afeld.me/). | ||
|
|
||
| Here is a [list of API suggestions](https://gist.github.com/afeld/4952991). | ||
|
|
||
| ## V1 | ||
|
|
||
| Get the data to show up on the page. | ||
|
|
||
| ## V2 | ||
|
|
||
| First pass. Get your main feature working in the simplest way possible. | ||
|
|
||
| ## V3 | ||
|
|
||
| Iterate! | ||
|
|
||
| * Refactor | ||
| * Add a new feature | ||
|
|
||
| ## Bonus points | ||
|
|
||
| * build in an object-oriented way | ||
| * automated tests | ||
| * [Sinon.js fakeServer](http://sinonjs.org/docs/#fakeServer) may be helpful | ||
| * fancy interactivity/animations |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,59 @@ | ||
|
|
||
| var $token = $('#token'); | ||
| var $album = $('#album'); | ||
| var $albumlist = $('#albumlist'); | ||
| var $instagramDetails = $('#instagramdetails'); | ||
|
|
||
| function findTagFromInstagram(tag) { | ||
| console.log('tag', tag); | ||
| $.ajax({ | ||
| url: 'https://api.instagram.com/v1/tags/' + tag + '/media/recent?client_id=ce95cb4e56c146c994457b48a839f6a8', | ||
| dataType: 'jsonp', | ||
| success: function(result) { | ||
| $instagramDetails.html(''); | ||
| for (var i = 0; i < result.data.length; i++) { | ||
| var url = result.data[i].images.thumbnail.url; | ||
| $instagramDetails.append('<img src="' + url + '"/>'); | ||
| } | ||
| } | ||
| }); | ||
| }; | ||
|
|
||
|
|
||
| $('#submit').on('click', function() { | ||
| $.ajax({ | ||
| url: "https://api.spotify.com/v1/browse/new-releases", | ||
| dataType: 'json', | ||
| data: { | ||
| country: 'US', | ||
| limit: 10 | ||
| }, | ||
| success: function(data, status) { | ||
| $album.html(''); | ||
| $albumlist.html(''); | ||
|
|
||
| data.albums.items.forEach(function(album) { | ||
| var name = album.name.replace(/[^A-Z0-9]/ig, ''); | ||
| var $imageCover = $('<img class="albumcover" data-name="' + name + '" data-uri="' + album.uri + '" width="100" height="100" src="' + album.images[0].url + '"/>'); | ||
| $albumlist.append($imageCover); | ||
| $imageCover.on('click', function() { | ||
| var image = $(this); | ||
| var uri = image.data('uri'); | ||
| var name = image.data('name'); | ||
| var iframe = '<iframe class="spotifylink" src="https://embed.spotify.com/?uri=' + uri + '&" width="300" height="380" frameborder="0" allowtransparency="true"></iframe>'; | ||
| $album.html(iframe); | ||
| var albumName = name; | ||
| findTagFromInstagram(albumName); | ||
| }); | ||
| }); | ||
|
|
||
|
|
||
| }, | ||
| error: function(data) { | ||
| alert(data.responseJSON.error.message); | ||
| }, | ||
| beforeSend: function(xhr, settings) { | ||
| xhr.setRequestHeader('Authorization', 'Bearer ' + $token.val()); | ||
| } | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Just FYI that you can also pass in a |
||
| }); | ||
| }); | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,19 @@ | ||
| #album { | ||
| width: 300px; | ||
| height: 380px; | ||
| background-color: #cecece; | ||
| } | ||
|
|
||
| #instagramdetails { | ||
| background-color: #cecece; | ||
| width: 750px; | ||
| } | ||
|
|
||
| .wrapper { | ||
| display: flex; | ||
| flex-direction: row; | ||
| } | ||
|
|
||
| .albumcover { | ||
| cursor: pointer; | ||
| } |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As mentioned in class, there's a lot of nesting here, which makes the code difficult to follow...how could you make that more clear?