dart_zaim_client 0.1.0

  • Readme
  • Changelog
  • Example
  • Installing
  • 55

dart_zaim_client #

A Project that was made to use the Zaim API from flutter and dart.
this package is depended on oauth1.

Getting Started #

First, create your Zaim developer account and your application in https://dev.zaim.net.
After that, you can get consumer key and consumer secret.

Create a ZaimConfig object in your code.

import 'package:dart_zaim_client/dart_zaim_client.dart';

const String ZAIM_CONSUMER_KEY = 'YOUR_CONSUMER_KEY';
const String ZAIM_CONSUMER_SECRET = 'YOUR_CONSUMER_SECRET';

final zaimConfig = ZaimConfig(ZAIM_CONSUMER_KEY, ZAIM_CONSUMER_SECRET);

ZaimAuthorization #

For authorization, you can use ZaimAuthorization class.
This class needs a ZaimConfig argument at initialize.

ZaimAuthorization auth = ZaimAuthorization(zaimConfig);

This class has two methods.

// Get a authorization url with an onetime token.
getRequestTokenUrl(String callbackUri) => Future<String>
// Get an oauth token and an oauth secret
requestToken(String verifier) => Future<oauth1.Credentials>

For more usage, see an example.

ZaimClient #

For call Zaim API with credentials, use this class.

final client = ZaimClient(zaimConfig, credentials);

This client has below methods.
Returns the value of the original value as an object.
For the original return value, refer to Zaim API doc.

User

userVerify() => Future<UserVerifyResponse>

Money

getMoneyList() => Future<List<ZaimMoney>> 

When request with POST or PUT, arguments are needed two Objects.

payment

Argument nameValue
ZaimMoneyTypeZaimMoneyType.PAYMENT
MoneyRequestParameterPaymentRequestParameter(100, '2020-05-24', 10101, 101)

income

Argument nameValue
ZaimMoneyTypeZaimMoneyType.INCOME
MoneyRequestParameterIncomeRequestParameter(100, '2020-05-24', 101)

transfer

Argument nameValue
ZaimMoneyTypeZaimMoneyType.TRANSFER
MoneyRequestParameterTransferRequestParameter(100, '2020-05-24', 101, 102)
createMoney(ZaimMoneyType, MoneyRequestParameter) => Future<CreateMoneyResponse> 
updateMoney(ZaimMoneyType, MoneyRequestParameter) => Future<UpdateMoneyResponse> 
deleteMoney(ZaimMoneyType, int id) => Future<DeleteMoneyResponse> 

Category

getDefaultCategories() => Future<CategoriesResponse> 
getCategories() => Future<CategoriesResponse>

Genre

getDefaultGenres() => Future<GenresResponse> 
getGenres() => Future<GenresResponse> 

Account

getDefaultAccounts() => Future<AccountsResponse> 
getAccounts() => Future<AccountsResponse> 

Currency

getCurrencies() => Future<CurrenciesResponse> 

Error class #

ZaimError(int status, String message) 

For example:

try {
    final money = await client.getMoneyList();
} on ZaimError catch (e) {
    print(e.status);
    print(e.message);
}

[0.1.0] - 2020-05-26 #

  • Fix accounts, categories and genres response.
  • Create an error class.

[0.0.3] - 2020-05-26 #

  • Created each response classes.
  • Added tests of entities.
  • Added description to README.

[0.0.2] - 2020-05-24 #

  • Removed unnecessary new keyword.
  • Fixed description in pubspec.yml.
  • Added an example.

[0.0.1] - 2020-05-24 #

  • Initial version of package uploaded.

example/example.dart

import 'package:flutter/material.dart';
import 'package:url_launcher/url_launcher.dart';
import 'package:dart_zaim_client/dart_zaim_client.dart';

const String ZAIM_CONSUMER_KEY = 'YOUR_CONSUMER_KEY';
const String ZAIM_CONSUMER_SECRET = 'YOUR_CONSUMER_SECRET';

final zaimConfig = ZaimConfig(ZAIM_CONSUMER_KEY, ZAIM_CONSUMER_SECRET);

// ...

class _DartZaimApiSampleState extends State<MyHomePage> {
  ZaimAuthorization auth = ZaimAuthorization(zaimConfig);
  String _oauthVerifier;

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      body: Center(
        child: Column(
          mainAxisAlignment: MainAxisAlignment.center,
          children: <Widget>[
            FlatButton(
              child: Text('Click to open authorization page'),
              onPressed: () async {
                await auth.getRequestTokenUrl('http://localhost').then((url) {
                  // After getting authorization url, open the authorization page.
                  // For example, use url_launcher
                  launch(url);
                });
              },
            ),
            TextField(
                textAlign: TextAlign.center,
                obscureText: true,
                onChanged: (value) {
                  _oauthVerifier = value;
                },
                decoration: InputDecoration(
                  hintText: 'Enter a OAuth verifier',
                )),
            FlatButton(
              child: Text('Get Token and money list'),
              onPressed: () async {
                credentials = await auth.requestToken(_oauthVerifier);
                // Maybe save credentials...

                final client = ZaimClient(zaimConfig, credentials);
                final money = await client.getMoneyList();
                print(money);
                final createMoneyParams =
                    PaymentRequestParameter(100, '2020-05-24', 10101, 101);
                await client.createMoney(
                    ZaimMoneyType.PAYMENT, createMoneyParams);
              },
            ),
          ],
        ),
      ),
    );
  }
}

Use this package as a library

1. Depend on it

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


dependencies:
  dart_zaim_client: ^0.1.0

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:dart_zaim_client/dart_zaim_client.dart';
  
Popularity:
Describes how popular the package is relative to other packages. [more]
11
Health:
Code health derived from static analysis. [more]
97
Maintenance:
Reflects how tidy and up-to-date the package is. [more]
100
Overall:
Weighted score of the above. [more]
55
Learn more about scoring.

We analyzed this package on Jul 11, 2020, and provided a score, details, and suggestions below. Analysis was completed with status completed using:

  • Dart: 2.8.4
  • pana: 0.13.15

Health issues and suggestions

Document public APIs. (-0.89 points)

277 out of 278 API elements have no dartdoc comment.Providing good documentation for libraries, classes, functions, and other API elements improves code readability and helps developers find and use your API.

Fix lib/src/zaim_client.dart. (-1.99 points)

Analysis of lib/src/zaim_client.dart reported 4 hints:

line 41 col 13: Unnecessary new keyword.

line 66 col 13: Unnecessary new keyword.

line 89 col 13: Unnecessary new keyword.

line 171 col 13: Unnecessary new keyword.

Dependencies

Package Constraint Resolved Available
Direct dependencies
Dart SDK >=2.7.0 <3.0.0
oauth1 ^1.0.1 1.0.4
Transitive dependencies
charcode 1.1.3
collection 1.14.13 1.15.0-nullsafety
convert 2.1.1
crypto 2.1.5
http 0.12.1
http_parser 3.1.4
meta 1.2.2 1.3.0-nullsafety
path 1.7.0
pedantic 1.9.2
source_span 1.7.0
string_scanner 1.0.5
term_glyph 1.1.0
typed_data 1.2.0 1.3.0-nullsafety
Dev dependencies
test ^1.14.5