我正在尝试在命令行脚本中获取有关某些pub包的信息。
例如,也许我想知道角度2包的最后版本是什么。
我怎么能这样做?
答案 0 :(得分:4)
pub.dartlang.org提供了一个JSON API,NSString * downloadURL = @"http://192.168.1.3/getimage.php";
NSLog(@"downloadImageURL: %@", downloadURL);`
NSString *queryStringss = [NSString stringWithFormat:@"%@", downloadURL];
queryStringss = [queryStringss stringByAddingPercentEncodingWithAllowedCharacters:[NSCharacterSet URLQueryAllowedCharacterSet]];
_manager = [AFHTTPRequestOperationManager manager];
_manager.responseSerializer=[AFJSONResponseSerializer serializerWithReadingOptions:NSJSONReadingAllowFragments];`
NSString *usernameEncoded = marker.title;
NSDictionary *params = @{@"username": usernameEncoded, @"count": [object valueForKey:@"count"]};
NSMutableURLRequest *request = [[AFHTTPRequestSerializer serializer] requestWithMethod:@"POST" URLString:downloadURL parameters:params error:&error];
AFHTTPRequestOperation *requestOperation = [_manager HTTPRequestOperationWithRequest:request success:^(AFHTTPRequestOperation *operation, id responseObject) {
NSLog(@"operation success: %@\n %@", operation, responseObject);
NSData *decodedData = [[NSData alloc] initWithBase64EncodedString:responseObject[@"image"] options:0];
image.image = [UIImage imageWithData:decodedData scale:300/2448];
dispatch_async(dispatch_get_main_queue(), ^(void){
[progBar setHidden:YES];
[image setHidden:NO];
[respondButton setHidden:NO];
[xButton setHidden:NO];
});
} failure:^(AFHTTPRequestOperation *operation, NSError *error) {
NSLog(@"Error: %@", error);
}];
[requestOperation setDownloadProgressBlock:^(NSUInteger bytesRead, long long totalBytesRead, long long totalBytesExpectedToRead) {
progBar.hidden = NO;
double percentDone = ((double)totalBytesRead / (double)totalBytesExpectedToRead) * -.000001;
NSLog(@"progress updated(percentDone) : %f", percentDone);
[progBar setProgress:percentDone];
}];
[requestOperation start];
命令行工具也使用它。还有https://pub.dartlang.org/packages/pub_client和https://pub.dartlang.org/packages/bwu_pub_client为pub.dartlang.org提供了Dart API。有关更多详细信息,请参阅上面链接的包的来源。