Can’t consume. Coffee is of unacceptable quality. (Error 6661.7)

Can’t consume. Coffee is of unacceptable quality. (Error 6661.7)
See Also Specifics

You tried to consume coffee which is of an unacceptable quality.
The beverage did not reach quality controls for one of these reasons:
• You used the Decaffeinated method and opened the wrong container for access.
• In terms of Visual Basic, you are using the Coffee control, and you set the Instant property to True.
• The caffeine brand is defined as vbCheap in the office system or by your colleagues.
• The coffee is stored in a non airtight container.
• In a office system, you don’t have access privileges for the sugar container.
• When working with an expresso OCX, the machine or one of its objects (such as a tap control or water container) may have been set to vbSlow. You may not have adequate skills or abilities to manipulate this OCX with your user name and password.

Clear the cup (or mug if using NT kernel), resolve the unacceptable condition, and then refill the cup/mug for read/write access.

By Jolyon 1990s

Saving to Cloudant DBaaS from Corona SDK

Following on from my Cloudant DBaaS 101 post here is how you can save to a Cloudant DBaaS from Corona Labs SDK iOS/Android app.

Just raw code. Needs work but gives you a way to have a reusable function that also has a network listener to read the response from cloudant.

-- Require Objects
local socket = require("socket");
local http = require("socket.http");
local ltn12 = require("ltn12");
local json = require ("json");
local mime = require( "mime" );

-- The json data variable
jsondata = {}

-- Alert Box Handler
local function onGenericAlertBox( event )
if "clicked" == event.action then
local i = event.index
if 1 == i then
end
end
return true
end

-- The Network Save Listener
local function CloudantNetworkListener( event )
-- You function needs to be bigger than this but this gives you an idea how to process data back from Cloudant.
local retval
local errorCaptured = false
if ( event.isError ) then
if errorCaptured == false then
--ERROR: Error during request, code: -1003, details: A server with the specified hostname could not be found.
print ( "NetworkError:isError RESPONSE: " .. event.response )
retval = native.showAlert( "Error submitting your event", "This is embarrassing. There was an error saving your request. Here is the raw error: " .. event.response, { "OK" }, onGenericAlertBox)
errorCaptured = true
end

else
DoPrint("." .. event.response .. ".")
if (event.response == nil) then
-- show network down error

elseif (event.response == "") then
-- show network down error

elseif (string.find(event.response, "ok") > 1) then
if (string.find(event.response, "true") > 1) then
print ( "NetworkError: RESPONSE: " .. event.response )
retval = native.showAlert( "Saved", event.response , { "OK" }, onGenericAlertBox)
errorCaptured = true

end
elseif (string.find(event.response, "error") > 1) then
--{"error":"unauthorized","reason":"one of _writer, _creator is required for this request"}
if (string.find(event.response, "unauthorized") > 1) then
DoPrint ( "NetworkError: RESPONSE: " .. event.response )
retval = native.showAlert( "Error submitting your event", "This is embarrassing. I was unable to save your event due to invalid access." , { "OK" }, onGenericAlertBox)
errorCaptured = true
end
end

if errorCaptured == false then
print ( "NetworkError: RESPONSE: " .. event.response )
retval = native.showAlert( "Error submitting your event", "This is embarassing. There was an unknown error saving your request. Here is the raw error: " .. event.response, { "OK" }, onGenericAlertBox)
else
-- Save OK, Carry On
end
end
end

function SaveToCloudant(url, action, in_json, callback)

local json = require ( "json" )
local headers = {}

headers["Authorization"] = "Basic " .. mime.b64( "yourusername:yourpassword" )
headers["Content-Type"] = "application/json"

local params = {}
params.headers = headers
params.body = json.encode( in_json )

network.request ( url, action, callback, params )
end

-- The Data To Save
jsondata.nickname ="simon"
jsondata.sample_string = "yada"
jsondata.sample_int = 123
jsondata.datetime = tostring(os.time())

-- Save to Cloudant
SaveToCloudant("https://youraccount.cloudant.com/testtable", "POST", jsondata, CloudantNetworkListener)

Cloudant DBaaS 101

