Skip to content
This repository has been archived by the owner on Sep 5, 2020. It is now read-only.

Commit

Permalink
Updated API calls with new params
Browse files Browse the repository at this point in the history
Closes #24 & #25
Partially addresses #23
  • Loading branch information
thunsaker committed Sep 7, 2014
1 parent 278eacf commit 2be70d1
Show file tree
Hide file tree
Showing 7 changed files with 110 additions and 67 deletions.
102 changes: 49 additions & 53 deletions appinfo.json
Original file line number Diff line number Diff line change
@@ -1,94 +1,90 @@
{
"versionLabel": "1.5.2",
"uuid": "1cceab0a-8dc1-4641-b7b6-5ea9c827dd66",
"appKeys": {
"address": 5,
"error": 11,
"facebook": 10,
"id": 3,
"index": 2,
"location": 1,
"name": 4,
"twitter": 9,
"error": 11,
"refresh": 6,
"private": 8,
"refresh": 6,
"result": 7,
"token": 0,
"facebook": 10,
"location": 1,
"address": 5,
"id": 3,
"result": 7
"twitter": 9
},
"longName": "Spoon 1.5.2",
"versionCode": 6,
"capabilities": [
"location",
"configurable"
],
"shortName": "Spoon",
"companyName": "Thomas Hunsaker",
"watchapp": {
"watchface": false
},
"longName": "Spoon 1.6",
"projectType": "native",
"resources": {
"media": [
{
"type": "png",
"name": "IMAGE_CHECK_MENU",
"file": "images/menu_dots.png"
"file": "images/checkbox_off.png",
"name": "IMAGE_CHECK_OFF",
"type": "png"
},
{
"type": "png",
"name": "IMAGE_CHECK_GRANDE",
"file": "images/check_black_big.png"
"file": "images/checkbox_on.png",
"name": "IMAGE_CHECK_ON",
"type": "png"
},
{
"type": "png",
"name": "IMAGE_CHECK_SHARE",
"file": "images/share_black.png"
"file": "images/spoon_long_med.png",
"name": "IMAGE_APP_LOGO_LONG",
"type": "png"
},
{
"type": "png",
"name": "IMAGE_CHECK_PRIVATE",
"file": "images/private_black.png"
"file": "images/check_black.png",
"name": "IMAGE_CHECK_OK",
"type": "png"
},
{
"type": "png",
"file": "images/foursquare_cog.png",
"name": "IMAGE_FOURSQUARE_COG",
"file": "images/foursquare_cog.png"
"type": "png"
},
{
"type": "png",
"name": "IMAGE_CHECK_OK",
"file": "images/check_black.png"
"file": "images/private_black.png",
"name": "IMAGE_CHECK_PRIVATE",
"type": "png"
},
{
"type": "png",
"name": "IMAGE_APP_LOGO_LONG",
"file": "images/spoon_long_med.png"
"file": "images/share_black.png",
"name": "IMAGE_CHECK_SHARE",
"type": "png"
},
{
"menuIcon": true,
"type": "png",
"name": "IMAGE_APP_ICON",
"file": "images/spoon_pixelated_24x28.png"
"file": "images/check_black_big.png",
"name": "IMAGE_CHECK_GRANDE",
"type": "png"
},
{
"type": "png",
"name": "IMAGE_CHECK_ON",
"file": "images/checkbox_on.png"
"file": "images/spoon_pixelated_24x28.png",
"menuIcon": true,
"name": "IMAGE_APP_ICON",
"type": "png"
},
{
"type": "png",
"name": "IMAGE_CHECK_OFF",
"file": "images/checkbox_off.png"
"file": "images/share_facebook.png",
"name": "IMAGE_SHARE_FACEBOOK",
"type": "png"
},
{
"type": "png",
"file": "images/share_twitter.png",
"name": "IMAGE_SHARE_TWITTER",
"file": "images/share_twitter.png"
},
{
"type": "png",
"name": "IMAGE_SHARE_FACEBOOK",
"file": "images/share_facebook.png"
"type": "png"
}
]
},
"shortName": "Spoon",
"uuid": "1cceab0a-8dc1-4641-b7b6-5ea9c827dd66",
"versionCode": 6,
"versionLabel": "1.6",
"watchapp": {
"watchface": false
}
}
Binary file removed resources/images/menu_dots.png
Binary file not shown.
Binary file modified resources/images/share_facebook.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified resources/images/share_twitter.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion src/checkin.c
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
void send_checkin_request(char venue_guid[128], char venue_name[512], int private, int twitter, int facebook) {
if(venue_guid) {
Tuplet guid_tuple = TupletCString(SPOON_ID, venue_guid);
Tuplet name_tuple = TupletCString(SPOON_NAME, venue_name);
Tuplet name_tuple = TupletCString(SPOON_NAME, venue_name);
Tuplet private_tuple = TupletInteger(SPOON_PRIVATE, private);
Tuplet twitter_tuple = TupletInteger(SPOON_TWITTER, twitter);
Tuplet facebook_tuple = TupletInteger(SPOON_FACEBOOK, facebook);
Expand Down
27 changes: 14 additions & 13 deletions src/js/pebble-js-app.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,12 @@
var maxAppMessageTries = 3;
var appMessageRetryTimeout = 3000;
var appMessageTimeout = 100;
var httpTimeout = 12000;
var appMessageQueue = [];
var venues = {};
var max_venues = 10;
var isNewList = false;
var api_date = '20140905';
var api_mode = '&m=swarm';

Pebble.addEventListener('ready',
function(e) {
Expand All @@ -32,7 +33,7 @@ Pebble.addEventListener('showConfiguration',
Pebble.addEventListener('webviewclosed',
function(e) {
var configuration = JSON.parse(e.response);
if(configuration.result == true) {
if(configuration.result) {
localStorage.foursquare_token = configuration.token;
notifyPebbleConnected(localStorage.foursquare_token.toString());
isNewList = true;
Expand All @@ -44,18 +45,18 @@ Pebble.addEventListener('webviewclosed',
);

function notifyPebbleConnected(token) {
var transactionId = Pebble.sendAppMessage( { 'token' : token },
Pebble.sendAppMessage( { 'token' : token },
function(e) {
console.log('Successfully delivered token message with transactionId=' + e.data.transactionId);
},
function(e) {
console.log('Unable to deliver token message with transactionId=' + e.data.transactionId + ' Error is: ' + e.error.message);
}
);
}
);
}

function notifyPebbleCheckinOutcome(result, message) {
var transactionId = Pebble.sendAppMessage( { 'result' : result == true ? 1 : 0, 'name' : message },
Pebble.sendAppMessage( { 'result' : result ? 1 : 0, 'name' : message },
function(e) {
console.log('Successfully delivered token message with transactionId=' + e.data.transactionId);
},
Expand All @@ -74,7 +75,7 @@ var success = function(position) {
var userToken = localStorage.foursquare_token.toString();
if(userToken) {
var req = new XMLHttpRequest();
var requestUrl = 'https://api.foursquare.com/v2/venues/search?oauth_token=' + userToken + '&v=20131111&ll=' + position.coords.latitude + ',' + position.coords.longitude + '&limit=' + max_venues;
var requestUrl = 'https://api.foursquare.com/v2/venues/search?oauth_token=' + userToken + '&v=' + api_date + '&ll=' + position.coords.latitude + ',' + position.coords.longitude + '&limit=' + max_venues + api_mode;
req.open('GET', requestUrl, true);
req.onload = function(e) {
if (req.readyState == 4) {
Expand All @@ -84,14 +85,14 @@ var success = function(position) {
var response = JSON.parse(req.responseText);
venues = response.response.venues;
venues.forEach(function (element, index, array) {
var venueId = element.id;
var venueName = element.name.length > 45 ? element.name.substring(0,45) : element.name;
var venueId = element.id.replace('\'','');
var venueName = element.name.length > 45 ? element.name.substring(0,45).replace('\'','') : element.name.replace('\'','');
var venueAddress = element.location.address != null ? element.location.address.length > 20 ? element.location.address.substring(0,20) : element.location.address : '(No Address)';
if(element.location.distance != null) {
var venueDistance = element.location.distance >= 1000 ? (element.location.distance/1000).toFixed(2) + "km - " : element.location.distance + "m - ";
venueAddress = venueDistance + venueAddress;
}
if(isNewList == true) {
if(isNewList) {
appMessageQueue.push({'message': {'id':venueId, 'name':venueName, 'address':venueAddress,'index': index }});
} else {
appMessageQueue.push({'message': {'id': venueId, 'name': venueName, 'address': venueAddress, 'index': index}});
Expand Down Expand Up @@ -162,7 +163,7 @@ function attemptCheckin(id, name, private, twitter, facebook) {
if (navigator.geolocation) {
navigator.geolocation.getCurrentPosition(function(position) {
var req = new XMLHttpRequest();
var checkinRequestUrl = 'https://api.foursquare.com/v2/checkins/add?oauth_token=' + userToken + '&v=20131111&ll=' + position.coords.latitude + ',' + position.coords.longitude + '&venueId=' + id;
var checkinRequestUrl = 'https://api.foursquare.com/v2/checkins/add?oauth_token=' + userToken + '&v=' + api_date + '&ll=' + position.coords.latitude + ',' + position.coords.longitude + '&venueId=' + id + api_mode;
var broadcastType = '';
if(private == 1) {
broadcastType = 'private';
Expand All @@ -185,7 +186,7 @@ function attemptCheckin(id, name, private, twitter, facebook) {
if (req.status == 200) {
if (req.responseText) {
var response = JSON.parse(req.responseText);
//console.log('Response: ' + response.toString());
console.log('Response: ' + response.toString());
if(response)
notifyPebbleCheckinOutcome(true, name);
} else {
Expand Down Expand Up @@ -219,7 +220,7 @@ function attemptCheckin(id, name, private, twitter, facebook) {

Pebble.addEventListener('appmessage',
function(e) {
//console.log('Received message: ' + e.payload.toString());
console.log('Received message: ' + e.payload.toString());
if (e.payload.id) {
attemptCheckin(e.payload.id,e.payload.name,e.payload.private,e.payload.twitter,e.payload.facebook);
} else if (e.payload.refresh) {
Expand Down
46 changes: 46 additions & 0 deletions wscript
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@

#
# This file is the default set of rules to compile a Pebble project.
#
# Feel free to customize this to your needs.
#

try:
from sh import CommandNotFound, jshint, cat, ErrorReturnCode_2
hint = jshint
except (ImportError, CommandNotFound):
hint = None

top = '.'
out = 'build'

def options(ctx):
ctx.load('pebble_sdk')

def configure(ctx):
ctx.load('pebble_sdk')
global hint
if hint is not None:
hint = hint.bake(['--config', 'pebble-jshintrc'])

def build(ctx):
if False and hint is not None:
try:
hint([node.abspath() for node in ctx.path.ant_glob("src/**/*.js")], _tty_out=False) # no tty because there are none in the cloudpebble sandbox.
except ErrorReturnCode_2 as e:
ctx.fatal("\nJavaScript linting failed (you can disable this in Project Settings):\n" + e.stdout)

# Concatenate all our JS files (but not recursively), and only if any JS exists in the first place.
ctx.path.make_node('src/js/').mkdir()
js_paths = [node.abspath() for node in ctx.path.ant_glob("src/*.js")]
if js_paths:
ctx.exec_command(['cat'] + js_paths, stdout=open('src/js/pebble-js-app.js', 'a'))

ctx.load('pebble_sdk')

ctx.pbl_program(source=ctx.path.ant_glob('src/**/*.c'),
target='pebble-app.elf')

ctx.pbl_bundle(elf='pebble-app.elf',
js=ctx.path.ant_glob('src/js/**/*.js'))

0 comments on commit 2be70d1

Please sign in to comment.