How to get country name from currency code? Is this possible or not?
Alternative option, using Swift 3 Locale class data:
struct CurrencyToRegionMapper {
static let locales = Locale.availableIdentifiers.map(Locale.init)
static func locales(currencyCode: String) -> Set<Locale> {
let localesWithCode = self.locales.filter { locale in
locale.currencyCode == currencyCode
}
return Set(localesWithCode)
}
static func locales(currencySymbol: String) -> Set<Locale> {
let localesWithSymbol = self.locales.filter { locale in
locale.currencySymbol == currencySymbol
}
return Set(localesWithSymbol)
}
static func regionNames(currencyCode: String, forLocale locale: Locale = Locale.autoupdatingCurrent) -> Set<String> {
let locale = Locale(identifier: locale.identifier) // .current and .autoupdatingCurrent doesn't work without this hack for some reason
let localesForCode = self.locales(currencyCode: currencyCode)
let names: [String] = localesForCode.flatMap { loc in
if let regionCode = loc.regionCode {
return locale.localizedString(forRegionCode: regionCode)
} else {
return locale.localizedString(forIdentifier: loc.identifier)
}
}
return Set(names)
}
static func regionNames(currencySymbol: String, forLocale locale: Locale = Locale.autoupdatingCurrent) -> Set<String> {
let locale = Locale(identifier: locale.identifier) // .current and .autoupdatingCurrent doesn't work without this hack for some reason
let localesForSymbol = self.locales(currencySymbol: currencySymbol)
let names: [String] = localesForSymbol.flatMap { loc in
if let regionCode = loc.regionCode {
return locale.localizedString(forRegionCode: regionCode)
} else {
return locale.localizedString(forIdentifier: loc.identifier)
}
}
return Set(names)
}
}
Usage:
CurrencyToRegionMapper.locales(currencyCode: "EUR") // Returns set of locales, where currency is Euro
CurrencyToRegionMapper.locales(currencySymbol: "$") // Returns set of locales, where currency symbol is $
CurrencyToRegionMapper.regionNames(currencyCode: "GBP", forLocale: Locale(identifier: "en_POSIX")) // Returns set of regions(countries) names which use british pound in POSIX locale: ["United Kingdom", "Guernsey", "Jersey", "Isle of Man"]
CurrencyToRegionMapper.regionNames(currencySymbol: "¥", forLocale: Locale(identifier: "fi_FI")) // Returns set of regions which use currency with symbol ¥ in Finnish locale: ["Kiina", "Japani"]
I found the whole list of currency codes and countires at this link
let codeToCountry = [
"AED" : "United Arab Emirates",
"AFN" : "Afghanistan",
"ALL" : "Albania",
"AMD" : "Armenia",
"ANG" : "Netherlands Antilles",
"AOA" : "Angola",
"ARS" : "Argentina",
"AUD" : "Australia, Australian Antarctic Territory, Christmas Island, Cocos (Keeling) Islands, Heard and McDonald Islands, Kiribati, Nauru, Norfolk Island, Tuvalu",
"AWG" : "Aruba",
"AZN" : "Azerbaijan",
"BAM" : "Bosnia and Herzegovina",
"BBD" : "Barbados",
"BDT" : "Bangladesh",
"BGN" : "Bulgaria",
"BHD" : "Bahrain",
"BIF" : "Burundi",
"BMD" : "Bermuda",
"BND" : "Brunei",
"BOB" : "Bolivia",
"BOV" : "Bolivia",
"BRL" : "Brazil",
"BSD" : "Bahamas",
"BTN" : "Bhutan",
"BWP" : "Botswana",
"BYR" : "Belarus",
"BZD" : "Belize",
"CAD" : "Canada",
"CDF" : "Democratic Republic of Congo",
"CHE" : "Switzerland",
"CHF" : "Switzerland, Liechtenstein",
"CHW" : "Switzerland",
"CLF" : "Chile",
"CLP" : "Chile",
"CNY" : "Mainland China",
"COP" : "Colombia",
"COU" : "Colombia",
"CRC" : "Costa Rica",
"CUP" : "Cuba",
"CVE" : "Cape Verde",
"CYP" : "Cyprus",
"CZK" : "Czech Republic",
"DJF" : "Djibouti",
"DKK" : "Denmark, Faroe Islands, Greenland",
"DOP" : "Dominican Republic",
"DZD" : "Algeria",
"EEK" : "Estonia",
"EGP" : "Egypt",
"ERN" : "Eritrea",
"ETB" : "Ethiopia",
"EUR" : "European Union, see eurozone",
"FJD" : "Fiji",
"FKP" : "Falkland Islands",
"GBP" : "United Kingdom",
"GEL" : "Georgia",
"GHS" : "Ghana",
"GIP" : "Gibraltar",
"GMD" : "Gambia",
"GNF" : "Guinea",
"GTQ" : "Guatemala",
"GYD" : "Guyana",
"HKD" : "Hong Kong Special Administrative Region",
"HNL" : "Honduras",
"HRK" : "Croatia",
"HTG" : "Haiti",
"HUF" : "Hungary",
"IDR" : "Indonesia",
"ILS" : "Israel",
"INR" : "Bhutan, India",
"IQD" : "Iraq",
"IRR" : "Iran",
"ISK" : "Iceland",
"JMD" : "Jamaica",
"JOD" : "Jordan",
"JPY" : "Japan",
"KES" : "Kenya",
"KGS" : "Kyrgyzstan",
"KHR" : "Cambodia",
"KMF" : "Comoros",
"KPW" : "North Korea",
"KRW" : "South Korea",
"KWD" : "Kuwait",
"KYD" : "Cayman Islands",
"KZT" : "Kazakhstan",
"LAK" : "Laos",
"LBP" : "Lebanon",
"LKR" : "Sri Lanka",
"LRD" : "Liberia",
"LSL" : "Lesotho",
"LTL" : "Lithuania",
"LVL" : "Latvia",
"LYD" : "Libya",
"MAD" : "Morocco, Western Sahara",
"MDL" : "Moldova",
"MGA" : "Madagascar",
"MKD" : "Former Yugoslav Republic of Macedonia",
"MMK" : "Myanmar",
"MNT" : "Mongolia",
"MOP" : "Macau Special Administrative Region",
"MRO" : "Mauritania",
"MTL" : "Malta",
"MUR" : "Mauritius",
"MVR" : "Maldives",
"MWK" : "Malawi",
"MXN" : "Mexico",
"MXV" : "Mexico",
"MYR" : "Malaysia",
"MZN" : "Mozambique",
"NAD" : "Namibia",
"NGN" : "Nigeria",
"NIO" : "Nicaragua",
"NOK" : "Norway",
"NPR" : "Nepal",
"NZD" : "Cook Islands, New Zealand, Niue, Pitcairn, Tokelau",
"OMR" : "Oman",
"PAB" : "Panama",
"PEN" : "Peru",
"PGK" : "Papua New Guinea",
"PHP" : "Philippines",
"PKR" : "Pakistan",
"PLN" : "Poland",
"PYG" : "Paraguay",
"QAR" : "Qatar",
"RON" : "Romania",
"RSD" : "Serbia",
"RUB" : "Russia, Abkhazia, South Ossetia",
"RWF" : "Rwanda",
"SAR" : "Saudi Arabia",
"SBD" : "Solomon Islands",
"SCR" : "Seychelles",
"SDG" : "Sudan",
"SEK" : "Sweden",
"SGD" : "Singapore",
"SHP" : "Saint Helena",
"SKK" : "Slovakia",
"SLL" : "Sierra Leone",
"SOS" : "Somalia",
"SRD" : "Suriname",
"STD" : "São Tomé and Príncipe",
"SYP" : "Syria",
"SZL" : "Swaziland",
"THB" : "Thailand",
"TJS" : "Tajikistan",
"TMM" : "Turkmenistan",
"TND" : "Tunisia",
"TOP" : "Tonga",
"TRY" : "Turkey",
"TTD" : "Trinidad and Tobago",
"TWD" : "Taiwan and other islands that are under the effective control of the Republic of China (ROC)",
"TZS" : "Tanzania",
"UAH" : "Ukraine",
"UGX" : "Uganda",
"USD" : "American Samoa, British Indian Ocean Territory, Ecuador, El Salvador, Guam, Haiti, Marshall Islands, Micronesia, Northern Mariana Islands, Palau, Panama, Puerto Rico, East Timor, Turks and Caicos Islands, United States, Virgin Islands",
"USN" : "United States",
"USS" : "United States",
"UYU" : "Uruguay",
"UZS" : "Uzbekistan",
"VEB" : "Venezuela",
"VND" : "Vietnam",
"VUV" : "Vanuatu",
"WST" : "Samoa",
"XAF" : "Cameroon, Central African Republic, Congo, Chad, Equatorial Guinea, Gabon",
"XAG" : "",
"XAU" : "",
"XBA" : "",
"XBB" : "",
"XBC" : "",
"XBD" : "",
"XCD" : "Anguilla, Antigua and Barbuda, Dominica, Grenada, Montserrat, Saint Kitts and Nevis, Saint Lucia, Saint Vincent and the Grenadines",
"XDR" : "International Monetary Fund",
"XFO" : "Bank for International Settlements",
"XFU" : "International Union of Railways",
"XOF" : "Benin, Burkina Faso, Côte d'Ivoire, Guinea-Bissau, Mali, Niger, Senegal, Togo",
"XPD" : "",
"XPF" : "French Polynesia, New Caledonia, Wallis and Futuna",
"XPT" : "",
"XTS" : "",
"XXX" : "",
"YER" : "Yemen",
"ZAR" : "South Africa",
"ZMK" : "Zambia",
"ZWD" : "Zimbabwe"]
and some function to parse dict:
func countryBy(code : String) -> String? {
return codeToCountry[code]
}
countryBy(code: "ZWD")
countryBy(code: "")
countryBy(code: "asda")
Here it's some working example:
https://iswift.org/playground?blvcE5
The country is not unique per currency. An alternative solution can be finding currency through country first (e.g. by using this), grouping by currency, and having a list of countries using that currency. Finally, you can select a representative country for those currencies with more than one country.
Assuming a pandas DataFrame with country and currency as its columns, grouping can be done with the following:
df.groupby('currency').country.apply(list).reset_index()
Related
I'm able to run an aggregate MongoDb (3.8) request in the mongo shell but I can't get it out working using the java driver (3.4 java 8).
here's the input source structure. I want to aggregate informations to provide company activities stats. note that the ape document states for the company registered activity. I want to group on the first 3 digits of the ape code
{
"_id" : "00552017600016",
"sirene" : "005520176",
"nic" : "00016",
"natureCode" : "5710",
"natureLabel" : "SAS, société par actions simplifiée",
"name" : "HERNAS CARTONNAGE",
"brand" : "",
"registerDate" : ISODate("1954-12-31T23:00:00Z"),
"startDate" : ISODate("1954-12-31T23:00:00Z"),
"headquaters" : true,
"address" : {
"number" : 50,
"ext" : null,
"lane" : "RUE PASTEUR",
"zipcode" : "80210",
"city" : "FEUQUIERES EN VIMEU",
"country" : "FRANCE",
"location" : {
"type" : "Point",
"coordinates" : [
1.60319694244078,
50.0537636973407
],
"accuracy" : 0,
"ban" : "ADRNIVX_0000000260779642"
}
},
"ape" : {
"code" : "1721A",
"label" : "Fabrication de carton ondulé"
},
"staff" : {
"count" : 50,
"year" : 2016
}
}
running this commands in the shell works like a charm
db.companies_geo.aggregate([ {$match:{"address.city":"LE MANS"}},
{$group:{_id:{$substrBytes:["$ape.code",0,2]}, count:{$sum:1}, code:{$last:"$ape.code"}, label:{$last:"$ape.label"}}},
{$project:{count:1, code:1, label:1}},
{$sort:{count:-1}},
{$limit:20}
])
it produces this result
{ "_id" : "68", "count" : 4603, "code" : "6832B", "label" : "Supports juridiques de gestion de patrimoine immobilier" }
{ "_id" : "47", "count" : 1929, "code" : "4799B", "label" : "Vente par automate, aut. com. dét. hors mag., éventaire ou marché" }
{ "_id" : "94", "count" : 1874, "code" : "9499Z", "label" : "Autres organisations fonctionnant par adhésion volontaire" }
{ "_id" : "86", "count" : 1704, "code" : "8690F", "label" : "Activités de santé humaine non classées ailleurs" }
{ "_id" : "56", "count" : 832, "code" : "5630Z", "label" : "Débits de boissons" }
{ "_id" : "90", "count" : 816, "code" : "9004Z", "label" : "Gestion de salles de spectacles" }
{ "_id" : "85", "count" : 769, "code" : "8560Z", "label" : "Activités de soutien à l'enseignement" }
{ "_id" : "70", "count" : 592, "code" : "7022Z", "label" : "Conseil pour les affaires et autres conseils de gestion" }
{ "_id" : "96", "count" : 585, "code" : "9609Z", "label" : "Autres services personnels n.c.a." }
{ "_id" : "81", "count" : 582, "code" : "8130Z", "label" : "Services d'aménagement paysager" }
on the java side I've tried this but the code line bellow the while iteration raises the exception org.bson.codecs.configuration.CodecConfigurationException: Can't find a codec for class com.mongodb.client.model.BsonField.
private List<Document> cityActivityGraph() {
Bson filter = Filters.eq("address.city", "LE MANS");
BsonField id = new BsonField("_id", Filters.eq(new Document("$substrBytes", Arrays.asList("$ape.code", 0, 2))));
BsonField count = Accumulators.sum("count", 1);
BsonField label = Accumulators.last("ape.label", 1);
BsonField code = Accumulators.last("ape.code", 1);
Bson group = Aggregates.group(id, count, code, label);
Bson match = Aggregates.match(filter);
Bson projections = Projections.include("code", "label", "count");
Bson project = Aggregates.project(projections);
Bson sort = Sorts.descending("count");
MongoCursor<Document> cursor = getTable().aggregate(Arrays.asList(
Aggregates.match(match),
Aggregates.group(group),
Aggregates.project(project),
Aggregates.sort(sort))).iterator(); <--- exception here
List<Document> result = new ArrayList<>();
while (cursor.hasNext()) {
Document doc = cursor.next();
System.out.println(doc.toJson());
result.add(doc);
}
return result;
}
any idea ? thanks in advance
found a solution, perhaps not the most efficient but it works
Bson id = new Document("_id", new Document("$substrBytes", Arrays.asList("$ape.code", 0, 3)));
BsonField code = Accumulators.last("code", "$ape.code");
BsonField label = Accumulators.last("label", "$ape.label");
BsonField count = Accumulators.sum("count", 1);
Bson projections = Projections.include("code", "label", "count");
Bson sort = Sorts.descending("count");
AggregateIterable<Document> stats = getTable().aggregate(Arrays.asList(
Aggregates.match(filter),
Aggregates.group(id, code, label, count),
Aggregates.project(projections),
Aggregates.limit(limit),
Aggregates.sort(sort)
));
List<Document> result = new ArrayList<>();
for (Document d:stats) {
result.add(d);
}
return result;
I'm trying to get values from this JSON. This is part of the JSON because the real JSON data is too long.
"hits" : [ {
"recipe" : {
"uri" : "http://www.edamam.com/ontologies/edamam.owl#recipe_bd8def1d09d8c308f659e6945f366271",
"label" : "Pinchos de carne",
"image" : "http://img.recetascomidas.com/recetas/640_480/pinchos-de-carne.jpg",
"source" : "Recetal Comidas",
"url" : "http://pinchos-de-carne.recetascomidas.com/",
"shareAs" : "http://www.edamam.com/recipe/pinchos-de-carne-bd8def1d09d8c308f659e6945f366271/carne",
"yield" : 6.0,
"dietLabels" : [ "Low-Carb" ],
"healthLabels" : [ "Dairy-Free", "Gluten-Free", "Egg-Free", "Peanut-Free", "Tree-Nut-Free", "Soy-Free", "Fish-Free", "Shellfish-Free" ],
"cautions" : [ ],
"ingredientLines" : [ "600 gr. de carne magra de cerdo", "2 cucharadas de pimentón dulce", "1 cucharada de pimentón picante", "1 cucharada de cúrcuma", "1 cucharada de sazonador especial para carnes", "3 cucharadas de perejil fresco bien picadito", "1/2 cucharada de comino", "Aceite de oliva", "3 patatas", "1 diente de ajo", "Pimienta negra", "Sal" ],
"ingredients" : [ {
"text" : "600 gr. de carne magra de cerdo",
"quantity" : 600.0,
"measure" : null,
"food" : "carne magra cerdo",
"weight" : 600.0
}, {
"text" : "2 cucharadas de pimentón dulce",
"quantity" : 2.0,
"measure" : "tbsp",
"food" : "pimenton dulce",
"weight" : 13.6
}, {
"text" : "1 cucharada de pimentón picante",
"quantity" : 1.0,
"measure" : "tbsp",
"food" : "pimenton picante",
"weight" : 6.8
}, {
"text" : "1 cucharada de cúrcuma",
"quantity" : 1.0,
"measure" : "tbsp",
"food" : "curcuma",
"weight" : 6.8
}, {
"text" : "1 cucharada de sazonador especial para carnes",
"quantity" : 1.0,
"measure" : "tbsp",
"food" : "sazonador",
"weight" : 2.7
}, {
"text" : "3 cucharadas de perejil fresco bien picadito",
"quantity" : 3.0,
"measure" : "tbsp",
"food" : "perejil fresco",
"weight" : 11.4
}, {
"text" : "1/2 cucharada de comino",
"quantity" : 0.5,
"measure" : "tbsp",
"food" : "comino",
"weight" : 3.0
}, {
"text" : "Aceite de oliva",
"quantity" : 2.0,
"measure" : "tbsp",
"food" : "aceite oliva",
"weight" : 27.0
}, {
"text" : "3 patatas",
"quantity" : 3.0,
"measure" : null,
"food" : "patatas",
"weight" : 195.0
}, {
"text" : "1 diente de ajo",
"quantity" : 1.0,
"measure" : null,
"food" : "ajo",
"weight" : 3.0
}, {
"text" : "Pimienta negra",
"quantity" : 1.0,
"measure" : "peppercorn",
"food" : "pimienta negra",
"weight" : 0.3
}, {
"text" : "Sal",
"quantity" : 0.0,
"measure" : null,
"food" : "sal",
"weight" : 3.3346887
} ]
For example, I want to get label values that is inside "recipe". I successfully print in console all the JSON, but I don't know how to get recipe values.
I hope you can help me.
This is the code I have now.
let url: String = "https://test-es.edamam.com/search?q=pollo"
var arregloHits: NSMutableArray = []
override func viewDidLoad() {
super.viewDidLoad()
pruebaJson()
}
func pruebaJson(){
if ControladorService.conexionInternet(){
ControladorService.sharedInstance.callUrlWithCompletion(url: url, params: nil, completion: { (finished, response) in
if finished{
let result = NSMutableArray(array: response["hits"] as! NSArray)
self.arregloHits = result
print(self.arregloHits)
}else{
print("Connection failed")
}
}, method: .get)
}else{
print("No Internet")
}
}
Your top level json structure is a dictionary. So you need to parse it into [String: Any]. Then your hints level is a JSON array, so you need to parse it into [Any]
Here is an example. Don't forget to handle unwrap
do{
let json = try JSONSerialization.jsonObject(with: yourJSONData, options: []) as? [String: Any]
let hits = json?["hits"] as? [Any]
dump(hits)
}catch let error{
}
I'm trying to update 8 locations at a time in Firebase, using the Swift SDK. Somehow I managed to update the first two, but the other six only writes to the father node, and lost its correspondent path. Below is the data of my Firebase DB that illustrates the issue better:
{
"districts" : {
"did01" : {
"name" : "Teusaquillo",
"peopleids" : {
"stateid01" : true,
"stateid02" : true,
"stateid03" : true
},
"schools" : {
"schoolid01" : {
"location" : "norte 50 grados sur 42 ",
"name" : "Agustiniano Salitre",
"posts" : {
"eighth" : {
"nola" : "hola"
},
"eighth-KaG1PA5r7cl70FtBsE4" : "angela",
"eleventh" : {
"name" : "haka"
},
"eleventh-KaG1PA5r7cl70FtBsE4" : "angela",
"fifth" : {
"-KaG1PA5r7cl70FtBsE4" : "angela",
"dsadsad" : {
"name" : "Hola"
},
"dsfsdfdsf" : true
},
"first" : {
"1" : {
"author" : "Giovanny Piñeros",
"text" : "Test"
},
"01" : {
"author" : "Giovanny Piñeros",
"text" : "Capo"
},
"abdffg" : {
"author" : "Gio",
"text" : "hola"
},
"fdgfdg" : {
"author" : "Giovanny Piñeros",
"text" : "Hola"
},
"nfdsfds" : {
"author" : "Giovanny Piñeros",
"text" : "Vivir de lo que amo"
},
"postid01" : {
"author" : "Papa frita",
"text" : "Hola",
"topic" : "Informatics",
"year" : "first"
},
"rtyrty" : {
"author" : "Giovanny Piñeros",
"text" : "Si con headapp solo sabia manejar strings y colores, imaginate ahora lo que puedo crear"
},
"zsadsa" : {
"author" : "Gio",
"text" : "Trest"
}
},
"fourth" : {
"name" : "hqiq"
},
"fourth-KaG1PA5r7cl70FtBsE4" : "angela",
"ninth" : {
"hola" : "ahah"
},
"ninth-KaG1PA5r7cl70FtBsE4" : "angela",
"postid01" : {
"-KaG0b-X9sWXxXlXlmeK" : "angela",
"-KaG0wNu0Gz5oxu4__Ej" : "angela",
"author" : "Papa frita",
"likes" : {
"userid01" : "Giovanny Piñeros"
},
"text" : "hola",
"topic " : "Informatics",
"year" : "first"
},
"postid02" : {
"autor" : "Directive",
"text" : "Free for the day",
"topic" : "General",
"year" : "all"
},
"second" : {
"-KaFnTl89keEOx3UpnGJ" : true,
"-KaFpLsNy6z-TshUJONx" : true,
"-KaFpMwBdHqBwsq-k6i3" : true,
"-KaFpz6qwQ2uTevvpxXo" : true,
"-KaFq21Qdv-Z6KFcu8ZT" : true,
"-KaFq34fN1-ZxO0EtqEw" : true,
"-KaFv7a9JvEjPLDDzT8S" : "angela",
"-KaFw9Hb6OjIRzeP6jdk" : "angela",
"-KaFwAFvFoVEvpzaaVO2" : "angela",
"-KaFwAboyWtEOG3NU1yZ" : "angela",
"-KaFwAji3rR6e5fCHjFc" : "angela",
"-KaFwAmisIA5i4UhvcRw" : "angela",
"-KaFyJHEqDzoVoj_zUWI" : "angela",
"-KaFy_cqf1mvTxRGN5j_" : "angela",
"-KaG-_r4ql2YVc19gbkt" : "angela",
"dsfsdf" : {
"hola" : "dfsad"
}
},
"seventh" : {
"name" : "dsfhksd"
},
"sixth" : {
"name" : "haaka"
},
"tenth" : {
"name" : "hola"
},
"tenth-KaG1PA5r7cl70FtBsE4" : "angela",
"third" : {
"-KaFnTl89keEOx3UpnGJ" : true,
"-KaFpLsNy6z-TshUJONx" : true,
"-KaFpMwBdHqBwsq-k6i3" : true,
"-KaFpz6qwQ2uTevvpxXo" : true,
"-KaFq21Qdv-Z6KFcu8ZT" : true,
"-KaFq34fN1-ZxO0EtqEw" : true,
"-KaFv7a9JvEjPLDDzT8S" : "angela",
"-KaFw9Hb6OjIRzeP6jdk" : "angela",
"-KaFwAFvFoVEvpzaaVO2" : "angela",
"-KaFwAboyWtEOG3NU1yZ" : "angela",
"-KaFwAji3rR6e5fCHjFc" : "angela",
"-KaFwAmisIA5i4UhvcRw" : "angela",
"-KaFyJHEqDzoVoj_zUWI" : "angela",
"-KaFy_cqf1mvTxRGN5j_" : "angela",
"-KaG-_r4ql2YVc19gbkt" : "angela",
"-KaG0b-X9sWXxXlXlmeK" : "angela",
"-KaG0wNu0Gz5oxu4__Ej" : "angela",
"-KaG1PA5r7cl70FtBsE4" : "angela",
"author" : "hola"
},
"twelfth" : {
"name" : "haoao"
}
},
"users" : {
"userid01" : {
"likes" : {
"postid01" : true
},
"name" : "Giovanny Piñeros",
"rol" : "student",
"stateid" : "stateid01",
"year" : "first"
},
"userid03" : {
"Posts" : {
"postid01" : {
"fjsldkfj" : "nombre",
"texzto" : "fksdjh"
}
},
"name" : "Papa frita",
"rol" : "teacher"
}
}
}
}
},
"did02" : {
"name" : "Austin",
"peopleids" : {
"stateid04" : true,
"stateid05" : true,
"stateid06" : true
}
}
},
"eventos" : {
"attendiees" : {
"adshfksafjh" : "giovanny"
},
"nombre" : "fiesta"
},
"queue" : {
"specs" : {
"specstest" : 0
},
"tasks" : {
"ido" : {
"_error_details" : {
"error" : "Task was malformed",
"error_stack" : "Error: Task was malformed\n at Object.update (/Users/Giovanny/Dropbox/Proyectos/NotifyMe/NotifyMeServer/notifymeserver/node_modules/firebase-queue/dist/lib/queue_worker.js:453:27)\n at Ih (/Users/Giovanny/Dropbox/Proyectos/NotifyMe/NotifyMeServer/notifymeserver/node_modules/firebase-admin/lib/database/database.js:233:395)\n at R.h.transaction (/Users/Giovanny/Dropbox/Proyectos/NotifyMe/NotifyMeServer/notifymeserver/node_modules/firebase-admin/lib/database/database.js:248:466)\n at /Users/Giovanny/Dropbox/Proyectos/NotifyMe/NotifyMeServer/notifymeserver/node_modules/firebase-queue/dist/lib/queue_worker.js:446:30\n at c (/Users/Giovanny/Dropbox/Proyectos/NotifyMe/NotifyMeServer/notifymeserver/node_modules/firebase-admin/lib/database/database.js:135:58)\n at /Users/Giovanny/Dropbox/Proyectos/NotifyMe/NotifyMeServer/notifymeserver/node_modules/firebase-admin/lib/database/database.js:126:791\n at Ac (/Users/Giovanny/Dropbox/Proyectos/NotifyMe/NotifyMeServer/notifymeserver/node_modules/firebase-admin/lib/database/database.js:63:165)\n at jf (/Users/Giovanny/Dropbox/Proyectos/NotifyMe/NotifyMeServer/notifymeserver/node_modules/firebase-admin/lib/database/database.js:126:215)\n at hf (/Users/Giovanny/Dropbox/Proyectos/NotifyMe/NotifyMeServer/notifymeserver/node_modules/firebase-admin/lib/database/database.js:125:479)\n at vf (/Users/Giovanny/Dropbox/Proyectos/NotifyMe/NotifyMeServer/notifymeserver/node_modules/firebase-admin/lib/database/database.js:231:426)",
"original_task" : 0
},
"_state" : "error",
"_state_changed" : 1482958978549
}
}
},
"usuarios" : {
"hvlksdj" : {
"edad" : 26,
"nombre" : "giovanny"
}
}
}
As you can see, the child nodes postid01 and second are updated, creating a new child, but for the other locations, this doesn't happen.
Here is my code. I did the following according to the Firebase guidelines:
let ref = FIRDatabase.database().reference()
var newPost = ref.childByAutoId()
let newKey = newPost.key
let dict = ["districts/did01/schools/schoolid01/posts/fifth/\(newKey)" : "test","districts/did01/schools/schoolid01/posts/third/\(newKey)": "test",
"districts/did01/schools/schoolid01/posts/fourth\(newKey)": "test","districts/did01/schools/schoolid01/posts/postid02\(newKey)": "test",
"districts/did01/schools/schoolid01/posts/sixth\(newKey)": "test","districts/did01/schools/schoolid01/posts/seventh\(newKey)": "test",
"districts/did01/schools/schoolid01/posts/eighth\(newKey)": "test", "districts/did01/schools/schoolid01/posts/ninth\(newKey)": "test", "districts/did01/schools/schoolid01/posts/tenth\(newKey)": "test", "districts/did01/schools/schoolid01/posts/eleventh\(newKey)": "test", "districts/did01/schools/schoolid01/posts/postid04\(newKey)" : "test"]
ref.updateChildValues(dict, withCompletionBlock: {(Error,FIRDatabaseReference) in
if(Error == nil){
print("EXITO :)")
}else{
print("PAILA :(")
}
})
I've just found the error, it was so simple, i make a mistake on the dictionary. The locations that weren't updated were written like this :
"districts/did01/schools/schoolid01/posts/fourth\(newKey)": "test"
As you can see the last part is missing a "/" just before the newKey.
Is it possible to create Salesreceipt without product/service value through QBO API? I have tried through API but it's not reflecting rate value and storing description value only.
If I remove ItemRef attribute(in request body) then it's reflecting rate and amount values and it's assigning some default and random product/service.
It is possible directly in QBO UI.
Request body where only description value storing:
{
"TxnDate" : "2016-05-27",
"Line" : [ {
"Amount" : 2222.00,
"Description" : "hi chk",
"DetailType" : "ItemReceiptLineDetail",
"ItemReceiptLineDetail" : {
"ItemRef" : { },
"Qty" : 1,
"UnitPrice" : 2222
} }
],
"CustomerRef" : {
"value" : "67"
},
"CustomerMemo" : {
"value" : "Thanks for your business! We appreciate referrals!"
},
"TotalAmt": 2222.00,
"PrivateNote" : "",
"CustomField" : [ {
"DefinitionId" : "1",
"Type" : "StringType",
"StringValue" : ""
} ]
}
Request body where default product/service assigning:
{
"TxnDate" : "2016-05-27",
"Line" : [ {
"Amount" : 2222.00,
"Description" : "hi chk",
"DetailType" : "ItemReceiptLineDetail",
"ItemReceiptLineDetail" : {
"Qty" : 1,
"UnitPrice" : 2222
} }
],
"CustomerRef" : {
"value" : "67"
},
"CustomerMemo" : {
"value" : "Thanks for your business! We appreciate referrals!"
},
"TotalAmt": 2222.00,
"PrivateNote" : "",
"CustomField" : [ {
"DefinitionId" : "1",
"Type" : "StringType",
"StringValue" : ""
} ]
}
No.
QuickBooks Online does not support this.
I generate one passbook using this gem in rails and it seen that works but when I open the passbook .pkpass file I see this message:
It's in spanish but basically it says that this card isn't valid anymore.
Here is my JSON:
{
"formatVersion" : 1,
"passTypeIdentifier" : "{MY PASS ID HERE}",
"serialNumber" : "E5982H-I2",
"teamIdentifier" : "{MY TEAM ID HERE}",
"webServiceURL" : "https://example.com/passes/",
"authenticationToken" : "vxwxd7J8AlNNFPS8k0a0FfUFtq0ewzFdc",
"barcode" : {
"message" : "123456789",
"format" : "PKBarcodeFormatPDF417",
"messageEncoding" : "iso-8859-1"
},
"locations" : [
{
"longitude" : -122.3748889,
"latitude" : 37.6189722
},
{
"longitude" : -122.03118,
"latitude" : 37.33182
}
],
"organizationName" : "CROCANTICKETS SL",
"description" : "Paw Planet Coupon",
"logoText" : "Paw Planet",
"foregroundColor" : "rgb(255, 255, 255)",
"backgroundColor" : "#FF4B33",
"coupon" : {
"primaryFields" : [
{
"key" : "offer",
"label" : "Any premium dog food",
"value" : "20% off"
}
],
"auxiliaryFields" : [
{
"key" : "expires",
"label" : "EXPIRES",
"value" : "2016-04-24T10:00-05:00",
"isRelative" : true,
"dateStyle" : "PKDateStyleShort"
}
]
}
}
Any idea? Thanks!
According to the Expiration Keys in the Passbook Package Format Reference check the expirationDate and voided keys. Since you do not have those in your JSON, it might be added by the gem you are using.