Last active
December 17, 2015 23:39
-
-
Save to4iki/5690963 to your computer and use it in GitHub Desktop.
twitter-search
This file contains 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
define ['jquery'], ($) -> | |
### | |
Class | |
### | |
class Qiita | |
_end_point = 'https://qiita.com/api/v1/' | |
constructor: () -> | |
@item = {} | |
@loading = false | |
request: (url, params, callback, type = 'GET') -> | |
$.ajax( | |
url: _end_point + url, | |
data: params | |
dataType: 'json' | |
type: type | |
).done((data) -> | |
console.log 'success' | |
).fail (data) -> | |
console.log 'error' | |
# public | |
Qiita: Qiita |
This file contains 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
$.ajax({ | |
url: 'https://qiita.com/api/v1/tags/QiitaAPI/items', | |
dataType: 'json' | |
}).done(function(data) { | |
console.log(data); | |
var title = _.map(data, function(kiji) { | |
return kiji.body; | |
}); | |
console.log(title); | |
}).fail(function(data) { | |
console.log('error'); | |
}); |
This file contains 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
<!DOCTYPE html> | |
<html lang="ja"> | |
<head> | |
<meta charset="UTF-8"> | |
<title>ajax</title> | |
<script src="http://code.jquery.com/jquery-2.0.0.min.js"></script> | |
<!--<script src="//ajax.googleapis.com/ajax/libs/jquery/1.8.2/jquery.min.js"></script>--> | |
</head> | |
<body> | |
<input type="submit" id="button" value="search" /> | |
<div id="tweets"> | |
</div> | |
<script> | |
/** | |
* [jQuery モダンAjaxな書き方を目指して 〜deferredを使ったAJAX〜 - Hack Your Design!](http://blog.toshimaru.net/jquery-ajaxdeferredajax/) | |
*/ | |
$(function() { | |
var Twitter = { | |
search: function(query) { | |
var defer = $.Deferred(); | |
$.ajax({ | |
url: "http://search.twitter.com/search.json", | |
data: { | |
q: query, | |
rpp: 50 | |
}, | |
dataType: 'jsonp', | |
success: defer.resolve, | |
error: defer.reject | |
}); | |
return defer.promise(); | |
} | |
}; | |
$('#button').on('click', function() { | |
Twitter.search('bamtsk').done(function(data) { | |
console.log(data); | |
$(data.results).each(function(k, v) { | |
$('#tweets').append(v.text + '<br/>'); | |
}); | |
}); | |
}); | |
}); | |
</script> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment