PageRenderTime 53ms CodeModel.GetById 7ms app.highlight 42ms RepoModel.GetById 1ms app.codeStats 0ms

/core/externals/update-engine/Samples/EngineRunner/ERAddTicketCommand.m

http://macfuse.googlecode.com/
Objective C | 74 lines | 36 code | 19 blank | 19 comment | 0 complexity | c91c151a87f64cf46624b076e65541f3 MD5 | raw file
 1// Copyright 2008 Google Inc.
 2//
 3// Licensed under the Apache License, Version 2.0 (the "License");
 4// you may not use this file except in compliance with the License.
 5// You may obtain a copy of the License at
 6//
 7//     http://www.apache.org/licenses/LICENSE-2.0
 8//
 9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14
15#import "ERAddTicketCommand.h"
16
17#import "KSUpdateEngine.h"
18
19
20@implementation ERAddTicketCommand
21
22- (NSString *)name {
23  return @"add";
24}  // name
25
26
27- (NSString *)blurb {
28  return @"Add a new ticket to a ticket store";
29}  // blurb
30
31
32- (NSDictionary *)requiredArguments {
33  return [NSDictionary dictionaryWithObjectsAndKeys:
34                       @"Path to the ticket store to add to", @"store",
35                       @"Product ID for the new ticket", @"productid",
36                       @"Product version for the new ticket", @"version",
37                       @"Existence checker path", @"xcpath",
38                       @"Server URL", @"url",
39                       nil];
40
41}  // requiredArguments
42
43
44- (BOOL)runWithArguments:(NSDictionary *)args {
45  // Grab the ticket store
46  NSString *storePath = [args objectForKey:@"store"];
47  KSTicketStore *ticketStore = [KSTicketStore ticketStoreWithPath:storePath];
48
49  // Extract the values for the new ticket.
50  NSString *productID = [args objectForKey:@"productid"];
51  NSString *version = [args objectForKey:@"version"];
52
53  // Make a path existence checker.  Exercise for the reader is to
54  // add support for the Spotlight / LunchServices existence checkers.
55  NSString *xcpath = [args objectForKey:@"xcpath"];
56  KSExistenceChecker *existenceChecker =
57    [KSPathExistenceChecker checkerWithPath:xcpath];
58
59  // Build the server URL.
60  NSString *urlString = [args objectForKey:@"url"];
61  NSURL *serverURL = [NSURL URLWithString:urlString];
62
63  // Now that all of the pieces are together, make the ticket.
64  KSTicket *ticket = [KSTicket ticketWithProductID:productID
65                                           version:version
66                                  existenceChecker:existenceChecker
67                                         serverURL:serverURL];
68  BOOL result = [ticketStore storeTicket:ticket];
69
70  return result;
71
72}  // runWithArguments
73
74@end  // ERAddTicketCommand