I have no idea about Ruby on rails
I have a task to create web-service with Ruby on rails
. I am trying with AFNetworking and NSURLConnection but did not got responce.
TIMESTAMP_KEY = '6ad3e2c0ffa4a89217e0'
SECRET_KEY = 'fd83be9e64ddec6ee8344708a189d039ad9e9d51'
HOST = 'http://em.dev.apb.com
URL = 'company_users/login'
They said above parameters is predefine and its ruby code like:
1 params = []
2 sorted_params = params.sort.join
3 puts "sorted_params=#{sorted_params}"
4 digest = Digest::SHA1.hexdigest("#{timestamp}#{TIMESTAMP_KEY}")
5 puts "digest=#{digest}"
6 puts "SHA1(#{URL}#{sorted_params}#{SECRET_KEY}#{digest})"
7 signature = Digest::SHA1.hexdigest("#{URL}#{sorted_params}#{SECRET_KEY}#{digest}")
puts "#{HOST}#{URL}"
response = RestClient.post "#{HOST}/#{URL}/#{signature}/#{timestamp}", :email => email, :password => password
I have no idea how to get its Response in objective C:
I am trying AFnetworking
AFHTTPRequestOperationManager *manager = [AFHTTPRequestOperationManager manager];
NSString *signature =[self sha1:@"fd83be9e64ddec6ee8344708a189d039ad9e9d51"];
NSString *timestep =[self sha1:@"6ad3e2c0ffa4a89217e0"];
NSDictionary *params = @{@"email": @"abc@superuser.com",@"password": @"aaa111"};
NSLog(@"%@",params);
NSString *url =[NSString stringWithFormat:@"http://em.dev.abc.com/company_users/login/%@/%@",signature,timestep];
[manager POST:url parameters:params success:^(AFHTTPRequestOperation *operation, id responseObject) {
NSLog(@"JSON: %@", responseObject);
} failure:^(AFHTTPRequestOperation *operation, NSError *error) {
NSLog(@"Error: %@", error);
}];
I got this Link
So I use this method
-(NSString*) sha1:(NSString*)input
{
const char *cstr = [input cStringUsingEncoding:NSUTF8StringEncoding];
NSData *data = [NSData dataWithBytes:cstr length:input.length];
uint8_t digest[CC_SHA1_DIGEST_LENGTH];
CC_SHA1(data.bytes, data.length, digest);
NSMutableString* output = [NSMutableString stringWithCapacity:CC_SHA1_DIGEST_LENGTH * 2];
for(int i = 0; i < CC_SHA1_DIGEST_LENGTH; i++)
[output appendFormat:@"%02x", digest[i]];
return output;
}
Every time I get this output as an Error like:
Error: Error Domain=NSCocoaErrorDomain Code=3840 "The operation couldn’t be completed. (Cocoa error 3840.)" (JSON text did not start with array or object and option to allow fragments not set.) UserInfo=0x8c56190 {NSDebugDescription=JSON text did not start with array or object and option to allow fragments not set.