-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDiabloAPIClient.m
More file actions
99 lines (83 loc) · 2.54 KB
/
DiabloAPIClient.m
File metadata and controls
99 lines (83 loc) · 2.54 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
//
// DiabloAPIClient.m
// Diablo Connect
//
// Created by Andy Jacobs on 18/06/12.
// Copyright (c) 2012 REVOLVER. All rights reserved.
//
#import "DiabloAPIClient.h"
#import "AFJSONRequestOperation.h"
NSString * const kDiabloAPIBaseURLString = @"http://%@.battle.net/api/d3/";
//NSString * const kDiabloAPIBaseURLString = @"http://diablo.revolver.be/api/d3/";
@implementation DiabloAPIClient
@synthesize currentRegion = _currentRegion;
+ (DiabloAPIClient *)sharedClient {
static DiabloAPIClient *_sharedClient = nil;
static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{
_sharedClient = [[DiabloAPIClient alloc] initWithBaseURL:[NSURL URLWithString:kDiabloAPIBaseURLString]];
});
return _sharedClient;
}
- (id)initWithBaseURL:(NSURL *)url {
self = [super initWithBaseURL:url];
if (!self) {
return nil;
}
[self registerHTTPOperationClass:[AFJSONRequestOperation class]];
// Accept HTTP Header; see http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.1
[self setDefaultHeader:@"Accept" value:@"application/json"];
return self;
}
- (void) changeRegion:(DiabloRegion)region
{
_currentRegion = region;
self.baseURL = [self APIDomain];
}
- (NSURLRequest *) URLRequestForBlacksmith
{
return [NSURLRequest requestWithURL:[NSURL URLWithString:[NSString stringWithFormat:@"%@data/artisan/blacksmith",[self APIDomain]]]];
}
- (NSURLRequest *) URLRequestForJeweler
{
return [NSURLRequest requestWithURL:[NSURL URLWithString:[NSString stringWithFormat:@"%@data/artisan/jeweler",[self APIDomain]]]];
}
- (NSURLRequest *) URLRequestforItem:(NSString *)path
{
return [NSURLRequest requestWithURL:[NSURL URLWithString:[NSString stringWithFormat:@"%@%@",[self APIDomain],path]]];
}
- (NSURL *) APIDomain
{
NSString *domainString = [NSString stringWithFormat:kDiabloAPIBaseURLString,[DiabloAPIClient domainCodeForRegion:_currentRegion]];
return [NSURL URLWithString:domainString];
}
+ (NSString *) domainCodeForRegion:(DiabloRegion)region
{
NSString *domainCode = @"";
switch (region) {
case DiabloRegionAmericas:
{
domainCode = @"US";
break;
}
case DiabloRegionEU:
{
domainCode = @"EU";
break;
}
case DiabloRegionKR:
{
domainCode = @"KR";
break;
}
case DiabloRegionTW:
{
domainCode = @"TW";
break;
}
default:
break;
}
return domainCode;
}
@end