Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

重构

  • Loading branch information...
commit 5b3edf12a4d41091417bef153fcb02bb1bea817e 1 parent fd49c50
@lincode lincode authored
Showing with 1,165 additions and 813 deletions.
  1. +49 −21 DoubanAPIEngine/DoubanAPIEngine.xcodeproj/project.pbxproj
  2. +10 −0 DoubanAPIEngine/DoubanAPIEngine/OtherSources/JSON/JSON.h
  3. +2 −2 DoubanAPIEngine/DoubanAPIEngine/OtherSources/JSON/NSObject+SBJson.m
  4. +7 −1 DoubanAPIEngine/DoubanAPIEngine/OtherSources/JSON/SBJsonParser.h
  5. +7 −3 DoubanAPIEngine/DoubanAPIEngine/OtherSources/JSON/SBJsonParser.m
  6. +9 −3 DoubanAPIEngine/DoubanAPIEngine/OtherSources/JSON/SBJsonStreamParser.h
  7. +99 −108 DoubanAPIEngine/DoubanAPIEngine/OtherSources/JSON/SBJsonStreamParser.m
  8. +5 −2 DoubanAPIEngine/DoubanAPIEngine/OtherSources/JSON/SBJsonStreamParserAccumulator.h
  9. +6 −2 DoubanAPIEngine/DoubanAPIEngine/OtherSources/JSON/SBJsonStreamParserAccumulator.m
  10. +7 −7 DoubanAPIEngine/DoubanAPIEngine/OtherSources/JSON/SBJsonStreamParserAdapter.h
  11. +15 −8 DoubanAPIEngine/DoubanAPIEngine/OtherSources/JSON/SBJsonStreamParserAdapter.m
  12. +0 −2  DoubanAPIEngine/DoubanAPIEngine/OtherSources/JSON/SBJsonStreamParserState.h
  13. +0 −8 DoubanAPIEngine/DoubanAPIEngine/OtherSources/JSON/SBJsonStreamParserState.m
  14. +10 −4 DoubanAPIEngine/DoubanAPIEngine/OtherSources/JSON/SBJsonStreamWriter.h
  15. +26 −17 DoubanAPIEngine/DoubanAPIEngine/OtherSources/JSON/SBJsonStreamWriter.m
  16. +5 −2 DoubanAPIEngine/DoubanAPIEngine/OtherSources/JSON/SBJsonStreamWriterAccumulator.h
  17. +4 −0 DoubanAPIEngine/DoubanAPIEngine/OtherSources/JSON/SBJsonStreamWriterAccumulator.m
  18. +5 −2 DoubanAPIEngine/DoubanAPIEngine/OtherSources/JSON/SBJsonTokeniser.h
  19. +42 −46 DoubanAPIEngine/DoubanAPIEngine/OtherSources/JSON/SBJsonTokeniser.m
  20. +2 −1  DoubanAPIEngine/DoubanAPIEngine/OtherSources/JSON/SBJsonUTF8Stream.h
  21. +9 −5 DoubanAPIEngine/DoubanAPIEngine/OtherSources/JSON/SBJsonUTF8Stream.m
  22. +6 −1 DoubanAPIEngine/DoubanAPIEngine/OtherSources/JSON/SBJsonWriter.h
  23. +7 −3 DoubanAPIEngine/DoubanAPIEngine/OtherSources/JSON/SBJsonWriter.m
  24. +2 −1  DoubanAPIEngine/DoubanAPIEngine/Sources/DOUAPIConfig.h
  25. +6 −4 DoubanAPIEngine/DoubanAPIEngine/Sources/DOUAPIConfig.m
  26. +6 −5 DoubanAPIEngine/DoubanAPIEngine/Sources/DOUAPIEngine.h
  27. +19 −0 DoubanAPIEngine/DoubanAPIEngine/Sources/GDataDoubanWrapper/Clients/Event/DoubanEntryCity.m
  28. +3 −3 DoubanAPIEngine/DoubanAPIEngine/Sources/Network/DOUHttpRequest.h
  29. +4 −1 DoubanAPIEngine/DoubanAPIEngine/Sources/Network/DOUHttpRequest.m
  30. +2 −0  DoubanAPIEngine/DoubanAPIEngine/Sources/Network/DOUQuery.h
  31. +2 −2 DoubanAPIEngine/DoubanAPIEngine/Sources/Network/DOUQuery.m
  32. +17 −49 DoubanAPIEngine/DoubanAPIEngine/Sources/Network/DOUService.h
  33. +110 −110 DoubanAPIEngine/DoubanAPIEngine/Sources/Network/DOUService.m
  34. +0 −2  DoubanAPIEngine/DoubanAPIEngine/Sources/OAuth2/DOUOAuth2.h
  35. +0 −47 DoubanAPIEngine/DoubanAPIEngine/Sources/OAuth2/DOUOAuth2Provider.h
  36. +0 −198 DoubanAPIEngine/DoubanAPIEngine/Sources/OAuth2/DOUOAuth2Provider.m
  37. +72 −0 DoubanAPIEngine/DoubanAPIEngine/Sources/OAuth2/DOUOAuthService.h
  38. +247 −0 DoubanAPIEngine/DoubanAPIEngine/Sources/OAuth2/DOUOAuthService.m
  39. +7 −19 DoubanAPIEngine/DoubanAPIEngine/Sources/OAuth2/{DOUOAuth2Consumer.h → DOUOAuthStore.h}
  40. +81 −77 DoubanAPIEngine/DoubanAPIEngine/Sources/OAuth2/{DOUOAuth2Consumer.m → DOUOAuthStore.m}
  41. +64 −0 DoubanAPIEngine/DoubanAPIEngineTests/DOUOAuthServiceTests.m
  42. +37 −0 DoubanAPIEngine/DoubanAPIEngineTests/Testing/DOUTestResponseLoader.h
  43. +115 −0 DoubanAPIEngine/DoubanAPIEngineTests/Testing/DOUTestResponseLoader.m
  44. +0 −4 DoubanAPIEngineDemo/DoubanAPIEngineDemo.xcodeproj/project.pbxproj
  45. +3 −3 DoubanAPIEngineDemo/DoubanAPIEngineDemo/AppDelegate.m
  46. +2 −0  DoubanAPIEngineDemo/DoubanAPIEngineDemo/GetEventController.m
  47. +7 −2 DoubanAPIEngineDemo/DoubanAPIEngineDemo/NavController.m
  48. +2 −2 DoubanAPIEngineDemo/DoubanAPIEngineDemo/WebViewController.h
  49. +22 −8 DoubanAPIEngineDemo/DoubanAPIEngineDemo/WebViewController.m
  50. +3 −28 README.markdown
