Handprinter API: Difference between revisions

From Opasnet
Jump to navigation Jump to search
(now it works)
 
(One intermediate revision by the same user not shown)
Line 1: Line 1:
===Application programming interface (API)===
===Application programming interface (API)===


The first code on this page is an API that takes in user input and stores that into Opasnet base. The code below is mimicking an application (e.g. in a cell phone) that takes in user input and converts that into an output that can be used as an interface data package between the API and Opasnet. In practice, the application produces an URL that links to this page and contains parameter values for all fields of the API code.
:''[http://en.opasnet.org/en-opwiki/index.php?title=Handprinter_API&oldid=31672 Previous version] was designed for the user. This version is designed for an application to enter all parameter values.


For more about the URL formatting, see [[R-tools#Giving parameters in an URL]].
The code on this page uploads leaf suggestions to Handprinter database. In addition, it produces a URL link that contains the data given, and so it shows how the same data can be uploaded using an application external to Opasnet. For more about the URL formatting, see [[R-tools#Giving parameters in an URL]].


<rcode name="application" embed=1 label="Create URL for API" variables="
The input is a table where the columns are separated by "|" and rows are separated by "||". The test version has four columns: Leaf_id, Name, Idea, and Result.
name:email|description:Your email (personal information is not revealed to third parties)|type:text|
 
category:Information about your action. Note! You must fill all fields.|
You must know the password to make the code actually work. At this testing phase, it is 72634524.
name:phone|description:Your phone number (with international and area code)|type:text|
 
name:actiondescription|description:Description of your action|type:text|
<rcode name="app" embed=1 recall_inputs=1 label="Upload data" variables="
name:benefits|description:What are the benefits that will occur with your action?|type:text|
name:pw|description:Give the password to enter data|type:default|
name:actionname|description:Give a name for your action|type:text|
category:Give data to be entered into the database as a text string.|
name:actioncontext|description:What is the context of your action?|type:selection|options:
name:inp|description:Input as a table made into a string|type:text
; - select -;
'Home';Home;
'Consumer';Consumer;
'Manufacturing';Manufacturing;
'Retail';Retail;
'Farming and agriculture';Farming and agriculture|
name:category|description:To which category does your action belong?|type:selection|options:
; - select -;
'Behavior change';Behavior change;
'Process change';Process change;
'Infrastructure change';Infrastructure change|
name:activity|description:To what activity does your action relate?|type:selection|options:
; - select -;
'A';Agriculture, forestry and fishing;
'B';Mining and quarrying|
name:subactivity|description:Select a sub-activity|type:selection|options:
;- select -;
'A01';Crop and animal production, hunting and related service activities;
'A02';Forestry and logging;
'A03';Fishing and aquaculture|
category:Subactivity|category_conditions:activity;'A'|
name:subactivity|description:Select a sub-activity|type:selection|options:
;- select -;
'B05';Mining of coal and lignite;
'B06';Extraction of crude petroleum and natural gas;
'B07';Mining of metal ores;
'B08';Other mining and quarrying;
'B09';Mining support service activities|
category:Subactivity|category_conditions:activity;'B'
">
">
library(OpasnetUtils)
library(OpasnetUtils)
library(OpasnetUtilsExt)
library(OpasnetUtilsExt)


dat <- data.frame(
colnam <- c("Leaf_id", "Name", "Idea", "Result")
Email = email,
 
Phone = phone,
set.seed(pw)
Action.name = actionname,
if(round(runif(1), 6) != 0.921817) stop("Wrong password")
Action.context = actioncontext,
 
Category = category,
dat <- strsplit(inp, split = "\\|\\|")[[1]]
Benefits = benefits,
dat <- strsplit(dat, split = "\\|")
Description = actiondescription,
dat <- as.data.frame(t(as.data.frame(dat)))
Activity = activity,
colnames(dat) <- colnam
Subactivity = subactivity,
rownames(dat) <- 1:nrow(dat)
Result = 0
)


oprint(dat)
oprint(dat)


out <- paste(
out <- paste("Handprinter_API?app[pw]=00000000&app[inp]=", inp, sep = "")
"Handprinter?add[email]=", email,
 
"&add[phone]=", phone,
olink(out, wiki = "op_en", text = "This URL uploads the data given to the API")
"&add[actionname]=", actionname,
 
"&add[actioncontext]='", actioncontext, "'",
opbase.upload(
"&add[category]='", category, "'",
dat,  
"&add[actiondescription]=", actiondescription,
ident = "Op_en6285",  
"&add[benefits]=", benefits,
name = "Handprinter_API",  
"&add[activity]='", activity, "'",
subset = "Leaves",  
"&add[subactivity]='", subactivity, "'",
act_type = "append",  
"#Calculations",
language = "eng",  
sep = ""
who = wiki_username
)
)
olink(out, wiki = "op_en", text = "This URL uploads the data given to the API")


</rcode>
</rcode>
=== Show leaves in the database ===
{{resultlink}}

Latest revision as of 14:53, 6 February 2016

Application programming interface (API)

Previous version was designed for the user. This version is designed for an application to enter all parameter values.

The code on this page uploads leaf suggestions to Handprinter database. In addition, it produces a URL link that contains the data given, and so it shows how the same data can be uploaded using an application external to Opasnet. For more about the URL formatting, see R-tools#Giving parameters in an URL.

The input is a table where the columns are separated by "|" and rows are separated by "||". The test version has four columns: Leaf_id, Name, Idea, and Result.

You must know the password to make the code actually work. At this testing phase, it is 72634524.

Give data to be entered into the database as a text string.

Give the password to enter data:

Input as a table made into a string:

+ Show code

Show leaves in the database

{{#opasnet_base_link:Op_en6285}}