OSDN Git Service

/kcsapi/api_get_master/maparea に対応
authormasakih <masakih@users.sourceforge.jp>
Sun, 16 Feb 2014 07:27:08 +0000 (16:27 +0900)
committermasakih <masakih@users.sourceforge.jp>
Sun, 16 Feb 2014 07:27:08 +0000 (16:27 +0900)
KCD.xcodeproj/project.pbxproj
KCD/HMMasterMapAreaCommand.h [new file with mode: 0644]
KCD/HMMasterMapAreaCommand.m [new file with mode: 0644]
KCD/KCD.xcdatamodeld/KCD.xcdatamodel/contents

index 833b47d..926cd84 100644 (file)
@@ -14,6 +14,7 @@
                F46F104918ABAC910063E503 /* KCD.xcdatamodeld in Sources */ = {isa = PBXBuildFile; fileRef = F46F104718ABAC910063E503 /* KCD.xcdatamodeld */; };
                F47B78B218A7B42B0011386E /* HMJSONViewWindowController.m in Sources */ = {isa = PBXBuildFile; fileRef = F47B78B018A7B42B0011386E /* HMJSONViewWindowController.m */; };
                F47B78B318A7B42B0011386E /* HMJSONViewWindowController.xib in Resources */ = {isa = PBXBuildFile; fileRef = F47B78B118A7B42B0011386E /* HMJSONViewWindowController.xib */; };
+               F4B414E918B09A4B00468DAF /* HMMasterMapAreaCommand.m in Sources */ = {isa = PBXBuildFile; fileRef = F4B414E818B09A4B00468DAF /* HMMasterMapAreaCommand.m */; };
                F4BDEB47187252F30069D0CE /* Cocoa.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = F4BDEB46187252F30069D0CE /* Cocoa.framework */; };
                F4BDEB51187252F30069D0CE /* InfoPlist.strings in Resources */ = {isa = PBXBuildFile; fileRef = F4BDEB4F187252F30069D0CE /* InfoPlist.strings */; };
                F4BDEB53187252F30069D0CE /* main.m in Sources */ = {isa = PBXBuildFile; fileRef = F4BDEB52187252F30069D0CE /* main.m */; };
@@ -62,6 +63,8 @@
                F47B78AF18A7B42B0011386E /* HMJSONViewWindowController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = HMJSONViewWindowController.h; sourceTree = "<group>"; };
                F47B78B018A7B42B0011386E /* HMJSONViewWindowController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = HMJSONViewWindowController.m; sourceTree = "<group>"; };
                F47B78B118A7B42B0011386E /* HMJSONViewWindowController.xib */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.xib; path = HMJSONViewWindowController.xib; sourceTree = "<group>"; };
+               F4B414E718B09A4B00468DAF /* HMMasterMapAreaCommand.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = HMMasterMapAreaCommand.h; sourceTree = "<group>"; };
+               F4B414E818B09A4B00468DAF /* HMMasterMapAreaCommand.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = HMMasterMapAreaCommand.m; sourceTree = "<group>"; };
                F4BDEB43187252F30069D0CE /* KCD.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = KCD.app; sourceTree = BUILT_PRODUCTS_DIR; };
                F4BDEB46187252F30069D0CE /* Cocoa.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Cocoa.framework; path = System/Library/Frameworks/Cocoa.framework; sourceTree = SDKROOT; };
                F4BDEB49187252F30069D0CE /* AppKit.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = AppKit.framework; path = System/Library/Frameworks/AppKit.framework; sourceTree = SDKROOT; };
                                F4D2CBC118AD0E1A000EBC59 /* HMMasterSTypeCommand.m */,
                                F4D2CBC918B05E58000EBC59 /* HMMaserShipCommand.h */,
                                F4D2CBCA18B05E58000EBC59 /* HMMaserShipCommand.m */,
+                               F4B414E718B09A4B00468DAF /* HMMasterMapAreaCommand.h */,
+                               F4B414E818B09A4B00468DAF /* HMMasterMapAreaCommand.m */,
                        );
                        name = Command;
                        sourceTree = "<group>";
                                F4D2CBCB18B05E58000EBC59 /* HMMaserShipCommand.m in Sources */,
                                F46F104118A9B85E0063E503 /* HMJSONNode.m in Sources */,
                                F4C1190818A746EB005D5B25 /* HMJSONTracker.m in Sources */,
+                               F4B414E918B09A4B00468DAF /* HMMasterMapAreaCommand.m in Sources */,
                                F4C118FB18A67B1C005D5B25 /* CanonicalRequest.m in Sources */,
                                F4BDEB5A187252F30069D0CE /* HMAppDelegate.m in Sources */,
                                F46F104918ABAC910063E503 /* KCD.xcdatamodeld in Sources */,
