Skip to content

Commit a338c06

Browse files
author
Marvin Zhang
committed
chore: updated examples
1 parent 04b2acf commit a338c06

File tree

2 files changed

+74
-2
lines changed

2 files changed

+74
-2
lines changed

README.md

+19-2
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,21 @@ mvn clean install
1111

1212
## Usage
1313

14+
Add the following dependency to your `pom.xml` file:
15+
16+
```xml
17+
<dependency>
18+
<groupId>io.crawlab</groupId>
19+
<artifactId>sdk</artifactId>
20+
<version>1.0.0</version>
21+
</dependency>
22+
```
23+
24+
Then you can use the SDK in your Java code:
25+
1426
```java
27+
package com.example;
28+
1529
import java.util.ArrayList;
1630
import java.util.Map;
1731
import java.util.HashMap;
@@ -50,11 +64,14 @@ public class Main {
5064
);
5165

5266
// Using custom objects
53-
public class Person {
67+
class Person {
5468
private String name;
5569
private int age;
5670

57-
// Constructor, getters, setters...
71+
public Person(String name, int age) {
72+
this.name = name;
73+
this.age = age;
74+
}
5875
}
5976

6077
Person person1 = new Person("John", 25);
+55
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
package io.crawlab.example;
2+
3+
import java.util.ArrayList;
4+
import java.util.Map;
5+
import java.util.HashMap;
6+
import java.util.Arrays;
7+
8+
import io.crawlab.sdk.CrawlabSDK;
9+
10+
public class Main {
11+
public static void main(String[] args) {
12+
// Save a data item (will be serialized to JSON)
13+
Map<String, Object> data = Map.of("name", "John", "age", 25);
14+
CrawlabSDK.saveItem(data);
15+
16+
// Save multiple data items
17+
Map<String, Object> data1 = Map.of("name", "John", "age", 25);
18+
Map<String, Object> data2 = Map.of("name", "Jane", "age", 30);
19+
CrawlabSDK.saveItem(data1, data2);
20+
21+
// Save dynamic-sized data items
22+
ArrayList<Map<String, Object>> dataList = new ArrayList<>();
23+
dataList.add(Map.of("name", "John", "age", 25));
24+
dataList.add(Map.of("name", "Jane", "age", 30));
25+
CrawlabSDK.saveItem(dataList);
26+
27+
// Passing Dynamic Arguments
28+
Map<String, Object> dataMap = new HashMap<>();
29+
dataMap.put("name", "John");
30+
dataMap.put("age", 25);
31+
dataMap.put("skills", Arrays.asList("Java", "Python"));
32+
CrawlabSDK.saveItem(dataMap);
33+
34+
// Using varargs for multiple items
35+
CrawlabSDK.saveItem(
36+
Map.of("name", "John", "age", 25),
37+
Map.of("name", "Jane", "age", 30)
38+
);
39+
40+
// Using custom objects
41+
class Person {
42+
private String name;
43+
private int age;
44+
45+
public Person(String name, int age) {
46+
this.name = name;
47+
this.age = age;
48+
}
49+
}
50+
51+
Person person1 = new Person("John", 25);
52+
Person person2 = new Person("Jane", 30);
53+
CrawlabSDK.saveItem(person1, person2);
54+
}
55+
}

0 commit comments

Comments
 (0)