Skip to content

Commit

Permalink
- enable Travis CI
Browse files Browse the repository at this point in the history
- add badges
- fix some linter hints/warnings
- switch from `unittest` to `test`
- use bwu_utils_dev default Grinder tasks
  • Loading branch information
zoechigist committed Jun 8, 2015
1 parent c590efd commit decfffd
Show file tree
Hide file tree
Showing 10 changed files with 208 additions and 97 deletions.
23 changes: 23 additions & 0 deletions .travis.yml
@@ -0,0 +1,23 @@
language: dart

dart:
- stable
- dev

env:
- PUB=DOWNGRADE
- PUB=UPGRADE

script: dart -c tool/grind.dart travis

# Speed up builds by using containerization. Disable this if you need to use
# sudo in your scripts.
sudo: false

#branches:
# only:
# - master

cache:
directories:
- $HOME/.pub-cache
16 changes: 11 additions & 5 deletions README.md
@@ -1,11 +1,17 @@
## Shelf Response Formatter ##
#Shelf Response Formatter

[![Star this Repo](https://img.shields.io/github/stars/bwu-dart/shelf_response_formatter.svg?style=flat)](https://github.com/bwu-dart/shelf_response_formatter)
[![Pub Package](https://img.shields.io/pub/v/shelf_response_formatter.svg?style=flat)](https://pub.dartlang.org/packages/shelf_response_formatter)
[![Build Status](https://travis-ci.org/bwu-dart/shelf_response_formatter.svg?branch=travis)](https://travis-ci.org/bwu-dart/shelf_response_formatter)
[![Coverage Status](https://coveralls.io/repos/bwu-dart/shelf_response_formatter/badge.svg)](https://coveralls.io/r/bwu-dart/shelf_response_formatter)

A small class that, given a [shelf](http://pub.dartlang.org/packages/shelf)
request and some simple data, will determine a correct response format (eg.:
Json or XML) and convert the data to the appropriate format.

This package is a fork of [tentacle_response_formatter](https://pub.dartlang.org/packages/tentacle_response_formatter).

### How to use ###
##How to use
```dart
// ResponseFormatter is a Singleton so you will always get the same instance
// with
Expand All @@ -23,7 +29,7 @@ print(result.body) // -> '{"message":"hello"}' or
print(result.contentType) // -> "application/json" or "application/xml" or "text/plain"
```

### How is the response format detected ###
##How is the response format detected
There are currently 3 values that influence the response format detection. They
are applied in the following order:

Expand All @@ -43,7 +49,7 @@ response otherwise the result will be an empty String. The string formatter is
not a real formatter but rather a fallback. Read later on how to add your own
formatter and register it for content types.

### Add your own response formatter ###
##Add your own response formatter
You may want to add your own formatters or content-type mappings to the
formatter. To do so you have to provide a formatter function which takes dynamic
data and returns a String. Furthermore you have to provide a unique name and may
Expand All @@ -69,5 +75,5 @@ formatter.registerFormatter("json", "application/json", (dynamic data) {
// initially registered for
```

### License ###
##License
Apache 2.0
2 changes: 1 addition & 1 deletion lib/shelf_response_formatter.dart
Expand Up @@ -100,7 +100,7 @@ class ResponseFormatter {
}

// from accept header
List<String> accepts = _parseAcceptHeaders(request.headers['accept']);
List<String> accepts = _parseAcceptHeaders(acceptHeaders);
String accepted =
accepts.firstWhere((accept) => acceptMappings.containsKey(accept));
return acceptMappings[accepted];
Expand Down
2 changes: 1 addition & 1 deletion lib/xml_converter.dart
@@ -1,4 +1,4 @@
library shelf_response_formatter.XmlConverter;
library shelf_response_formatter.xml_converter;

import 'package:xml/xml.dart';

Expand Down
176 changes: 158 additions & 18 deletions pubspec.lock
Expand Up @@ -4,31 +4,83 @@ packages:
analyzer:
description: analyzer
source: hosted
version: "0.25.0-dev.3"
version: "0.25.0+1"
ansicolor:
description: ansicolor
source: hosted
version: "0.0.9"
archive:
description: archive
source: hosted
version: "1.0.19"
args:
description: args
source: hosted
version: "0.12.2+6"
version: "0.13.1"
barback:
description: barback
source: hosted
version: "0.15.2+4"
browser:
description: browser
source: hosted
version: "0.10.0+2"
bwu_dart_archive_downloader:
description: bwu_dart_archive_downloader
source: hosted
version: "0.2.0+1"
bwu_utils:
description: bwu_utils
source: hosted
version: "0.1.0-dev.3"
bwu_utils_dev:
description: bwu_utils_dev
source: hosted
version: "0.1.0-dev.9"
cli_util:
description: cli_util
source: hosted
version: "0.0.1+1"
version: "0.0.1+2"
code_transformers:
description: code_transformers
source: hosted
version: "0.2.9"
collection:
description: collection
source: hosted
version: "1.1.0"
version: "1.1.1"
crypto:
description: crypto
source: hosted
version: "0.9.0"
csslib:
description: csslib
source: hosted
version: "0.12.0+1"
dart_style:
description: dart_style
source: hosted
version: "0.1.8"
glob:
description: glob
source: hosted
version: "1.0.4"
grinder:
description: grinder
source: hosted
version: "0.7.0-dev.1"
version: "0.7.1+3"
html:
description: html
source: hosted
version: "0.12.1+1"
http:
description: http
source: hosted
version: "0.11.2"
http_multi_server:
description: http_multi_server
source: hosted
version: "1.3.2"
http_parser:
description: http_parser
source: hosted
Expand All @@ -37,54 +89,142 @@ packages:
description: http_server
source: hosted
version: "0.9.5+1"
linter:
description: linter
initialize:
description: initialize
source: hosted
version: "0.0.2+1"
version: "0.6.1"
intl:
description: intl
source: hosted
version: "0.12.4"
logging:
description: logging
source: hosted
version: "0.9.3"
version: "0.11.1"
matcher:
description: matcher
source: hosted
version: "0.11.4+4"
version: "0.12.0+1"
mime:
description: mime
source: hosted
version: "0.9.3"
mockable_filesystem:
description: mockable_filesystem
source: hosted
version: "0.0.3"
observe:
description: observe
source: hosted
version: "0.13.1+1"
path:
description: path
source: hosted
version: "1.3.4"
version: "1.3.5"
petitparser:
description: petitparser
source: hosted
version: "1.3.7"
version: "1.4.3"
polymer:
description: polymer
source: hosted
version: "0.16.3+3"
polymer_expressions:
description: polymer_expressions
source: hosted
version: "0.13.1"
polymer_interop:
description: polymer_interop
source: hosted
version: "0.1.1"
pool:
description: pool
source: hosted
version: "1.0.2"
pub_semver:
description: pub_semver
source: hosted
version: "1.2.1"
quiver:
description: quiver
source: hosted
version: "0.21.4"
quiver_log:
description: quiver_log
source: hosted
version: "1.0.3"
shelf:
description: shelf
source: hosted
version: "0.6.1+1"
version: "0.6.1+2"
shelf_static:
description: shelf_static
source: hosted
version: "0.2.2"
shelf_web_socket:
description: shelf_web_socket
source: hosted
version: "0.0.1+2"
smoke:
description: smoke
source: hosted
version: "0.3.3+1"
source_map_stack_trace:
description: source_map_stack_trace
source: hosted
version: "1.0.4"
source_maps:
description: source_maps
source: hosted
version: "0.10.1"
source_span:
description: source_span
source: hosted
version: "1.1.2"
stack_trace:
description: stack_trace
source: hosted
version: "1.2.4"
version: "1.3.2"
string_scanner:
description: string_scanner
source: hosted
version: "0.1.3+1"
unittest:
description: unittest
supports_color:
description: supports_color
source: hosted
version: "0.1.1"
template_binding:
description: template_binding
source: hosted
version: "0.14.0+2"
test:
description: test
source: hosted
version: "0.12.3"
unscripted:
description: unscripted
source: hosted
version: "0.6.1+1"
utf:
description: utf
source: hosted
version: "0.11.5+4"
version: "0.9.0+2"
watcher:
description: watcher
source: hosted
version: "0.9.5"
web_components:
description: web_components
source: hosted
version: "0.11.4+1"
webdriver:
description: webdriver
source: hosted
version: "0.10.0-pre.9"
webkit_inspection_protocol:
description: webkit_inspection_protocol
source: hosted
version: "0.0.1+1"
when:
description: when
source: hosted
Expand All @@ -96,7 +236,7 @@ packages:
xml:
description: xml
source: hosted
version: "2.2.3"
version: "2.3.2"
yaml:
description: yaml
source: hosted
Expand Down
7 changes: 2 additions & 5 deletions pubspec.yaml
Expand Up @@ -15,9 +15,6 @@ dependencies:
xml: '>=2.1.0 <3.0.0'

dev_dependencies:
unittest: '>=0.9.0 <0.13.0'
analyzer: '>=0.24.0 <0.26.0'
grinder: '>=0.7.0-dev.1 <0.8.0'
linter: '>=0.0.2 <0.1.0'
unittest: any
bwu_utils_dev: '>=0.1.0-dev.5 <0.2.0'
test: '>=0.12.0 <0.13.0'

8 changes: 4 additions & 4 deletions test/formatter_test.dart
@@ -1,15 +1,15 @@
library tentacle_response_formatter.test.formatter;
library shelf_response_formatter.test.formatter;

import 'dart:convert';
import 'package:unittest/unittest.dart';
import 'package:test/test.dart';
import 'package:shelf/shelf.dart' as shelf;
import 'package:shelf_response_formatter/shelf_response_formatter.dart';

void main() {
String BASE_URL = "http://www.test.io";
String baseUrl = "http://www.test.io";
shelf.Request createShelfRequest(String method, String path,
[Map<String, String> headers]) {
Uri uri = Uri.parse(BASE_URL + path);
Uri uri = Uri.parse(baseUrl + path);
if (headers == null) {
headers = {'accept': '*/*'};
}
Expand Down
4 changes: 2 additions & 2 deletions test/xml_converter_test.dart
@@ -1,6 +1,6 @@
library tentacle_response_formatter.test.xml_converter;
library shelf_response_formatter.test.xml_converter;

import 'package:unittest/unittest.dart';
import 'package:test/test.dart';
import 'package:shelf_response_formatter/xml_converter.dart';

void main() {
Expand Down

0 comments on commit decfffd

Please sign in to comment.