diff --git a/KCD/HMMasterMapAreaCommand.h b/KCD/HMMasterMapAreaCommand.h
new file mode 100644 (file)
index 0000000..c82648b
--- /dev/null
@@ -0,0 +1,13 @@
+//
+//  HMMasterMapAreaCommand.h
+//  KCD
+//
+//  Created by Hori,Masaki on 2014/02/16.
+//  Copyright (c) 2014年 Hori,Masaki. All rights reserved.
+//
+
+#import "HMJSONCommand.h"
+
+@interface HMMasterMapAreaCommand : HMJSONCommand
+
+@end
diff --git a/KCD/HMMasterMapAreaCommand.m b/KCD/HMMasterMapAreaCommand.m
new file mode 100644 (file)
index 0000000..43a44e0
--- /dev/null
@@ -0,0 +1,62 @@
+//
+//  HMMasterMapAreaCommand.m
+//  KCD
+//
+//  Created by Hori,Masaki on 2014/02/16.
+//  Copyright (c) 2014年 Hori,Masaki. All rights reserved.
+//
+
+#import "HMMasterMapAreaCommand.h"
+
+@implementation HMMasterMapAreaCommand
++ (void)load
+{
+       static dispatch_once_t onceToken;
+       dispatch_once(&onceToken, ^{
+               [HMJSONCommand registerClass:self];
+       });
+}
+
++ (BOOL)canExcuteAPI:(NSString *)api
+{
+       return [api isEqualToString:@"/kcsapi/api_get_master/maparea"];
+}
+- (void)execute
+{
+       NSArray *api_data = [self.json objectForKey:@"api_data"];
+       if(![api_data isKindOfClass:[NSArray class]]) {
+               [self log:@"api_data is NOT NSArray."];
+               return;
+       }
+       
+       NSManagedObjectContext *managedObjectContext = [[NSApp delegate] managedObjectContext];
+       
+       for(NSDictionary *type in api_data) {
+               NSString *stypeID = type[@"api_id"];
+               NSFetchRequest *req = [NSFetchRequest fetchRequestWithEntityName:@"MasterMapArea"];
+               NSPredicate *predicate = [NSPredicate predicateWithFormat:@"id = %@", stypeID];
+               [req setPredicate:predicate];
+               NSError *error = nil;
+               id result = [managedObjectContext executeFetchRequest:req
+                                                                                                               error:&error];
+               if(error) {
+                       [self log:@"Fetch error: %@", error];
+                       continue;
+               }
+               NSManagedObject *object = nil;
+               if(!result || [result count] == 0) {
+                       object = [NSEntityDescription insertNewObjectForEntityForName:@"MasterMapArea"
+                                                                                                  inManagedObjectContext:managedObjectContext];
+               } else {
+                       object = result[0];
+               }
+               
+               for(NSString *key in type) {
+                       id value = type[key];
+                       if([object validateValue:&value forKey:key error:NULL]) {
+                               [object setValue:value forKey:key];
+                       }
+               }
+       }
+}
+@end
index 7a74819..d30e197 100644 (file)
@@ -1,5 +1,10 @@
 <?xml version="1.0" encoding="UTF-8" standalone="yes"?>
 <model userDefinedModelVersionIdentifier="" type="com.apple.IDECoreDataModeler.DataModel" documentVersion="1.0" lastSavedToolsVersion="3401" systemVersion="13B42" minimumToolsVersion="Xcode 4.3" macOSVersion="Automatic" iOSVersion="Automatic">
+    <entity name="MasterMapArea" representedClassName="HMKCManagedObject" syncable="YES">
+        <attribute name="id" attributeType="Integer 32" syncable="YES"/>
+        <attribute name="name" attributeType="String" syncable="YES"/>
+        <attribute name="type" optional="YES" attributeType="Integer 32" syncable="YES"/>
+    </entity>
     <entity name="MasterShip" representedClassName="HMKCManagedObject" syncable="YES">
         <attribute name="afterbull" attributeType="Integer 32" syncable="YES"/>
         <attribute name="afterfuel" attributeType="Integer 32" syncable="YES"/>
@@ -62,7 +67,8 @@
         <relationship name="ships" optional="YES" toMany="YES" deletionRule="Nullify" destinationEntity="MasterShip" inverseName="stype" inverseEntity="MasterShip" syncable="YES"/>
     </entity>
     <elements>
-        <element name="MasterSType" positionX="0" positionY="0" width="0" height="0"/>
         <element name="MasterShip" positionX="0" positionY="0" width="0" height="0"/>
+        <element name="MasterSType" positionX="0" positionY="0" width="0" height="0"/>
+        <element name="MasterMapArea" positionX="0" positionY="0" width="0" height="0"/>
     </elements>
 </model>
\ No newline at end of file