Ruby on rails: Substring with quotes search inside JSON object - ruby-on-rails

I have retrieved a json object using typhoeus gem.
url = 'www.example.com' <br>
request = ::Typhoeus::Request.get(url,userpwd: username + ":" + pass)<br>
content = JSON.parse(request.body)
I would like to count the occurence of "Priority":"high" including the quotes inside the json response. How do I go about doing this?
Edit:
"priority":"high" is a key value pair. It is deeply nested inside the json tree.(Don't how deeply it is nested). All I need is count of occurence of "priority":"high"
Any and all suggestion is welcome.
Sample data:
"tickets": [{
"url": "https://.zendesk.com/api/v2/tickets/xxxx.json",
"id": xxxxx,
"external_id": null,
"via": {
"channel": "email",
"source": {
"from": {
"address": "#compli.com",
"name": ""
},
"to": {
"name": "organization Global Support",
"address": "support#organization.zendesk.com"
},
"rel": null
}
},
"created_at": "2016-08-04T16:23:13Z",
"updated_at": "2016-08-08T20:26:01Z",
"type": "problem",
"subject": "Problems with abc Connect",
"raw_subject": "Problems with abc Connect",
"description": "Hi – our Tenet ID is 5675.\n\n \n\nThe abc report is not providing the full data when I run the billing preview. I am running it using Chrome. Attached are snapshots of what I’m doing plus the report generated.\n\n \n\nA perfect example of the problem is shown at the bottom of the report generated. Garber Automotive Group, account number A00000490 does not display the data for all of their products. Their data is shown on rows 5658 thru 5712 on the excel file BillingPreviewResult_201620 report run 08.04.16.\n\n \n\nHowever the EXACT same report (all the parameters are the same) run on 07/01/16 included all of Garber’s information. The excel file abc report run 07.01.16 10.13 AM has the data for Garber on rows 6099 – 6182.\n\n \n\nThe report is cutting off a lot of data for some reason. As you can see by comparing the amount of data between the two excel reports there are much fewer lines on the report run on today as opposed to the one run on 07/01, 6182 rows vs 5712 rows.\n\n \n\nThis is a business critical report for us. It is used for cash forecasting, monthly financial reporting, rolling budgeting and ad hoc reporting.\n\n \n\nWe need this problem identified and fixed immediately. It is already causing a problem with finalizing our July results.\n\n \n\nLet me know if you have any questions or need any additional data.\n\n \n\n \n\nRegards,\n\n \n\n \n\n \n\n| Controller\ndesk: 503.963-4239 | fax: 503.294.1200 | \n\nCompli - Cool, Calm and Compliant. TM\n\nVisit() to learn more.\n\n \n\nFollow us on LinkedIn () and Twitter",
"priority": "normal",
"status": "open",
"recipient": "support#organization.zendesk.com",
"requester_id": 1336424406,
"submitter_id": 1336424406,
"assignee_id": null,
"organization_id": 224504969,
"group_id": 21606503,
"collaborator_ids": [560973773, 786229209, 421597631, 539566717, 707192615, 1336424406, 31365392, 719608577, 1817633993],
"forum_topic_id": null,
"problem_id": null,
"has_incidents": false,
"due_at": null,
"tags": ["1_price", "best_practice_advise", "engage_global_services__email_", "escalate", "hard", "internal_escalation", "p0", "yes_escalated", "xxxxx", "zhub"],
"custom_fields": [{
"id": 22024091,
"value": "p0"
}, {
"id": 24212576,
"value": "best_practice_advise"
}, {
"id": 22035048,
"value": "xxx and so on.....

Related

MSgraph, takes up to 48 hours before changes are visible

We use MSgraph and EWS API for our products.
When we do changes in our test Microsoft 365 environment (Add/change/delete - roomlists and rooms) we see the changes immediately when testing with EWS Editor.
But it takes up to 48 hours before we se the changes by using MSgraph Explorer.
I would guess that this is not expected behavior?
We understand it might take some time (Up to 30 minutes) but up to 48 hours?
Our test environment is a pure Microsoft 365 tenant (No hybrid)
The MSgraph API calls we test is:
GET /places/microsoft.graph.room and GET /places/microsoft.graph.roomlist
It seems that this issue might have been introduced after our environment was moved to the Norwegian datacenter.
No error messages from MSgraph, all seems normal..
Here is the results from MSgraph when i ask for roomlist:
"#odata.context": "https://graph.microsoft.com/v1.0/$metadata#places/microsoft.graph.roomList",
"value": [
{
"id": "32d75744-113e-4bec-91c4-811623d11521",
"displayName": "Test2",
"address": null,
"geoCoordinates": null,
"phone": "",
"emailAddress": "Test2#loop24.no"
},
{
"id": "1d535e8b-c44d-498a-9046-dbbe1ae3be75",
"displayName": "TestList",
"address": null,
"geoCoordinates": null,
"phone": "",
"emailAddress": "testlist#loop24.no"
},
{
"id": "b9ea8bd6-32da-4d6d-b38e-db6c03f4fa54",
"displayName": "RoomList",
"address": null,
"geoCoordinates": null,
"phone": "",
"emailAddress": "roomlist#loop24.no"
Here is the results from EWSEditor (This is correct)
Call Get Roomlist roomlist#loop24.no Roomlist

Getting album, album art, and run time info from musicbrainz

Is there any way of getting a list of albums for an artist (band), along with a link to album art and runtime?
I've been given this endpoint, but the data it returns is confusing:
http://musicbrainz.org/ws/2/recording?query=artist:%22Queen%22%20and%20type:album&fmt=json
The data isn't really organized around albums, and the "length" data returns something like 203000. But it's better if you see it in context, so here's the first bit of it (sorry I couldn't get it indented):
{
"created": "2018-02-17T03:47:57.052Z",
"count": 9533710,
"offset": 0,
"recordings": [
{
"id": "c2e919f7-ecb9-4fdf-9162-3c26d0127fa0",
"score": "100",
"title": "Son and Daughter",
"length": 203000,
"video": null,
"artist-credit": [
{
"artist": {
"id": "0383dadf-2a4e-4d10-a46a-e9e041da8eb3",
"name": "Queen",
"sort-name": "Queen",
"disambiguation": "UK rock group",
"aliases": [
{
"sort-name": "Queen + Adam Lambert",
"name": "Queen + Adam Lambert",
"locale": null,
"type": null,
"primary": null,
"begin-date": "2011",
"end-date": null
}
]
}
}
],
"releases": [
{
"id": "bb19abaf-80b3-4a3e-846d-5f12b12af827",
"title": "Queen",
"status": "Official",
"release-group": {
"id": "810068af-2b3c-3e9c-b2ab-68a3f3e3787d",
"primary-type": "Album"
},
"date": "1994",
"country": "NL",
"release-events": [
{
"date": "1994",
"area": {
"id": "ef1b7cc0-cd26-36f4-8ea0-04d9623786c7",
"name": "Netherlands",
"sort-name": "Netherlands",
"iso-3166-1-codes": [
"NL"
]
}
}
],
"track-count": 10,
"media": [
{
"position": 1,
"format": "CD",
"track": [
{
"id": "3a26455e-2660-30dc-a652-6a2b40f1fbe5",
"number": "8",
"title": "Son and Daughter",
"length": 203400
}
],
"track-count": 10,
"track-offset": 7
}
]
},
{
"id": "1783da6a-9315-3602-a488-1738eb733a0f",
"title": "Queen",
"status": "Official",
"release-group": {
"id": "810068af-2b3c-3e9c-b2ab-68a3f3e3787d",
"primary-type": "Album"
},
"date": "1973-09-04",
"country": "US",
"release-events": [
{
"date": "1973-09-04",
"area": {
"id": "489ce91b-6658-3307-9877-795b68554c98",
"name": "United States",
"sort-name": "United States",
"iso-3166-1-codes": [
"US"
]
}
}
],
If someone can explain this data to me, then I don't need another endpoint. But I've been hunting around the musicbrainz docs and they're not super helpful.
Preferably it would be with one call, but I can do successive calls if necessary.
Thanks for your help.
First off:
Is there any way of getting a list of albums for an artist (band), along with a link to album art and runtime?
Yes, definitely.
First you will want to find the artist, say, the Queen that did Bohemian Rhapsody. They're identified with MusicBrainz Artist ID "0383dadf-2a4e-4d10-a46a-e9e041da8eb3", so you can do a browse request for Releases by this artist: https://musicbrainz.org/ws/2/release/?artist=0383dadf-2a4e-4d10-a46a-e9e041da8eb3&inc=recordings&fmt=json (note the inc=recordings)
This gives you most of what you are asking for. A list of releases and their runtime—kind of. Each Release should have one or more medium properties that in turn have a track-list with a number of tracks. The sum of the length of each of these tracks is what makes up the runtime (the length is given in milliseconds).
For cover art, you may notice that the output has a cover-art-archive property. For cover art, MusicBrainz uses Cover Art Archive which uses MusicBrainz IDs as identifiers. The cover-art-archive attribute states whether any cover art exists in Cover Art Archive and a few details about this—e.g., does CAA have any images at all (artwork)? Does it have a back image (back) and/or a front image (front)? How many images are there in all for the release (count)? If the cover-art-archive→artwork is true, we can go on and fetch cover art from the CAA. The CAA's API is really simple: to get the "front" image of a release, say the 1974 UK single "Killer Queen" that has MusicBrainz Release ID "a2d12ee8-9aeb-4d91-bfab-5c21f7a577fc", you can simply do https://coverartarchive.org/release/a2d12ee8-9aeb-4d91-bfab-5c21f7a577fc/front
You can also do https://coverartarchive.org/release/a2d12ee8-9aeb-4d91-bfab-5c21f7a577fc to get a JSON document with more details about what cover art images are available (e.g., this one has two images: one Front+Medium and one Back+Medium image).
The Cover Art Archive API is documented at https://musicbrainz.org/doc/Cover_Art_Archive/API and the MusicBrainz API/web service documentation can be found at https://musicbrainz.org/doc/Development/XML_Web_Service/Version_2
Note that using browse requests you can page through the results using offset and vary the amount of results per query using limit, see the "Paging" section under the browse request section in the MusicBrainz WS documentation.
Secondly: Though you don't ask about this directly, you're using a search query using a generic term in your question, so I thought I'd talk about this for a bit. In MusicBrainz everything is identified using MusicBrainz identifiers (IDs). (I kind of mentioned them in the first section too.)
The reason for this is that many, many names are not unique. There are as of this writing three unique artists known as "Queen" in MusicBrainz: https://musicbrainz.org/search?query=%22queen%22&type=artist&method=advanced – not counting any of the 321 other artists that have "queen" as part of their name. Without more information, it is not possible for MusicBrainz to know which of them you want to find out information from, so your first step will likely be to somehow either narrow the search (e.g., add type:group narrows the search to 123 results, using country:gb limits to 21 results, doing both gives 11 results (see the search syntax documentation for more details)) or somehow filter afterwards.
Once you've narrowed it down to the specific artist you want, you can continue with the steps outlined above to get the details you want. The steps for narrowing it down will depend on your specific application/use case.
Finally: You seem to have some missing understanding at the asbstract level about how MusicBrainz's data is structured. E.g., all of the above is assuming that by album you mean a specific released version like the 1974 UK "Killer Queen" single, and not a more generic concept of a release like any version of the "Killer Queen" single, which in MusicBrainz terminology would be a Release Group.
https://musicbrainz.org/doc/MusicBrainz_Entity is a list of entities used in MusicBrainz. Understanding the differences between a Release Group and a Release as well as between Tracks and Recordings (and Works) will put you in a much better position to effectively use the web service and the MusicBrainz data in general.
https://musicbrainz.org/doc/MusicBrainz_Database/Schema is a introduction to how MusicBrainz is structured. Knowing how artist credits, ("advanced") relationships, and mediums play into things is also likely to save you a lot of headache later.
You need to understand the format of the data returned, copy the result in to a JSON formatting service such as https://jsonformatter.curiousconcept.com/
You will then realise you have multiple artists in the returned data, which is why it's not as simple as "albums by artist"
I’m guessing the "length" data is in milliseconds.

Getting the Highway name - Skobbler

I need to get the highway name on which the user is currently navigating.
That can be done in navigation mode, getting it from
-(void)routingService:(SKRoutingService *)routingService didChangeCurrentStreetName:(NSString *)currentStreetName streetType:(SKStreetType)streetType countryCode:(NSString *)countryCode
So, when I was testing my app yesterday, I was on the highway, and yes, Skobbler did recognised that I am on one, and yes, I got the Highway name back.
It was "Brooklyn-Queens Expressway".
But, Brooklyn-Queens Expressway is actually name of the I-278 Interstate highway, and all the functions I would later have to use, need to get Highway name in that format I-nnn
Here is the map photo of what I mean
So, Is there a way to get streetName in that I-nnn format, when the streetType is recognised as an interstate highway?
Or is there any Open Streetmap database we could consult? I wasn't able to find anything on OSM Wiki.
Don't know about the Skobbler SDK, but if online query is available and you have the approximate geographical area and the name of the motorway, you may use the Overpass API (http://wiki.openstreetmap.org/wiki/Overpass_API) to query the openstreetmap database for the highway reference.
For example, the following query (for a particular bbox which contains a small section of the highway):
[out:json]
[timeout:25]
;
(
way
["highway"="motorway"]
["name"="Brooklyn-Queens Expressway"]
(40.73483602685421,-73.91463160514832,40.73785205632046,-73.9096748828888);
);
out body qt;
returns (with some key-value pairs omitted for simplicity):
{
"version": 0.6,
"generator": "Overpass API",
"osm3s": {
"timestamp_osm_base": "2015-09-18T20:21:02Z",
"copyright": "The data included in this document is from www.openstreetmap.org. The data is made available under ODbL."
},
"elements": [
{
"type": "way",
"id": 46723482,
"nodes": [
488264429,
488264444,
488264461,
488264512,
488264530,
488264541,
597315979
],
"tags": {
"bicycle": "no",
"bridge": "yes",
"foot": "no",
"hgv": "designated",
"highway": "motorway",
"horse": "no",
"lanes": "3",
"layer": "1",
"name": "Brooklyn-Queens Expressway",
"oneway": "yes",
"ref": "I 278",
"sidewalk": "none",
}
},
{
"type": "way",
"id": 46724225,
"nodes": [
597315978,
488242888,
488248526,
488248544,
488248607
],
"tags": {
"bicycle": "no",
"bridge": "yes",
"foot": "no",
"hgv": "designated",
"highway": "motorway",
"horse": "no",
"lanes": "3",
"layer": "1",
"name": "Brooklyn-Queens Expressway",
"oneway": "yes",
"ref": "I 278",
"sidewalk": "none",
}
}
]
}
Which are 2 sections of the road in the osm database. In the US the "ref" tag for interstates is in the form "I XXX" (See http://wiki.openstreetmap.org/wiki/Interstate_Highways and note the format for co-location). You can retrieve the interstate name accordingly.
You can try the above query in overpass-turbo (a UI for the service) at http://overpass-turbo.eu/s/bxi (Press RUN and the DATA tab for the returned data, and pan the map for query in another bbox).
The "ref" information is not exposed in the SDK (will put this on the TODO list).
A workaround would be to look in the text advices (when using TTS) as this information is there (if you look at the $ref parameter, that contains the information you are looking for).
For more details regarding the text advices structure, see this blog article.

Query for all tasks in specific workspace that are not completed

I have the following cURL cmd running which returns all tasks for a specific userID within a specific workspaceID, but the "completed=false" part of the cmd doesn't influence the data returned. I am trying to exclude all "completed" tasks. Everything else is working as I expected. Below is the current cmd string and a snippet of the data returned back. As you can see one of the returned tasks indicates "completed" is true while the other indicates false.
Anyone see what I may be missing? Thanks in advance for your help.
cURL cmd:
curl -u <api-key>: "https://app.asana.com/api/1.0/tasks?workspace=<workspace>&assignee=<teamMemberId>&completed=false&opt_fields=name,assignee,assignee_status,notes,created_at,modified_at,completed_at,due_on,completed&opt_pretty"
output (partial)
{
"data": [
{
"id": <ID>,
"created_at": "2014-03-11T03:34:52.002Z",
"modified_at": "2014-03-11T23:33:07.544Z",
"name": "<nameoftask>",
"notes": "",
"assignee": {
"id": <ID>
},
"completed": true,
"assignee_status": "upcoming",
"completed_at": "2014-03-11T23:33:06.729Z",
"due_on": "2014-03-11"
},
{
"id": <ID>,
"created_at": "2014-03-11T23:33:07.196Z",
"modified_at": "2014-03-11T23:33:07.196Z",
"name": "<nameoftask>",
"notes": "",
"assignee": {
"id": ID>
},
"completed": false,
"assignee_status": "upcoming",
"completed_at": null,
"due_on": "2014-03-14"
},
TL;DR: You want completed_since=now, not completed=false.
The GET /tasks endpoint doesn't take a parameter completed - it does however take completed_since, which can take a timestamp (as provided by JS's .toISOString()) or the string "now". It always includes incomplete tasks. This is documented in the API Docs on Tasks (specifically the section on "Querying for tasks").
We're looking to improve the way you can filter tasks, but for right now what's documented there is all there is.

Event search returns event outside date range

I have been noticing that sometimes the response to an event search returns an event that is outside of the date range in the que3. Here is an example (with my key removed):
http://www.eventbrite.com/json/event_search?app_key=mykey&keywords=Photography&max=10&latitude=34.19751&longitude=-119.1771&within=50&within_unit=K&date=2012-07-20%202012-07-22
Here are the parameters, one per line:
http://www.eventbrite.com/json/event_search
?app_key=mykey
&keywords=Photography
&max=10
&latitude=34.19751
&longitude=-119.1771
&within=50
&within_unit=K
&date=2012-07-20%202012-07-22
If I run this query, I get 3 events, one of which looks like this (with some items shortened for brevity):
"event": {
"box_header_text_color": "005580",
"link_color": "EE6600",
"box_background_color": "FFFFFF",
"timezone": "US/Pacific",
"box_border_color": "D5D5D3",
"logo": "http://...",
"organizer": {
"url": "http://...,
"id": 1066754373,
"name": "Red Brick Gallery"
},
"background_color": "FFFFFF",
"id": 2667310999,
"category": "seminars,entertainment",
"box_header_background_color": "EFEFEF",
"capacity": 8,
"num_attendee_rows": 9,
"title": "Copy of Watercolor Workshops with Joe Cibere",
"start_date": "2011-07-23 14:00:00",
"status": "Started",
"description": "...",
"end_date": "2012-06-16 17:00:00",
"tags": "...",
"text_color": "005580",
"repeat_schedule": "custom-2659333",
"title_text_color": "", ...
I use the keys (under "event") "start_date" and "end_date" to identify the event dates, which spans from 2011-07-23 to 2012-06-16.
The query spans from 2012-07-20 to 2012-07-22.
The date span of the event and the date span of the query don't overlap.
Am I doing something wrong with my query, or is the response incorrect?
Although this event is scheduled to end on '2012-06-16', it is configured to repeat on various dates in the future. See the "repeats" and "repeat_schedule" attributes for more information.
We recently added support for allowing you to access the array of 'start_date' and 'end_date' pairs (per each repeating instance).
The additional response output should be included any time you add a "display" parameter with a value of "repeat_schedule" to the event_get, event_search, user_list_events, or organizer_list_events API calls.

Resources