NSMutableData to NSString conversion fails if special character present - nsstring

I'm writing an app to interact with a DirecTV receiver through the http server interface. I'm able to query the device and get the SJON formatted response.
Here is my sample code:
- (NSDictionary *) readDVRData
{
NSMutableData *rData = [[NSMutableData alloc] initWithContentsOfFile:#"./data"];
//NSLog(#"rData = %#",rData);
NSString *rString = [[NSString alloc] initWithData:rData encoding:NSUTF8StringEncoding];
NSLog(#"rString = %#",rString);
NSError *error;
SBJSON *json = [[SBJSON new] autorelease];
NSDictionary *response = [json objectWithString:rString error:&error];
//NSLog(#"response = %#",response);
return response;
}
For testing purposes, I saved the response to the data file and I'm reading from it in the example above. The conversion from NSMutableData to NSString via:
NSString *rString = [[NSString alloc] initWithData:rData encoding:NSUTF8StringEncoding];
fails if the following character is in place. È as in CrÈme Fraiche. For reference this was in the episodeTitle and description from a South Park recording.
If I change this character to just an upper case "E", the conversion works. Is there a different method I should use to catch something like this? Or is there a simple way to remove characters like this? Please keep in mind I will not know before hand if it's and accent mark or something different that might cause the conversion to fail.
Thanks,
Dave
Snippet of data file if that is needed. I would include the entire text, but it pushes the character limit above the 30000 limit.
{
"groupId": "1 1 381C3",
"groupTitle": "South Park",
"isRecording": false,
"numItems": 10,
"numNewItems": 10,
"programs": [
{
"callsign": "COMHD",
"contentId": "1 1 381C3 198",
"description": "\"CrÈme Fraiche\" Animation, Comedy. (2010) Trey Parker, Matt Stone. Randy's obsession with the Food Network forces Sharon to explore a new interest of her own. Series.",
"duration": 1800,
"episodeTitle": "CrÈme Fraiche",
"expiration": "0",
"isHd": true,
"isPartial": false,
"isPpv": false,
"isRecording": false,
"isViewed": false,
"isVod": false,
"keepUntilFull": true,
"major": 249,
"minor": 65535,
"programId": "6937756",
"rating": "TV-MA-L",
"startTime": 1290056400,
"title": "South Park",
"uniqueId": "5397375192530140068"
},
{
"callsign": "COMHD",
"contentId": "1 1 381C3 197",
"description": "\"Coon vs. Coon & Friends\" Animation, Comedy. (2010) Trey Parker, Matt Stone. Coon and Friends find themselves at the mercy of Cartman who now has the dark lord doing his bidding; Kenny wrestles with the curse of his super power. Series.",
"duration": 1800,
"episodeTitle": "Coon vs. Coon & Friends",
"expiration": "0",
"isHd": true,
"isPartial": false,
"isPpv": false,
"isRecording": false,
"isViewed": false,
"isVod": false,
"keepUntilFull": true,
"major": 249,
"minor": 65535,
"programId": "6918387",
"rating": "TV-MA-L",
"startTime": 1289444400,
"title": "South Park",
"uniqueId": "8476957599452610419"
},
{
"callsign": "COMHD",
"contentId": "1 1 381C3 196",
"description": "\"Mysterion Rises\" Animation, Comedy. (2010) Trey Parker, Matt Stone. Mysterion's true identity is revealed; scorned by fellow superheroes, one goes out for revenge. Series.",
"duration": 1800,
"episodeTitle": "Mysterion Rises",
"expiration": "0",
"isHd": true,
"isPartial": false,
"isPpv": false,
"isRecording": false,
"isViewed": false,
"isVod": false,
"keepUntilFull": true,
"major": 249,
"minor": 65535,
"programId": "6896823",
"rating": "TV-MA-L",
"startTime": 1288843200,
"title": "South Park",
"uniqueId": "2113731123121326471"
},
{
"callsign": "COMHD",
"contentId": "1 1 381C3 0",
"description": "Animation, Comedy. Trey Parker, Matt Stone. The adventures of four boys who live in South Park, Colo. Series.",
"duration": 1800,
"episodeTitle": "",
"expiration": "0",
"isHd": true,
"isPartial": false,
"isPpv": false,
"isRecording": false,
"isViewed": false,
"isVod": false,
"keepUntilFull": true,
"major": 249,
"minor": 65535,
"programId": "6830127",
"rating": "TV-MA-L",
"startTime": 1288751400,
"title": "South Park",
"uniqueId": "2166056034991125062"
},
{
"callsign": "COMHD",
"contentId": "1 1 381C3 195",
"description": "\"Coon 2: Hindsight\" Animation, Comedy. (2010) Trey Parker, Matt Stone. Coon and friends set out to help the victims of BP's latest catastrophic drilling accident in the Gulf. Series.",
"duration": 1800,
"episodeTitle": "Coon 2: Hindsight",
"expiration": "0",
"isHd": true,
"isPartial": false,
"isPpv": false,
"isRecording": false,
"isViewed": false,
"isVod": false,
"keepUntilFull": true,
"major": 249,
"minor": 65535,
"programId": "6876407",
"rating": "TV-MA-L",
"startTime": 1288238400,
"title": "South Park",
"uniqueId": "8615834721021879366"
},
{
"callsign": "COMHD",
"contentId": "1 1 381C3 194",
"description": "\"Insheeption\" Animation, Comedy. (2010) Trey Parker, Matt Stone. When Stan is sent to the school counselor because he's holding on to an obscene number of useless possessions, he realizes that Mr. Mackey had a hoarding disorder too. Series.",
"duration": 1783,
"episodeTitle": "Insheeption",
"expiration": "0",
"isHd": true,
"isPartial": false,
"isPpv": false,
"isRecording": false,
"isViewed": false,
"isVod": false,
"keepUntilFull": true,
"major": 249,
"minor": 65535,
"programId": "6857628",
"rating": "TV-MA-L",
"startTime": 1287626416,
"title": "South Park",
"uniqueId": "1547798106243799673"
},
{
"callsign": "COMHD",
"contentId": "1 1 381C3 193",
"description": "\"It's a Jersey Thing\" Animation, Comedy. (2010) Trey Parker, Matt Stone. New Jersey is taking over the nation one state at a time, Randy and the boys take a stand as the Jerseyites approach South Park. Series.",
"duration": 1800,
"episodeTitle": "It's a Jersey Thing",
"expiration": "0",
"isHd": true,
"isPartial": false,
"isPpv": false,
"isRecording": false,
"isViewed": false,
"isVod": false,
"keepUntilFull": true,
"major": 249,
"minor": 65535,
"programId": "6839243",
"rating": "TV-MA-L",
"startTime": 1287028800,
"title": "South Park",
"uniqueId": "8123622337314668826"
},
{
"callsign": "COMHD",
"contentId": "1 1 381C3 193",
"description": "\"It's a Jersey Thing\" Animation, Comedy. (2010) Trey Parker, Matt Stone. New Jersey is taking over the nation one state at a time, Randy and the boys take a stand as the Jerseyites approach South Park. Series.",
"duration": 1784,
"episodeTitle": "It's a Jersey Thing",
"expiration": "0",
"isHd": true,
"isPartial": false,
"isPpv": false,
"isRecording": false,
"isViewed": false,
"isVod": false,
"keepUntilFull": true,
"major": 249,
"minor": 65535,
"programId": "6839243",
"rating": "TV-MA-L",
"startTime": 1287021615,
"title": "South Park",
"uniqueId": "949183344652655207"
},
{
"callsign": "COMHD",
"contentId": "1 1 381C3 0",
"description": "Animation, Comedy. Trey Parker, Matt Stone. The adventures of four boys who live in South Park, Colo. Series.",
"duration": 1800,
"episodeTitle": "",
"expiration": "0",
"isHd": true,
"isPartial": false,
"isPpv": false,
"isRecording": false,
"isViewed": false,
"isVod": false,
"keepUntilFull": true,
"major": 249,
"minor": 65535,
"programId": "6830127",
"rating": "TV-MA-L",
"startTime": 1286937000,
"title": "South Park",
"uniqueId": "7841891672059226043"
},
{
"callsign": "COMHD",
"contentId": "1 1 381C3 0",
"description": "Animation, Comedy. Trey Parker, Matt Stone. The adventures of four boys who live in South Park, Colo. Series.",
"duration": 1800,
"episodeTitle": "",
"expiration": "0",
"isHd": true,
"isPartial": false,
"isPpv": false,
"isRecording": false,
"isViewed": false,
"isVod": false,
"keepUntilFull": true,
"major": 249,
"minor": 65535,
"programId": "6830127",
"rating": "TV-MA-L",
"startTime": 1286856000,
"title": "South Park",
"uniqueId": "3872435936942587460"
}
]
}

Have you tried other encodings, such as NSISOLatin1StringEncoding?

It's likely an encoding problem from the web server. You're expecting UTF-8 data, but I bet you that's not what they are sending you. Try reading using [NSString stringWithContentsOfFile:] instead and see if anything changes.
The compiler will throw a warning because that method is deprecated. In fact, you could use stringWithContentsOfFile:usedEncoding:error: instead, but I and others have reported that it doesn't seem to work as well as the old method for data that is not perfectly encoded (that is, 90% of the web :-)).

Check the HTTP headers in the DirecTV unit's response. It is probably not using UTF-8. Figure out which encoding it is using, then supply the correct constant to initWithData:encoding:.
You can use the command curl -i http://directv-data-url to see the HTTP headers.

Related

How to convert a nested json file into a dataframe in R and extract the values in different columns?

I am very new to R and trying to convert the below json file into nicer dataframe
json_file <- "path_to_json_file/file.json"
json_data <- read_json(json_file, simplifyVector = TRUE)
json_data <- json_data %>% as_tibble()
glimpse(json_data)
My json file file.json:
{
"data": {
"sessionId": "AV50BX6JXG5UN0UF",
"lang": "en-us",
"disposition": {
"bestPath": [],
"allPath": []
},
"nlpEntities": {
"status": "Success",
"message": "Success",
"sessionId": "AV50BX6JXG5UN0UF",
"lang": "en-us",
"startTime": 1660813927150,
"entities": [
{
"id": "2660",
"modelType": "nlp",
"intentChannel": "agent",
"entityType": "STRING",
"asrValue": "welcome to c",
"normalizedValue": "welcome to c",
"preprocessedValue": "welcome to c",
"valid": true,
"channel": "agent",
"intentTurnNo": 0,
"turnId": [
1
],
"asrValueCharSpan": {},
"position": 6,
"contributedWords": "welcome to c",
"detectedSentence": "agent: hello welcome to c my name is christian direc spread for today may i know your name please hello welcome to c my name is christian expired for today may i know your name please im sorry i cannot hear any response on the other line and i will need to disconnect the call please call us back thank you"
},
{
"id": "2661",
"modelType": "nlp",
"intentChannel": "agent",
"entityType": "STRING",
"asrValue": "cannot hear",
"normalizedValue": "cannot hear",
"preprocessedValue": "cannot hear",
"valid": true,
"channel": "agent",
"intentTurnNo": 0,
"turnId": [
1
],
"asrValueCharSpan": {},
"position": 214,
"contributedWords": "cannot hear",
"detectedSentence": "agent: hello welcome to c my name is christian direc spread for today may i know your name please hello welcome to c my name is christian expired for today may i know your name please im sorry i cannot hear any response on the other line and i will need to disconnect the call please call us back thank you"
},
{
"id": "2601",
"modelType": "nlp",
"intentChannel": "agent",
"entityType": "STRING",
"asrValue": "line",
"normalizedValue": "line",
"preprocessedValue": "line",
"valid": true,
"channel": "agent",
"intentTurnNo": 0,
"turnId": [
1
],
"asrValueCharSpan": {},
"position": 252,
"contributedWords": "line",
"detectedSentence": "agent: hello welcome to c my name is christian direc spread for today may i know your name please hello welcome to c my name is christian expired for today may i know your name please im sorry i cannot hear any response on the other line and i will need to disconnect the call please call us back thank you"
},
{
"id": "2559",
"modelType": "nlp",
"intentChannel": "agent",
"entityType": "STRING",
"asrValue": "line",
"normalizedValue": "line",
"preprocessedValue": "line",
"valid": true,
"channel": "agent",
"intentTurnNo": 0,
"turnId": [
1
],
"asrValueCharSpan": {},
"position": 252,
"contributedWords": "line",
"detectedSentence": "agent: hello welcome to c my name is christian direc spread for today may i know your name please hello welcome to c my name is christian expired for today may i know your name please im sorry i cannot hear any response on the other line and i will need to disconnect the call please call us back thank you"
},
{
"id": "2698",
"modelType": "nlp",
"intentChannel": "agent",
"entityType": "STRING",
"asrValue": "disconnect",
"normalizedValue": "disconnect",
"preprocessedValue": "disconnect",
"valid": true,
"channel": "agent",
"intentTurnNo": 0,
"turnId": [
1
],
"asrValueCharSpan": {},
"position": 276,
"contributedWords": "disconnect",
"detectedSentence": "agent: hello welcome to c my name is christian direc spread for today may i know your name please hello welcome to c my name is christian expired for today may i know your name please im sorry i cannot hear any response on the other line and i will need to disconnect the call please call us back thank you"
},
{
"id": "2389",
"modelType": "nlp",
"intentChannel": "agent",
"entityType": "STRING",
"asrValue": "call",
"normalizedValue": "call",
"preprocessedValue": "call",
"valid": true,
"channel": "agent",
"intentTurnNo": 0,
"turnId": [
1
],
"asrValueCharSpan": {},
"position": 291,
"contributedWords": "call",
"detectedSentence": "agent: hello welcome to c my name is christian direc spread for today may i know your name please hello welcome to c my name is christian expired for today may i know your name please im sorry i cannot hear any response on the other line and i will need to disconnect the call please call us back thank you"
},
{
"id": "2615",
"modelType": "nlp",
"intentChannel": "agent",
"entityType": "STRING",
"asrValue": "call us back",
"normalizedValue": "call us back",
"preprocessedValue": "call us back",
"valid": true,
"channel": "agent",
"intentTurnNo": 0,
"turnId": [
1
],
"asrValueCharSpan": {},
"position": 303,
"contributedWords": "call us back",
"detectedSentence": "agent: hello welcome to c my name is christian direc spread for today may i know your name please hello welcome to c my name is christian expired for today may i know your name please im sorry i cannot hear any response on the other line and i will need to disconnect the call please call us back thank you"
},
{
"id": "3594",
"modelType": "nlp",
"intentChannel": "customer",
"entityType": "STRING",
"asrValue": "make",
"normalizedValue": "make",
"preprocessedValue": "make",
"valid": true,
"channel": "customer",
"intentTurnNo": 1,
"turnId": [
2
],
"asrValueCharSpan": {},
"position": 8,
"contributedWords": "make",
"detectedSentence": "customer: i wanna make a call complaining"
},
{
"id": "2661",
"modelType": "nlp",
"intentChannel": "agent",
"entityType": "STRING",
"asrValue": "hear me",
"normalizedValue": "hear me",
"preprocessedValue": "hear me",
"valid": true,
"channel": "agent",
"intentTurnNo": 2,
"turnId": [
3
],
"asrValueCharSpan": {},
"position": 14,
"contributedWords": "hear me",
"detectedSentence": "agent: hello can you hear me mm hello can you hear me mm im sorry i cant hear her any response on the other line and i will need to disconnect the call please call us back thank you im sorry i cannot hear any risk once on the other line and i will need to disconnect the call please call us back thank you"
},
{
"id": "2601",
"modelType": "nlp",
"intentChannel": "agent",
"entityType": "STRING",
"asrValue": "line",
"normalizedValue": "line",
"preprocessedValue": "line",
"valid": true,
"channel": "agent",
"intentTurnNo": 2,
"turnId": [
3
],
"asrValueCharSpan": {},
"position": 101,
"contributedWords": "line",
"detectedSentence": "agent: hello can you hear me mm hello can you hear me mm im sorry i cant hear her any response on the other line and i will need to disconnect the call please call us back thank you im sorry i cannot hear any risk once on the other line and i will need to disconnect the call please call us back thank you"
},
{
"id": "2559",
"modelType": "nlp",
"intentChannel": "agent",
"entityType": "STRING",
"asrValue": "line",
"normalizedValue": "line",
"preprocessedValue": "line",
"valid": true,
"channel": "agent",
"intentTurnNo": 2,
"turnId": [
3
],
"asrValueCharSpan": {},
"position": 101,
"contributedWords": "line",
"detectedSentence": "agent: hello can you hear me mm hello can you hear me mm im sorry i cant hear her any response on the other line and i will need to disconnect the call please call us back thank you im sorry i cannot hear any risk once on the other line and i will need to disconnect the call please call us back thank you"
},
{
"id": "2698",
"modelType": "nlp",
"intentChannel": "agent",
"entityType": "STRING",
"asrValue": "disconnect",
"normalizedValue": "disconnect",
"preprocessedValue": "disconnect",
"valid": true,
"channel": "agent",
"intentTurnNo": 2,
"turnId": [
3
],
"asrValueCharSpan": {},
"position": 125,
"contributedWords": "disconnect",
"detectedSentence": "agent: hello can you hear me mm hello can you hear me mm im sorry i cant hear her any response on the other line and i will need to disconnect the call please call us back thank you im sorry i cannot hear any risk once on the other line and i will need to disconnect the call please call us back thank you"
},
{
"id": "2389",
"modelType": "nlp",
"intentChannel": "agent",
"entityType": "STRING",
"asrValue": "call",
"normalizedValue": "call",
"preprocessedValue": "call",
"valid": true,
"channel": "agent",
"intentTurnNo": 2,
"turnId": [
3
],
"asrValueCharSpan": {},
"position": 140,
"contributedWords": "call",
"detectedSentence": "agent: hello can you hear me mm hello can you hear me mm im sorry i cant hear her any response on the other line and i will need to disconnect the call please call us back thank you im sorry i cannot hear any risk once on the other line and i will need to disconnect the call please call us back thank you"
},
{
"id": "2615",
"modelType": "nlp",
"intentChannel": "agent",
"entityType": "STRING",
"asrValue": "call us back",
"normalizedValue": "call us back",
"preprocessedValue": "call us back",
"valid": true,
"channel": "agent",
"intentTurnNo": 2,
"turnId": [
3
],
"asrValueCharSpan": {},
"position": 152,
"contributedWords": "call us back",
"detectedSentence": "agent: hello can you hear me mm hello can you hear me mm im sorry i cant hear her any response on the other line and i will need to disconnect the call please call us back thank you im sorry i cannot hear any risk once on the other line and i will need to disconnect the call please call us back thank you"
},
{
"id": "2661",
"modelType": "nlp",
"intentChannel": "agent",
"entityType": "STRING",
"asrValue": "cannot hear",
"normalizedValue": "cannot hear",
"preprocessedValue": "cannot hear",
"valid": true,
"channel": "agent",
"intentTurnNo": 2,
"turnId": [
3
],
"asrValueCharSpan": {},
"position": 186,
"contributedWords": "cannot hear",
"detectedSentence": "agent: hello can you hear me mm hello can you hear me mm im sorry i cant hear her any response on the other line and i will need to disconnect the call please call us back thank you im sorry i cannot hear any risk once on the other line and i will need to disconnect the call please call us back thank you"
}
],
"metadata": {
"agentId": "11",
"customerId": "44",
"agentClientId": "Agent_07",
"customerClientId": "77",
"tenantId": "33",
"organizationId": "185",
"categoryId": "314"
},
"intents": null,
"isChunk": false,
"isLastChunk": true
},
"connectorResponse": {},
"ruleOutput": [
{
"id": "3165",
"modelType": null,
"intentChannel": null,
"entityType": null,
"asrValue": null,
"normalizedValue": "#Ghost",
"preprocessedValue": null,
"valid": false,
"channel": null,
"intentTurnNo": 0,
"turnId": [
999999
],
"asrValueCharSpan": null,
"position": 0,
"contributedWords": "",
"detectedSentence": ""
},
{
"id": "3583",
"modelType": null,
"intentChannel": null,
"entityType": null,
"asrValue": null,
"normalizedValue": "No Response",
"preprocessedValue": null,
"valid": false,
"channel": null,
"intentTurnNo": 0,
"turnId": [
999999
],
"asrValueCharSpan": null,
"position": 0,
"contributedWords": "",
"detectedSentence": ""
},
{
"id": "3584",
"modelType": null,
"intentChannel": null,
"entityType": null,
"asrValue": null,
"normalizedValue": "Bug fixed",
"preprocessedValue": null,
"valid": false,
"channel": null,
"intentTurnNo": 0,
"turnId": [
999999
],
"asrValueCharSpan": null,
"position": 0,
"contributedWords": "",
"detectedSentence": ""
},
{
"id": "3582",
"modelType": null,
"intentChannel": null,
"entityType": null,
"asrValue": null,
"normalizedValue": "#Ghost",
"preprocessedValue": null,
"valid": false,
"channel": null,
"intentTurnNo": 0,
"turnId": [
999999
],
"asrValueCharSpan": null,
"position": 0,
"contributedWords": "",
"detectedSentence": ""
}
],
"summary": {
"format": "bulletPoint",
"templateId": 271,
"bullet": [
"Issue - No Response",
"Resolution - Bug fixed",
"Hashtags - #Ghost",
"Primary Intent - #Ghost"
],
"paragraph": null
}
},
"errors": ""
}
Json file has two different main keys data and error. data key has some data in it while error key is completely empty
I want extract specially only bullet key values from summary key which is in data key.
My desired output should look like:
Issue Resolution Hashtags Primary Intent
No Response Bug fixed #Ghost #Ghost
I would really appreciate any help.
I think this should give you the desired output:
library(rjson)
library(janitor)
library(tidyverse)
data <- fromJSON(file = "file.json")
df <- data.frame(str_split(data$data$summary$bullet, pattern = " - ")) %>%
row_to_names(row_number = 1)
Created on 2022-08-18 with reprex v2.0.2

How can I get the translated only products with translation from WooCommerce Multilingual & Multicurrency with Rest API?

The problem is that I get this excerpt of a product from Woocommerce:
[
{
"id": 73,
"name": "cBox",
"slug": "cbox",
"sku": "",
"price": "169",
"regular_price": "169",
"sale_price": "",
"on_sale": false,
"purchasable": true,
"total_sales": 0,
"virtual": false,
"downloadable": false,
"downloads": [],
"download_limit": -1,
"download_expiry": -1,
"external_url": "",
"button_text": "",
"tax_status": "taxable",
"tax_class": "",
"manage_stock": false,
"stock_quantity": null,
"backorders": "no",
"backorders_allowed": false,
"backordered": false,
"low_stock_amount": null,
"sold_individually": false,
"shipping_required": true,
"shipping_taxable": true,
"shipping_class": "",
"shipping_class_id": 0,
"reviews_allowed": true,
"average_rating": "0.00",
"rating_count": 0,
"upsell_ids": [],
"cross_sell_ids": [],
"parent_id": 0,
"purchase_note": "",
"attributes": [],
"default_attributes": [],
"variations": [],
"grouped_products": [],
"menu_order": 0,
"stock_status": "instock",
"has_options": true,
"translations": {
"de": "73",
"en": "76"
},
"lang": "de",
}
]
You can see the translations, at least the ID's of the translated products. My question is how can I get directly via rest-api only the translated products?
Because with the property "lang=en" it does not work in the url
What does your request look like?
It should work with the lang parameter, you can read more here: https://wpml.org/documentation/related-projects/woocommerce-multilingual/using-wordpress-rest-api-woocommerce-multilingual/

Here API Indoor discovery

I am trying to get the venue list using the API
https://indoor-discovery.venue.maps.api.here.com/discovery/v2?app_id=XXXXXXXXXXXXXXXXXXXX&app_code=XXXXXXXXXXXXXXXXXXXX&at=31.2403,74.6354,8.6291,77.5743
The "at" parameter almost covers the country. but the results always come back as
{
"hostname": "ip-10-13-214-44",
"type": "venues",
"status": {
"code": "OK",
"reason": "DISCOVERY_SUCCESSFULL"
},
"results": {
"items": []
}
}
The maximum value for the bounding box is at 100km x 100km. If you search within a smaller area you will get some results in the list. Here is one for the coverage of Chennai:
https://indoor-discovery.venue.maps.api.here.com/discovery/v2?app_id=yyy&app_code=xxxx&at=13.2403,79.8454,12.7291,80.5743
{
"hostname": "ip-10-13-214-44",
"type": "venues",
"status": {
"code": "OK",
"reason": "DISCOVERY_SUCCESSFULL"
},
"results": {
"items": [
{
"id": "DM_17331",
"title": "Phoenix Marketcity Mall",
"address": {
"countryCode": "IND",
"city": "Chennai",
"postalCode": "600042",
"street": "Radha Mohan Street",
"house": ""
},
"position": [
12.991487949990416,
80.21652530007341
],
"distance": 1045.380777404391,
"type": "urn:nlp-types:venue",
"vicinity": "Radha Mohan Street,600042,Chennai,IND",
"bbox": [
[
12.992687434189028,
80.21572801724027
],
[
12.990288596080005,
80.21732267846822
]
],
"minFloor": -1,
"maxFloor": 3,
"namespace": "public"
},
{
"id": "DM_3869",
"title": "Maya Plaza",
"address": {
"countryCode": "IND",
"city": "Chennai",
"postalCode": "600017",
"street": "Sir Thyagaraya Road",
"house": ""
},
"position": [
13.041404800089397,
80.23480899848522
],
"distance": 6860.646286724997,
"type": "urn:nlp-types:venue",
"vicinity": "Sir Thyagaraya Road,600017,Chennai,IND",
"bbox": [
[
13.041557002816027,
80.23472596161558
],
[
13.04125261448761,
80.23489217568006
]
],
"minFloor": 0,
"maxFloor": 4,
"namespace": "public"
},
{
"id": "DM_3866",
"title": "Challa Mall",
"address": {
"countryCode": "IND",
"city": "Chennai",
"postalCode": "600017",
"street": "Sir Thyagaraya Road",
"house": ""
},
"position": [
13.040501949969517,
80.24325910031074
],
"distance": 7183.4301593814025,
"type": "urn:nlp-types:venue",
"vicinity": "Sir Thyagaraya Road,600017,Chennai,IND",
"bbox": [
[
13.040704496188196,
80.24306093132118
],
[
13.040299554031115,
80.24345735684514
]
],
"minFloor": -1,
"maxFloor": 1,
"namespace": "public"
},
{
"id": "DM_3871",
"title": "Kasi Arcade Mall",
"address": {
"countryCode": "IND",
"city": "Chennai",
"postalCode": "600017",
"street": "Sir Thyagaraya Road",
"house": ""
},
"position": [
13.040300249964666,
80.24435859999508
],
"distance": 7224.9813794400025,
"type": "urn:nlp-types:venue",
"vicinity": "Sir Thyagaraya Road,600017,Chennai,IND",
"bbox": [
[
13.040532567087016,
80.24415738929856
],
[
13.04006805606027,
80.24455999517599
]
],
"minFloor": -1,
"maxFloor": 1,
"namespace": "public"
},
I had copied the lat/long from google maps, then I realized that the longitude has space, in the beginning, I removed the space and it started to work!

WooCommerce Order API always creates empty orders

Im playing around with Woo Commerce API (v3.4.4). I can get a product with:
curl -X GET \
'http://localhost/wp-json/wc/v2/products/7?oauth_consumer_key=ck_8cbe42fb09c04954a63994c22145270f27871dec&oauth_signature_method=HMAC-SHA1&oauth_timestamp=1535381325&oauth_nonce=iApWJblA1A5&oauth_version=1.0&oauth_signature=9T1T43FvOpBzVBU+RQS90zMB/XM=' \
-H 'Cache-Control: no-cache' \
-H 'Postman-Token: bdb7f5c9-5719-4bcf-b4fc-38aed3bd5d08'
I get the response:
{
"id": 7,
"name": "Test product",
"slug": "test-product",
"permalink": "http://localhost/product/test-product/",
"date_created": "2018-08-22T15:25:26",
"date_created_gmt": "2018-08-22T15:25:26",
"date_modified": "2018-08-22T15:25:26",
"date_modified_gmt": "2018-08-22T15:25:26",
"type": "simple",
"status": "publish",
"featured": false,
"catalog_visibility": "visible",
"description": "<p>this is a test product</p>\n",
"short_description": "<p>the short desc</p>\n",
"sku": "",
"price": "9",
"regular_price": "10",
"sale_price": "9",
"date_on_sale_from": null,
"date_on_sale_from_gmt": null,
"date_on_sale_to": null,
"date_on_sale_to_gmt": null,
"price_html": "<del><span class=\"woocommerce-Price-amount amount\"><span class=\"woocommerce-Price-currencySymbol\">€</span>10.00</span></del> <ins><span class=\"woocommerce-Price-amount amount\"><span class=\"woocommerce-Price-currencySymbol\">€</span>9.00</span></ins>",
"on_sale": true,
"purchasable": true,
"total_sales": 3,
"virtual": false,
"downloadable": false,
"downloads": [],
"download_limit": -1,
"download_expiry": -1,
"external_url": "",
"button_text": "",
"tax_status": "taxable",
"tax_class": "",
"manage_stock": false,
"stock_quantity": null,
"in_stock": true,
"backorders": "no",
"backorders_allowed": false,
"backordered": false,
"sold_individually": false,
"weight": "",
"dimensions": {
"length": "",
"width": "",
"height": ""
},
"shipping_required": true,
"shipping_taxable": true,
"shipping_class": "",
"shipping_class_id": 0,
"reviews_allowed": true,
"average_rating": "0.00",
"rating_count": 0,
"related_ids": [
36,
41
],
"upsell_ids": [],
"cross_sell_ids": [],
"parent_id": 0,
"purchase_note": "",
"categories": [
{
"id": 15,
"name": "Uncategorized",
"slug": "uncategorized"
}
],
"tags": [],
"images": [
{
"id": 8,
"date_created": "2018-08-22T15:24:00",
"date_created_gmt": "2018-08-22T15:24:00",
"date_modified": "2018-08-22T15:24:00",
"date_modified_gmt": "2018-08-22T15:24:00",
"src": "http://localhost/wp-content/uploads/2018/08/sock.jpeg",
"name": "sock",
"alt": "",
"position": 0
}
],
"attributes": [
{
"id": 0,
"name": "size",
"position": 0,
"visible": true,
"variation": false,
"options": [
"small",
"medium",
"large"
]
}
],
"default_attributes": [],
"variations": [],
"grouped_products": [],
"menu_order": 0,
"meta_data": [],
"_links": {
"self": [
{
"href": "http://localhost/wp-json/wc/v2/products/7"
}
],
"collection": [
{
"href": "http://localhost/wp-json/wc/v2/products"
}
]
}
}
This works running the request using CURL on the command line, and running the request in Postman.
But now I try to create an order:
curl -X POST \
'http://localhost/wp-json/wc/v2/orders?oauth_consumer_key=ck_8cbe42fb09c04954a63994c22145270f27871dec&oauth_signature_method=HMAC-SHA1&oauth_timestamp=1535382336&oauth_nonce=P8RWaD9DnZ9&oauth_version=1.0&oauth_signature=GFxtI7+gqbah5fu68gSdqL4V3fs=' \
-H 'Cache-Control: no-cache' \
-H 'Postman-Token: f17bec6a-c76b-4a6c-8797-1df9dac73f36' \
-d '{
"payment_method": "bacs",
"payment_method_title": "Direct Bank Transfer",
"set_paid": true,
"billing": {
"first_name": "John",
"last_name": "Doe",
"address_1": "969 Market",
"address_2": "",
"city": "San Francisco",
"state": "CA",
"postcode": "94103",
"country": "US",
"email": "john.doe#example.com",
"phone": "(555) 555-5555"
},
"shipping": {
"first_name": "John",
"last_name": "Doe",
"address_1": "969 Market",
"address_2": "",
"city": "San Francisco",
"state": "CA",
"postcode": "94103",
"country": "US"
},
"line_items": [
{
"product_id": 7,
"quantity": 1
}
],
"shipping_lines": [
{
"method_id": "flat_rate",
"method_title": "Flat Rate",
"total": 7
}
]
}'
When I run the above request with Postman, it creates an empty order and I get the response:
{
"id": 59,
"parent_id": 0,
"number": "59",
"order_key": "wc_order_5b8413f8ed585",
"created_via": "rest-api",
"version": "3.4.4",
"status": "pending",
"currency": "EUR",
"date_created": "2018-08-27T15:08:40",
"date_created_gmt": "2018-08-27T15:08:40",
"date_modified": "2018-08-27T15:08:41",
"date_modified_gmt": "2018-08-27T15:08:41",
"discount_total": "0.00",
"discount_tax": "0.00",
"shipping_total": "0.00",
"shipping_tax": "0.00",
"cart_tax": "0.00",
"total": "0.00",
"total_tax": "0.00",
"prices_include_tax": false,
"customer_id": 0,
"customer_ip_address": "",
"customer_user_agent": "",
"customer_note": "",
"billing": {
"first_name": "",
"last_name": "",
"company": "",
"address_1": "",
"address_2": "",
"city": "",
"state": "",
"postcode": "",
"country": "",
"email": "",
"phone": ""
},
"shipping": {
"first_name": "",
"last_name": "",
"company": "",
"address_1": "",
"address_2": "",
"city": "",
"state": "",
"postcode": "",
"country": ""
},
"payment_method": "",
"payment_method_title": "",
"transaction_id": "",
"date_paid": null,
"date_paid_gmt": null,
"date_completed": null,
"date_completed_gmt": null,
"cart_hash": "",
"meta_data": [],
"line_items": [],
"tax_lines": [],
"shipping_lines": [],
"fee_lines": [],
"coupon_lines": [],
"refunds": [],
"_links": {
"self": [
{
"href": "http://localhost/wp-json/wc/v2/orders/59"
}
],
"collection": [
{
"href": "http://localhost/wp-json/wc/v2/orders"
}
]
}
}
Bizarrely, when i run the EXACT same request with CURL on the command line, I get the response:
{"code":"woocommerce_rest_authentication_error","message":"Invalid signature - provided signature does not match.","data":{"status":401}}
If I run the request in Postman, but for "product_id" I use "this is a completely fake id" it still creates an empty order and responds with:
{
"id": 60,
"parent_id": 0,
"number": "60",
"order_key": "wc_order_5b84148e002da",
"created_via": "rest-api",
"version": "3.4.4",
"status": "pending",
"currency": "EUR",
"date_created": "2018-08-27T15:11:10",
"date_created_gmt": "2018-08-27T15:11:10",
"date_modified": "2018-08-27T15:11:10",
"date_modified_gmt": "2018-08-27T15:11:10",
"discount_total": "0.00",
"discount_tax": "0.00",
"shipping_total": "0.00",
"shipping_tax": "0.00",
"cart_tax": "0.00",
"total": "0.00",
"total_tax": "0.00",
"prices_include_tax": false,
"customer_id": 0,
"customer_ip_address": "",
"customer_user_agent": "",
"customer_note": "",
"billing": {
"first_name": "",
"last_name": "",
"company": "",
"address_1": "",
"address_2": "",
"city": "",
"state": "",
"postcode": "",
"country": "",
"email": "",
"phone": ""
},
"shipping": {
"first_name": "",
"last_name": "",
"company": "",
"address_1": "",
"address_2": "",
"city": "",
"state": "",
"postcode": "",
"country": ""
},
"payment_method": "",
"payment_method_title": "",
"transaction_id": "",
"date_paid": null,
"date_paid_gmt": null,
"date_completed": null,
"date_completed_gmt": null,
"cart_hash": "",
"meta_data": [],
"line_items": [],
"tax_lines": [],
"shipping_lines": [],
"fee_lines": [],
"coupon_lines": [],
"refunds": [],
"_links": {
"self": [
{
"href": "http://localhost/wp-json/wc/v2/orders/60"
}
],
"collection": [
{
"href": "http://localhost/wp-json/wc/v2/orders"
}
]
}
}
So I have a number of problems:
1/ No matter what product_id I use, the order that's created is always empty
2/ Even if I provide a fake product_id, an order is still created by Woo Commerce. Surely this is incorrect?
3/ Running the create order requests on the command line is giving different responses to Postman
I was missing:
-H 'Content-Type: application/json' \
from the request. I had this entered in Postman, but had not ticked the check box:

Sort value from nested object using c#

I am trying to sort an object by SpaceType, TimeInterval and Price. It's a nested object as shown below. Can someone suggest me a sample on how to sort it in an efficient way using c# 4.0
ParkingFacility -> Cost -> TimeInterval
"VendorID": 1200,
"FacilityID": 931,
"ParkingType": "Garage",
"Price": null,
"BARTValidationRequired": null,
"LotName": "Civic Center Garage",
"City": "San Francisco",
"Street": "355 McAllister Street",
"Neighborhood": "Hayes Valley/Civic Center",
"Latitude": "37.780200",
"Longitude": "-122.417800",
"Distance": "",
"Availability": "Space Available: <b>62%</b> (515/843) <br/>Current Price: <b>N/A</b><br />6:00 AM-12:00 AM",
"Details": null,
"Hours": "Sunday : 9:00 AM-10:00 PM <br />Monday : 6:00 AM-12:00 AM <br />Tuesday : 6:00 AM-12:00 AM <br />Wednesday : 6:00 AM-12:00 AM <br />Thursday : 6:00 AM-12:00 AM <br />Friday : 6:00 AM-12:00 AM <br />Saturday : 8:00 AM-12:00 AM <br />",
"Entrance": null,
"Contact": "",
"TodayTimings": "6:00 AM-12:00 AM",
"TotalParkingSpace": 843,
"AvailableParkingSpace": 515,
"OccupiedParkingSpace": 328,
"PercentFull": 38,
"Rendering": 3,
"ZoneID": 0,
"OwnershipAgencyType": null,
"Cost": [
[
{
"DayType": "Thursday",
"SpaceType": "Motorcycle",
"Description": "Motorcycle: Flatrate",
"TimeInterval": 0,
"Cost": "$5.00",
"FaciltyID": 0
},
{
"DayType": "Thursday",
"SpaceType": "Auto",
"Description": null,
"TimeInterval": 0,
"Cost": "$5.00",
"FaciltyID": 0
}
],
[
{
"DayType": "MondayToFridayExceptHolidays",
"SpaceType": "Auto",
"Description": "Early Bird: Flat rate. Mon-Fri (excl. Tue): In by 9AM/Out by 7PM;No Tues Early Bird",
"TimeInterval": 0,
"Cost": "$15.00",
"FaciltyID": 0
}
],
[
{
"DayType": "Thursday",
"SpaceType": "Auto",
"Description": "Per hour",
"TimeInterval": 60,
"Cost": "$3.00",
"FaciltyID": 0
},
{
"DayType": "Thursday",
"SpaceType": "Auto",
"Description": "12-Hour Max",
"TimeInterval": 720,
"Cost": "$24.00",
"FaciltyID": 0
},
{
"DayType": "Thursday",
"SpaceType": "Auto",
"Description": "24-Hour Max/Lost Tkt",
"TimeInterval": 0,
"Cost": "$30.00",
"FaciltyID": 0
},
{
"DayType": "Thursday",
"SpaceType": "Auto",
"Description": null,
"TimeInterval": 0,
"Cost": "$30.00",
"FaciltyID": 0
}
]]
}
So assuming you have it in a structure in c# you can use linq to order by multiple items.
e.g.
listOfPeople.OrderBy(person => person.LastName)
.ThenBy(person => person.FirstName)
.ThenBy(person => person.DOB)
This is a trivial example of course but depending on how you wanted them sorted - if inside their own container or all as one - you could run this iterator. It is quite efficient - better programmers than you and I made it so.
Probably tougher is how to sort the spaceType - as just doing it like that would do it alphabetically which might not be what you want.

Resources