[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
SF.net SVN: ledger-smb:[4749] trunk
- Subject: SF.net SVN: ledger-smb:[4749] trunk
- From: ..hidden..
- Date: Tue, 22 May 2012 07:58:57 +0000
Revision: 4749
http://ledger-smb.svn.sourceforge.net/ledger-smb/?rev=4749&view=rev
Author: einhverfr
Date: 2012-05-22 07:58:57 +0000 (Tue, 22 May 2012)
Log Message:
-----------
new JSON support for web services
minor fixes to XML support to make consistent with JSON decoding
Modified Paths:
--------------
trunk/LedgerSMB/REST_Format/xml.pm
Added Paths:
-----------
trunk/LedgerSMB/REST_Format/json.pm
trunk/t/data/rest_samples/sample_customer.json
Copied: trunk/LedgerSMB/REST_Format/json.pm (from rev 4748, trunk/LedgerSMB/REST_Format/xml.pm)
===================================================================
--- trunk/LedgerSMB/REST_Format/json.pm (rev 0)
+++ trunk/LedgerSMB/REST_Format/json.pm 2012-05-22 07:58:57 UTC (rev 4749)
@@ -0,0 +1,37 @@
+=head1 NAME
+
+LedgerSMB::REST_Format::json - JSON support for LedgerSMB RESTful web services.
+
+=head1 SYNOPSYS
+
+
+my $hash = LedgerSMB::REST_Format::json::from_input($request);
+my $json = LedgerSMB::REST_Format::json::to_output($request);
+
+=head1 COPYRIGHT
+
+Copyright (C) 2012 The LedgerSMB Core Team.
+
+This file may be used under the terms of the GNU General Public License
+version 2 or at your option any later version. Please see the included
+LICENSE.TXT file.
+
+=cut
+
+use JSON;
+use strict;
+use warnings;
+
+local $JSON::UTF8 = 1;
+
+sub from_input{
+ my $request = shift @_;
+ return decode_json($request->{payload});
+}
+
+sub to_output{
+ my $request = shift @_;
+ return encode_json($request->{payload}, { pretty => 1, indent => 2 };
+}
+
+1;
Modified: trunk/LedgerSMB/REST_Format/xml.pm
===================================================================
--- trunk/LedgerSMB/REST_Format/xml.pm 2012-05-22 07:29:25 UTC (rev 4748)
+++ trunk/LedgerSMB/REST_Format/xml.pm 2012-05-22 07:58:57 UTC (rev 4749)
@@ -25,7 +25,7 @@
sub from_input{
my $request = shift @_;
- return XMLin($request->{payload}, ForceArray=>1, ContentKey => 'text');
+ return XMLin($request->{payload}, ForceArray=>1);
}
sub to_output{
Added: trunk/t/data/rest_samples/sample_customer.json
===================================================================
--- trunk/t/data/rest_samples/sample_customer.json (rev 0)
+++ trunk/t/data/rest_samples/sample_customer.json 2012-05-22 07:58:57 UTC (rev 4749)
@@ -0,0 +1,67 @@
+{
+ "bank_acct" : [
+ {
+ "iban" : "3245431235",
+ "bic" : "12435655"
+ }
+ ],
+ "eca" : [
+ {
+ "location" : [
+ {
+ "city" : "Red City",
+ "country_code" : "US",
+ "class_id" : "1",
+ "mail_code" : "97432",
+ "line_one" : "103 Park Road",
+ "state" : "Washington"
+ }
+ ],
+ "language" : "en_US",
+ "meta_number" : "C123",
+ "terms" : "30",
+ "contact" : [
+ {
+ "contact" : "..hidden..",
+ "class" : "email",
+ "description" : "Accounts Payable"
+ }
+ ],
+ "cash_accno" : "1060",
+ "arap_accno" : "1200",
+ "description" : "Example",
+ "note" : [
+ "This is a note about the customer account."
+ ],
+ "currency" : "USD",
+ "entity_class" : "2",
+ "pay_to" : "Examples, Inc",
+ "start_date" : "2011-01-01",
+ "credit_limit" : "500"
+ },
+ {
+ "language" : "en_US",
+ "meta_number" : "V123",
+ "terms" : "30",
+ "cash_accno" : "1060",
+ "arap_accno" : "1200",
+ "description" : "Example",
+ "currency" : "USD",
+ "entity_class" : "1",
+ "pay_to" : "Examples, Inc",
+ "start_date" : "2011-01-01",
+ "credit_limit" : "500"
+ }
+ ],
+ "company" : [
+ {
+ "taxnumber" : "12345",
+ "entity_class" : "2",
+ "country_code" : "US",
+ "legal_name" : "Test Company"
+ }
+ ],
+ "note" : [
+ "This is a note about the entity and will show up on both accounts.\n "
+ ]
+}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.