I have been playing with http://www.cloudant.com DBaaS and I am very impressed. If you want a NoSQL scalable database goto https://cloudant.com/sign-up/ and create free account. They have reasonable rates once you go beyond the free tier but you will never get a bill if you use less than $50 a month (approx 1,600,000 light reads or 300,000 heavy writes) or 50GB. Cloudant can handle billions of transactions a day, replicate data across data centres, secure/encrypt your data etc

The hardest part is understanding how to prepare HTTP requests to the server (and formatting/reading the JSON payloads) but that is way simple than dealing with the hell of SQL and HTTP forms, sessions and SQL injection stuff. When you signup choose your name (e.g “testuser”) this will become the URL to your database (“https://testuser.cloudant.com”). You can also choose where your database is located (US, London, Singapore etc) but don’t worry, this can be changed later. By default all traffic to/from cloudant is via https (at no cost) unless you opt out.

If you are unsure just goto https://cloudant.com/sign-up/ and wait 5 min and a popup live chat window will appear and ask away. You can also follow @cloudant on twitter, join the community on IRC or email support@cloudant.com.

My blog post is certainly not going to teach your the right terminology (for that go here https://cloudant.com/for-developers/ and https://docs.cloudant.com) but in a few minutes you can easily create a table, write new records, query and modify records in minutes.

How to create a table

Once you have created an account you can create tables (database) via the Cloudant url (https://{yourusername}.cloudant.com/dashboard.html) or remotely via a number of ways (e.g a Python Script). You do not need to use Python, you could use .NET, HTTP code from an Arduino or PHP code on a website. As long as you can send a http request with authorisation (login details) and attach/decode JSON you can talk to/from a Cloudant DBaaS.

import requests
import json
auth = ('yourusername', 'yourpassword')
post_url = "https://yourusername.cloudant.com/testtable".format(auth[0])
r = requests.put(post_url, auth=auth)
print json.dumps(r.json(), indent=1)

This will create table called “testtable”

If you do something wrong cloudant will let you know via the API and HTTP response code https://docs.cloudant.com/api/basics.html. Always check the response codes.

How to save a new record into a table

Obviously you need to decide on the table names and fields in your database table but here is a quick way to throw a record at the database above with python.

import requests
import json
doc = {'username':'kerrie','high_score':550, 'level':3}
auth = ('yourusername', 'yourpassword')
headers = {'Content-type': 'application/json'}
post_url = "https://yourusername.cloudant.com/testtable/kerrie".format(auth[0])
r = requests.put(post_url, auth=auth, headers=headers, data=json.dumps(doc))
print json.dumps(r.json(), indent=1)

You can see that we are creating a JSON array (containing some key pair values and passing that to a URL via HTTP packet data).

How to query a record

Simply query the URL (http://yourusername.cloudant.com/table/record

and process the JSON returned.

import requests
import json
auth = ('yourusername', 'yourpassword')
get_url = "https://yourusername.cloudant.com/testtable/kerrie".format(auth[0])
r = requests.get(get_url, auth=auth)
print json.dumps(r.json(), indent=1)

There is a whole topic on querying by ID’s and versioning that is not covered here.

How to query all record

You can also return all records in a table by querying the URL: https://yourusername.cloudant.com/testtable/_all_docs

Results would be returned something like this:

{"total_rows":4,"offset":0,"rows":[
{"id":"jane","key":"jane","value":{"rev":"5-t8ca55e2c81d38895ba8eff46a53c5db"}},
{"id":"kerrie","key":"kerrie","value":{"rev":"4-5e21e7e140af02afdc2f37b7538bcc34"}},
{"id":"marc","key":"marc","value":{"rev":"5-ha8a12fc9829baa09c5940edcr6fdf9f"}},
{"id":"simon","key":"simon","value":{"rev":"6-a9e10252931e4df63aa5ce055c56aac9"}}
]}

There is also syntax for maximum items returned and pagination that you can read up on.

Now that you understand the basics you can plan how you want to talk to your database, it could be via .NET, PHP, Perl, Corona SDK or via Python. Do check out the official create/read/update and delete examples and read the getting started guide.

In the next post I will add some CoronaSDK to Cloudant tips.

Edit 2/Jan/2015: Cloudant have increased the freebies 10 fold (I have updated the prices above).