-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathPriceHandler.m
More file actions
43 lines (39 loc) · 1.25 KB
/
PriceHandler.m
File metadata and controls
43 lines (39 loc) · 1.25 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
//
// PriceHandler.m
// DogeKeeper
//
// Created by Andrew on 7/30/14.
// Copyright (c) 2014 Andrew Arpasi. All rights reserved.
//
#import "PriceHandler.h"
@implementation PriceHandler
+(NSString*)makeUrlRequest:(NSURL*)requestURL
{
[[NSURLCache sharedURLCache] removeAllCachedResponses];
NSURLRequest* request = [NSURLRequest requestWithURL:requestURL cachePolicy:0 timeoutInterval:15];
NSData* data=[NSURLConnection sendSynchronousRequest:request returningResponse:nil error:nil];
NSString* stringFromServer = [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding];
return stringFromServer;
}
+(NSArray*)getPricesFromSoChain
{
NSURL * request = [[NSURL alloc] initWithString:@"https://chain.so/api/v2/get_price/DOGE"];
NSString * response = [self makeUrlRequest:request];
NSMutableDictionary * pricedata;
if(response != nil)
{
pricedata = [NSJSONSerialization JSONObjectWithData:[response dataUsingEncoding:NSUTF8StringEncoding] options:kNilOptions error:nil];
}
else
{
return nil;
}
NSDictionary * data = pricedata[@"data"];
if([pricedata[@"status"] isEqualToString:@"success"])
{
NSArray * prices = data[@"prices"];
return prices;
}
return nil;
}
@end