Difference between revisions of "Handprinter API"

From Testiwiki
Jump to: navigation, search
(Application programming interface (API): quantification removed)
(updated code for API use)
Line 1: Line 1:
 
===Application programming interface (API)===
 
===Application programming interface (API)===
 +
{{variable}}
 +
:''[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.
  
 
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.
 
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.
Line 5: Line 7:
 
For more about the URL formatting, see [[R-tools#Giving parameters in an URL]].
 
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="
+
<rcode name="app" embed=1 recall_inputs=1 label="Create URL for API" variables="
name:email|description:Your email (personal information is not revealed to third parties)|type:text|
+
name:pw|description:Give the password to enter data|type:default|
category:Information about your action. Note! You must fill all fields.|
+
category:Give data to be entered into the database as a text string.|
name:phone|description:Your phone number (with international and area code)|type:text|
+
name:inp|description:Input as a table made into a string|type:text
name:actiondescription|description:Description of your action|type:text|
 
name:benefits|description:What are the benefits that will occur with your action?|type:text|
 
name:actionname|description:Give a name for your action|type:text|
 
name:actioncontext|description:What is the context of your action?|type:selection|options:
 
; - 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", "References")
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[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 = "replace",  
"#Calculations",
+
language = "eng",  
sep = ""
+
who = wiki_username
 
)
 
)
olink(out, wiki = "op_en", text = "This URL uploads the data given to the API")
+
 
  
 
</rcode>
 
</rcode>

Revision as of 12:55, 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 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.

For more about the URL formatting, see R-tools#Giving parameters in an URL.

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