csplookup 0.9.6

  • Readme
  • Changelog
  • Example
  • Installing
  • 62

csplookup #

Client package for CSP Lookup API.

Install #

dependencies:
  csplookup: ^0.9.6

Usage #

import 'package:csplookup/csplookup.dart' as csplookup;

var client = csplookup.LookupClient(apiKey: 'YOUR_API_KEY');
client.ipLookup('1.1.1.1').then((response) => handleResponse(response));


void handleResponse(csplookup.LookupResponse response) {
	// call checkAPIError() to check for API errors (Limit reached, Invalid key, etc.)
	try {
		response.checkAPIError();
	} on csplookup.InvalidKeyException {
		print('api key is not valid');
		return;
		// All exceptions are avilable in exceptions file
	} catch(e) {
		print('exception: ' + e.toString());
		return;
	}

	var result = response.getResult();
	print(result);
	// Instance of LookupResult
	print(result.country.isoCode);
	// Country iso code
}

Client methods:

// set https for request
// Default: true
client.setHttps(false)

// Set request timeout
// Default: 10 seconds
client.setTimeout(Duration(seconds: 2))

Response methods:

// returns Result instance
// same as 'response.result'
response.getResult()


// returns country iso code (String)
// same as 'response.result.country.isoCode'
response.getCountryCode()

// returns country name in english (String)
// other languages are available in 'result.country.names' (Map<String,String>)
// same as 'response.result.country.names['en']'
response.getCountryName()

// returns city name in english (String)
// other languages are available in 'result.city.names' (Map<String,String>)
// same as 'response.result.city.names['en']'
response.getCityName()

License #

MIT

0.9.6 #

  • Fixed a bug while parsing json for Subdivisions.

0.9.5 #

  • Updated README.

0.9.4 #

  • Added library name.

0.9.3 #

  • Edited READMED.md file.

0.9.2 #

  • Updated sdk version.
  • Added example.

0.9.1 #

  • Removed new keywords.

0.9.0 #

  • Initial release.

example/example.dart

import 'package:csplookup/csplookup.dart' as csplookup;

void handleResponse(csplookup.LookupResponse response) {
	// call checkAPIError() to check for API errors (Limit reached, Invalid key, etc.)
	try {
		response.checkAPIError();
	} on csplookup.InvalidKeyException {
		print('api key is not valid');
		return;
		// All exceptions are avilable in exceptions file
	} catch(e) {
		print('exception: ' + e.toString());
		return;
	}

	var result = response.getResult();
	print(result);
	// Instance of LookupResult
	print(result.country.isoCode);
	// Country iso code
}

void main(List<String> arguments) async {
  var client = csplookup.LookupClient(apiKey: 'YOUR_API_KEY');
  client.ipLookup('1.1.1.1').then((response) => handleResponse(response));
}

Use this package as a library

1. Depend on it

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


dependencies:
  csplookup: ^0.9.6

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

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

  • Dart: 2.8.4
  • pana: 0.13.13

Health issues and suggestions

Document public APIs. (-1 points)

169 out of 169 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.

Format lib/src/result.dart.

Run dartfmt to format lib/src/result.dart.

Dependencies

Package Constraint Resolved Available
Direct dependencies
Dart SDK >=2.4.0 <3.0.0
http ^0.12.0+4 0.12.1
Transitive dependencies
charcode 1.1.3
collection 1.14.13
http_parser 3.1.4
meta 1.1.8
path 1.7.0
pedantic 1.9.0 1.9.1
source_span 1.7.0
string_scanner 1.0.5
term_glyph 1.1.0
typed_data 1.2.0