Skip to content

extract_from_source_samples_population

roei sabag edited this page Jul 12, 2020 · 1 revision

Content

Examples: SQL Server

Example no. 1

Can be tested on

Extract all students First Name into a table with FirstName column and save it to SQL Server. The saving will be done when the extraction rule execution completed.

If the database or repository does not exists, Gravity will create them, otherwise will append to them.

Action Rule, Extraction Rule (JSON)

// action rule
{
    "action": "ExtractFromDom"
}

// extraction rule
{
    "dataSource": {
        "type": "SQLServer",
        "source": "Data Source=.\\SQLEXPRESS;Initial Catalog=FooDatabase;Integrated Security=True",
        "repository": "StudentsTable"
    }    
    "onRootElement": "//td[contains(@id,'student_first_name')]",
    "pageSource": true,
    "onElements": [
        {
            "key": "FirstName"
        }
    ]
}

Rhino Literal

extract from dom on {//td[contains(@id,'student_first_name')]}
    < column {FirstName}
    < save {StudentsTable} on {Data Source=.\SQLEXPRESS;Initial Catalog=FooDatabase;Integrated Security=True} using {SQLServer}

CSharp

// action rule - option no.1
var actionRule = new ActionRule
{
    Action = PluginsList.ExtractFromSource
};

// extraction rule - option no.1
var extractionRule = new ExtractionRule
{
    DataSource = new DataSource
    {
        Type = DataSourcesList.SQLServer,
        Source = @"Data Source=.\\SQLEXPRESS;Initial Catalog=FooDatabase;Integrated Security=True",
        Repository = "StudentsTable"
    },
    OnRootElement = "//td[contains(@id,'student_first_name')]",
    PageSource = true,
    OnElements = new ContentEntry[]
    {
        new ContentEntry
        { 
            Key = "FirstName"
        }
    }
};

Python

# action rule
action_rule = {
    "action": "ExtractFromSource"
}

# extraction rule
extraction_rule = {
    "dataSource": {
        "type": "SQLServer",
        "source": "Data Source=.\\SQLEXPRESS;Initial Catalog=FooDatabase;Integrated Security=True",
        "repository": "StudentsTable"
    },    
    "onRootElement": "//td[contains(@id,'student_first_name')]",
    "pageSource": True,
    "onElements": [
        { 
            "key": "FirstName" 
        }
    ]
}

Java Script

// action rule
action_rule = {
    action: "ExtractFromSource"
};

// extraction rule
extraction_rule = {
    dataSource: {
        type: "SQLServer",
        source: "Data Source=.\\SQLEXPRESS;Initial Catalog=FooDatabase;Integrated Security=True",
        repository: "StudentsTable"
    },    
    onRootElement: "//td[contains(@id,'student_first_name')]",
    pageSource: true,
    onElements: [
        { 
            key: "FirstName"
        }
    ]
};

Java

// action rule
ActionRule actionRule = new ActionRule()
    .setAction(action: "ExtractFromSource");

// extration rule
ExtractionRule extractionRule = new ExtractionRule()
    .setDataSource(new DataSource()
            .setType("SQLServer")
            .setSource("Data Source=.\\SQLEXPRESS;Initial Catalog=FooDatabase;Integrated Security=True")
            .setRepository("StudentsTable"))
    .setOnRootElements("//td[contains(@id,'student_first_name')]")
    .setPageSource(true)
    .addElementToExtract(new ContentEntry("FirstName"));

Example no. 2

Can be tested on

Extract all students First Name into a table with FirstName column and save it to SQL Server. The saving will be done when the content entry execution completed.

If the database or repository does not exists, Gravity will create them, otherwise will append to them.

Action Rule, Extraction Rule (JSON)

// action rule
{
    "action": "ExtractFromDom"
}

// extraction rule
{
    "dataSource": {
        "type": "SQLServer",
        "source": "Data Source=.\\SQLEXPRESS;Initial Catalog=FooDatabase;Integrated Security=True",
        "repository": "StudentsTable",
        "writePerEntry": true
    }    
    "onRootElement": "//td[contains(@id,'student_first_name')]",
    "pageSource": true,
    "onElements": [
        {
            "key": "FirstName"
        }
    ]
}

Rhino Literal

extract from dom on {//td[contains(@id,'student_first_name')]}
    < column {FirstName}
    < save {{$ --repository:StudentsTable --write_per_entry}} on {Data Source=.\\SQLEXPRESS;Initial Catalog=FooDatabase;Integrated Security=True} using {SQLServer}

CSharp

// action rule - option no.1
var actionRule = new ActionRule
{
    Action = PluginsList.ExtractFromSource
};

// extraction rule - option no.1
var extractionRule = new ExtractionRule
{
    DataSource = new DataSource
    {
        Type = DataSourcesList.SQLServer,
        Source = @"Data Source=.\\SQLEXPRESS;Initial Catalog=FooDatabase;Integrated Security=True",
        Repository = "StudentsTable",
        WritePerEntry = true
    },
    OnRootElement = "//td[contains(@id,'student_first_name')]",
    PageSource = true,
    OnElements = new ContentEntry[]
    {
        new ContentEntry
        { 
            Key = "FirstName"
        }
    }
};

Python

# action rule
action_rule = {
    "action": "ExtractFromSource"
}

# extraction rule
extraction_rule = {
    "dataSource": {
        "type": "SQLServer",
        "source": "Data Source=.\\SQLEXPRESS;Initial Catalog=FooDatabase;Integrated Security=True",
        "repository": "StudentsTable",
        "writePerEntry": True
    },    
    "onRootElement": "//td[contains(@id,'student_first_name')]",
    "pageSource": True,
    "onElements": [
        { 
            "key": "FirstName" 
        }
    ]
}

Java Script

// action rule
action_rule = {
    action: "ExtractFromSource"
};

// extraction rule
extraction_rule = {
    dataSource: {
        type: "SQLServer",
        source: "Data Source=.\\SQLEXPRESS;Initial Catalog=FooDatabase;Integrated Security=True",
        repository: "StudentsTable",
        writePerEntry: true
    },    
    onRootElement: "//td[contains(@id,'student_first_name')]",
    pageSource: true,
    onElements: [
        { 
            key: "FirstName"
        }
    ]
};

Java

// action rule
ActionRule actionRule = new ActionRule()
    .setAction(action: "ExtractFromSource");

// extration rule
ExtractionRule extractionRule = new ExtractionRule()
    .setDataSource(new DataSource()
            .setType("SQLServer")
            .setSource("Data Source=.\\SQLEXPRESS;Initial Catalog=FooDatabase;Integrated Security=True")
            .setRepository("StudentsTable"))
    .setOnRootElements("//td[contains(@id,'student_first_name')]")
    .setPageSource(true)
    .addElementToExtract(new ContentEntry("FirstName"));

Examples: CSV

Example no. 1

Can be tested on

Extract all students First Name into a table with FirstName column and save it a CSV file. The saving will be done when the extraction rule execution completed.

If the file or folder(s) does not exists, Gravity will create them, otherwise will append to them.

Action Rule, Extraction Rule (JSON)

// action rule
{
    "action": "ExtractFromDom"
}

// extraction rule
{
    "dataSource": {
        "type": "CSV",
        "source": "Data/StudentsTable.csv"
    }    
    "onRootElement": "//td[contains(@id,'student_first_name')]",
    "pageSource": true,
    "onElements": [
        {
            "key": "FirstName"
        }
    ]
}

Rhino Literal

extract from dom on {//td[contains(@id,'student_first_name')]}
    < column {FirstName}
    < save on {Data/StudentsTable.csv} using {csv}

CSharp

// action rule - option no.1
var actionRule = new ActionRule
{
    Action = PluginsList.ExtractFromSource
};

// extraction rule - option no.1
var extractionRule = new ExtractionRule
{
    DataSource = new DataSource
    {
        Type = DataSourcesList.CSV,
        Source = "Data/StudentsTable.csv"
    },
    OnRootElement = "//td[contains(@id,'student_first_name')]",
    PageSource = true,
    OnElements = new ContentEntry[]
    {
        new ContentEntry
        { 
            Key = "FirstName"
        }
    }
};

Python

# action rule
action_rule = {
    "action": "ExtractFromSource"
}

# extraction rule
extraction_rule = {
    "dataSource": {
        "type": "CSV",
        "source": "Data/StudentsTable.csv"
    },    
    "onRootElement": "//td[contains(@id,'student_first_name')]",
    "pageSource": True,
    "onElements": [
        { 
            "key": "FirstName" 
        }
    ]
}

Java Script

// action rule
action_rule = {
    action: "ExtractFromSource"
};

// extraction rule
extraction_rule = {
    dataSource: {
        type: "CSV",
        source: "Data/StudentsTable.csv"
    },    
    onRootElement: "//td[contains(@id,'student_first_name')]",
    pageSource: true,
    onElements: [
        { 
            key: "FirstName"
        }
    ]
};

Java

// action rule
ActionRule actionRule = new ActionRule()
    .setAction(action: "ExtractFromSource");

// extration rule
ExtractionRule extractionRule = new ExtractionRule()
    .setDataSource(new DataSource()
            .setType("CSV")
            .setSource("Data/StudentsTable.csv"))
    .setOnRootElements("//td[contains(@id,'student_first_name')]")
    .setPageSource(true)
    .addElementToExtract(new ContentEntry("FirstName"));

Example no. 2

Can be tested on

Extract all students First Name into a table with FirstName column and save it to a CSV file. The saving will be done when the content entry execution completed.

If the file or folder(s) does not exists, Gravity will create them, otherwise will append to them.

Action Rule, Extraction Rule (JSON)

// action rule
{
    "action": "ExtractFromDom"
}

// extraction rule
{
    "dataSource": {
        "type": "CSV",
        "source": "Data/StudentsTable.csv",
        "writePerEntry": true
    }    
    "onRootElement": "//td[contains(@id,'student_first_name')]",
    "pageSource": true,
    "onElements": [
        {
            "key": "FirstName"
        }
    ]
}

Rhino Literal

extract from dom on {//td[contains(@id,'student_first_name')]}
    < column {FirstName}
    < save {{$ --write_per_entry}} on {Data/StudentsTable.csv} using {csv}

CSharp

// action rule - option no.1
var actionRule = new ActionRule
{
    Action = PluginsList.ExtractFromSource
};

// extraction rule - option no.1
var extractionRule = new ExtractionRule
{
    DataSource = new DataSource
    {
        Type = DataSourcesList.CSV,
        Source = "Data/StudentsTable.csv",
        WritePerEntry = true
    },
    OnRootElement = "//td[contains(@id,'student_first_name')]",
    PageSource = true,
    OnElements = new ContentEntry[]
    {
        new ContentEntry
        { 
            Key = "FirstName"
        }
    }
};

Python

# action rule
action_rule = {
    "action": "ExtractFromSource"
}

# extraction rule
extraction_rule = {
    "dataSource": {
        "type": "CSV",
        "source": "Data/StudentsTable.csv",
        "writePerEntry": True
    },    
    "onRootElement": "//td[contains(@id,'student_first_name')]",
    "pageSource": True,
    "onElements": [
        { 
            "key": "FirstName" 
        }
    ]
}

Java Script

// action rule
action_rule = {
    action: "ExtractFromSource"
};

// extraction rule
extraction_rule = {
    dataSource: {
        type: "CSV",
        source: "Data/StudentsTable.csv",
        writePerEntry: true
    },    
    onRootElement: "//td[contains(@id,'student_first_name')]",
    onElements: [
        { 
            key: "FirstName"
        }
    ]
};

Java

// action rule
ActionRule actionRule = new ActionRule()
    .setAction(action: "ExtractFromSource");

// extration rule
ExtractionRule extractionRule = new ExtractionRule()
    .setDataSource(new DataSource()
            .setType("CSV")
            .setSource("Data/StudentsTable.csv"))
    .setOnRootElements("//td[contains(@id,'student_first_name')]")
    .setPageSource(true)
    .addElementToExtract(new ContentEntry("FirstName"));

Examples: JSON

Example no. 1

Can be tested on

Extract all students First Name into a table with FirstName column and save it a JSON file. The saving will be done when the extraction rule execution completed.

If the file or folder(s) does not exists, Gravity will create them, otherwise will append to them.

Action Rule, Extraction Rule (JSON)

// action rule
{
    "action": "ExtractFromDom"
}

// extraction rule
{
    "dataSource": {
        "type": "JSON",
        "source": "Data/StudentsTable.json"
    }    
    "onRootElement": "//td[contains(@id,'student_first_name')]",
    "pageSource": true,
    "onElements": [
        {
            "key": "FirstName"
        }
    ]
}

Rhino Literal

extract from dom on {//td[contains(@id,'student_first_name')]}
    < column {FirstName}
    < save on {Data/StudentsTable.json} using {json}

CSharp

// action rule - option no.1
var actionRule = new ActionRule
{
    Action = PluginsList.ExtractFromSource
};

// extraction rule - option no.1
var extractionRule = new ExtractionRule
{
    DataSource = new DataSource
    {
        Type = DataSourcesList.JSON,
        Source = "Data/StudentsTable.json"
    },
    OnRootElement = "//td[contains(@id,'student_first_name')]",
    PageSource = true,
    OnElements = new ContentEntry[]
    {
        new ContentEntry
        { 
            Key = "FirstName"
        }
    }
};

Python

# action rule
action_rule = {
    "action": "ExtractFromSource"
}

# extraction rule
extraction_rule = {
    "dataSource": {
        "type": "JSON",
        "source": "Data/StudentsTable.json"
    },    
    "onRootElement": "//td[contains(@id,'student_first_name')]",
    "pageSource": True,
    "onElements": [
        { 
            "key": "FirstName" 
        }
    ]
}

Java Script

// action rule
action_rule = {
    action: "ExtractFromSource"
};

// extraction rule
extraction_rule = {
    dataSource: {
        type: "JSON",
        source: "Data/StudentsTable.json"
    },    
    onRootElement: "//td[contains(@id,'student_first_name')]",
    pageSource: true,
    onElements: [
        { 
            key: "FirstName"
        }
    ]
};

Java

// action rule
ActionRule actionRule = new ActionRule()
    .setAction(action: "ExtractFromSource");

// extration rule
ExtractionRule extractionRule = new ExtractionRule()
    .setDataSource(new DataSource()
            .setType("JSON")
            .setSource("Data/StudentsTable.json"))
    .setOnRootElements("//td[contains(@id,'student_first_name')]")
    .setPageSource(true)
    .addElementToExtract(new ContentEntry("FirstName"));

Example no. 2

Can be tested on

Extract all students First Name into a table with FirstName column and save it to a JSON file. The saving will be done when the content entry execution completed.

If the file or folder(s) does not exists, Gravity will create them, otherwise will append to them.

Action Rule, Extraction Rule (JSON)

// action rule
{
    "action": "ExtractFromDom"
}

// extraction rule
{
    "dataSource": {
        "type": "JSON",
        "source": "Data/StudentsTable.json",
        "writePerEntry": true
    }    
    "onRootElement": "//td[contains(@id,'student_first_name')]",
    "pageSource": true,
    "onElements": [
        {
            "key": "FirstName"
        }
    ]
}

Rhino Literal

extract from dom on {//td[contains(@id,'student_first_name')]}
    < column {FirstName}
    < save {{$ --write_per_entry}} on {Data/StudentsTable.json} using {json}

CSharp

// action rule - option no.1
var actionRule = new ActionRule
{
    Action = PluginsList.ExtractFromSource
};

// extraction rule - option no.1
var extractionRule = new ExtractionRule
{
    DataSource = new DataSource
    {
        Type = DataSourcesList.JSON,
        Source = "Data/StudentsTable.json",
        WritePerEntry = true
    },
    OnRootElement = "//td[contains(@id,'student_first_name')]",
    PageSource = true,
    OnElements = new ContentEntry[]
    {
        new ContentEntry
        { 
            Key = "FirstName"
        }
    }
};

Python

# action rule
action_rule = {
    "action": "ExtractFromSource"
}

# extraction rule
extraction_rule = {
    "dataSource": {
        "type": "JSON",
        "source": "Data/StudentsTable.json",
        "writePerEntry": True
    },    
    "onRootElement": "//td[contains(@id,'student_first_name')]",
    "pageSource": True,
    "onElements": [
        { 
            "key": "FirstName" 
        }
    ]
}

Java Script

// action rule
action_rule = {
    action: "ExtractFromSource"
};

// extraction rule
extraction_rule = {
    dataSource: {
        type: "JSON",
        source: "Data/StudentsTable.json",
        writePerEntry: true
    },    
    onRootElement: "//td[contains(@id,'student_first_name')]",
    pageSource: true,
    onElements: [
        { 
            key: "FirstName"
        }
    ]
};

Java

// action rule
ActionRule actionRule = new ActionRule()
    .setAction(action: "ExtractFromSource");

// extration rule
ExtractionRule extractionRule = new ExtractionRule()
    .setDataSource(new DataSource()
            .setType("JSON")
            .setSource("Data/StudentsTable.json"))
    .setOnRootElements("//td[contains(@id,'student_first_name')]")
    .setPageSource(true)
    .addElementToExtract(new ContentEntry("FirstName"));

Examples: XML

Example no. 1

Can be tested on

Extract all students First Name into a table with FirstName column and save it to XML file. The saving will be done when the extraction rule execution completed.

If the file or folder(s) does not exists, Gravity will create them, otherwise will append to them.

Action Rule, Extraction Rule (JSON)

// action rule
{
    "action": "ExtractFromDom"
}

// extraction rule
{
    "dataSource": {
        "type": "XML",
        "source": "Data/StudentsTable.xml"
    }    
    "onRootElement": "//td[contains(@id,'student_first_name')]",
    "pageSource": true,
    "onElements": [
        {
            "key": "FirstName"
        }
    ]
}

Rhino Literal

extract from dom on {//td[contains(@id,'student_first_name')]}
    < column {FirstName}
    < save on {Data/StudentsTable.xml} using {xml}

CSharp

// action rule - option no.1
var actionRule = new ActionRule
{
    Action = PluginsList.ExtractFromSource
};

// extraction rule - option no.1
var extractionRule = new ExtractionRule
{
    DataSource = new DataSource
    {
        Type = DataSourcesList.XML,
        Source = "Data/StudentsTable.xml"
    },
    OnRootElement = "//td[contains(@id,'student_first_name')]",
    PageSource = true,
    OnElements = new ContentEntry[]
    {
        new ContentEntry
        { 
            Key = "FirstName"
        }
    }
};

Python

# action rule
action_rule = {
    "action": "ExtractFromSource"
}

# extraction rule
extraction_rule = {
    "dataSource": {
        "type": "XML",
        "source": "Data/StudentsTable.xml"
    },    
    "onRootElement": "//td[contains(@id,'student_first_name')]",
    "pageSource": True,
    "onElements": [
        { 
            "key": "FirstName" 
        }
    ]
}

Java Script

// action rule
action_rule = {
    action: "ExtractFromSource"
};

// extraction rule
extraction_rule = {
    dataSource: {
        type: "XML",
        source: "Data/StudentsTable.xml"
    },    
    onRootElement: "//td[contains(@id,'student_first_name')]",
    pageSource: true,
    onElements: [
        { 
            key: "FirstName"
        }
    ]
};

Java

// action rule
ActionRule actionRule = new ActionRule()
    .setAction(action: "ExtractFromSource");

// extration rule
ExtractionRule extractionRule = new ExtractionRule()
    .setDataSource(new DataSource()
            .setType("XML")
            .setSource("Data/StudentsTable.xml"))
    .setOnRootElements("//td[contains(@id,'student_first_name')]")
    .setPageSource(true)
    .addElementToExtract(new ContentEntry("FirstName"));

Example no. 2

Can be tested on

Extract all students First Name into a table with FirstName column and save it to XML file. The saving will be done when the content entry execution completed.

If the file or folder(s) does not exists, Gravity will create them, otherwise will append to them.

Action Rule, Extraction Rule (JSON)

// action rule
{
    "action": "ExtractFromDom"
}

// extraction rule
{
    "dataSource": {
        "type": "XML",
        "source": "Data/StudentsTable.xml",
        "writePerEntry": true
    }    
    "onRootElement": "//td[contains(@id,'student_first_name')]",
    "pageSource": true,
    "onElements": [
        {
            "key": "FirstName"
        }
    ]
}

Rhino Literal

extract from dom on {//td[contains(@id,'student_first_name')]}
    < column {FirstName}
    < save {{$ --write_per_entry}} on {Data/StudentsTable.xml} using {xml}

CSharp

// action rule - option no.1
var actionRule = new ActionRule
{
    Action = PluginsList.ExtractFromSource
};

// extraction rule - option no.1
var extractionRule = new ExtractionRule
{
    DataSource = new DataSource
    {
        Type = DataSourcesList.XML,
        Source = "Data/StudentsTable.xml",
        WritePerEntry = true
    },
    OnRootElement = "//td[contains(@id,'student_first_name')]",
    PageSource = true,
    OnElements = new ContentEntry[]
    {
        new ContentEntry
        { 
            Key = "FirstName"
        }
    }
};

Python

# action rule
action_rule = {
    "action": "ExtractFromSource"
}

# extraction rule
extraction_rule = {
    "dataSource": {
        "type": "XML",
        "source": "Data/StudentsTable.xml",
        "writePerEntry": True
    },    
    "onRootElement": "//td[contains(@id,'student_first_name')]",
    "pageSource": True,
    "onElements": [
        { 
            "key": "FirstName" 
        }
    ]
}

Java Script

// action rule
action_rule = {
    action: "ExtractFromSource"
};

// extraction rule
extraction_rule = {
    dataSource: {
        type: "XML",
        source: "Data/StudentsTable.xml",
        writePerEntry: true
    },    
    onRootElement: "//td[contains(@id,'student_first_name')]",
    pageSource: true,
    onElements: [
        { 
            key: "FirstName"
        }
    ]
};

Java

// action rule
ActionRule actionRule = new ActionRule()
    .setAction(action: "ExtractFromSource");

// extration rule
ExtractionRule extractionRule = new ExtractionRule()
    .setDataSource(new DataSource()
            .setType("XML")
            .setSource("Data/StudentsTable.xml"))
    .setOnRootElements("//td[contains(@id,'student_first_name')]")
    .setPageSource(true)
    .addElementToExtract(new ContentEntry("FirstName"));

Examples: Rest API

Example no. 1

Can be tested on

Extract all students First Name into a table with FirstName column and send it to a Rest API using HTTP post. The saving will be done when the extraction rule execution completed.

Authentication will be basic using the following formats.

  1. http://[user]:[password]@foo-bar.io/data
  2. https://[user]:[password]@foo-bar.io/data
  3. http://www.[user]:[password]@foo-bar.io/data
  4. https://www.[user]:[password]@foo-bar.io/data
  5. http://www.foo-bar.io/data - no authentication
  6. https://www.foo-bar.io/data - no authentication

Action Rule, Extraction Rule (JSON)

// action rule
{
    "action": "ExtractFromDom"
}

// extraction rule
{
    "dataSource": {
        "type": "RestApi",
        "source": "http://www.@foo-bar.io/data"
    }    
    "onRootElement": "//td[contains(@id,'student_first_name')]",
    "pageSource": true,
    "onElements": [
        {
            "key": "FirstName"
        }
    ]
}

Rhino Literal

extract from dom on {//td[contains(@id,'student_first_name')]}
    < column {FirstName}
    < save on {http://www.@foo-bar.io/data} using {RestApi}

CSharp

// action rule - option no.1
var actionRule = new ActionRule
{
    Action = PluginsList.ExtractFromSource
};

// extraction rule - option no.1
var extractionRule = new ExtractionRule
{
    DataSource = new DataSource
    {
        Type = DataSourcesList.RestApi,
        Source = "http://www.@foo-bar.io/data"
    },
    OnRootElement = "//td[contains(@id,'student_first_name')]",
    PageSource = true,
    OnElements = new ContentEntry[]
    {
        new ContentEntry
        { 
            Key = "FirstName"
        }
    }
};

Python

# action rule
action_rule = {
    "action": "ExtractFromSource"
}

# extraction rule
extraction_rule = {
    "dataSource": {
        "type": "RestApi",
        "source": "http://www.@foo-bar.io/data"
    },
    "onRootElement": "//td[contains(@id,'student_first_name')]",
    "pageSource": True,
    "onElements": [
        { 
            "key": "FirstName" 
        }
    ]
}

Java Script

// action rule
action_rule = {
    "action": "ExtractFromSource"
};

// extraction rule
extraction_rule = {
    dataSource: {
        type: "RestApi",
        source: "http://www.@foo-bar.io/data"
    },    
    onRootElement: "//td[contains(@id,'student_first_name')]",
    pageSource: true,
    onElements: [
        { 
            key: "FirstName"
        }
    ]
};

Java

// action rule
ActionRule actionRule = new ActionRule()
    .setAction("ExtractFromSource");

// extration rule
ExtractionRule extractionRule = new ExtractionRule()
    .setDataSource(new DataSource()
            .setType("RestApi")
            .setSource("http://www.@foo-bar.io/data")
    .setOnRootElements("//td[contains(@id,'student_first_name')]")
    .setPageSource(true)
    .addElementToExtract(new ContentEntry("FirstName"));

Example no. 2

Can be tested on

Extract all students First Name into a table with FirstName column and send it to a Rest API using HTTP post. The saving will be done when the content entry execution completed.

Authentication will be basic using the following formats.

  1. http://[user]:[password]@foo-bar.io/data
  2. https://[user]:[password]@foo-bar.io/data
  3. http://www.[user]:[password]@foo-bar.io/data
  4. https://www.[user]:[password]@foo-bar.io/data
  5. http://www.foo-bar.io/data - no authentication
  6. https://www.foo-bar.io/data - no authentication

Action Rule, Extraction Rule (JSON)

// action rule
{
    "action": "ExtractFromSource",
}

// extraction rule
{
    "dataSource": {
        "type": "RestApi",
        "source": "http://www.@foo-bar.io/data",
        "writePerEntity": true
    },
    "onRootElement": "//td[contains(@id,'student_first_name')]",
    "pageSource": true,
    "onElements": [
        {
            "key": "FirstName"
        }
    ]
}

Rhino Literal

extract from dom on {//td[contains(@id,'student_first_name')]}
    < column {FirstName}
    < save {{$ --write_per_entry}} on {http://www.@foo-bar.io/data} using {RestApi}

CSharp

// action rule - option no.1
var actionRule = new ActionRule
{
    Action = PluginsList.ExtractFromSource
};

// extraction rule - option no.1
var extractionRule = new ExtractionRule
{
    DataSource = new DataSource
    {
        Type = DataSourcesList.RestApi,
        Source = "http://www.@foo-bar.io/data",
        WritePerEntity = true
    },
    OnRootElement = "//td[contains(@id,'student_first_name')]",
    PageSource = true,
    OnElements = new ContentEntry[]
    {
        new ContentEntry
        { 
            Key = "FirstName"
        }
    }
};

Python

# action rule
action_rule = {
    "action": "ExtractFromSource"
}

# extraction rule
extraction_rule = {
    "dataSource": {
        "type": "RestApi",
        "source": "http://www.@foo-bar.io/data",
        "writePerEntity": True
    },    
    "onRootElement": "//td[contains(@id,'student_first_name')]",
    "pageSource": True,
    "onElements": [
        { 
            "key": "FirstName" 
        }
    ]
}

Java Script

// action rule
action_rule = {
    "action": "ExtractFromSource"
};

// extraction rule
extraction_rule = {
    dataSource: {
        type: "RestApi",
        source: "http://www.@foo-bar.io/data",
        writePerEntity: true
    },    
    onRootElement: "//td[contains(@id,'student_first_name')]",
    pageSource: true,
    onElements: [
        { 
            key: "FirstName"
        }
    ]
};

Java

// action rule
ActionRule actionRule = new ActionRule()
    .setAction("ExtractFromSource");

// extration rule
ExtractionRule extractionRule = new ExtractionRule()
    .setDataSource(new DataSource()
            .setType("RestApi")
            .setSource("http://www.@foo-bar.io/data")
            .setWritePerEntity(true)
    .setOnRootElements("//td[contains(@id,'student_first_name')]")
    .setPageSource(true)
    .addElementToExtract(new ContentEntry("FirstName"));

Clone this wiki locally