View
70 DoubanAPIEngine/DoubanAPIEngine.xcodeproj/project.pbxproj
@@ -17,10 +17,6 @@
D800D56E146908AF009F64FD /* DOUHttpRequest.h in Headers */ = {isa = PBXBuildFile; fileRef = D800D565146908AF009F64FD /* DOUHttpRequest.h */; };
D800D56F146908AF009F64FD /* DOUHttpRequest.m in Sources */ = {isa = PBXBuildFile; fileRef = D800D566146908AF009F64FD /* DOUHttpRequest.m */; };
D800D570146908AF009F64FD /* DOUOAuth2.h in Headers */ = {isa = PBXBuildFile; fileRef = D800D568146908AF009F64FD /* DOUOAuth2.h */; };
- D800D571146908AF009F64FD /* DOUOAuth2Consumer.h in Headers */ = {isa = PBXBuildFile; fileRef = D800D569146908AF009F64FD /* DOUOAuth2Consumer.h */; };
- D800D572146908AF009F64FD /* DOUOAuth2Consumer.m in Sources */ = {isa = PBXBuildFile; fileRef = D800D56A146908AF009F64FD /* DOUOAuth2Consumer.m */; };
- D800D573146908AF009F64FD /* DOUOAuth2Provider.h in Headers */ = {isa = PBXBuildFile; fileRef = D800D56B146908AF009F64FD /* DOUOAuth2Provider.h */; };
- D800D574146908AF009F64FD /* DOUOAuth2Provider.m in Sources */ = {isa = PBXBuildFile; fileRef = D800D56C146908AF009F64FD /* DOUOAuth2Provider.m */; };
D800D5C9146908FD009F64FD /* ASIAuthenticationDialog.h in Headers */ = {isa = PBXBuildFile; fileRef = D800D577146908FD009F64FD /* ASIAuthenticationDialog.h */; };
D800D5CA146908FD009F64FD /* ASIAuthenticationDialog.m in Sources */ = {isa = PBXBuildFile; fileRef = D800D578146908FD009F64FD /* ASIAuthenticationDialog.m */; };
D800D5CB146908FD009F64FD /* ASICacheDelegate.h in Headers */ = {isa = PBXBuildFile; fileRef = D800D579146908FD009F64FD /* ASICacheDelegate.h */; };
@@ -235,6 +231,12 @@
D858E04714C3AC0D00335280 /* DOUQuery.m in Sources */ = {isa = PBXBuildFile; fileRef = D858E04514C3AC0D00335280 /* DOUQuery.m */; };
D858E04E14C3DA9100335280 /* DOUService.h in Headers */ = {isa = PBXBuildFile; fileRef = D858E04C14C3DA9100335280 /* DOUService.h */; };
D858E04F14C3DA9100335280 /* DOUService.m in Sources */ = {isa = PBXBuildFile; fileRef = D858E04D14C3DA9100335280 /* DOUService.m */; };
+ D882161015889C5F004B4AD4 /* DOUOAuthService.h in Headers */ = {isa = PBXBuildFile; fileRef = D882160C15889C5F004B4AD4 /* DOUOAuthService.h */; };
+ D882161115889C5F004B4AD4 /* DOUOAuthService.m in Sources */ = {isa = PBXBuildFile; fileRef = D882160D15889C5F004B4AD4 /* DOUOAuthService.m */; };
+ D882161215889C5F004B4AD4 /* DOUOAuthStore.h in Headers */ = {isa = PBXBuildFile; fileRef = D882160E15889C5F004B4AD4 /* DOUOAuthStore.h */; };
+ D882161315889C5F004B4AD4 /* DOUOAuthStore.m in Sources */ = {isa = PBXBuildFile; fileRef = D882160F15889C5F004B4AD4 /* DOUOAuthStore.m */; };
+ D882161915889DDE004B4AD4 /* DOUOAuthServiceTests.m in Sources */ = {isa = PBXBuildFile; fileRef = D882161415889DDE004B4AD4 /* DOUOAuthServiceTests.m */; };
+ D882161B15889DDE004B4AD4 /* DOUTestResponseLoader.m in Sources */ = {isa = PBXBuildFile; fileRef = D882161815889DDE004B4AD4 /* DOUTestResponseLoader.m */; };
D8839940149F14EF00099D23 /* DoubanPhotoTests.m in Sources */ = {isa = PBXBuildFile; fileRef = D883993F149F14EF00099D23 /* DoubanPhotoTests.m */; };
D8839941149F185E00099D23 /* DoubanEntryPhoto.xml in Resources */ = {isa = PBXBuildFile; fileRef = D883993B149F143C00099D23 /* DoubanEntryPhoto.xml */; };
D8839942149F186100099D23 /* DoubanFeedPhoto.xml in Resources */ = {isa = PBXBuildFile; fileRef = D883993C149F143C00099D23 /* DoubanFeedPhoto.xml */; };
@@ -319,10 +321,6 @@
D800D565146908AF009F64FD /* DOUHttpRequest.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = DOUHttpRequest.h; sourceTree = "<group>"; };
D800D566146908AF009F64FD /* DOUHttpRequest.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = DOUHttpRequest.m; sourceTree = "<group>"; };
D800D568146908AF009F64FD /* DOUOAuth2.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = DOUOAuth2.h; sourceTree = "<group>"; };
- D800D569146908AF009F64FD /* DOUOAuth2Consumer.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = DOUOAuth2Consumer.h; sourceTree = "<group>"; };
- D800D56A146908AF009F64FD /* DOUOAuth2Consumer.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = DOUOAuth2Consumer.m; sourceTree = "<group>"; };
- D800D56B146908AF009F64FD /* DOUOAuth2Provider.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = DOUOAuth2Provider.h; sourceTree = "<group>"; };
- D800D56C146908AF009F64FD /* DOUOAuth2Provider.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = DOUOAuth2Provider.m; sourceTree = "<group>"; };
D800D577146908FD009F64FD /* ASIAuthenticationDialog.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ASIAuthenticationDialog.h; sourceTree = "<group>"; };
D800D578146908FD009F64FD /* ASIAuthenticationDialog.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = ASIAuthenticationDialog.m; sourceTree = "<group>"; };
D800D579146908FD009F64FD /* ASICacheDelegate.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ASICacheDelegate.h; sourceTree = "<group>"; };
@@ -531,6 +529,13 @@
D858E04514C3AC0D00335280 /* DOUQuery.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = DOUQuery.m; sourceTree = "<group>"; };
D858E04C14C3DA9100335280 /* DOUService.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = DOUService.h; sourceTree = "<group>"; };
D858E04D14C3DA9100335280 /* DOUService.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = DOUService.m; sourceTree = "<group>"; };
+ D882160C15889C5F004B4AD4 /* DOUOAuthService.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = DOUOAuthService.h; sourceTree = "<group>"; };
+ D882160D15889C5F004B4AD4 /* DOUOAuthService.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = DOUOAuthService.m; sourceTree = "<group>"; };
+ D882160E15889C5F004B4AD4 /* DOUOAuthStore.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = DOUOAuthStore.h; sourceTree = "<group>"; };
+ D882160F15889C5F004B4AD4 /* DOUOAuthStore.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = DOUOAuthStore.m; sourceTree = "<group>"; };
+ D882161415889DDE004B4AD4 /* DOUOAuthServiceTests.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = DOUOAuthServiceTests.m; sourceTree = "<group>"; };
+ D882161715889DDE004B4AD4 /* DOUTestResponseLoader.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = DOUTestResponseLoader.h; sourceTree = "<group>"; };
+ D882161815889DDE004B4AD4 /* DOUTestResponseLoader.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = DOUTestResponseLoader.m; sourceTree = "<group>"; };
D883993B149F143C00099D23 /* DoubanEntryPhoto.xml */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.xml; path = DoubanEntryPhoto.xml; sourceTree = "<group>"; };
D883993C149F143C00099D23 /* DoubanFeedPhoto.xml */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.xml; path = DoubanFeedPhoto.xml; sourceTree = "<group>"; };
D883993F149F14EF00099D23 /* DoubanPhotoTests.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = DoubanPhotoTests.m; sourceTree = "<group>"; };
@@ -580,7 +585,6 @@
D8D28D5814A81F99003570B0 /* DoubanFeedEventCategory.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = DoubanFeedEventCategory.m; sourceTree = "<group>"; };
D8D28D5C14A82356003570B0 /* DoubanFeedEventCategory.xml */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.xml; path = DoubanFeedEventCategory.xml; sourceTree = "<group>"; };
D8D28D5D14A825DC003570B0 /* DoubanEventCategoryTests.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = DoubanEventCategoryTests.m; sourceTree = "<group>"; };
- D8D58D91148DC01400741BF5 /* README.markdown */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; name = README.markdown; path = ../README.markdown; sourceTree = "<group>"; };
D8D8C66814D45EF70084D6E9 /* GDataEntryBase+Extension.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "GDataEntryBase+Extension.h"; sourceTree = "<group>"; };
D8D8C66914D45EF70084D6E9 /* GDataEntryBase+Extension.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "GDataEntryBase+Extension.m"; sourceTree = "<group>"; };
D8DEDC5514D0D2C300500C56 /* GDataAtomAuthor+Extension.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "GDataAtomAuthor+Extension.h"; sourceTree = "<group>"; };
@@ -632,7 +636,6 @@
D800D52D146907B2009F64FD = {
isa = PBXGroup;
children = (
- D8D58D91148DC01400741BF5 /* README.markdown */,
D800D53D146907B2009F64FD /* DoubanAPIEngine */,
D800D551146907B2009F64FD /* DoubanAPIEngineTests */,
D800D53A146907B2009F64FD /* Frameworks */,
@@ -687,6 +690,8 @@
D800D551146907B2009F64FD /* DoubanAPIEngineTests */ = {
isa = PBXGroup;
children = (
+ D882161415889DDE004B4AD4 /* DOUOAuthServiceTests.m */,
+ D882161615889DDE004B4AD4 /* Testing */,
D88EAF3514692D9400A4DE43 /* Resources */,
D8CFD433151C5C5200CCC311 /* DoubanCommentTests.m */,
D883996F149F479A00099D23 /* DoubanRecommendationTests.m */,
@@ -742,11 +747,11 @@
D800D567146908AF009F64FD /* OAuth2 */ = {
isa = PBXGroup;
children = (
+ D882160C15889C5F004B4AD4 /* DOUOAuthService.h */,
+ D882160D15889C5F004B4AD4 /* DOUOAuthService.m */,
+ D882160E15889C5F004B4AD4 /* DOUOAuthStore.h */,
+ D882160F15889C5F004B4AD4 /* DOUOAuthStore.m */,
D800D568146908AF009F64FD /* DOUOAuth2.h */,
- D800D569146908AF009F64FD /* DOUOAuth2Consumer.h */,
- D800D56A146908AF009F64FD /* DOUOAuth2Consumer.m */,
- D800D56B146908AF009F64FD /* DOUOAuth2Provider.h */,
- D800D56C146908AF009F64FD /* DOUOAuth2Provider.m */,
);
path = OAuth2;
sourceTree = "<group>";
@@ -1130,6 +1135,15 @@
path = Elements;
sourceTree = "<group>";
};
+ D882161615889DDE004B4AD4 /* Testing */ = {
+ isa = PBXGroup;
+ children = (
+ D882161715889DDE004B4AD4 /* DOUTestResponseLoader.h */,
+ D882161815889DDE004B4AD4 /* DOUTestResponseLoader.m */,
+ );
+ path = Testing;
+ sourceTree = "<group>";
+ };
D883995A149F41DA00099D23 /* Recommendation */ = {
isa = PBXGroup;
children = (
@@ -1207,8 +1221,6 @@
D800D56D146908AF009F64FD /* DOUAPIEngine.h in Headers */,
D800D56E146908AF009F64FD /* DOUHttpRequest.h in Headers */,
D800D570146908AF009F64FD /* DOUOAuth2.h in Headers */,
- D800D571146908AF009F64FD /* DOUOAuth2Consumer.h in Headers */,
- D800D573146908AF009F64FD /* DOUOAuth2Provider.h in Headers */,
D800D5C9146908FD009F64FD /* ASIAuthenticationDialog.h in Headers */,
D800D5CB146908FD009F64FD /* ASICacheDelegate.h in Headers */,
D800D5CC146908FD009F64FD /* ASIDataCompressor.h in Headers */,
@@ -1329,6 +1341,8 @@
D8EC0049151C274600A7066F /* DoubanFeedComment.h in Headers */,
D8CFD43F151C757200CCC311 /* NSString+Base64Encoding.h in Headers */,
D8CFD443151C760700CCC311 /* NSData+Base64Decoding.h in Headers */,
+ D882161015889C5F004B4AD4 /* DOUOAuthService.h in Headers */,
+ D882161215889C5F004B4AD4 /* DOUOAuthStore.h in Headers */,
);
runOnlyForDeploymentPostprocessing = 0;
};
@@ -1377,7 +1391,7 @@
D800D52F146907B2009F64FD /* Project object */ = {
isa = PBXProject;
attributes = {
- LastUpgradeCheck = 0420;
+ LastUpgradeCheck = 0430;
ORGANIZATIONNAME = "Douban Inc";
};
buildConfigurationList = D800D532146907B2009F64FD /* Build configuration list for PBXProject "DoubanAPIEngine" */;
@@ -1447,8 +1461,6 @@
buildActionMask = 2147483647;
files = (
D800D56F146908AF009F64FD /* DOUHttpRequest.m in Sources */,
- D800D572146908AF009F64FD /* DOUOAuth2Consumer.m in Sources */,
- D800D574146908AF009F64FD /* DOUOAuth2Provider.m in Sources */,
D800D5CA146908FD009F64FD /* ASIAuthenticationDialog.m in Sources */,
D800D5CD146908FD009F64FD /* ASIDataCompressor.m in Sources */,
D800D5CF146908FD009F64FD /* ASIDataDecompressor.m in Sources */,
@@ -1561,6 +1573,8 @@
D8EC004A151C274600A7066F /* DoubanFeedComment.m in Sources */,
D8CFD440151C757200CCC311 /* NSString+Base64Encoding.m in Sources */,
D8CFD444151C760700CCC311 /* NSData+Base64Decoding.m in Sources */,
+ D882161115889C5F004B4AD4 /* DOUOAuthService.m in Sources */,
+ D882161315889C5F004B4AD4 /* DOUOAuthStore.m in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
@@ -1578,6 +1592,8 @@
D8D28D5E14A825DC003570B0 /* DoubanEventCategoryTests.m in Sources */,
D815D1CE14A9A6F4008BD224 /* DoubanCityTests.m in Sources */,
D8CFD435151C5C7A00CCC311 /* DoubanCommentTests.m in Sources */,
+ D882161915889DDE004B4AD4 /* DOUOAuthServiceTests.m in Sources */,
+ D882161B15889DDE004B4AD4 /* DOUTestResponseLoader.m in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
@@ -1607,7 +1623,10 @@
isa = XCBuildConfiguration;
buildSettings = {
ALWAYS_SEARCH_USER_PATHS = NO;
- ARCHS = "$(ARCHS_STANDARD_32_BIT)";
+ ARCHS = (
+ armv6,
+ "$(ARCHS_STANDARD_32_BIT)",
+ );
COPY_PHASE_STRIP = NO;
GCC_C_LANGUAGE_STANDARD = gnu99;
GCC_DYNAMIC_NO_PIC = NO;
@@ -1617,6 +1636,7 @@
"$(inherited)",
);
GCC_SYMBOLS_PRIVATE_EXTERN = NO;
+ GCC_THUMB_SUPPORT = NO;
GCC_VERSION = com.apple.compilers.llvm.clang.1_0;
GCC_WARN_ABOUT_MISSING_PROTOTYPES = YES;
GCC_WARN_ABOUT_RETURN_TYPE = YES;
@@ -1630,9 +1650,13 @@
isa = XCBuildConfiguration;
buildSettings = {
ALWAYS_SEARCH_USER_PATHS = NO;
- ARCHS = "$(ARCHS_STANDARD_32_BIT)";
+ ARCHS = (
+ armv6,
+ "$(ARCHS_STANDARD_32_BIT)",
+ );
COPY_PHASE_STRIP = YES;
GCC_C_LANGUAGE_STANDARD = gnu99;
+ GCC_THUMB_SUPPORT = NO;
GCC_VERSION = com.apple.compilers.llvm.clang.1_0;
GCC_WARN_ABOUT_MISSING_PROTOTYPES = YES;
GCC_WARN_ABOUT_RETURN_TYPE = YES;
@@ -1653,6 +1677,7 @@
DSTROOT = /tmp/DoubanAPIEngine.dst;
GCC_PRECOMPILE_PREFIX_HEADER = YES;
GCC_PREFIX_HEADER = "DoubanAPIEngine/DoubanAPIEngine-Prefix.pch";
+ GCC_THUMB_SUPPORT = NO;
GCC_VERSION = com.apple.compilers.llvm.clang.1_0;
HEADER_SEARCH_PATHS = "${SDK_DIR}/usr/include/libxml2";
ONLY_ACTIVE_ARCH = NO;
@@ -1672,6 +1697,7 @@
DSTROOT = /tmp/DoubanAPIEngine.dst;
GCC_PRECOMPILE_PREFIX_HEADER = YES;
GCC_PREFIX_HEADER = "DoubanAPIEngine/DoubanAPIEngine-Prefix.pch";
+ GCC_THUMB_SUPPORT = NO;
GCC_VERSION = com.apple.compilers.llvm.clang.1_0;
HEADER_SEARCH_PATHS = "${SDK_DIR}/usr/include/libxml2";
ONLY_ACTIVE_ARCH = NO;
@@ -1690,6 +1716,7 @@
);
GCC_PRECOMPILE_PREFIX_HEADER = YES;
GCC_PREFIX_HEADER = "DoubanAPIEngine/DoubanAPIEngine-Prefix.pch";
+ GCC_THUMB_SUPPORT = NO;
HEADER_SEARCH_PATHS = "${SDK_DIR}/usr/include/libxml2";
INFOPLIST_FILE = "DoubanAPIEngineTests/DoubanAPIEngineTests-Info.plist";
OTHER_LDFLAGS = (
@@ -1711,6 +1738,7 @@
);
GCC_PRECOMPILE_PREFIX_HEADER = YES;
GCC_PREFIX_HEADER = "DoubanAPIEngine/DoubanAPIEngine-Prefix.pch";
+ GCC_THUMB_SUPPORT = NO;
HEADER_SEARCH_PATHS = "${SDK_DIR}/usr/include/libxml2";
INFOPLIST_FILE = "DoubanAPIEngineTests/DoubanAPIEngineTests-Info.plist";
OTHER_LDFLAGS = (
View
10 DoubanAPIEngine/DoubanAPIEngine/OtherSources/JSON/JSON.h
@@ -0,0 +1,10 @@
+//
+// JSON.h
+// SBJson
+//
+// Created by Stig Brautaset on 01/06/2011.
+// Copyright 2011 Stig Brautaset. All rights reserved.
+//
+
+#warning The JSON.h header is deprecated, and will disappear in a future release. Please change to include SBJson.h instead.
+#include "SBJson.h"
View
4 DoubanAPIEngine/DoubanAPIEngine/OtherSources/JSON/NSObject+SBJson.m
@@ -34,7 +34,7 @@ OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
@implementation NSObject (NSObject_SBJsonWriting)
- (NSString *)JSONRepresentation {
- SBJsonWriter *writer = [[SBJsonWriter alloc] init];
+ SBJsonWriter *writer = [[[SBJsonWriter alloc] init] autorelease];
NSString *json = [writer stringWithObject:self];
if (!json)
NSLog(@"-JSONRepresentation failed. Error is: %@", writer.error);
@@ -48,7 +48,7 @@ - (NSString *)JSONRepresentation {
@implementation NSString (NSString_SBJsonParsing)
- (id)JSONValue {
- SBJsonParser *parser = [[SBJsonParser alloc] init];
+ SBJsonParser *parser = [[[SBJsonParser alloc] init] autorelease];
id repr = [parser objectWithString:self];
if (!repr)
NSLog(@"-JSONValue failed. Error is: %@", parser.error);
View
8 DoubanAPIEngine/DoubanAPIEngine/OtherSources/JSON/SBJsonParser.h
@@ -38,7 +38,13 @@
*/
-@interface SBJsonParser : NSObject
+@interface SBJsonParser : NSObject {
+
+@private
+ NSString *error;
+ NSUInteger depth, maxDepth;
+
+}
/**
@brief The maximum recursing depth.
View
10 DoubanAPIEngine/DoubanAPIEngine/OtherSources/JSON/SBJsonParser.m
@@ -44,6 +44,10 @@ - (id)init {
return self;
}
+- (void)dealloc {
+ [error release];
+ [super dealloc];
+}
#pragma mark Methods
@@ -54,12 +58,12 @@ - (id)objectWithData:(NSData *)data {
return nil;
}
- SBJsonStreamParserAccumulator *accumulator = [[SBJsonStreamParserAccumulator alloc] init];
+ SBJsonStreamParserAccumulator *accumulator = [[[SBJsonStreamParserAccumulator alloc] init] autorelease];
- SBJsonStreamParserAdapter *adapter = [[SBJsonStreamParserAdapter alloc] init];
+ SBJsonStreamParserAdapter *adapter = [[[SBJsonStreamParserAdapter alloc] init] autorelease];
adapter.delegate = accumulator;
- SBJsonStreamParser *parser = [[SBJsonStreamParser alloc] init];
+ SBJsonStreamParser *parser = [[[SBJsonStreamParser alloc] init] autorelease];
parser.maxDepth = self.maxDepth;
parser.delegate = adapter;
View
12 DoubanAPIEngine/DoubanAPIEngine/OtherSources/JSON/SBJsonStreamParser.h
@@ -99,11 +99,17 @@ typedef enum {
*/
@interface SBJsonStreamParser : NSObject {
@private
+ BOOL supportMultipleDocuments;
+ id<SBJsonStreamParserDelegate> delegate;
SBJsonTokeniser *tokeniser;
+ NSMutableArray *stateStack;
+ __weak SBJsonStreamParserState *state;
+ NSUInteger maxDepth;
+ NSString *error;
}
-@property (nonatomic, unsafe_unretained) SBJsonStreamParserState *state; // Private
-@property (nonatomic, readonly, strong) NSMutableArray *stateStack; // Private
+@property (nonatomic, assign) __weak SBJsonStreamParserState *state; // Private
+@property (nonatomic, readonly, retain) NSMutableArray *stateStack; // Private
/**
@brief Expect multiple documents separated by whitespace
@@ -129,7 +135,7 @@ typedef enum {
Usually this should be an instance of SBJsonStreamParserAdapter, but you can
substitute your own implementation of the SBJsonStreamParserDelegate protocol if you need to.
*/
-@property (unsafe_unretained) id<SBJsonStreamParserDelegate> delegate;
+@property (assign) id<SBJsonStreamParserDelegate> delegate;
/**
@brief The max parse depth
View
207 DoubanAPIEngine/DoubanAPIEngine/OtherSources/JSON/SBJsonStreamParser.m
@@ -58,7 +58,11 @@ - (id)init {
}
- (void)dealloc {
+ self.error = nil;
self.state = nil;
+ [stateStack release];
+ [tokeniser release];
+ [super dealloc];
}
#pragma mark Methods
@@ -130,13 +134,6 @@ - (void)handleObjectStart {
self.state = [SBJsonStreamParserStateObjectStart sharedInstance];
}
-- (void)handleObjectEnd: (sbjson_token_t) tok {
- self.state = [stateStack lastObject];
- [stateStack removeLastObject];
- [state parser:self shouldTransitionTo:tok];
- [delegate parserFoundObjectEnd:self];
-}
-
- (void)handleArrayStart {
if (stateStack.count >= maxDepth) {
[self maxDepthError];
@@ -148,108 +145,102 @@ - (void)handleArrayStart {
self.state = [SBJsonStreamParserStateArrayStart sharedInstance];
}
-- (void)handleArrayEnd: (sbjson_token_t) tok {
- self.state = [stateStack lastObject];
- [stateStack removeLastObject];
- [state parser:self shouldTransitionTo:tok];
- [delegate parserFoundArrayEnd:self];
-}
-
-- (void) handleTokenNotExpectedHere: (sbjson_token_t) tok {
- NSString *tokenName = [self tokenName:tok];
- NSString *stateName = [state name];
-
- self.error = [NSString stringWithFormat:@"Token '%@' not expected %@", tokenName, stateName];
- self.state = [SBJsonStreamParserStateError sharedInstance];
-}
-
- (SBJsonStreamParserStatus)parse:(NSData *)data_ {
- @autoreleasepool {
- [tokeniser appendData:data_];
-
- for (;;) {
-
- if ([state isError])
- return SBJsonStreamParserError;
-
- NSObject *token;
- sbjson_token_t tok = [tokeniser getToken:&token];
- switch (tok) {
- case sbjson_token_eof:
- return [state parserShouldReturn:self];
- break;
-
- case sbjson_token_error:
- self.state = [SBJsonStreamParserStateError sharedInstance];
- self.error = tokeniser.error;
- return SBJsonStreamParserError;
- break;
-
- default:
-
- if (![state parser:self shouldAcceptToken:tok]) {
- [self handleTokenNotExpectedHere: tok];
- return SBJsonStreamParserError;
- }
-
- switch (tok) {
- case sbjson_token_object_start:
- [self handleObjectStart];
- break;
-
- case sbjson_token_object_end:
- [self handleObjectEnd: tok];
- break;
-
- case sbjson_token_array_start:
- [self handleArrayStart];
- break;
-
- case sbjson_token_array_end:
- [self handleArrayEnd: tok];
- break;
-
- case sbjson_token_separator:
- case sbjson_token_keyval_separator:
- [state parser:self shouldTransitionTo:tok];
- break;
-
- case sbjson_token_true:
- [delegate parser:self foundBoolean:YES];
- [state parser:self shouldTransitionTo:tok];
- break;
-
- case sbjson_token_false:
- [delegate parser:self foundBoolean:NO];
- [state parser:self shouldTransitionTo:tok];
- break;
-
- case sbjson_token_null:
- [delegate parserFoundNull:self];
- [state parser:self shouldTransitionTo:tok];
- break;
-
- case sbjson_token_number:
- [delegate parser:self foundNumber:(NSNumber*)token];
- [state parser:self shouldTransitionTo:tok];
- break;
-
- case sbjson_token_string:
- if ([state needKey])
- [delegate parser:self foundObjectKey:(NSString*)token];
- else
- [delegate parser:self foundString:(NSString*)token];
- [state parser:self shouldTransitionTo:tok];
- break;
-
- default:
- break;
- }
- break;
- }
- }
- return SBJsonStreamParserComplete;
- }
+ [tokeniser appendData:data_];
+
+
+ for (;;) {
+
+ if ([state isKindOfClass:[SBJsonStreamParserStateError class]])
+ return SBJsonStreamParserError;
+
+ NSObject *token;
+ sbjson_token_t tok = [tokeniser getToken:&token];
+ switch (tok) {
+ case sbjson_token_eof:
+ return [state parserShouldReturn:self];
+ break;
+
+ case sbjson_token_error:
+ self.state = [SBJsonStreamParserStateError sharedInstance];
+ self.error = tokeniser.error;
+ return SBJsonStreamParserError;
+ break;
+
+ default:
+
+ if (![state parser:self shouldAcceptToken:tok]) {
+ NSString *tokenName = [self tokenName:tok];
+ NSString *stateName = [state name];
+
+ self.error = [NSString stringWithFormat:@"Token '%@' not expected %@", tokenName, stateName];
+ self.state = [SBJsonStreamParserStateError sharedInstance];
+ return SBJsonStreamParserError;
+ }
+
+ switch (tok) {
+ case sbjson_token_object_start:
+ [self handleObjectStart];
+ break;
+
+ case sbjson_token_object_end:
+ self.state = [stateStack lastObject];
+ [stateStack removeLastObject];
+ [state parser:self shouldTransitionTo:tok];
+ [delegate parserFoundObjectEnd:self];
+ break;
+
+ case sbjson_token_array_start:
+ [self handleArrayStart];
+ break;
+
+ case sbjson_token_array_end:
+ self.state = [stateStack lastObject];
+ [stateStack removeLastObject];
+ [state parser:self shouldTransitionTo:tok];
+ [delegate parserFoundArrayEnd:self];
+ break;
+
+ case sbjson_token_separator:
+ case sbjson_token_keyval_separator:
+ [state parser:self shouldTransitionTo:tok];
+ break;
+
+ case sbjson_token_true:
+ [delegate parser:self foundBoolean:YES];
+ [state parser:self shouldTransitionTo:tok];
+ break;
+
+ case sbjson_token_false:
+ [delegate parser:self foundBoolean:NO];
+ [state parser:self shouldTransitionTo:tok];
+ break;
+
+ case sbjson_token_null:
+ [delegate parserFoundNull:self];
+ [state parser:self shouldTransitionTo:tok];
+ break;
+
+ case sbjson_token_number:
+ [delegate parser:self foundNumber:(NSNumber*)token];
+ [state parser:self shouldTransitionTo:tok];
+ break;
+
+ case sbjson_token_string:
+ if ([state needKey])
+ [delegate parser:self foundObjectKey:(NSString*)token];
+ else
+ [delegate parser:self foundString:(NSString*)token];
+ [state parser:self shouldTransitionTo:tok];
+ break;
+
+ default:
+ break;
+ }
+ break;
+ }
+ }
+ return SBJsonStreamParserComplete;
}
@end
View
7 DoubanAPIEngine/DoubanAPIEngine/OtherSources/JSON/SBJsonStreamParserAccumulator.h
@@ -30,8 +30,11 @@
#import <Foundation/Foundation.h>
#import "SBJsonStreamParserAdapter.h"
-@interface SBJsonStreamParserAccumulator : NSObject <SBJsonStreamParserAdapterDelegate>
+@interface SBJsonStreamParserAccumulator : NSObject <SBJsonStreamParserAdapterDelegate> {
+@private
+ id value;
+}
-@property (copy) id value;
+@property (readonly, copy) id value;
@end
View
8 DoubanAPIEngine/DoubanAPIEngine/OtherSources/JSON/SBJsonStreamParserAccumulator.m
@@ -33,15 +33,19 @@ @implementation SBJsonStreamParserAccumulator
@synthesize value;
+- (void)dealloc {
+ [value release];
+ [super dealloc];
+}
#pragma mark SBJsonStreamParserAdapterDelegate
- (void)parser:(SBJsonStreamParser*)parser foundArray:(NSArray *)array {
- value = array;
+ value = [array retain];
}
- (void)parser:(SBJsonStreamParser*)parser foundObject:(NSDictionary *)dict {
- value = dict;
+ value = [dict retain];
}
@end
View
14 DoubanAPIEngine/DoubanAPIEngine/OtherSources/JSON/SBJsonStreamParserAdapter.h
@@ -70,9 +70,8 @@ typedef enum {
most likely find it much more convenient to use an instance of this class and
implement the SBJsonStreamParserAdapterDelegate protocol instead.
- The default behaviour is that the delegate only receives one call from
- either the -parser:foundArray: or -parser:foundObject: method when the
- document is fully parsed. However, if your inputs contains multiple JSON
+ Normally you would only get one call from either the -parser:foundArray: or
+ -parser:foundObject: method. However, if your inputs contains multiple JSON
documents and you set the parser's -supportMultipleDocuments property to YES
you will get one call for each full method.
@@ -118,9 +117,10 @@ typedef enum {
*/
@interface SBJsonStreamParserAdapter : NSObject <SBJsonStreamParserDelegate> {
@private
- NSUInteger depth;
- NSMutableArray *array;
- NSMutableDictionary *dict;
+ id<SBJsonStreamParserAdapterDelegate> delegate;
+ NSUInteger levelsToSkip, depth;
+ __weak NSMutableArray *array;
+ __weak NSMutableDictionary *dict;
NSMutableArray *keyStack;
NSMutableArray *stack;
@@ -143,6 +143,6 @@ typedef enum {
@brief Your delegate object
Set this to the object you want to receive the SBJsonStreamParserAdapterDelegate messages.
*/
-@property (unsafe_unretained) id<SBJsonStreamParserAdapterDelegate> delegate;
+@property (assign) id<SBJsonStreamParserAdapterDelegate> delegate;
@end
View
23 DoubanAPIEngine/DoubanAPIEngine/OtherSources/JSON/SBJsonStreamParserAdapter.m
@@ -59,6 +59,11 @@ - (id)init {
return self;
}
+- (void)dealloc {
+ [keyStack release];
+ [stack release];
+ [super dealloc];
+}
#pragma mark Private methods
@@ -110,8 +115,8 @@ - (void)parser:(SBJsonStreamParser*)parser found:(id)obj {
#pragma mark Delegate methods
- (void)parserFoundObjectStart:(SBJsonStreamParser*)parser {
- if (++depth > self.levelsToSkip) {
- dict = [NSMutableDictionary new];
+ if (++depth > levelsToSkip) {
+ dict = [[NSMutableDictionary new] autorelease];
[stack addObject:dict];
currentType = SBJsonStreamParserAdapterObject;
}
@@ -122,26 +127,28 @@ - (void)parser:(SBJsonStreamParser*)parser foundObjectKey:(NSString*)key_ {
}
- (void)parserFoundObjectEnd:(SBJsonStreamParser*)parser {
- if (depth-- > self.levelsToSkip) {
- id value = dict;
+ if (depth-- > levelsToSkip) {
+ id value = [dict retain];
[self pop];
[self parser:parser found:value];
+ [value release];
}
}
- (void)parserFoundArrayStart:(SBJsonStreamParser*)parser {
- if (++depth > self.levelsToSkip) {
- array = [NSMutableArray new];
+ if (++depth > levelsToSkip) {
+ array = [[NSMutableArray new] autorelease];
[stack addObject:array];
currentType = SBJsonStreamParserAdapterArray;
}
}
- (void)parserFoundArrayEnd:(SBJsonStreamParser*)parser {
- if (depth-- > self.levelsToSkip) {
- id value = array;
+ if (depth-- > levelsToSkip) {
+ id value = [array retain];
[self pop];
[self parser:parser found:value];
+ [value release];
}
}
View
2  DoubanAPIEngine/DoubanAPIEngine/OtherSources/JSON/SBJsonStreamParserState.h
@@ -37,12 +37,10 @@
@interface SBJsonStreamParserState : NSObject
+ (id)sharedInstance;
-
- (BOOL)parser:(SBJsonStreamParser*)parser shouldAcceptToken:(sbjson_token_t)token;
- (SBJsonStreamParserStatus)parserShouldReturn:(SBJsonStreamParser*)parser;
- (void)parser:(SBJsonStreamParser*)parser shouldTransitionTo:(sbjson_token_t)tok;
- (BOOL)needKey;
-- (BOOL)isError;
- (NSString*)name;
View
8 DoubanAPIEngine/DoubanAPIEngine/OtherSources/JSON/SBJsonStreamParserState.m
@@ -62,10 +62,6 @@ - (NSString*)name {
return @"<aaiie!>";
}
-- (BOOL)isError {
- return NO;
-}
-
@end
#pragma mark -
@@ -140,10 +136,6 @@ - (SBJsonStreamParserStatus)parserShouldReturn:(SBJsonStreamParser*)parser {
return SBJsonStreamParserError;
}
-- (BOOL)isError {
- return YES;
-}
-
@end
#pragma mark -
View
14 DoubanAPIEngine/DoubanAPIEngine/OtherSources/JSON/SBJsonStreamWriter.h
@@ -83,17 +83,23 @@
*/
@interface SBJsonStreamWriter : NSObject {
- NSMutableDictionary *cache;
+@private
+ NSString *error;
+ NSMutableArray *stateStack;
+ __weak SBJsonStreamWriterState *state;
+ id<SBJsonStreamWriterDelegate> delegate;
+ NSUInteger maxDepth;
+ BOOL sortKeys, humanReadable;
}
-@property (nonatomic, unsafe_unretained) SBJsonStreamWriterState *state; // Internal
-@property (nonatomic, readonly, strong) NSMutableArray *stateStack; // Internal
+@property (nonatomic, assign) __weak SBJsonStreamWriterState *state; // Internal
+@property (nonatomic, readonly, retain) NSMutableArray *stateStack; // Internal
/**
@brief delegate to receive JSON output
Delegate that will receive messages with output.
*/
-@property (unsafe_unretained) id<SBJsonStreamWriterDelegate> delegate;
+@property (assign) id<SBJsonStreamWriterDelegate> delegate;
/**
@brief The maximum recursing depth.
View
43 DoubanAPIEngine/DoubanAPIEngine/OtherSources/JSON/SBJsonStreamWriter.m
@@ -33,11 +33,8 @@
#import "SBJsonStreamWriter.h"
#import "SBJsonStreamWriterState.h"
-static NSNumber *kNotANumber;
-static NSNumber *kTrue;
-static NSNumber *kFalse;
-static NSNumber *kPositiveInfinity;
-static NSNumber *kNegativeInfinity;
+static NSDecimalNumber *kNotANumber;
+static id kStaticStringCache;
@implementation SBJsonStreamWriter
@@ -51,10 +48,16 @@ @implementation SBJsonStreamWriter
+ (void)initialize {
kNotANumber = [NSDecimalNumber notANumber];
- kPositiveInfinity = [NSNumber numberWithDouble:+INFINITY];
- kNegativeInfinity = [NSNumber numberWithDouble:-INFINITY];
- kTrue = [NSNumber numberWithBool:YES];
- kFalse = [NSNumber numberWithBool:NO];
+
+ Class cacheClass = NSClassFromString(@"NSCache");
+ if (cacheClass) {
+ NSLog(@"%s NSCache supported", __FUNCTION__);
+ kStaticStringCache = [[cacheClass alloc] init];
+ }else {
+ NSLog(@"%s NSCache not supported", __FUNCTION__);
+ }
+
+
}
#pragma mark Housekeeping
@@ -67,13 +70,15 @@ - (id)init {
maxDepth = 32u;
stateStack = [[NSMutableArray alloc] initWithCapacity:maxDepth];
state = [SBJsonStreamWriterStateStart sharedInstance];
- cache = [[NSMutableDictionary alloc] initWithCapacity:32];
}
return self;
}
- (void)dealloc {
+ self.error = nil;
self.state = nil;
+ [stateStack release];
+ [super dealloc];
}
#pragma mark Methods
@@ -280,14 +285,14 @@ - (BOOL)writeString:(NSString*)string {
[state appendSeparator:self];
if (humanReadable) [state appendWhitespace:self];
- NSMutableData *buf = [cache objectForKey:string];
+ NSMutableData *buf = [kStaticStringCache objectForKey:string];
if (!buf) {
NSUInteger len = [string lengthOfBytesUsingEncoding:NSUTF8StringEncoding];
const char *utf8 = [string UTF8String];
NSUInteger written = 0, i = 0;
- buf = [NSMutableData dataWithCapacity:(NSUInteger)(len * 1.1f)];
+ buf = [NSMutableData dataWithCapacity:len * 1.1f];
[buf appendBytes:"\"" length:1];
for (i = 0; i < len; i++) {
@@ -307,7 +312,7 @@ - (BOOL)writeString:(NSString*)string {
[buf appendBytes:utf8 + written length:i - written];
[buf appendBytes:"\"" length:1];
- [cache setObject:buf forKey:string];
+ [kStaticStringCache setObject:buf forKey:string];
}
[delegate writer:self appendBytes:[buf bytes] length:[buf length]];
@@ -316,7 +321,7 @@ - (BOOL)writeString:(NSString*)string {
}
- (BOOL)writeNumber:(NSNumber*)number {
- if (number == kTrue || number == kFalse)
+ if ((CFBooleanRef)number == kCFBooleanTrue || (CFBooleanRef)number == kCFBooleanFalse)
return [self writeBool:[number boolValue]];
if ([state isInvalidState:self]) return NO;
@@ -324,15 +329,19 @@ - (BOOL)writeNumber:(NSNumber*)number {
[state appendSeparator:self];
if (humanReadable) [state appendWhitespace:self];
- if ([kPositiveInfinity isEqualToNumber:number]) {
+ if ((CFNumberRef)number == kCFNumberPositiveInfinity) {
self.error = @"+Infinity is not a valid number in JSON";
return NO;
- } else if ([kNegativeInfinity isEqualToNumber:number]) {
+ } else if ((CFNumberRef)number == kCFNumberNegativeInfinity) {
self.error = @"-Infinity is not a valid number in JSON";
return NO;
- } else if ([kNotANumber isEqualToNumber:number]) {
+ } else if ((CFNumberRef)number == kCFNumberNaN) {
+ self.error = @"NaN is not a valid number in JSON";
+ return NO;
+
+ } else if (number == kNotANumber) {
self.error = @"NaN is not a valid number in JSON";
return NO;
}
View
7 DoubanAPIEngine/DoubanAPIEngine/OtherSources/JSON/SBJsonStreamWriterAccumulator.h
@@ -29,8 +29,11 @@
#import "SBJsonStreamWriter.h"
-@interface SBJsonStreamWriterAccumulator : NSObject <SBJsonStreamWriterDelegate>
+@interface SBJsonStreamWriterAccumulator : NSObject <SBJsonStreamWriterDelegate> {
+@private
+ NSMutableData *data;
+}
-@property (readonly, copy) NSMutableData* data;
+@property (readonly, copy) NSData* data;
@end
View
4 DoubanAPIEngine/DoubanAPIEngine/OtherSources/JSON/SBJsonStreamWriterAccumulator.m
@@ -42,6 +42,10 @@ - (id)init {
return self;
}
+- (void)dealloc {
+ [data release];
+ [super dealloc];
+}
#pragma mark SBJsonStreamWriterDelegate
View
7 DoubanAPIEngine/DoubanAPIEngine/OtherSources/JSON/SBJsonTokeniser.h
@@ -55,9 +55,12 @@ typedef enum {
@class SBJsonUTF8Stream;
-@interface SBJsonTokeniser : NSObject
+@interface SBJsonTokeniser : NSObject {
+@private
+ SBJsonUTF8Stream *_stream;
+ NSString *_error;
+}
-@property (strong) SBJsonUTF8Stream *stream;
@property (copy) NSString *error;
- (void)appendData:(NSData*)data_;
View
88 DoubanAPIEngine/DoubanAPIEngine/OtherSources/JSON/SBJsonTokeniser.m
@@ -32,14 +32,12 @@
#import "SBJsonTokeniser.h"
#import "SBJsonUTF8Stream.h"
-#define SBStringIsIllegalSurrogateHighCharacter(character) (((character) >= 0xD800UL) && ((character) <= 0xDFFFUL))
-#define SBStringIsSurrogateLowCharacter(character) ((character >= 0xDC00UL) && (character <= 0xDFFFUL))
-#define SBStringIsSurrogateHighCharacter(character) ((character >= 0xD800UL) && (character <= 0xDBFFUL))
+#define SBStringIsIllegalSurrogateHighCharacter(x) (((x) >= 0xd800) && ((x) <= 0xdfff))
+
@implementation SBJsonTokeniser
@synthesize error = _error;
-@synthesize stream = _stream;
- (id)init {
self = [super init];
@@ -51,6 +49,10 @@ - (id)init {
return self;
}
+- (void)dealloc {
+ [_stream release];
+ [super dealloc];
+}
- (void)appendData:(NSData *)data_ {
[_stream appendData:data_];
@@ -140,36 +142,30 @@ - (sbjson_token_t)getStringToken:(NSObject**)token {
unichar ch;
{
NSMutableString *string = nil;
- @try {
- if (![_stream getRetainedStringFragment:&string])
- return sbjson_token_eof;
-
- if (!string) {
- self.error = @"Broken Unicode encoding";
- return sbjson_token_error;
- }
+ if (![_stream getSimpleString:&string])
+ return sbjson_token_eof;
- if (![_stream getUnichar:&ch]) {
- return sbjson_token_eof;
- }
+ if (!string) {
+ self.error = @"Broken Unicode encoding";
+ return sbjson_token_error;
+ }
+
+
+ if (![_stream getUnichar:&ch])
+ return sbjson_token_eof;
+
+ if (acc) {
+ [acc appendString:string];
- if (acc) {
- [acc appendString:string];
+ } else if (ch == '"') {
+ *token = string;
+ [_stream skip];
+ return sbjson_token_string;
- } else if (ch == '"') {
- *token = [string copy];
- [_stream skip];
- return sbjson_token_string;
-
- } else {
- acc = [string mutableCopy];
- }
- }
- @finally {
- string = nil;
+ } else {
+ acc = [[string mutableCopy] autorelease];
}
}
-
switch (ch) {
case 0 ... 0x1F:
@@ -197,7 +193,7 @@ - (sbjson_token_t)getStringToken:(NSObject**)token {
return sbjson_token_error;
}
- if (SBStringIsSurrogateHighCharacter(hi)) {
+ if (CFStringIsSurrogateHighCharacter(hi)) {
unichar lo;
if (![_stream haveRemainingCharacters:6])
@@ -210,17 +206,18 @@ - (sbjson_token_t)getStringToken:(NSObject**)token {
return sbjson_token_error;
}
- if (!SBStringIsSurrogateLowCharacter(lo)) {
+ if (!CFStringIsSurrogateLowCharacter(lo)) {
self.error = @"Invalid low character in surrogate pair";
return sbjson_token_error;
}
- [acc appendFormat:@"%C%C", hi, lo];
+ unichar pair[2] = {hi, lo};
+ CFStringAppendCharacters((CFMutableStringRef)acc, pair, 2);
} else if (SBStringIsIllegalSurrogateHighCharacter(hi)) {
self.error = @"Invalid high character in surrogate pair";
return sbjson_token_error;
} else {
- [acc appendFormat:@"%C", hi];
+ CFStringAppendCharacters((CFMutableStringRef)acc, &hi, 1);
}
@@ -228,7 +225,7 @@ - (sbjson_token_t)getStringToken:(NSObject**)token {
unichar decoded;
if (![self decodeEscape:ch into:&decoded])
return sbjson_token_error;
- [acc appendFormat:@"%C", decoded];
+ CFStringAppendCharacters((CFMutableStringRef)acc, &decoded, 1);
}
break;
@@ -259,11 +256,7 @@ - (sbjson_token_t)getNumberToken:(NSObject**)token {
return sbjson_token_eof;
}
- unsigned long long mantissa = 0;
- int mantissa_length = 0;
-
if (ch == '0') {
- mantissa_length++;
if (![_stream getNextUnichar:&ch])
return sbjson_token_eof;
@@ -273,6 +266,9 @@ - (sbjson_token_t)getNumberToken:(NSObject**)token {
}
}
+ unsigned long long mantissa = 0;
+ int mantissa_length = 0;
+
while ([digits characterIsMember:ch]) {
mantissa *= 10;
mantissa += (ch - '0');
@@ -324,26 +320,26 @@ - (sbjson_token_t)getNumberToken:(NSObject**)token {
return sbjson_token_eof;
}
- short explicit_exponent = 0;
- short explicit_exponent_length = 0;
+ short exp = 0;
+ short exp_length = 0;
while ([digits characterIsMember:ch]) {
- explicit_exponent *= 10;
- explicit_exponent += (ch - '0');
- explicit_exponent_length++;
+ exp *= 10;
+ exp += (ch - '0');
+ exp_length++;
if (![_stream getNextUnichar:&ch])
return sbjson_token_eof;
}
- if (explicit_exponent_length == 0) {
+ if (exp_length == 0) {
self.error = @"No digits in exponent";
return sbjson_token_error;
}
if (expIsNegative)
- exponent -= explicit_exponent;
+ exponent -= exp;
else
- exponent += explicit_exponent;
+ exponent += exp;
}
if (!mantissa_length && isNegative) {
View
3  DoubanAPIEngine/DoubanAPIEngine/OtherSources/JSON/SBJsonUTF8Stream.h
@@ -37,6 +37,7 @@
const char *_bytes;
NSMutableData *_data;
NSUInteger _length;
+ NSUInteger _index;
}
@property (assign) NSUInteger index;
@@ -51,7 +52,7 @@
- (BOOL)getUnichar:(unichar*)ch;
- (BOOL)getNextUnichar:(unichar*)ch;
-- (BOOL)getRetainedStringFragment:(NSString**)string;
+- (BOOL)getSimpleString:(NSString**)string;
- (NSString*)stringWithRange:(NSRange)range;
View
14 DoubanAPIEngine/DoubanAPIEngine/OtherSources/JSON/SBJsonUTF8Stream.m
@@ -44,6 +44,10 @@ - (id)init {
return self;
}
+- (void)dealloc {
+ [_data release];
+ [super dealloc];
+}
- (void)appendData:(NSData *)data_ {
@@ -58,7 +62,7 @@ - (void)appendData:(NSData *)data_ {
[_data appendData:data_];
// This is an optimisation.
- _bytes = (const char*)[_data bytes];
+ _bytes = [_data bytes];
_length = [_data length];
}
@@ -79,14 +83,14 @@ - (BOOL)getNextUnichar:(unichar*)ch {
return NO;
}
-- (BOOL)getRetainedStringFragment:(NSString **)string {
+- (BOOL)getSimpleString:(NSString **)string {
NSUInteger start = _index;
while (_index < _length) {
switch (_bytes[_index]) {
case '"':
case '\\':
case 0 ... 0x1f:
- *string = [[NSString alloc] initWithBytes:(_bytes + start) length:(_index - start) encoding:NSUTF8StringEncoding];
+ *string = [[[NSString alloc] initWithBytes:(_bytes + start) length:(_index - start) encoding:NSUTF8StringEncoding] autorelease];
return YES;
break;
default:
@@ -122,7 +126,7 @@ - (BOOL)haveRemainingCharacters:(NSUInteger)chars {
}
- (BOOL)skipCharacters:(const char *)chars length:(NSUInteger)len {
- const void *bytes = ((const char*)[_data bytes]) + _index;
+ const void *bytes = [_data bytes] + _index;
if (!memcmp(bytes, chars, len)) {
_index += len;
return YES;
@@ -131,7 +135,7 @@ - (BOOL)skipCharacters:(const char *)chars length:(NSUInteger)len {
}
- (NSString*)stringWithRange:(NSRange)range {
- return [[NSString alloc] initWithBytes:_bytes + range.location length:range.length encoding:NSUTF8StringEncoding];
+ return [[[NSString alloc] initWithBytes:_bytes + range.location length:range.length encoding:NSUTF8StringEncoding] autorelease];
}
View
7 DoubanAPIEngine/DoubanAPIEngine/OtherSources/JSON/SBJsonWriter.h
@@ -37,7 +37,12 @@
@see @ref json2objc
*/
-@interface SBJsonWriter : NSObject
+@interface SBJsonWriter : NSObject {
+@private
+ NSString *error;
+ NSUInteger maxDepth;
+ BOOL sortKeys, humanReadable;
+}
/**
@brief The maximum recursing depth.
View
10 DoubanAPIEngine/DoubanAPIEngine/OtherSources/JSON/SBJsonWriter.m
@@ -52,11 +52,15 @@ - (id)init {
return self;
}
+- (void)dealloc {
+ [error release];
+ [super dealloc];
+}
- (NSString*)stringWithObject:(id)value {
NSData *data = [self dataWithObject:value];
if (data)
- return [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding];
+ return [[[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding] autorelease];
return nil;
}
@@ -76,9 +80,9 @@ - (NSString*)stringWithObject:(id)value error:(NSError**)error_ {
- (NSData*)dataWithObject:(id)object {
self.error = nil;
- SBJsonStreamWriterAccumulator *accumulator = [[SBJsonStreamWriterAccumulator alloc] init];
+ SBJsonStreamWriterAccumulator *accumulator = [[[SBJsonStreamWriterAccumulator alloc] init] autorelease];
- SBJsonStreamWriter *streamWriter = [[SBJsonStreamWriter alloc] init];
+ SBJsonStreamWriter *streamWriter = [[[SBJsonStreamWriter alloc] init] autorelease];
streamWriter.sortKeys = self.sortKeys;
streamWriter.maxDepth = self.maxDepth;
streamWriter.humanReadable = self.humanReadable;
View
3  DoubanAPIEngine/DoubanAPIEngine/Sources/DOUAPIConfig.h
@@ -8,7 +8,8 @@
#import <Foundation/Foundation.h>
-extern NSString * const kAPIBaseUrl;
+extern NSString * const kHttpsApiBaseUrl;
+extern NSString * const kHttpApiBaseUrl;
extern NSString * const kAuthUrl;
extern NSString * const kTokenUrl;
View
10 DoubanAPIEngine/DoubanAPIEngine/Sources/DOUAPIConfig.m
@@ -11,10 +11,12 @@
//
// Douban parameters:
//
-NSString * const kAPIBaseUrl = @"https://api.douban.com";
+
+NSString * const kHttpsApiBaseUrl = @"https://api.douban.com";
+NSString * const kHttpApiBaseUrl = @"http://api.douban.com";
+
+//NSString * const kAPIBaseUrl = @"https://loc-zeta.douban.com/service/api";
+
NSString * const kAuthUrl = @"https://www.douban.com/service/auth2/auth";
NSString * const kTokenUrl = @"https://www.douban.com/service/auth2/token";
-//NSString * const kAPIBaseUrl = @"https://zeta.douban.com/service/api";
-//NSString * const kAuthUrl = @"https://zeta.douban.com/service/auth2/auth";
-//NSString * const kTokenUrl = @"https://zeta.douban.com/service/auth2/token";
View
11 DoubanAPIEngine/DoubanAPIEngine/Sources/DOUAPIEngine.h
@@ -6,15 +6,16 @@
// Copyright (c) 2011年 Douban Inc. All rights reserved.
//
-#import "DoubanDefines.h"
-#import "DOUService.h"
+#import "DOUAPIConfig.h"
#import "DOUQuery.h"
-#import "DOUOAuth2.h"
-
-#import "DOUOAuth2Consumer.h"
+#import "DOUService.h"
+#import "DOUOAuthService.h"
+#import "DOUOAuth2.h"
+#import "DOUOAuthStore.h"
#import "DOUHttpRequest.h"
+#import "DoubanDefines.h"
#import "DoubanAttribute.h"
#import "DoubanLocation.h"
#import "DoubanTag.h"
View
19 DoubanAPIEngine/DoubanAPIEngine/Sources/GDataDoubanWrapper/Clients/Event/DoubanEntryCity.m
@@ -89,4 +89,23 @@ - (BOOL)isHabitable {
}
+- (BOOL)isEqual:(id)object {
+ if (self == object) {
+ return YES;
+ }
+ if ([object isKindOfClass:[self class]]) {
+ if (![[self uid] isEqualToString:[(DoubanEntryCity *)object uid]])
+ return NO;
+
+ return YES;
+ }
+ return NO;
+}
+
+
+- (NSUInteger)hash {
+ return [[self uid] hash];
+}
+
+
@end
View
6 DoubanAPIEngine/DoubanAPIEngine/Sources/Network/DOUHttpRequest.h
@@ -8,8 +8,7 @@
#import <Foundation/Foundation.h>
#import "ASIFormDataRequest.h"
-#import "DOUQuery.h"
-#import "DOUOAuth2Consumer.h"
+
extern NSUInteger const kDefaultTimeoutSeconds;
@@ -19,7 +18,8 @@ extern NSString * const DOUOAuthErrorDomain;
extern NSString * const DOUErrorDomain;
-
+@class DOUHttpRequest;
+@class DOUQuery;
@protocol DOUHttpRequestDelegate <NSObject>
@required
View
5 DoubanAPIEngine/DoubanAPIEngine/Sources/Network/DOUHttpRequest.m
@@ -8,6 +8,8 @@
#import "DOUHttpRequest.h"
#import "DOUOAuth2.h"
+#import "DOUQuery.h"
+
#import "DOUAPIConfig.h"
#import "SBJson.h"
@@ -28,6 +30,7 @@ @implementation DOUHttpRequest
+ (DOUHttpRequest *)requestWithURL:(NSURL *)URL {
DOUHttpRequest *req = [[[DOUHttpRequest alloc] initWithURL:URL] autorelease];
+ [req setValidatesSecureCertificate:NO];
[req setAllowCompressedResponse:YES];// YES is the default
[req setTimeOutSeconds:kDefaultTimeoutSeconds];
return req;
@@ -165,7 +168,7 @@ - (NSError *)doubanError {
}
NSError *otherError = [NSError errorWithDomain:DOUErrorDomain
- code:statusCode
+ code:error.code
userInfo:nil];
return otherError;
View
2  DoubanAPIEngine/DoubanAPIEngine/Sources/Network/DOUQuery.h
@@ -15,10 +15,12 @@
@private
NSString *subPath_;
NSDictionary *parameters_;
+ NSString *apiBaseUrlString_;
}
@property (nonatomic, copy) NSString *subPath;
@property (nonatomic, retain) NSDictionary *parameters;
+@property (nonatomic, copy) NSString *apiBaseUrlString;
- (id)initWithSubPath:(NSString *)aSubPath parameters:(NSDictionary *)theParameters;
View
4 DoubanAPIEngine/DoubanAPIEngine/Sources/Network/DOUQuery.m
@@ -7,13 +7,13 @@
//
#import "DOUQuery.h"
-#import "DOUAPIConfig.h"
@implementation DOUQuery
@synthesize subPath = subPath_;
@synthesize parameters = parameters_;
+@synthesize apiBaseUrlString = apiBaseUrlString_;
- (id)initWithSubPath:(NSString *)aSubPath parameters:(NSDictionary *)theParameters {
@@ -51,7 +51,7 @@ - (NSString *)parametersUrlString {
- (NSString *)requestURLString {
- NSString *url = [NSString stringWithFormat:@"%@%@", kAPIBaseUrl, subPath_];
+ NSString *url = [NSString stringWithFormat:@"%@%@", apiBaseUrlString_, subPath_];
NSString *parameterStr = [self parametersUrlString];
if ( parameterStr != nil && [parameterStr length] > 0 ) {
url = [url stringByAppendingString:parameterStr];
View
66 DoubanAPIEngine/DoubanAPIEngine/Sources/Network/DOUService.h
@@ -13,84 +13,52 @@
@class ASINetworkQueue;
-@class DOUOAuth2Consumer;
-@class DOUOAuth2Provider;
-@class DOUHttpRequest;
@interface DOUService : NSObject {
@private
- ASINetworkQueue *queue_;
- DOUOAuth2Consumer *consumer_;
- DOUOAuth2Provider *provider_;
+ ASINetworkQueue *queue_;
+ NSString *apiBaseUrlString_;
+ NSString *clientId_;
+ NSString *clientSecret_;
}
-
-@property (nonatomic, retain) ASINetworkQueue *queue;
-@property (nonatomic, retain) DOUOAuth2Consumer *consumer;
-@property (nonatomic, retain) DOUOAuth2Provider *provider;
+@property (nonatomic, copy) NSString *apiBaseUrlString;
+@property (nonatomic, copy) NSString *clientId;
+@property (nonatomic, copy) NSString *clientSecret;
+ (DOUService *)sharedInstance;
-+ (NSString *)apiKey;
-+ (void)setAPIKey:(NSString *)theAPIKey;
-+ (NSString *)redirectUrl;
-+ (void)setRedirectUrl:(NSString *)theRedirectUrl;
-+ (void)setPrivateKey:(NSString *)thePrivateKey;
-
-- (void)addRequest:(DOUHttpRequest *)request;
-
-- (void)setMaxConcurrentOperationCount:(NSUInteger)maxConcurrentOperationCount;
-
-- (NSString *)accessToken;
-
-- (int)userId;
-
- (BOOL)isValid;
-- (NSError *)executeRefreshToken;
+- (void)addRequest:(DOUHttpRequest *)request;
-- (void)logout;
#if NS_BLOCKS_AVAILABLE
-- (void)loginWithUsername:(NSString *)username
- password:(NSString *)password
- callback:(DOUBasicBlock)block;
-
-- (void)loginWithAuthorizationCode:(NSString *)authorizationCode
- callback:(DOUBasicBlock)block;
+- (DOUHttpRequest *)get:(DOUQuery *)query callback:(DOUReqBlock)block;
-- (void)get:(DOUQuery *)query callback:(DOUReqBlock)block;
+- (DOUHttpRequest *)post:(DOUQuery *)query callback:(DOUReqBlock)block;
-- (void)post:(DOUQuery *)query callback:(DOUReqBlock)block;
+- (DOUHttpRequest *)post:(DOUQuery *)query object:(GDataEntryBase *)object callback:(DOUReqBlock)block;
-- (void)post:(DOUQuery *)query object:(GDataEntryBase *)object callback:(DOUReqBlock)block;
-
-- (void)post:(DOUQuery *)query
+- (DOUHttpRequest *)post:(DOUQuery *)query
photoData:(NSData *)photoData
format:(NSString *)format
description:(NSString *)description
callback:(DOUReqBlock)block;
-- (void)del:(DOUQuery *)query callback:(DOUReqBlock)block;
+- (DOUHttpRequest *)delete:(DOUQuery *)query callback:(DOUReqBlock)block;
#endif
-- (void)loginWithUsername:(NSString *)username
- password:(NSString *)password
- delegate:(id<DOUHttpRequestDelegate>)delegate;
-
-- (void)loginWithAuthorizationCode:(NSString *)code
- delegate:(id<DOUHttpRequestDelegate>)delegate;
-
-- (void)get:(DOUQuery *)query target:(id<DOUHttpRequestDelegate>)delegate;
+- (DOUHttpRequest *)get:(DOUQuery *)query delegate:(id<DOUHttpRequestDelegate>)delegate;
-- (void)post:(DOUQuery *)query target:(id<DOUHttpRequestDelegate>)delegate;
+- (DOUHttpRequest *)post:(DOUQuery *)query delegate:(id<DOUHttpRequestDelegate>)delegate;
-- (void)post:(DOUQuery *)query object:(GDataEntryBase *)object target:(id<DOUHttpRequestDelegate>)delegate;
+- (DOUHttpRequest *)post:(DOUQuery *)query object:(GDataEntryBase *)object delegate:(id<DOUHttpRequestDelegate>)delegate;
-- (void)del:(DOUQuery *)query target:(id<DOUHttpRequestDelegate>)delegate;
+- (DOUHttpRequest *)delete:(DOUQuery *)query delegate:(id<DOUHttpRequestDelegate>)delegate;
@end
View
220 DoubanAPIEngine/DoubanAPIEngine/Sources/Network/DOUService.m
@@ -9,9 +9,9 @@
#import "DOUService.h"
#import "DOUHTTPRequest.h"
#import "DOUAPIConfig.h"
-#import "DOUOAuth2.h"
-#import "DOUOAuth2Provider.h"
-#import "DOUOAuth2Consumer.h"
+#import "DOUOAuthService.h"
+#import "DOUOAuthStore.h"
+#import "DOUQuery.h"
#import "NSString+Base64Encoding.h"
#import "ASINetworkQueue.h"
@@ -19,7 +19,10 @@
@interface DOUService ()
+@property (nonatomic, retain) ASINetworkQueue *queue;
+
- (void)addRequest:(DOUHttpRequest *)request;
+- (void)setMaxConcurrentOperationCount:(NSUInteger)maxConcurrentOperationCount;
@end
@@ -28,50 +31,16 @@ @implementation DOUService
NSUInteger const kDefaultMaxConcurrentOperationCount = 4;
@synthesize queue = queue_;
-@synthesize consumer = consumer_;
-@synthesize provider = provider_;
-
-#pragma mark - Auth2 Parameters
-
-static NSString *APIKey;
-static NSString *privateKey;
-static NSString *redirectUrl;
-
-+ (void)setAPIKey:(NSString *)theAPIKey {
- APIKey = theAPIKey;
-}
-
-
-+ (void)setPrivateKey:(NSString *)thePrivateKey {
- privateKey = thePrivateKey;
-}
-
-+ (void)setRedirectUrl:(NSString *)theRedirectUrl {
- redirectUrl = theRedirectUrl;
-}
-
-
-+ (NSString *)apiKey {
- return APIKey;
-}
-
-
-+ (NSString *)redirectUrl {
- return redirectUrl;
-}
+@synthesize apiBaseUrlString = apiBaseUrlString_;
+@synthesize clientId = clientId_;
+@synthesize clientSecret = clientSecret_;
- (id)init {
self = [super init];
if (self) {
- self.consumer = [[[DOUOAuth2Consumer alloc] initWithKey:APIKey
- secret:privateKey
- redirectURL:redirectUrl] autorelease];
- [consumer_ updateWithUserDefaults];
- self.provider = [[[DOUOAuth2Provider alloc] initWithAuthURL:kAuthUrl
- tokenURL:kTokenUrl] autorelease];
}
return self;
}
@@ -79,8 +48,6 @@ - (id)init {
- (void)dealloc {
[queue_ release]; queue_ = nil;
- [consumer_ release]; consumer_ = nil;
- [provider_ release]; provider_ = nil;
[super dealloc];
}
@@ -136,16 +103,68 @@ - (id)autorelease {
}
-#pragma mark - login
+
+- (NSError *)executeRefreshToken {
+ DOUOAuthService *service = [DOUOAuthService sharedInstance];
+ service.authorizationURL = kTokenUrl;
+ service.clientId = self.clientId;
+ service.clientSecret = self.clientSecret;
+ return [service validateRefresh];
+}
-- (void)logout {
- [consumer_ clear];
+
+- (NSDictionary *)parseQueryString:(NSString *)query {
+ NSMutableDictionary *dict = [[[NSMutableDictionary alloc] initWithCapacity:6] autorelease];
+ NSArray *pairs = [query componentsSeparatedByString:@"&"];
+
+ for (NSString *pair in pairs) {
+ NSArray *elements = [pair componentsSeparatedByString:@"="];
+ NSString *key =
+ [[elements objectAtIndex:0] stringByReplacingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
+ NSString *val =
+ [[elements objectAtIndex:1] stringByReplacingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
+
+ [dict setObject:val forKey:key];
+ }
+ return dict;
}
-- (NSError *)executeRefreshToken {
- return [provider_ accessTokenByRefresh:consumer_];
+- (void)sign:(DOUHttpRequest *)request {
+ DOUOAuthStore *store = [DOUOAuthStore sharedInstance];
+ if (store.accessToken && ![store hasExpired]) {
+ NSString *authValue = [NSString stringWithFormat:@"%@ %@", @"Bearer", store.accessToken];
+ [request addRequestHeader:@"Authorization" value:authValue];
+ }
+ else {
+ NSString *clientId = self.clientId;
+ if (!clientId) {
+ return ;
+ }
+
+ NSURL *url = [request url];
+ NSString *urlString = [url absoluteString];
+ NSString *query = [url query];
+ if (query) {
+ NSDictionary *parameters = [self parseQueryString:query];
+
+ NSArray *keys = [parameters allKeys];
+ if ([keys count] == 0) {
+ urlString = [urlString stringByAppendingFormat:@"?%@=%@", @"apikey", clientId];
+ }
+ else {
+ urlString = [urlString stringByAppendingFormat:@"&%@=%@", @"apikey", clientId];
+ }
+ }
+ else {
+ urlString = [urlString stringByAppendingFormat:@"?%@=%@", @"apikey", clientId];
+ }
+
+ NSString *afterUrl = [urlString stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
+ request.url = [NSURL URLWithString:afterUrl];
+ }
+
}
@@ -156,12 +175,13 @@ - (void)addRequest:(DOUHttpRequest *)request {
self.queue.maxConcurrentOperationCount = kDefaultMaxConcurrentOperationCount;
}
- if (consumer_.userId != 0 && [consumer_ hasExpired]) {
+ DOUOAuthStore *store = [DOUOAuthStore sharedInstance];
+ if (store.userId != 0 && store.refreshToken && [store shouldRefreshToken]) {
[self executeRefreshToken];
}
- [consumer_ sign:request];
- //NSLog(@"request url:%@", [request.url absoluteString]);
+ [self sign:request];
+ NSLog(@"request url:%@", [request.url absoluteString]);
[[self queue] addOperation:request];
[[self queue] go];
@@ -173,19 +193,10 @@ - (void)setMaxConcurrentOperationCount:(NSUInteger)maxCount {
}
-- (NSString *)accessToken {
- return consumer_.accessToken;
-}
-
-
-- (int)userId {
- return consumer_.userId;
-}
-
-
- (BOOL)isValid {
- if (consumer_.accessToken) {
- return ![consumer_ hasExpired];
+ DOUOAuthStore *store = [DOUOAuthStore sharedInstance];
+ if (store.accessToken) {
+ return ![store hasExpired];
}
return NO;
}
@@ -193,41 +204,31 @@ - (BOOL)isValid {
#if NS_BLOCKS_AVAILABLE
-- (void)loginWithUsername:(NSString *)username
- password:(NSString *)password
- callback:(DOUBasicBlock)block {
- [provider_ accessTokenByPassword:password
- username:username
- consumer:consumer_
- callback:block];
-}
-
-
-- (void)loginWithAuthorizationCode:(NSString *)authorizationCode
- callback:(DOUBasicBlock)block {
- [provider_ accessTokenByAuthorizationCode:authorizationCode
- consumer:consumer_
- callback:block];
-}
-
-- (void)get:(DOUQuery *)query callback:(DOUReqBlock)block {
+- (DOUHttpRequest *)get:(DOUQuery *)query callback:(DOUReqBlock)block {
+ query.apiBaseUrlString = self.apiBaseUrlString;
// __block, It tells the block not to retain the request, which is important in preventing a retain-cycle,
// since the request will always retain the block
__block DOUHttpRequest * req = [DOUHttpRequest requestWithQuery:query completionBlock:^{
block(req);
}];
+ [req setRequestMethod:@"GET"];
+
[self addRequest:req];
+ return req;
}
-- (void)post:(DOUQuery *)query callback:(DOUReqBlock)block {
- [self post:query object:nil callback:block];
+- (DOUHttpRequest *)post:(DOUQuery *)query callback:(DOUReqBlock)block {
+ query.apiBaseUrlString = self.apiBaseUrlString;
+ return [self post:query object:nil callback:block];
}
-- (void)post:(DOUQuery *)query object:(GDataEntryBase *)object callback:(DOUReqBlock)block {
+- (DOUHttpRequest *)post:(DOUQuery *)query object:(GDataEntryBase *)object callback:(DOUReqBlock)block {
+ query.apiBaseUrlString = self.apiBaseUrlString;
+
__block DOUHttpRequest * req = [DOUHttpRequest requestWithQuery:query completionBlock:^{
block(req);
}];
@@ -248,14 +249,18 @@ - (void)post:(DOUQuery *)query object:(GDataEntryBase *)object callback:(DOUReqB
[req setResponseEncoding:NSUTF8StringEncoding];
[self addRequest:req];
+ return req;
}
-- (void)post:(DOUQuery *)query
+- (DOUHttpRequest *)post:(DOUQuery *)query
photoData:(NSData *)photoData
format:(NSString *)format
description:(NSString *)description
callback:(DOUReqBlock)block {
+
+ query.apiBaseUrlString = self.apiBaseUrlString;
+
__block DOUHttpRequest * req = [DOUHttpRequest requestWithQuery:query completionBlock:^{
block(req);
}];
@@ -266,9 +271,10 @@ - (void)post:(DOUQuery *)query
NSString *postContent = @"Media multipart posting\n--END_OF_PART\nContent-Type: application/atom+xml\n\n";
- GDataEntryBase *emptyEntry = [[GDataEntryBase alloc] init];
+ GDataEntryBase *emptyEntry = [[GDataEntryBase alloc] init] ;
emptyEntry.contentStringValue = description;
NSString *descStr = [[emptyEntry XMLElement] XMLString];
+ [emptyEntry release];
postContent = [postContent stringByAppendingString:descStr];
postContent = [postContent stringByAppendingString:@"\n--END_OF_PART"];
postContent = [postContent stringByAppendingFormat:@"\nContent-Type: image/%@\n", format];
@@ -282,10 +288,14 @@ - (void)post:(DOUQuery *)query
NSInteger length = [postData length];
[req addRequestHeader:@"Content-Length" value:[NSString stringWithFormat:@"%d", length]];
[self addRequest:req];
+ return req;
}
-- (void)del:(DOUQuery *)query callback:(DOUReqBlock)block {
+- (DOUHttpRequest *)delete:(DOUQuery *)query callback:(DOUReqBlock)block {
+
+ query.apiBaseUrlString = self.apiBaseUrlString;
+
__block DOUHttpRequest * req = [DOUHttpRequest requestWithQuery:query completionBlock:^{
block(req);
}];
@@ -294,43 +304,29 @@ - (void)del:(DOUQuery *)query callback:(DOUReqBlock)block {
[req addRequestHeader:@"Content-Type" value:@"application/atom+xml"];
[req addRequestHeader:@"CONTENT_LENGTH" value:@"0"];
[self addRequest:req];
+ return req;
}
#endif
-- (void)loginWithUsername:(NSString *)username
- password:(NSString *)password
- delegate:(id<DOUHttpRequestDelegate>)delegate {
- [provider_ accessTokenByPassword:password
- username:username
- consumer:consumer_
- delegate:delegate];
-}
-
-
-- (void)loginWithAuthorizationCode:(NSString *)code
- delegate:(id<DOUHttpRequestDelegate>)delegate {
- [provider_ accessTokenByAuthorizationCode:code
- consumer:consumer_
- delegate:delegate];
-}
-
-
-- (void)get:(DOUQuery *)query target:(id<DOUHttpRequestDelegate>)delegate {
+- (DOUHttpRequest *)get:(DOUQuery *)query delegate:(id<DOUHttpRequestDelegate>)delegate {
+ query.apiBaseUrlString = self.apiBaseUrlString;
DOUHttpRequest * req = [DOUHttpRequest requestWithQuery:query target:delegate];
[self addRequest:req];
+ return req;
}
-- (void)post:(DOUQuery *)query target:(id<DOUHttpRequestDelegate>)delegate {
- [self post:query object:nil target:delegate];
+- (DOUHttpRequest *)post:(DOUQuery *)query delegate:(id<DOUHttpRequestDelegate>)delegate {
+ query.apiBaseUrlString = self.apiBaseUrlString;
+ return [self post:query object:nil delegate:delegate];
}
-- (void)post:(DOUQuery *)query object:(GDataEntryBase *)object target:(id<DOUHttpRequestDelegate>)delegate {
-
+- (DOUHttpRequest *)post:(DOUQuery *)query object:(GDataEntryBase *)object delegate:(id<DOUHttpRequestDelegate>)delegate {
+ query.apiBaseUrlString = self.apiBaseUrlString;
DOUHttpRequest * req = [DOUHttpRequest requestWithQuery:query target:delegate];
[req setRequestMethod:@"POST"];
@@ -349,15 +345,19 @@ - (void)post:(DOUQuery *)query object:(GDataEntryBase *)object target:(id<DOUHtt
[req setResponseEncoding:NSUTF8StringEncoding];
[self addRequest:req];
+ return req;
}
-- (void)del:(DOUQuery *)query target:(id<DOUHttpRequestDelegate>)delegate {
+- (DOUHttpRequest *)delete:(DOUQuery *)query delegate:(id<DOUHttpRequestDelegate>)delegate {
+ query.apiBaseUrlString = self.apiBaseUrlString;
+
DOUHttpRequest * req = [DOUHttpRequest requestWithQuery:query target:delegate];
[req setRequestMethod:@"DELETE"];
[req addRequestHeader:@"Content-Type" value:@"application/atom+xml"];
[req addRequestHeader:@"CONTENT_LENGTH" value:@"0"];
[self addRequest:req];
+ return req;
}
View
2  DoubanAPIEngine/DoubanAPIEngine/Sources/OAuth2/DOUOAuth2.h
@@ -61,8 +61,6 @@ static NSString * const kPasswordKey = @"password";
static NSString * const kDoubanUserIdKey = @"douban_user_id";
-static NSString * const kOAuth2 = @"Bearer";
-static NSString * const kOAuth2AuthorizationHttpHeader = @"Authorization";
static NSString * const kOAuth2ResponseType = @"response_type";
static NSString * const kOAuth2ResponseTypeCode = @"code";
static NSString * const kOAuth2ResponseTypeToken = @"refresh_token";
View
47 DoubanAPIEngine/DoubanAPIEngine/Sources/OAuth2/DOUOAuth2Provider.h
@@ -1,47 +0,0 @@
-//
-// DOUOAuth2Request.h
-// DOUAPIEngine
-//
-// Created by Lin GUO on 11-10-31.
-// Copyright (c) 2011年 Douban Inc. All rights reserved.
-//
-
-#import <Foundation/Foundation.h>
-#import "DOUOAuth2Consumer.h"
-#import "DOUService.h"
-
-@interface DOUOAuth2Provider : NSObject {
- @private
- NSString *authURL_;
- NSString *tokenURL_;
-}
-
-- (id)initWithAuthURL:(NSString *)anAuthURL tokenURL:(NSString *)aTokenURL;
-
-- (void)accessTokenByPassword:(NSString *)password
- username:(NSString *)username
- consumer:(DOUOAuth2Consumer *)consumer
- delegate:(id<DOUHttpRequestDelegate>)delegate;
-
-- (void)accessTokenByAuthorizationCode:(NSString *)authorizationCode
- consumer:(DOUOAuth2Consumer *)consumer
- delegate:(id<DOUHttpRequestDelegate>)delegate;
-
-- (NSError *)accessTokenByRefresh:(DOUOAuth2Consumer *)consumer;
-
-
-#if NS_BLOCKS_AVAILABLE
-
-- (void)accessTokenByPassword:(NSString *)password
- username:(NSString *)username
- consumer:(DOUOAuth2Consumer *)consumer
- callback:(DOUBasicBlock)block;
-
-- (void)accessTokenByAuthorizationCode:(NSString *)authorizationCode
- consumer:(DOUOAuth2Consumer *)consumer
- callback:(DOUBasicBlock)block;
-
-#endif
-
-
-@end
View
198 DoubanAPIEngine/DoubanAPIEngine/Sources/OAuth2/DOUOAuth2Provider.m
@@ -1,198 +0,0 @@
-//
-// DOUOAuthRequest.m
-// DOUAPIEngine
-//
-// Created by Lin GUO on 11-10-31.
-// Copyright (c) 2011年 Douban Inc. All rights reserved.
-//
-
-#import "DOUOAuth2Provider.h"
-#import "DOUOAuth2.h"
-#import "SBJson.h"
-
-
-@implementation DOUOAuth2Provider
-
-
-static NSString *kConsumerKey = @"ConsumerKey";
-static NSString *kDelegateKey = @"DelegateKey";
-
-
-- (id)initWithAuthURL:(NSString *)anAuthURL tokenURL:(NSString *)aTokenURL {
- self = [super init];
- if (self) {
- authURL_ = [anAuthURL retain];
- tokenURL_ = [aTokenURL retain];
- }
- return self;
-}
-
-
-- (void)dealloc {
- [authURL_ release]; authURL_ = nil;
- [tokenURL_ release]; tokenURL_ = nil;
- [super dealloc];
-}
-
-
-- (ASIFormDataRequest *)auth2Request:(DOUOAuth2Consumer *)consumer {
-
- ASIFormDataRequest *req = [ASIFormDataRequest requestWithURL:[NSURL URLWithString:tokenURL_]];
- [req setRequestMethod:@"POST"];
-
- [req setAllowCompressedResponse:YES]; // YES is the default
- [req setTimeOutSeconds:kDefaultTimeoutSeconds];
-
- [req setPostValue:consumer.key forKey:kClientIdKey];
- [req setPostValue:consumer.secret forKey:kClientSecretKey];
- [req setPostValue:consumer.redirectURL forKey:kRedirectURIKey];
-
- [req setStringEncoding:NSUTF8StringEncoding];
- return req;
-}
-
-
-#pragma mark - Auth2 actions
-
-- (void)accessTokenByPassword:(NSString *)password
- username:(NSString *)username
- consumer:(DOUOAuth2Consumer *)consumer
- delegate:(id<DOUHttpRequestDelegate>)delegate {
- ASIFormDataRequest *req = [self auth2Request:consumer];
- [req setPostValue:kGrantTypePassword forKey:kGrantTypeKey];
- [req setPostValue:username forKey:kUsernameKey];
- [req setPostValue:password forKey:kPasswordKey];
- [req setDelegate:self];
-
- NSDictionary *dic = [NSDictionary dictionaryWithObjectsAndKeys:consumer, kConsumerKey, delegate, kDelegateKey, nil];
- [req setUserInfo:dic];
- [req startAsynchronous];
-}
-
-
-- (void)accessTokenByAuthorizationCode:(NSString *)authorizationCode
- consumer:(DOUOAuth2Consumer *)consumer
- delegate:(id<DOUHttpRequestDelegate>)delegate {
- ASIFormDataRequest *req = [self auth2Request:consumer];
- [req setPostValue:kGrantTypeAuthorizationCode forKey:kGrantTypeKey];
- [req setPostValue:authorizationCode forKey:kOAuth2ResponseTypeCode];;
- [req setDelegate:self];
-
- NSDictionary *dic = [NSDictionary dictionaryWithObjectsAndKeys:consumer, kConsumerKey, delegate, kDelegateKey, nil];
- [req setUserInfo:dic];
- [req startAsynchronous];
-}
-
-
-
-- (void)requestFailed:(ASIHTTPRequest *)req {
- NSError *error = nil;
-
- NSError *asiError = [req error];
- // handle the http error
- if (asiError) {
- error = [DOUHttpRequest adapterError:asiError];
- }
-
- // handle the oauth error
- int statusCode = [req responseStatusCode];
- if (statusCode == 400) {
- NSString *response = [req responseString];
- NSDictionary *dic = [response JSONValue];
- if (dic) {
- NSInteger code = [[dic objectForKey:@"code"] integerValue];
- error = [NSError errorWithDomain:DOUOAuthErrorDomain
- code:code
- userInfo:dic];
- }
- }
-
- // handled by delegate
- id delegate = [[req userInfo] objectForKey:kDelegateKey];
- if ([delegate respondsToSelector:@selector(requestFailed:)]) {
- [req setError:error];
- [delegate requestFailed:req];
- }
-}
-
-
-- (void)requestFinished:(ASIHTTPRequest *)req {
-
- NSLog(@"login response: %@", [req responseString]);
- NSError *error = [req error];
- if (!error) {
-
- int code = [req responseStatusCode];
- if (code == 201 || code == 200) {
- // success
- DOUOAuth2Consumer *consumer = (DOUOAuth2Consumer *)[[req userInfo] objectForKey:kConsumerKey];
- NSString* responseStr = [req responseString];
- [consumer updateWithHTTPResponse:responseStr];
- [consumer save];
-
- // handled by delegate
- id delegate = [[req userInfo] objectForKey:kDelegateKey];
- if ([delegate respondsToSelector:@selector(requestFinished:)]){
- [delegate requestFinished:req];
- }
- return ;
- }
- }
-
- [self requestFailed:req];
-}
-
-
-- (NSError *)accessTokenByRefresh:(DOUOAuth2Consumer *)consumer {
-
- ASIFormDataRequest *req = [self auth2Request:consumer];
- [req setPostValue:kGrantTypeRefreshToken forKey:kGrantTypeKey];
- [req setPostValue:consumer.refreshToken forKey:kOAuth2ResponseTypeToken];
- [req startSynchronous];
-
- NSError *error = [req error];
- if (!error) {
- NSString* responseStr = [req responseString];
- NSLog(@"response: %@", responseStr);
- [consumer updateWithHTTPResponse:responseStr];
- [consumer save];
- }
-
- return error;
-}
-
-
-
-#if NS_BLOCKS_AVAILABLE
-
-- (void)accessTokenByPassword:(NSString *)password
- username:(NSString *)username
- consumer:(DOUOAuth2Consumer *)consumer
- callback:(DOUBasicBlock)block {
- ASIFormDataRequest *req = [self auth2Request:consumer];
- [req setPostValue:username forKey:kUsernameKey];
- [req setPostValue:password forKey:kPasswordKey];
- [req setCompletionBlock:block];
- [req setFailedBlock:block];
-
- [req startAsynchronous];
-}
-
-
-- (void)accessTokenByAuthorizationCode:(NSString *)authorizationCode
- consumer:(DOUOAuth2Consumer *)consumer
- callback:(DOUBasicBlock)block {
- ASIFormDataRequest *req = [self auth2Request:consumer];
- [req setPostValue:kGrantTypeAuthorizationCode forKey:kGrantTypeKey];
- [req setPostValue:authorizationCode forKey:kOAuth2ResponseTypeCode];;
- [req setCompletionBlock:block];
- [req setFailedBlock:block];
-
- [req startAsynchronous];
-}
-
-
-#endif
-
-
-@end