Skip to content

Commit 9b84ac8

Browse files
Panayot PanayotovPanayot Panayotov
authored andcommitted
initial commit
1 parent c6f48db commit 9b84ac8

37 files changed

+1892
-0
lines changed

Antideo.xcodeproj/project.pbxproj

Lines changed: 555 additions & 0 deletions
Large diffs are not rendered by default.

Antideo.xcodeproj/project.xcworkspace/contents.xcworkspacedata

Lines changed: 7 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<Scheme
3+
LastUpgradeVersion = "0820"
4+
version = "1.3">
5+
<BuildAction
6+
parallelizeBuildables = "YES"
7+
buildImplicitDependencies = "YES">
8+
<BuildActionEntries>
9+
<BuildActionEntry
10+
buildForTesting = "YES"
11+
buildForRunning = "YES"
12+
buildForProfiling = "YES"
13+
buildForArchiving = "YES"
14+
buildForAnalyzing = "YES">
15+
<BuildableReference
16+
BuildableIdentifier = "primary"
17+
BlueprintIdentifier = "5ADEBA171E4B36C90043F088"
18+
BuildableName = "Antideo.framework"
19+
BlueprintName = "Antideo"
20+
ReferencedContainer = "container:Antideo.xcodeproj">
21+
</BuildableReference>
22+
</BuildActionEntry>
23+
</BuildActionEntries>
24+
</BuildAction>
25+
<TestAction
26+
buildConfiguration = "Debug"
27+
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
28+
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
29+
shouldUseLaunchSchemeArgsEnv = "YES">
30+
<Testables>
31+
<TestableReference
32+
skipped = "NO">
33+
<BuildableReference
34+
BuildableIdentifier = "primary"
35+
BlueprintIdentifier = "5ADEBA201E4B36CA0043F088"
36+
BuildableName = "AntideoTests.xctest"
37+
BlueprintName = "AntideoTests"
38+
ReferencedContainer = "container:Antideo.xcodeproj">
39+
</BuildableReference>
40+
</TestableReference>
41+
</Testables>
42+
<MacroExpansion>
43+
<BuildableReference
44+
BuildableIdentifier = "primary"
45+
BlueprintIdentifier = "5ADEBA171E4B36C90043F088"
46+
BuildableName = "Antideo.framework"
47+
BlueprintName = "Antideo"
48+
ReferencedContainer = "container:Antideo.xcodeproj">
49+
</BuildableReference>
50+
</MacroExpansion>
51+
<AdditionalOptions>
52+
</AdditionalOptions>
53+
</TestAction>
54+
<LaunchAction
55+
buildConfiguration = "Debug"
56+
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
57+
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
58+
launchStyle = "0"
59+
useCustomWorkingDirectory = "NO"
60+
ignoresPersistentStateOnLaunch = "NO"
61+
debugDocumentVersioning = "YES"
62+
debugServiceExtension = "internal"
63+
allowLocationSimulation = "YES">
64+
<MacroExpansion>
65+
<BuildableReference
66+
BuildableIdentifier = "primary"
67+
BlueprintIdentifier = "5ADEBA171E4B36C90043F088"
68+
BuildableName = "Antideo.framework"
69+
BlueprintName = "Antideo"
70+
ReferencedContainer = "container:Antideo.xcodeproj">
71+
</BuildableReference>
72+
</MacroExpansion>
73+
<AdditionalOptions>
74+
</AdditionalOptions>
75+
</LaunchAction>
76+
<ProfileAction
77+
buildConfiguration = "Release"
78+
shouldUseLaunchSchemeArgsEnv = "YES"
79+
savedToolIdentifier = ""
80+
useCustomWorkingDirectory = "NO"
81+
debugDocumentVersioning = "YES">
82+
<MacroExpansion>
83+
<BuildableReference
84+
BuildableIdentifier = "primary"
85+
BlueprintIdentifier = "5ADEBA171E4B36C90043F088"
86+
BuildableName = "Antideo.framework"
87+
BlueprintName = "Antideo"
88+
ReferencedContainer = "container:Antideo.xcodeproj">
89+
</BuildableReference>
90+
</MacroExpansion>
91+
</ProfileAction>
92+
<AnalyzeAction
93+
buildConfiguration = "Debug">
94+
</AnalyzeAction>
95+
<ArchiveAction
96+
buildConfiguration = "Release"
97+
revealArchiveInOrganizer = "YES">
98+
</ArchiveAction>
99+
</Scheme>

