Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Activity
    Brian
    @brmendez
    yo
    a little pathetic where I am :)
    +(NSDictionary *)parseJSONintoCar2GoOperationAreas:(NSData *)rawJSONData {
    
        NSDictionary *car2Go = [[NSDictionary alloc]init];
        NSError *error = nil;
        NSDictionary *JSONDictionary = [NSJSONSerialization JSONObjectWithData:rawJSONData options:0 error:&error];
    
        if (error) {
            NSLog(@"json parsing unsuccessful. %@", error.localizedDescription);
        } else {
    
            id JSONData = [JSONDictionary valueForKey:@"placemarks"];
            if ([JSONData isKindOfClass:[NSArray class]]) {
                NSDictionary *operatingAreas = JSONData[@"name"];
                NSLog(@"the operating areas: %@", operatingAreas);
            }
        }
    
        return car2Go;
    
    }
    Kolo13
    @Kolo13
    Looking at it. So did you do a request for all available cars?
    Brian
    @brmendez
    -(void)getCar2GoOperationAreas {
    
        NSString *operationAreasURL = @"operationareas";
        NSString *urlWithSearchTerm = [[NSString alloc]init];
        urlWithSearchTerm = [NSString stringWithFormat:@"%@%@?loc=%@&oauth_consumer_key=%@&format=json", URL, operationAreasURL, seattle, Client_Key];
    
        NSURL *url = [[NSURL alloc]initWithString:urlWithSearchTerm];
        NSURLSessionConfiguration *configuration = [NSURLSessionConfiguration defaultSessionConfiguration];
        NSURLSession *session = [NSURLSession sessionWithConfiguration:configuration];
        NSMutableURLRequest *request = [[NSMutableURLRequest alloc]initWithURL:url];
        NSURLSessionDataTask *dataTask = [session dataTaskWithRequest:request completionHandler:^(NSData *data, NSURLResponse *response, NSError *error) {
            if (error) {
                NSLog(@"%@", error.localizedDescription);
            } else {
                if ([response isKindOfClass:[NSHTTPURLResponse class]]) {
                    NSHTTPURLResponse *httpURLResponse = (NSHTTPURLResponse *) response;
                    NSLog(@"%ld", (long)httpURLResponse.statusCode);
                    if (httpURLResponse.statusCode >= 200 && httpURLResponse.statusCode <= 299) {
                        NSLog(@"success! code: %lu", httpURLResponse.statusCode);
    
                        NSDictionary *car2Go = [OperationAreas parseJSONintoCar2GoOperationAreas:data];
    
                    }
    
                }
            }
        }];
    
        [dataTask resume];
    }
    Kolo13
    @Kolo13
    ok. I think I see what's going on.
    id JSONData = [JSONDictionary valueForKey:@"placemarks"]; if ([JSONData isKindOfClass:[NSArray class]]) { NSDictionary *operatingAreas = JSONData[@"name"]; NSLog(@"the operating areas: %@", operatingAreas); } }
    crap
    I haven't used bitter in a while sorry
    after you get placemarks. You have a dictionary with one value, which is an array of dictionaries.
    You have to walk over the array and then pull out "name" as you hit each element
    Kolo13
    @Kolo13
    id JSONData = [JSONDictionary valueForKey:@"placemarks"];
            if ([JSONData isKindOfClass:[NSArray class]]) {
    
                for (NSDictionary *item in placemarksArray) {
                    NSDictionary *operatingAreas = item[@"name"];
                    NSLog(@"the operating areas: %@", operatingAreas);
                }
    
            }
        }
    Kolo13
    @Kolo13
    //
    //  ViewController.m
    //  TimeLapse
    //
    //  Created by kori kolodziejczak on 6/19/15.
    //  Copyright (c) 2015 kori kolodziejczak. All rights reserved.
    //
    
    #import "ViewController.h"
    #import <GoogleMaps/GoogleMaps.h>
    
    
    
    @interface ViewController ()
    
    @property (strong, nonatomic) GMSMapView *mapView;
    @property (strong, nonatomic) NSMutableArray *riderArray;
    
    @end
    
    @implementation ViewController
    
    - (void)viewDidLoad {
        [super viewDidLoad];
    
    
    
        GMSCameraPosition *camera = [GMSCameraPosition cameraWithLatitude:47.6207
                                                                longitude:-122.3487
                                                                     zoom:10.00
                                                                  bearing:0
                                                             viewingAngle:0];
    
        self.mapView = [GMSMapView mapWithFrame:self.view.bounds camera:camera];
        self.mapView.mapType = kGMSTypeTerrain;
        self.mapView.myLocationEnabled = YES;
        self.mapView.settings.compassButton = YES;
        self.mapView.settings.myLocationButton = YES;
    
    
        UILabel *label1 = [UILabel new];
        label1.text = @"Hello!";
    
        self.mapView.delegate = self;
        self.view = self.mapView;
    
    
        [NetworkController getCarLocations:nil completionHandler:^(NSDictionary *JSONDictionary) {
    
            [ParseJSON parseLocation:JSONDictionary completionHandler:^(NSMutableArray *rideArray) {
                for (NSDictionary *item in rideArray) {
                    dispatch_async(dispatch_get_main_queue(), ^{
                        CLLocationCoordinate2D position = CLLocationCoordinate2DMake([[item valueForKey:@"latitude"] doubleValue], [[item valueForKey:@"longitude"] doubleValue]);
                        GMSMarker *marker = [GMSMarker markerWithPosition:position];
                        marker.appearAnimation = kGMSMarkerAnimationPop;
                        marker.icon = [UIImage imageNamed:@"key"];
                        marker.flat = YES;
                        marker.map = self.mapView;
                    });
                }
            }];
        }];
    }
    
    - (void)mapView:(GMSMapView *)mapView idleAtCameraPosition:(GMSCameraPosition *)position {
        NSLog(@"Stopped Panning");
    }
    
    @end
    code
    Brian
    @brmendez
    Noticing that the variable 'car2Go' in line " NSDictionary *car2Go = [OperationAreas parseJSONintoCar2GoOperationAreas:data];
    does not have any values, the 'data' has bytes. Wondering why, it is an NSDictionary too.
    if ([response isKindOfClass:[NSHTTPURLResponse class]]) {
                    NSHTTPURLResponse *httpURLResponse = (NSHTTPURLResponse *) response;
                    NSLog(@"%ld", (long)httpURLResponse.statusCode);
                    if (httpURLResponse.statusCode >= 200 && httpURLResponse.statusCode <= 299) {
                        NSLog(@"success! code: %lu", httpURLResponse.statusCode);
    
                        NSDictionary *car2Go = [OperationAreas parseJSONintoCar2GoOperationAreas:data];
                        NSLog(@"The Car2Go's: %@", car2Go);
                    }
    
                }
    Brian
    @brmendez
    Im pretty sure it's because I don't have a completion handler declared in the method header.
    -(void)getCar2GoOperationAreas
    The header is JUST that. :/
    Kolo13
    @Kolo13
    This message was deleted
    This message was deleted
    This message was deleted
    This message was deleted
    curl -i https://www.car2go.com/api/reqtoken
    HTTP/1.1 400 Bad Request
    WWW-Authenticate: OAuth realm="car2go_api", oauth_parameters_absent="oauth_consumer_key%26oauth_timestamp%26oauth_nonce%26oauth_signature_method%26oauth_signature%26oauth_callback", oauth_problem="parameter_absent"
    Content-Language: en-US
    Transfer-Encoding: chunked
    Date: Fri, 04 Sep 2015 05:29:11 GMT
    Kolo13
    @Kolo13
    curl to the rescue... The required parameters are listed in this request response
    Brian
    @brmendez
    curl -i https://www.car2go.com/api/reqtoken?oauth_callback=oob&oauth_consumer_key=CarData&oauth_nonce=LVWcQRa2CjeNHMgPDTJpnCQKvf6chkhqRBhbh6dShvvzb9Jom8rx1UOePPYAu4MeIYRxF5kyuUBhjzPu&oauth_signature_method=HMAC-SHA1&oauth_version=1.0
    [1] 17873
    [2] 17874
    [3] 17875
    [4] 17876
    [2]   Done                    oauth_consumer_key=CarData
    [3]-  Done                    oauth_nonce=LVWcQRa2CjeNHMgPDTJpnCQKvf6chkhqRBhbh6dShvvzb9Jom8rx1UOePPYAu4MeIYRxF5kyuUBhjzPu
    [brianmendez~]>HTTP/1.1 400 Bad Request
    WWW-Authenticate: OAuth realm="car2go_api", oauth_parameters_absent="oauth_consumer_key%26oauth_timestamp%26oauth_nonce%26oauth_signature_method%26oauth_signature", oauth_problem="parameter_absent"
    Content-Language: en-US
    Transfer-Encoding: chunked
    Date: Sat, 05 Sep 2015 05:40:46 GMT
    Brian
    @brmendez
    hey dude ! How are you!?!?! :shipit:
    var aVariable = "Hello World"
    Kolo13
    @Kolo13
    +(NSString *)hmacsha1:(NSString *)data secret:(NSString *)key {
    
        const char *cKey  = [key cStringUsingEncoding:NSUTF8StringEncoding];
        const char *cData = [data cStringUsingEncoding:NSUTF8StringEncoding];
    
        unsigned char cHMAC[CC_SHA1_DIGEST_LENGTH];
    
        CCHmac(kCCHmacAlgSHA1, cKey, strlen(cKey), cData, strlen(cData), cHMAC);
    
        NSData *HMAC = [[NSData alloc] initWithBytes:cHMAC length:sizeof(cHMAC)];
    
        NSString *hash = [HMAC base64EncodedStringWithOptions:NSDataBase64Encoding64CharacterLineLength];
    
        return hash;
    }
    This message was deleted
    Kolo13
    @Kolo13
      NSString *encodedParameterString = [parameters stringByAddingPercentEncodingWithAllowedCharacters:[NSCharacterSet URLQueryAllowedCharacterSet]];
    
        NSString *encodedURLstring = [urlString stringByAddingPercentEncodingWithAllowedCharacters:[NSCharacterSet URLQueryAllowedCharacterSet]];
    
        NSString *baseString = [NSString stringWithFormat:@"GET&%@&%@", encodedURLstring, encodedParameterString];
    Kolo13
    @Kolo13
    2015-09-11 12:53:23.505 TimeLapse[26302:2703075] RESPONSE =================== <NSHTTPURLResponse: 0x7fa29638f560> { URL: https://www.car2go.com/en/austin/?oauth_callback=oob&oauth_consumer_key=CarData&oauth_nonce=588f848a9d9f4a2f2deaa5e9b0e04664&oauth_signature=E4JLOhnIrZM0xDGBdcJlkvUTsgw%25253D&oauth_signature_method=HMAC-SHA1&oauth_timestamp=1442001139 } { status code: 200, headers {
        "Accept-Ranges" = bytes;
        "Content-Encoding" = gzip;
        "Content-Length" = 10015;
        "Content-Type" = "text/html";
        Date = "Fri, 11 Sep 2015 19:53:22 GMT";
        "Last-Modified" = "Thu, 10 Sep 2015 16:16:10 GMT";
        Vary = "Accept-Encoding,User-Agent";