forked from kevintuhumury/itvdb
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTVDbClient.m
More file actions
65 lines (47 loc) · 1.41 KB
/
TVDbClient.m
File metadata and controls
65 lines (47 loc) · 1.41 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
//
// TVDbClient.m
// iTVDb
//
// Created by Kevin Tuhumury on 7/10/12.
// Copyright (c) 2012 Thmry. All rights reserved.
//
#import "TVDbClient.h"
#import "XMLReader.h"
@interface TVDbClient()
- (id)initWithLanguage:(NSString *)language;
@end
@implementation TVDbClient
@synthesize apiKey = _apiKey;
@synthesize language = _language;
# pragma mark - singleton
+ (TVDbClient *)sharedInstance
{
static dispatch_once_t onlyOnceToken = 0;
__strong static TVDbClient *sharedObject = nil;
dispatch_once(&onlyOnceToken, ^{
sharedObject = [[TVDbClient alloc] initWithLanguage: @"en"];
});
return sharedObject;
}
# pragma mark - initializers
- (id)initWithLanguage:(NSString *)language
{
if (self = [super init])
{
_language = language;
}
return self;
}
#pragma mark - public methods
- (NSDictionary *)requestURL:(NSString *)url
{
NSMutableData *data = [NSMutableData data];
NSString *baseUrl = [BASE_URI stringByAppendingString:url];
NSURLRequest *request = [NSURLRequest requestWithURL:[NSURL URLWithString:baseUrl]];
NSURLResponse *response = [[NSURLResponse alloc] init];
NSError *error = [[NSError alloc] init];
NSData *responseData = [NSURLConnection sendSynchronousRequest:request returningResponse:&response error:&error];
[data setData:responseData];
return [XMLReader dictionaryForXMLData:data error:&error];
}
@end