Antideo/AAAPIHelper.h

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
//
2+
// AAAPIHelper.h
3+
// Antideo
4+
//
5+
// Created by Panayot Panayotov on 08/02/2017.
6+
// Copyright © 2017 Antideo. All rights reserved.
7+
//
8+
9+
#import <Foundation/Foundation.h>
10+
#import "AAHTTPRequest.h"
11+
12+
typedef void(^APIHelperResponseBlock)(NSDictionary*response, NSError*error);
13+
14+
@interface AAAPIHelper : NSObject<NSURLSessionTaskDelegate>
15+
16+
+(void)request:(__kindof AAHTTPRequest *)request completion:(APIHelperResponseBlock)completion;
17+
18+
@end

Antideo/AAAPIHelper.m

Lines changed: 105 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,105 @@
1+
//
2+
// AAAPIHelper.m
3+
// Antideo
4+
//
5+
// Created by Panayot Panayotov on 08/02/2017.
6+
// Copyright © 2017 Antideo. All rights reserved.
7+
//
8+
9+
#import "AAAPIHelper.h"
10+
11+
12+
@implementation AAAPIHelper
13+
14+
+(void)request:(__kindof AAHTTPRequest *)request completion:(APIHelperResponseBlock)completion {
15+
NSURLComponents * urlComponents = [request urlComponents];
16+
17+
NSURLSessionConfiguration *config = [NSURLSessionConfiguration defaultSessionConfiguration];
18+
[config setHTTPAdditionalHeaders:[request headers]];
19+
20+
NSURLSession *session = [NSURLSession sessionWithConfiguration:config];
21+
22+
NSMutableURLRequest *urlrRequest = [[NSMutableURLRequest alloc] initWithURL:urlComponents.URL];
23+
urlrRequest.HTTPMethod = [self httpMethod:[request method]];
24+
25+
NSURLSessionDataTask *dataTask = [session dataTaskWithRequest:urlrRequest completionHandler:^(NSData * data, NSURLResponse * response, NSError * error) {
26+
if(error){
27+
completion(nil, error);
28+
} else {
29+
30+
NSInteger statusCode = [(NSHTTPURLResponse*)response statusCode];
31+
32+
NSError* deserializingError;
33+
NSDictionary* responseDict = [NSJSONSerialization JSONObjectWithData:data
34+
options:kNilOptions
35+
error:&deserializingError];
36+
37+
if(!deserializingError&&statusCode==200){
38+
completion(responseDict, nil);
39+
} else {
40+
completion(nil, [self errorForStatusCode:statusCode]);
41+
}
42+
}
43+
}];
44+
45+
[dataTask resume];
46+
}
47+
48+
+(NSString*)httpMethod:(HTTPMethod)method {
49+
switch (method) {
50+
case OPTIONS:
51+
return @"OPTIONS";
52+
case GET:
53+
return @"GET";
54+
case HEAD:
55+
return @"HEAD";
56+
case POST:
57+
return @"POST";
58+
case PUT:
59+
return @"PUT";
60+
case PATCH:
61+
return @"PATCH";
62+
case DELETE:
63+
return @"DELETE";
64+
case TRACE:
65+
return @"TRACE";
66+
case CONNECT:
67+
return @"CONNECT";
68+
}
69+
}
70+
71+
+(NSString*)localizedStringForErrorCode:(NSInteger)code{
72+
switch (code) {
73+
case 400:
74+
return NSLocalizedString(@"Bad Request.", @"Antideo 400 error message");
75+
case 401:
76+
return NSLocalizedString(@"Unauthorized.", @"Antideo 401 error message");
77+
case 403:
78+
return NSLocalizedString(@"Forbidden.", @"Antideo 403 error message");
79+
case 404:
80+
return NSLocalizedString(@"Not Found.", @"Antideo 404 error message");
81+
case 405:
82+
return NSLocalizedString(@"Method Not Allowed.", @"Antideo 405 error message");
83+
case 406:
84+
return NSLocalizedString(@"Not Acceptable.", @"Antideo 406 error message");
85+
case 500:
86+
return NSLocalizedString(@"Internal Server Error.", @"Antideo 500 error message");
87+
case 501:
88+
return NSLocalizedString(@"Not Implemented.", @"Antideo 501 error message");
89+
case 502:
90+
return NSLocalizedString(@"Bad Gateway.", @"Antideo 502 error message");
91+
case 503:
92+
return NSLocalizedString(@"Service Unavailable.", @"Antideo 503 error message");
93+
case 504:
94+
return NSLocalizedString(@"Gateway Timeout.", @"Antideo 504 error message");
95+
default:
96+
return nil;
97+
}
98+
}
99+
100+
+(NSError*)errorForStatusCode:(NSInteger)statusCode {
101+
NSString * erorString = [self localizedStringForErrorCode:statusCode];
102+
return [[NSError alloc]initWithDomain:@"com.antideo.framework" code:statusCode userInfo:@{NSLocalizedDescriptionKey:erorString}];
103+
}
104+
105+
@end

