xml_rpc 0.2.2

  • Readme
  • Changelog
  • Example
  • Installing
  • 63

xml_rpc #

Build Status

A library to communicate through the XML-RPC protocol.

Usage #

A simple usage example:

import 'package:xml_rpc/client.dart' as xml_rpc;

main() {
  final url = '...';
  xml_rpc
      .call(url, 'examples.getStateName', [41])
      .then((result) => print(result))
      .catchError((error) => print(error));
}

It will sent the following xml content:

<?xml version="1.0"?>
<methodCall>
  <methodName>examples.getStateName</methodName>
  <params>
    <param>
      <value><i4>41</i4></value>
    </param>
  </params>
</methodCall>

Every xmlrpc call has to be done with the call(...) function. You must give the url, the method name and the parameters. This function returns a Future with the result received. If the response contains a <fault> a Fault object is thrown and can be catch with the .catchError() on the Future.

To use this package from browser you can provide as client optional named argument on call a http.BrowserClient.

Parameter types #

Here are the conversion table.

xmlrpcDart
<int> or <i4>int
<boolean>bool
<string> or TextString
<double>double
<dateTime.iso8601>DateTime
<base64>Base64Value
<struct>Map<String, dynamic>
<array>List

XML-RPC Extension Types #

Some XML-RPC implementations handle additionnal types. For instance Apache ws-xmlrpc may support long values with <i8> and other types (see https://ws.apache.org/xmlrpc/types.html).

You can provide custom codecs that will be used to encode and decode those values.

If you use the XML-RPC for C and C++ library on the server side you can directly use the dart library client_c.dart to be able to handle <i8> and <nil>.

Using this package on JS side #

If you use this package on JS side you may face some problem dealing with numbers. On JS side there are no difference between int and double. So by default an double 1.0 will be encoded as <int>1</int>.

You can workaround this issue:

  • wrap doubles in a custom type:
    class _Double {
      _Double(this.value) : assert(value != null);
      final double value;
    }
    
  • create a codec for this wrapper type:
    final _doubleWrapperCodec = new SimpleCodec<_Double>(
      nodeLocalName: 'double',
      encodeValue: (value) => value.value.toString(),
      decodeValue: (text) => new _Double(double.parse(text)),
    );
    
  • create a list of codecs:
    final codecs = new List<Codec>.unmodifiable(<Codec>[
      _doubleWrapperCodec,
      intCodec,
      boolCodec,
      stringCodec,
      dateTimeCodec,
      base64Codec,
      structCodec,
      arrayCodec,
    ]);
    
  • make calls with your codecs:
    main() {
      xml_rpc.call(url, 'method', [params], encodeCodecs: codecs, decodeCodecs: codecs);
    }
    

Features and bugs #

Please file feature requests and bugs at the issue tracker.

Changelog #

0.2.2 (2018-08-01) #

  • Migration to Dart 2.

0.2.1 (2018-06-20) #

  • Handle <value /> that can occur with empty strings.

0.2.0 (2018-06-18) #

  • Switch to Dart 2.
  • Allow to specify the encoders/decoders used. This allows to communicate with XML-RPC implementation that have extensions like <nil>, <i8>...
  • Expose a client_c.dart library that directly handle <nil> and <i8> extension types.

0.1.4 (2016-11-24) #

  • Evo: remove crypto dependency

0.1.3 (2015-02-05) #

  • Evo: allow to specify encoding for calls.

0.1.2 (2015-01-31) #

  • Evo: call accepts an optional named parameter client allowing to make the calls from browser.
  • Fix: If no type is indicated, the type is string.
  • Fix: <boolean> instead of <bool>.

0.1.1 (2015-01-30) #

  • Fix: Http exception are not catched.

0.1.0 (2015-01-28) #

  • First completed version for client side usage.

Semantic Version Conventions #

http://semver.org/

  • Stable: All even numbered minor versions are considered API stable: i.e.: v1.0.x, v1.2.x, and so on.
  • Development: All odd numbered minor versions are considered API unstable: i.e.: v0.9.x, v1.1.x, and so on.

example/main.dart

// Copyright (c) 2015, Alexandre Ardhuin. All rights reserved. Use of this
// source code is governed by a BSD-style license that can be found in the
// LICENSE file.
import 'package:xml_rpc/client.dart' as xml_rpc;

void main() {
  const url = 'https://api.flickr.com/services/xmlrpc';
  xml_rpc
      .call(url, 'flickr.panda.getList', [
        {'api_key': 'yourApiKey'}
      ])
      .then(print)
      .catchError(print);
}

Use this package as a library

1. Depend on it

Add this to your package's pubspec.yaml file:


dependencies:
  xml_rpc: ^0.2.2

2. Install it

You can install packages from the command line:

with pub:


$ pub get

with Flutter:


$ flutter pub get

Alternatively, your editor might support pub get or flutter pub get. Check the docs for your editor to learn more.

3. Import it

Now in your Dart code, you can use:


import 'package:xml_rpc/client.dart';
import 'package:xml_rpc/client_c.dart';
  
Popularity:
Describes how popular the package is relative to other packages. [more]
64
Health:
Code health derived from static analysis. [more]
69
Maintenance:
Reflects how tidy and up-to-date the package is. [more]
49
Overall:
Weighted score of the above. [more]
63
Learn more about scoring.

We analyzed this package on Dec 10, 2019, and provided a score, details, and suggestions below. Analysis was completed with status completed using:

  • Dart: 2.7.0
  • pana: 0.13.1+4

Health suggestions

Fix lib/src/converter.dart. (-21.78 points)

Analysis of lib/src/converter.dart reported 49 hints, including:

line 10 col 24: Unnecessary new keyword.

line 39 col 28: Unnecessary new keyword.

line 41 col 12: Unnecessary new keyword.

line 42 col 7: Unnecessary new keyword.

line 44 col 8: Unnecessary new keyword.

Fix lib/src/client.dart. (-8.17 points)

Analysis of lib/src/client.dart reported 17 hints, including:

line 40 col 42: Unnecessary new keyword.

line 44 col 12: Unnecessary new keyword.

line 46 col 12: Unnecessary new keyword.

line 53 col 5: Unnecessary new keyword.

line 53 col 20: Unnecessary new keyword.

Fix lib/src/converter_extension.dart. (-3.45 points)

Analysis of lib/src/converter_extension.dart reported 7 hints, including:

line 9 col 17: Unnecessary new keyword.

line 15 col 18: Unnecessary new keyword.

line 20 col 30: Unnecessary new keyword.

line 22 col 12: Unnecessary new keyword.

line 22 col 27: Unnecessary new keyword.

Fix lib/client_c.dart. (-0.50 points)

Analysis of lib/client_c.dart reported 1 hint:

line 30 col 17: Unnecessary new keyword.

Maintenance issues and suggestions

Support latest dependencies. (-10 points)

The version constraint in pubspec.yaml does not support the latest published versions for 1 dependency (http).

Package is getting outdated. (-35.34 points)

The package was last published 70 weeks ago.

The package description is too short. (-6 points)

Add more detail to the description field of pubspec.yaml. Use 60 to 180 characters to describe the package, what it does, and its target use case.

Dependencies

Package Constraint Resolved Available
Direct dependencies
Dart SDK >=2.0.0-dev.62.0 <3.0.0
http ^0.11.0 0.11.3+17 0.12.0+2
meta ^1.1.5 1.1.8
xml ^3.0.0 3.6.1
Transitive dependencies
async 2.4.0
charcode 1.1.2
collection 1.14.12
convert 2.1.1
http_parser 3.1.3
path 1.6.4
petitparser 2.4.0
source_span 1.5.5
string_scanner 1.0.5
term_glyph 1.1.0
typed_data 1.1.6
Dev dependencies
test ^1.3.0