summaryrefslogtreecommitdiff
path: root/eg
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--eg/api.pl24
-rw-r--r--eg/apitest.json13
-rw-r--r--eg/apitest.yaml12
-rw-r--r--eg/couchdb.pl38
-rw-r--r--eg/github.json36
-rw-r--r--eg/github.yaml17
-rw-r--r--eg/test.pl21
-rw-r--r--eg/twitter.json27
-rw-r--r--eg/twitter.yaml19
9 files changed, 207 insertions, 0 deletions
diff --git a/eg/api.pl b/eg/api.pl
new file mode 100644
index 0000000..4e89701
--- /dev/null
+++ b/eg/api.pl
@@ -0,0 +1,24 @@
+use strict;
+use warnings;
+use 5.010;
+
+use Net::HTTP::Spore;
+
+my $username = shift;
+my $token = shift;
+
+my $api = Net::HTTP::Spore->new_from_spec(shift);
+
+$api->enable('Net::HTTP::Spore::Middleware::Format::JSON');
+
+$api->enable(
+ 'Net::HTTP::Spore::Middleware::Auth::Basic',
+ username => $username,
+ password => $token,
+);
+
+my ( $content, $result ) =
+ $api->user_information( format => 'json', username => 'franckcuny' );
+
+use YAML::Syck;
+warn Dump $content;
diff --git a/eg/apitest.json b/eg/apitest.json
new file mode 100644
index 0000000..8c26bae
--- /dev/null
+++ b/eg/apitest.json
@@ -0,0 +1,13 @@
+{
+ "methods" : {
+ "new_user" : {
+ "path" : "/user/",
+ "method" : "POST"
+ }
+ },
+ "declare" : {
+ "api_base_url" : "http://localhost:5000",
+ "api_format_mode" : "content-type",
+ "api_format" : "json"
+ }
+}
diff --git a/eg/apitest.yaml b/eg/apitest.yaml
new file mode 100644
index 0000000..9e3bad4
--- /dev/null
+++ b/eg/apitest.yaml
@@ -0,0 +1,12 @@
+name: apitest
+author:
+ - franck cuny <franck@lumberjaph.net>
+version: 0.01
+api_base_url: http://localhost:5000
+methods:
+ new_user:
+ method: POST
+ path: /user/
+ list_users:
+ method: GET
+ path: /user/list
diff --git a/eg/couchdb.pl b/eg/couchdb.pl
new file mode 100644
index 0000000..737e76b
--- /dev/null
+++ b/eg/couchdb.pl
@@ -0,0 +1,38 @@
+use strict;
+use warnings;
+use 5.010;
+use YAML::Syck;
+use Net::HTTP::Spore;
+use Try::Tiny;
+
+my $api = Net::HTTP::Spore->new_from_spec(shift, api_base_url => 'http://localhost:5984');
+
+$api->enable('Format::JSON');
+$api->enable('Runtime');
+$api->enable('UserAgent');
+
+#my $documents = $api->get_all_documents(database => 'spore');
+#warn Dump $documents;
+#say "status => ".$documents->[0];
+#say "body => ".Dump $documents->[2];
+#say "headers=> ".Dump $documents->[1];
+
+my $res;
+
+#$res = $api->create_document_with_id(database => 'spore', doc_id => 1, payload => {foo => 'bar'});
+#warn Dump $res;
+
+#$res = $api->delete_document(database =>'spore', doc_id => 1, rev => $res->body->{rev});
+#warn Dump $res;
+
+$res = $api->create_document_without_id(database => 'spore', payload => {foo => 'baz', bar => 'foobaz'});
+warn Dump $res;
+
+#try {
+ #$res = $api->get_document( database => 'spore', doc_id => 1 );
+#}
+#catch {
+ #warn Dump $_->[2];
+ #warn Dump $_->[1];
+#};
+
diff --git a/eg/github.json b/eg/github.json
new file mode 100644
index 0000000..4e3a051
--- /dev/null
+++ b/eg/github.json
@@ -0,0 +1,36 @@
+{
+ "declare" : {
+ "api_base_url" : "http://github.com/api/v2/",
+ "api_format_mode" : "content-type",
+ "api_format" : "json"
+ },
+ "methods" : {
+ "user_information" : {
+ "params" : [
+ "username",
+ "format"
+ ],
+ "required" : [
+ "format",
+ "username"
+ ],
+ "path" : "/:format/user/show/:username",
+ "method" : "GET",
+ "expected" : [
+ "200"
+ ]
+ },
+ "user_following" : {
+ "params" : [
+ "user",
+ "format"
+ ],
+ "required" : [
+ "user",
+ "format"
+ ],
+ "path" : "/:format/user/show/:user/followers",
+ "method" : "GET"
+ }
+ }
+}
diff --git a/eg/github.yaml b/eg/github.yaml
new file mode 100644
index 0000000..f844a41
--- /dev/null
+++ b/eg/github.yaml
@@ -0,0 +1,17 @@
+declare:
+ api_base_url: http://github.com/api/v2/
+methods:
+ user_information:
+ method: GET
+ path: /user/show/:username
+ params:
+ - username
+ required:
+ - username
+ user_following:
+ method: GET
+ path: /user/show/:user/followers
+ params:
+ - user
+ required:
+ - user
diff --git a/eg/test.pl b/eg/test.pl
new file mode 100644
index 0000000..b77d0bb
--- /dev/null
+++ b/eg/test.pl
@@ -0,0 +1,21 @@
+use strict;
+use warnings;
+use 5.010;
+
+use Net::HTTP::Spore;
+
+my $api = Net::HTTP::Spore->new_from_spec(shift, api_base_url => 'http://localhost:5000');
+
+$api->enable('Net::HTTP::Spore::Middleware::Format::JSON');
+
+$api->enable(
+ 'Net::HTTP::Spore::Middleware::Auth::Basic',
+ username => 'admin',
+ password => 's3cr3t'
+);
+
+my $content =
+ $api->new_user( input => { user => { francktest => { name => 'franck' } } } );
+
+use YAML::Syck;
+warn Dump $content;
diff --git a/eg/twitter.json b/eg/twitter.json
new file mode 100644
index 0000000..f07470e
--- /dev/null
+++ b/eg/twitter.json
@@ -0,0 +1,27 @@
+{
+ "declare" : {
+ "api_base_url" : "http://api.twitter.com/1",
+ "api_format_mode" : "append",
+ "api_format" : "json"
+ },
+ "methods" : {
+ "public_timeline" : {
+ "params" : [
+ "skip_user"
+ ],
+ "path" : "/statuses/public_timeline",
+ "method" : "GET"
+ },
+ "home_timeline" : {
+ "params" : [
+ "since_id",
+ "max_id",
+ "count",
+ "page",
+ "skip_user"
+ ],
+ "path" : "/statuses/home_timeline",
+ "method" : "GET"
+ }
+ }
+}
diff --git a/eg/twitter.yaml b/eg/twitter.yaml
new file mode 100644
index 0000000..92054b7
--- /dev/null
+++ b/eg/twitter.yaml
@@ -0,0 +1,19 @@
+declare:
+ api_base_url: http://api.twitter.com/1
+ api_format: json
+ api_format_mode: append
+methods:
+ public_timeline:
+ method: GET
+ path: /statuses/public_timeline
+ params:
+ - skip_user
+ home_timeline:
+ method: GET
+ path: /statuses/home_timeline
+ params:
+ - since_id
+ - max_id
+ - count
+ - page
+ - skip_user