Antideo/AAFormatter.h

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
//
2+
// AAFormatter.h
3+
// Antideo
4+
//
5+
// Created by Panayot Panayotov on 08/02/2017.
6+
// Copyright © 2017 Antideo. All rights reserved.
7+
//
8+
9+
#import <Foundation/Foundation.h>
10+
11+
@interface AAFormatter : NSObject
12+
13+
/*!
14+
* @discussion Formats API date string to NSDate object
15+
* @param dateString Date string returned from Antideo's REST API
16+
* @return NSDate object
17+
*/
18+
+(NSDate*)dateFromAPIDateString:(NSString*)dateString;
19+
20+
/*!
21+
* @discussion Formats asn_assigned date string (yyyymmdd) to NSDate object
22+
* @param dateString Date string returned from Antideo's REST API
23+
* @return NSDate object
24+
*/
25+
+(NSDate*)dateFromASNAssignedString:(NSString*)dateString;
26+
@end

Antideo/AAFormatter.m

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
//
2+
// AAFormatter.m
3+
// Antideo
4+
//
5+
// Created by Panayot Panayotov on 08/02/2017.
6+
// Copyright © 2017 Antideo. All rights reserved.
7+
//
8+
9+
#import "AAFormatter.h"
10+
11+
@implementation AAFormatter
12+
13+
+(NSDate*)dateFromAPIDateString:(NSString*)dateString {
14+
NSDateFormatter * formatter = [[NSDateFormatter alloc]init];
15+
[formatter setDateFormat:@"yyyy-MM-dd HH:mm:ss"];
16+
return [formatter dateFromString:dateString];
17+
}
18+
19+
+(NSDate*)dateFromASNAssignedString:(NSString*)dateString {
20+
if(dateString.length == 8) {
21+
NSString * year = [dateString substringWithRange:NSMakeRange(0, 4)];
22+
NSString * month = [dateString substringWithRange:NSMakeRange(dateString.length - 4 ,2)];
23+
NSString * day = [dateString substringWithRange:NSMakeRange(dateString.length - 2, 2)];
24+
return [self dateFromAPIDateString:[NSString stringWithFormat:@"%@-%@-%@ 00:00:00",year,month,day]];
25+
}
26+
return nil;
27+
}
28+
@end

Antideo/AAHTTPRequest.h

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
//
2+
// AAHTTPRequest.h
3+
// Antideo
4+
//
5+
// Created by Panayot Panayotov on 08/02/2017.
6+
// Copyright © 2017 Antideo. All rights reserved.
7+
//
8+
9+
#import <Foundation/Foundation.h>
10+
11+
/*!
12+
* @typedef HTTPMethod
13+
* @brief A list of all http methods.
14+
*/
15+
typedef enum{
16+
OPTIONS,
17+
GET,
18+
HEAD,
19+
POST,
20+
PUT,
21+
PATCH,
22+
DELETE,
23+
TRACE,
24+
CONNECT
25+
}HTTPMethod;
26+
27+
@protocol AAHTTPRequestProtocol <NSObject>
28+
29+
+(NSURLComponents *) urlComponents;
30+
+(NSString*)path;
31+
32+
@optional
33+
34+
+(NSString*)urlScheme;
35+
+(HTTPMethod) method;
36+
+(NSDictionary<NSString*,NSString*> *) headers;
37+
+(NSDictionary<NSString*,NSString*> *) parameters;
38+
39+
@end
40+
41+
42+
@interface AAHTTPRequest : NSObject<AAHTTPRequestProtocol>
43+
44+
45+
46+
/*!
47+
* @brief URL components
48+
*/
49+
+(NSURLComponents *) urlComponents;
50+
51+
/*!
52+
* @brief http method
53+
*/
54+
+(HTTPMethod) method;
55+
56+
/*!
57+
* @brief Scheme - http or https. Default value is HTTPS
58+
*/
59+
+(NSString*)urlScheme;
60+
61+
/*!
62+
* @brief http headers
63+
*/
64+
+(NSDictionary<NSString*,NSString*> *) headers;
65+
66+
/*!
67+
* @brief url parameters
68+
*/
69+
+(NSDictionary<NSString*,NSString*> *) parameters;
70+
71+
@end

0 commit comments

Comments
 (0)