JGForms

Support submitting Google Forms through Java API

License

License

Categories

Categories

ORM Data
GroupId

GroupId

io.github.stepio.jgforms
ArtifactId

ArtifactId

jgforms
Last Version

Last Version

1.0.1
Release Date

Release Date

Type

Type

jar
Description

Description

JGForms
Support submitting Google Forms through Java API
Project URL

Project URL

https://github.com/stepio/jgforms
Source Code Management

Source Code Management

https://github.com/stepio/jgforms

Download jgforms

How to add to project

<!-- https://jarcasting.com/artifacts/io.github.stepio.jgforms/jgforms/ -->
<dependency>
    <groupId>io.github.stepio.jgforms</groupId>
    <artifactId>jgforms</artifactId>
    <version>1.0.1</version>
</dependency>
// https://jarcasting.com/artifacts/io.github.stepio.jgforms/jgforms/
implementation 'io.github.stepio.jgforms:jgforms:1.0.1'
// https://jarcasting.com/artifacts/io.github.stepio.jgforms/jgforms/
implementation ("io.github.stepio.jgforms:jgforms:1.0.1")
'io.github.stepio.jgforms:jgforms:jar:1.0.1'
<dependency org="io.github.stepio.jgforms" name="jgforms" rev="1.0.1">
  <artifact name="jgforms" type="jar" />
</dependency>
@Grapes(
@Grab(group='io.github.stepio.jgforms', module='jgforms', version='1.0.1')
)
libraryDependencies += "io.github.stepio.jgforms" % "jgforms" % "1.0.1"
[io.github.stepio.jgforms/jgforms "1.0.1"]

Dependencies

test (2)

Group / Artifact Type Version
junit : junit jar 4.13
org.assertj : assertj-core jar 2.9.1

Project Modules

There are no modules declared in this project.

jgforms

Build Status Sonarcloud Status Codacy Badge DepShield Badge Maven Central Javadocs Apache 2.0 License

Support submitting Google Forms through Java API. No third-party dependencies (except of test-scoped), compatible with Java 7 and Android.

Suppose you have a Google Form with next URL:

https://docs.google.com/forms/d/1Gn8J8I-5k-0qETKchs-P2UOs3kCU17uHs0GtqCklgLk/edit

This part is "form's key": 1Gn8J8I-5k-0qETKchs-P2UOs3kCU17uHs0GtqCklgLk.

When you submit this form and check the resulting request through "DevTools", you can find next form data submitted:

entry.1464627081: 42
entry.786688631: This text is just dummy
entry.1117050788_year: 2019
entry.1117050788_month: 1
entry.1117050788_day: 10
entry.1117050788_hour: 11
entry.1117050788_minute: 46
entry.1536399354_hour: 09
entry.1536399354_minute: 23
entry.1536399354_second: 14

The above given numbers in each of the entry.<number>: value lines identify the appropriate questions in your Google Form. So while using the project you will need them along with the above mentioned form key.

To submit data to your form using this module, just follow next steps:

  1. Add dependency to the latest version:
<dependency>
    <groupId>io.github.stepio.jgforms</groupId>
    <artifactId>jgforms</artifactId>
    <version>1.0.1</version>
</dependency>
  1. Describe metadata, matching your Google Form:
public enum MyForm implements MetaData {

    SOME_SHORT_TEXT(1464627081L),
    MUCH_LONGER_TEXT(786688631L),
    EXTRA_DATE(1117050788L),
    SAMPLE_DURATION(1536399354L);

    private long id;

    JGForm(long id) {
        this.id = id;
    }

    @Override
    public long getId() {
        return this.id;
    }
}
  1. Use metadata to prepare form data and construct URL object with it:
Calendar date = Calendar.getInstance();
Calendar from = Calendar.getInstance();
from.set(date.get(Calendar.YEAR) - 1, date.get(Calendar.MONTH), date.get(Calendar.DAY_OF_MONTH), 1, 2, 3);
URL url = Builder.formKey("1FAIpQLScahJirT2sVrm0qDveeuiO1oZBJ5B7J0gdeI7UAZGohKEmi9g")
        .put(MyForm.SOME_SHORT_TEXT, 42)
        .put(MyForm.MUCH_LONGER_TEXT, "Any long text could be here")
        .putDateTime(MyForm.EXTRA_DATE, date)
        .putDuration(MyForm.SAMPLE_DURATION, from, date)
        .toUrl();

The above given code generates next URL:

https://docs.google.com/forms/d/e/1FAIpQLScahJirT2sVrm0qDveeuiO1oZBJ5B7J0gdeI7UAZGohKEmi9g/formResponse?entry.1117050788_month=1&entry.1117050788_day=13&entry.1117050788_year=2019&entry.1536399354_minute=16&entry.1536399354_second=43&entry.1117050788_hour=14&entry.1117050788_minute=18&entry.786688631=Any+long+text+could+be+here&entry.1536399354_hour=13&entry.1464627081=42
  1. Submit the form data:
Submitter submitter = new Submitter(
    new Configuration()
);
try {
   submitter.submitForm(url);
} catch (NotSubmittedException ex) {
    // TODO: log & handle the exception properly
}

Versions

Version
1.0.1
1.0.0