Skip to content

Commit

Permalink
Add Public Key Management
Browse files Browse the repository at this point in the history
  • Loading branch information
azenla committed Aug 24, 2014
1 parent 15a184a commit 63a0d6b
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 4 deletions.
6 changes: 2 additions & 4 deletions lib/common.dart
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,6 @@ import 'package:crypto/crypto.dart' show CryptoUtils;
import "package:html5lib/parser.dart" as htmlParser;
import "package:html5lib/dom.dart" as html;

import 'package:quiver/async.dart';
import 'package:quiver/streams.dart';

import 'http.dart' as http;

import 'src/common/util.dart';
Expand Down Expand Up @@ -38,4 +35,5 @@ part 'src/common/watchers.dart';
part 'src/common/trending.dart';
part 'src/common/pagination.dart';
part 'src/common/search.dart';
part 'src/common/events.dart';
part 'src/common/events.dart';
part 'src/common/keys.dart';
9 changes: 9 additions & 0 deletions lib/src/common/github.dart
Original file line number Diff line number Diff line change
Expand Up @@ -386,6 +386,15 @@ class GitHub {
return getJSON("/repos/${slug.fullName}/subscription", statusCode: 200, convert: RepositorySubscription.fromJSON);
}

Stream<PublicKey> publicKeys([String user]) {
var path = user == null ? "/user/keys" : "/users/${user}/keys";
return new PaginationHelper(this).objects("GET", path, PublicKey.fromJSON);
}

Future<PublicKey> createPublicKey(CreatePublicKey request) {
return postJSON("/user/keys", body: request.toJSON());
}

/**
* Search for Repositories using [query].
*
Expand Down
33 changes: 33 additions & 0 deletions lib/src/common/keys.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
part of github.common;

class PublicKey {
final GitHub github;

int id;
String key;
String title;

PublicKey(this.github);

static PublicKey fromJSON(GitHub github, input) {
if (input == null) return null;
return new PublicKey(github)
..id = input['id']
..key = input['key']
..title = input['title'];
}
}

class CreatePublicKey {
final String title;
final String key;

CreatePublicKey(this.title, this.key);

String toJSON() {
var map = {};
putValue("title", title, map);
putValue("key", key, map);
return JSON.encode(map);
}
}

0 comments on commit 63a0d6b

Please sign in to comment.