Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "0460"
LastUpgradeVersion = "0500"
version = "1.3">
<BuildAction
parallelizeBuildables = "YES"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@
55D278BB18298377008CB6B4 /* CoreLocation.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 55D278BA18298377008CB6B4 /* CoreLocation.framework */; };
55DB69CA184E66AA00677CEA /* Venues.json in Resources */ = {isa = PBXBuildFile; fileRef = 55DB69C9184E66AA00677CEA /* Venues.json */; };
55DB69CC184E66F400677CEA /* Venue.json in Resources */ = {isa = PBXBuildFile; fileRef = 55DB69CB184E66F400677CEA /* Venue.json */; };
55DD2B1D18C136DF00CF044B /* AFMMRecordServer.m in Sources */ = {isa = PBXBuildFile; fileRef = 55DD2B1C18C136DF00CF044B /* AFMMRecordServer.m */; };
55F8C4BB1848F8E000037D45 /* AFMMRecordResponseSerializer.m in Sources */ = {isa = PBXBuildFile; fileRef = 55F8C4BA1848F8E000037D45 /* AFMMRecordResponseSerializer.m */; };
/* End PBXBuildFile section */

Expand Down Expand Up @@ -159,6 +160,8 @@
55D278BA18298377008CB6B4 /* CoreLocation.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = CoreLocation.framework; path = System/Library/Frameworks/CoreLocation.framework; sourceTree = SDKROOT; };
55DB69C9184E66AA00677CEA /* Venues.json */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.json; path = Venues.json; sourceTree = "<group>"; };
55DB69CB184E66F400677CEA /* Venue.json */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.json; path = Venue.json; sourceTree = "<group>"; };
55DD2B1B18C136DF00CF044B /* AFMMRecordServer.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = AFMMRecordServer.h; sourceTree = "<group>"; };
55DD2B1C18C136DF00CF044B /* AFMMRecordServer.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = AFMMRecordServer.m; sourceTree = "<group>"; };
55F8C4B91848F8E000037D45 /* AFMMRecordResponseSerializer.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = AFMMRecordResponseSerializer.h; sourceTree = "<group>"; };
55F8C4BA1848F8E000037D45 /* AFMMRecordResponseSerializer.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = AFMMRecordResponseSerializer.m; sourceTree = "<group>"; };
/* End PBXFileReference section */
Expand Down Expand Up @@ -280,6 +283,7 @@
55D278411829769B008CB6B4 /* Vendor */ = {
isa = PBXGroup;
children = (
55DD2B1A18C136DF00CF044B /* AFMMRecordServer */,
55D278421829769B008CB6B4 /* AFNetworking */,
55F8C4B81848F8E000037D45 /* AFMMRecordResponseSerializer */,
55D2789018297E01008CB6B4 /* MMRecord */,
Expand Down Expand Up @@ -413,6 +417,16 @@
name = Resources;
sourceTree = "<group>";
};
55DD2B1A18C136DF00CF044B /* AFMMRecordServer */ = {
isa = PBXGroup;
children = (
55DD2B1B18C136DF00CF044B /* AFMMRecordServer.h */,
55DD2B1C18C136DF00CF044B /* AFMMRecordServer.m */,
);
name = AFMMRecordServer;
path = ../../../../../Source/AFMMRecordServer;
sourceTree = "<group>";
};
55F8C4B81848F8E000037D45 /* AFMMRecordResponseSerializer */ = {
isa = PBXGroup;
children = (
Expand Down Expand Up @@ -536,6 +550,7 @@
55D2785D1829769B008CB6B4 /* AFURLResponseSerialization.m in Sources */,
55D2785B1829769B008CB6B4 /* AFURLConnectionOperation.m in Sources */,
55D27866182977F5008CB6B4 /* MMFoursquareSessionManager.m in Sources */,
55DD2B1D18C136DF00CF044B /* AFMMRecordServer.m in Sources */,
55D2785A1829769B008CB6B4 /* AFSecurityPolicy.m in Sources */,
55D278AD18297E01008CB6B4 /* MMServerPageManager.m in Sources */,
55D278581829769B008CB6B4 /* AFHTTPSessionManager.m in Sources */,
Expand Down Expand Up @@ -612,7 +627,6 @@
isa = XCBuildConfiguration;
buildSettings = {
ALWAYS_SEARCH_USER_PATHS = NO;
ARCHS = "$(ARCHS_STANDARD_INCLUDING_64_BIT)";
CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x";
CLANG_CXX_LIBRARY = "libc++";
CLANG_ENABLE_MODULES = YES;
Expand Down Expand Up @@ -651,7 +665,6 @@
isa = XCBuildConfiguration;
buildSettings = {
ALWAYS_SEARCH_USER_PATHS = NO;
ARCHS = "$(ARCHS_STANDARD_INCLUDING_64_BIT)";
CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x";
CLANG_CXX_LIBRARY = "libc++";
CLANG_ENABLE_MODULES = YES;
Expand Down Expand Up @@ -711,7 +724,6 @@
55D2783D1829765E008CB6B4 /* Debug */ = {
isa = XCBuildConfiguration;
buildSettings = {
ARCHS = "$(ARCHS_STANDARD_INCLUDING_64_BIT)";
BUNDLE_LOADER = "$(BUILT_PRODUCTS_DIR)/MMRecordFoursquare.app/MMRecordFoursquare";
FRAMEWORK_SEARCH_PATHS = (
"$(SDKROOT)/Developer/Library/Frameworks",
Expand All @@ -734,7 +746,6 @@
55D2783E1829765E008CB6B4 /* Release */ = {
isa = XCBuildConfiguration;
buildSettings = {
ARCHS = "$(ARCHS_STANDARD_INCLUDING_64_BIT)";
BUNDLE_LOADER = "$(BUILT_PRODUCTS_DIR)/MMRecordFoursquare.app/MMRecordFoursquare";
FRAMEWORK_SEARCH_PATHS = (
"$(SDKROOT)/Developer/Library/Frameworks",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,6 @@
@interface MMFoursquareSessionManager : AFHTTPSessionManager

+ (instancetype)sharedClient;
+ (instancetype)serverClient;

@end
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,15 @@ + (instancetype)sharedClient {
return _sharedClient;
}

+ (instancetype)serverClient {
static MMFoursquareSessionManager *_serverClient = nil;
static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{
_serverClient = [[MMFoursquareSessionManager alloc] initWithBaseURL:[NSURL URLWithString:MMFoursquareAPIBaseURLString]];
[_serverClient setSecurityPolicy:[AFSecurityPolicy policyWithPinningMode:AFSSLPinningModeNone]];
});

return _serverClient;
}

@end
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,21 @@

#import "AFMMRecordResponseSerializer.h"
#import "AFMMRecordResponseSerializationMapper.h"
#import "AFMMRecordServer.h"
#import "FSRecord.h"
#import "MMDataManager.h"
#import "MMFoursquareSessionManager.h"

@implementation MMAppDelegate

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
MMFoursquareSessionManager *sessionManager = [MMFoursquareSessionManager sharedClient];
MMFoursquareSessionManager *serverClientManager = [MMFoursquareSessionManager serverClient];

[AFMMRecordServer registerAFHTTPSessionManager:serverClientManager];
[FSRecord registerServerClass:[AFMMRecordServer class]];

MMFoursquareSessionManager *sessionManager = [MMFoursquareSessionManager sharedClient];

NSManagedObjectContext *context = [[MMDataManager sharedDataManager] managedObjectContext];
AFHTTPResponseSerializer *HTTPResponseSerializer = [AFJSONResponseSerializer serializer];

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
#import "Location.h"

#import "MMVenueViewController.h"
#import "MMDataManager.h"

@interface MMViewController ()

Expand All @@ -26,6 +27,12 @@ @implementation MMViewController
- (void)viewDidLoad {
[super viewDidLoad];

self.refreshControl = [[UIRefreshControl alloc] init];
[self.refreshControl addTarget:self
action:@selector(refreshVenues)
forControlEvents:UIControlEventValueChanged];
[self setRefreshControl:self.refreshControl];

NSString *oAuthToken = @"RMRLHPHOTZBIHKAX2G1XMZ33XQYDYKVCAUTM5GCTAA03X04F";

[[MMFoursquareSessionManager sharedClient]
Expand All @@ -42,6 +49,30 @@ - (void)viewDidLoad {
}];
}

- (void)refreshVenues {
NSManagedObjectContext *context = [[MMDataManager sharedDataManager] managedObjectContext];

NSString *oAuthToken = @"RMRLHPHOTZBIHKAX2G1XMZ33XQYDYKVCAUTM5GCTAA03X04F";

[Venue
startRequestWithURN:@"venues/search?ll=30.25,-97.75"
data:@{@"oauth_token": oAuthToken, @"v": @"20131105"}
context:context
domain:nil
resultBlock:^(NSArray *records) {
NSArray *venues = records;

self.venues = venues;

[self.tableView reloadData];

[self.refreshControl endRefreshing];
}
failureBlock:^(NSError *error) {
[self.refreshControl endRefreshing];
}];
}

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
return 1;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "0460"
LastUpgradeVersion = "0500"
version = "1.3">
<BuildAction
parallelizeBuildables = "YES"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "0460"
LastUpgradeVersion = "0500"
version = "1.3">
<BuildAction
parallelizeBuildables = "YES"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "0460"
LastUpgradeVersion = "0500"
version = "1.3">
<BuildAction
parallelizeBuildables = "YES"
Expand Down
10 changes: 10 additions & 0 deletions MMRecord.xcworkspace/contents.xcworkspacedata

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

77 changes: 77 additions & 0 deletions Source/AFMMRecordServer/AFMMRecordServer.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
// AFServer.h
//
// Copyright (c) 2014 Mutual Mobile (http://www.mutualmobile.com/)
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.

#import "MMServer.h"

@class AFHTTPSessionManager;

/**
This server implementation is intended to be an example for how one might use AFNetworking 2.0 and
its encapsulation of NSURLSession along with MMRecord.

This is a basic implementation of `MMServer` that uses a simple configuration along with an
AFHTTPSessionManager as the backbone for making requests. This class allows you to register
your own AFHTTPSessionManager subclass to be used to make GET requests to whatever web server
it is configured for. The AFHTTPSessionManager will be used to make the requests sent to this
server. The response object is expected to be returned as an array or dictionary. Errors will get
forwarded through the failureBlock if the request fails.

This server implementation is not intended to be canonical. It is highly likely that this server
will not be sufficient for complex use cases and APIs. In those cases, it is highly recommended
that you subclass MMServer directly and provide your own implementation to fit your given API and
server. This implementation may be used as a guide to do that.

## AFNetworking

AFNetworking is a highly popular iOS networking framework. AFNetworking 2.0 is required to use this
server implementation. If you do not have AFNetworking 2.0 linked in your project, this server will
not work.

## Batching

This server implementation does support batching. If the request batching system in MMRecord is
used, then those requests will be batched using the registered AFHTTPSessionManager.

## Cancellation

This server implementation does support cancellation. In this case, the class name of the domain
object is associated with the NSURLSessionDataTask. If the server is asked to cancel requests
for a given domain, all NSURLSessionDataTasks associated with that domain will be cancelled.

## Pagination

This server implementation does NOT support pagination. You may, however, subclass this server
class to provide your own page manager class, which will then support pagination.
*/


@interface AFMMRecordServer : MMServer

/**
This method can be used to register an instance of an AFHTTPSessionManager.

@param client The client this server should use to make requests.
@return YES if the client was successfully registered. No otherwise.
*/
+ (BOOL)registerAFHTTPSessionManager:(AFHTTPSessionManager *)sessionManager;

@end
Loading