Created
March 21, 2015 01:00
-
-
Save 100ideas/4512f3d5b7997a719d7a to your computer and use it in GitHub Desktop.
learning how to use destructuring assignment for function parameters and how to express flow control elegantly
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
# not sure if it works yet... | |
tweetLocation2 = ({place: {name: placename}, coordinates: {coordinates: coords}, user: {location: loc}}) -> | |
geocode = (coordinates) -> | |
(coordinates? console.log "replace this function w/ a call to twitter reverse geocode api - #{coordinates}") ? false | |
placename ? (geocode coords) ? loc ? "somewhere" | |
# works | |
# remember tweet coords are long, lat | |
# https://dev.twitter.com/overview/api/tweets#obj-coordinates | |
# https://dev.twitter.com/rest/reference/get/geo/reverse_geocode | |
tweetLocation = ({place: {name: placename}, coordinates: {coordinates: coords}, user: {location: loc}}) -> | |
geocode = (coordinates) -> | |
if coordinates? | |
console.log "calling twitter reverse geocode api on #{coordinates}" | |
coordinates # insert call to twitter revgeo api | |
else | |
false | |
if placename? | |
placename | |
else if coords? | |
geocode coords | |
else if loc? | |
loc | |
else | |
"somewhere" | |
### tweet JSON | |
{ created_at: 'Thu Mar 19 07:46:43 +0000 2015', | |
id: 578462588721233900, | |
id_str: '578462588721233920', | |
text: '“Ministerial changes affect policy consistency at Sports Ministry”- Dr. Aggrey Darko : \nPolitical Science lect... http://t.co/FcbTNlve1Z', | |
source: '<a href="http://twitterfeed.com" rel="nofollow">twitterfeed</a>', | |
truncated: false, | |
in_reply_to_status_id: null, | |
in_reply_to_status_id_str: null, | |
in_reply_to_user_id: null, | |
in_reply_to_user_id_str: null, | |
in_reply_to_screen_name: null, | |
user: | |
{ id: 1129756027, | |
id_str: '1129756027', | |
name: 'Gh Jokes&News L.O.L', | |
screen_name: 'GhJokes_News', | |
location: 'ACCRA GHANA', | |
url: null, | |
description: '||GH|| GET Funny Jokes & NEW\'s Updates on ::||Celebrities Lifestyle||Latest Music||Upcoming Events||World News||Upcoming Artiste||Videos|| Hash Tag us #GHeN', | |
protected: false, | |
verified: false, | |
followers_count: 366, | |
friends_count: 9, | |
listed_count: 24, | |
favourites_count: 0, | |
statuses_count: 86507, | |
created_at: 'Tue Jan 29 01:46:25 +0000 2013', | |
utc_offset: null, | |
time_zone: null, | |
geo_enabled: true, | |
lang: 'en', | |
contributors_enabled: false, | |
is_translator: false, | |
profile_background_color: 'C0DEED', | |
profile_background_image_url: 'http://abs.twimg.com/images/themes/theme1/bg.png', | |
profile_background_image_url_https: 'https://abs.twimg.com/images/themes/theme1/bg.png', | |
profile_background_tile: false, | |
profile_link_color: '0084B4', | |
profile_sidebar_border_color: 'C0DEED', | |
profile_sidebar_fill_color: 'DDEEF6', | |
profile_text_color: '333333', | |
profile_use_background_image: true, | |
profile_image_url: 'http://pbs.twimg.com/profile_images/3177336412/763cb6d61bbcef1d95a5d0029cef90b6_normal.jpeg', | |
profile_image_url_https: 'https://pbs.twimg.com/profile_images/3177336412/763cb6d61bbcef1d95a5d0029cef90b6_normal.jpeg', | |
profile_banner_url: 'https://pbs.twimg.com/profile_banners/1129756027/1390097298', | |
default_profile: true, | |
default_profile_image: false, | |
following: null, | |
follow_request_sent: null, | |
notifications: null }, | |
geo: null, | |
coordinates: null, | |
place: null, | |
contributors: null, | |
retweet_count: 0, | |
favorite_count: 0, | |
entities: | |
{ hashtags: [], | |
trends: [], | |
urls: [ [Object] ], | |
user_mentions: [], | |
symbols: [] }, | |
favorited: false, | |
retweeted: false, | |
possibly_sensitive: false, | |
filter_level: 'low', | |
lang: 'en', | |
timestamp_ms: '1426751203123' } | |
### |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment