Google-Voice-java getSMS() - java

I am trying to use the google-voice-java API to read texts from a google voice account. I cannot find much documentation on using it other then the code.google.com page. I just need a little help on how to correctly use getSMS();

The google-voice-java API will simply return back raw HTML of your Google Voice data. Thus, you need to parse through the HTML returned by getSMS();, and do with the data as you see fit.
If you'd like to just see what the data returned looks like at a console window, do the following
Voice voice = new Voice(userName, password);
String sms = voice.getSMS();
System.out.println(sms);
Based on that, you can see what the HTML looks like and how to parse through it.
Edit: Probably worth noting that you need to include the additional dependency jars to your build path; that should be more explicitly clear on their GettingStarted!
Edit 2: Based on your comment below, there are the getUnreadSMS() and markAsRead(msgID), but the former appears to return read SMS messages along with the unread ones.
If you notice at the top of the response XML returned by the getSMS() method (and majority of the other API methods), there is JSON data in the <json> element, which seems to have all the necessary information you need (including a isRead variable to indicate if a SMS is marked read, or not).
Pull down a response from the getSMS() method and use this online JSON viewer to better inspect the data in the <json> element, so you have an idea of what's in there. When you paste in the JSON data into the online viewer, omit the leading <![CDATA and trailing ]> inside the <json> element.
I would just setup a JSON parser (maybe even use GSON) and create SMS model objects based on the JSON data, ignoring the HTML completely; for unread messages, you want JSON objects with the isRead field set to false, obviously. You could then use the id field to pass into the markAsRead(msgID) method, to mark them read (I just tested this method and it works).

Related

Validate JSON before further processing

I have the following csv file (In production the number of records can range from 20k-100k and has many fields )
id,firstname,lastname,email,profession
100,Betta,Wandie,Betta.Wandie#gmail.com,developer
101,Janey,Firmin,Janey.Firmin#gmail.com,doctor
I need to convert this to json and do further processing.
CSV->JSON->PROCESS FURTHER
.I am able to convert it to JSON directly using the code given here
directly convert CSV file to JSON file using the Jackson library
But i want do validations for json like if lastname has null value then ignore that record or id is missing then ignore that record.
How can i handle the validation?I am using Java 8 and spring boot latest version
I have done something similar by using JavaScript (Nashorn). Yes, that is nasty, but it works, and it is astonishingly fast!
Unfortunately, I do not have the source code at hand …
Why I did it that way had the same reasons as #chrylis-on strike implies in their comment: the validation is much easier if you have an object for each JSON record. But as I was lazy, and there was definitely no need for the Java object I had to create for this, I had the idea with the JavaScript script inside my Java program.
Basically, a JSON String is the source for a JavaScript program; you can assign it directly to a JavaScript variable and then you can access the records as array elements and the fields by their name. So your JavaScript code walks through the records and drops those that do not match your validation rules.
Now the Java part: the keyword here is JSR223; it is an API that allows you to execute scripts inside your Java environment. In your case, you have to provide the converted JSON in the context, then you start the script that writes the modified JSON back to the context.
If the converted JSON is too large, you can even use the same technique to check record by record; if you compile the script, it is nearly as fast as native Java.
You can even omit Jackson and let JavaScript do the conversion …
Sorry that I cannot provide code samples; I will try to get hold on them and add them if I get them.

How to extract last item in Json Array without parsing the entire Json message

My current Android application is employing RealmIO to store Json data.
I use the following Realm insert
backgroundRealm.createOrUpdateAllFromJson(Data.class, rawJson);
My raw Json data is retrieved via a REST API
The API supports paging however I need to pass subsequent calls the last Id contained within the previous rawJson.
These Json arrays have 25000 items. I dont want the cost of parsing the entire 25000 item array.
Is there any method I can use to extract the last array item to discover what the last Id value is?
each item resembles this
{"id":6,"risk":"xxxxxxxxx","active":0,"from":"2016-07-18"}
What options do I have?
is it just rawJson.lastIndexOf("id") and substring()?
There's no standard way to avoid parsing the entire JSON. You can, on the other hand, avoid storing it all in RAM, and extracting it into nodes. Take a streaming JSON parser (these exist) and watch for the events of the element you need. The last event of this kind you receive will contain the last ID.
On the other hand, if you know that the schema and the serialization format of the JSON are not going to change (e.g. you control it), you can just scan the text of unparsed JSON from the end and extract that value, by counting parens and quotes. This is, of course, a brittle approach, though very fast. Its brittleness definitely depends on the schema: if the list you're looking for is a last element of another list, it's much more robust than if it's a value under a particular key, and can end up anywhere in the map.
If you are in control of the REST API side of the app, consider rethinking it, e.g. passing the events from latest to earliest, so you can look for the first events while parsing, and safely discard the rest if you don't need the past.

Get notification in my client code

I want to get the notifications about any change in any issues in my jira server.
I have basic code for connecting jira from java code using jira-rest-java-client library that they have provided.
I searched their javadocs and also went through some classes in that API library but I could not find any methods/classes which would be helpful to me.
Does anyone know if it is possible to get notification events from changes in jira to my java code (may be via polling or something like that).
What do you want to achieve?
You want to have push notifications? There isn't any, IMHO.
UPDATE: However, there is this WebHook thingy: https://confluence.atlassian.com/display/JIRA/Managing+Webhooks.
I have no expertise with it, but it is promising, please read this short introduction also: http://blogs.atlassian.com/2012/10/jira-5-2-remote-integration-webhooks/.
You are looking for something that gives you back what changed in the last N minutes, something like the Activity Stream? You can get the RSS feed of Activity Streams for Projects and for Users.
How
The base URL is https://jira.contoso.com/activity. Then you can append querystring parameters, like maxResults for paginating.
Selecting the data source is through the filters you provide in the streams parameter. It looks like it is JQL, but it's not.
Examples:
List a project's activites: ?streams=key+IS+SOMEPROJ.
List a user's activites: ?streams=user+IS+foobar.
List event between two dates: ?streams=update-date+BETWEEN+1425300236000+1425300264999. (Note: the epoch is the millisecond precision epoch.)
List user activities in one project: ?streams=user+IS+JohnDoe&streams=key+IS+PROJECTKEY.
More complex ones: ?streams=user+IS+JohnDoe&streams=key+IS+PROJECTKEY&streams=activity+IS+issue:close
Watch out, it is case sensitive, on my JIRA 6.1.9, if I write Is instead of IS, I get an error page (but not if AFTER is not all uppercase o.O).
Also note, that spaces should be encoded as plus signs (+), not URL encoded (%20 for spaces).
If you go to your JIRA, and fetch the following URL: https://jira.yourserver.com/rest/activity-stream/1.0/config, it will list all the combinations it accepts.
What
The call returns a standard Atom feed. You can then process it with XML query tools, or with other Java-based RSS/ATOM reader libraries.
Noteworthy document about this topic: https://developer.atlassian.com/docs/atlassian-platform-common-components/activity-streams/consuming-an-activity-streams-feed

token (or something else) needed to use wikipedia api using eclipse

I need a java code to use wikipedia api. I would like to get the tags of a specific value on wikipedia (the tags that appear at the end of the page). I know that the api call I need is
"http://en.wikipedia.org/w/api.php?action=query&format=json&titles=Albert%20Einstein&prop=categories"
(for the example of Albert Einstein)
But I find it difficult to understand from the MediaWiki API documentation page if I need a token and hash, or to log in or not. I know that sometimes it is not necessary to log in.
Right now my code is:
JSONArray wikiResult=null;
String url1= "http://en.wikipedia.org/w/api.php?action=query&format=json&titles=Albert%20Einstein&prop=categories";
wikiResult=ApiCall(url1);
where ApiCall is a function that sends the call, and it works fine, I have checked it.
the JSONArray returned is empty.
Can somebody please tell me what I'm doing wrong?
You don't need to log in or get token for prop=categories.
The actual error is probably explained in the response. It's possible that you're getting an empty result, because the response is not JSON (that happens with some errors).
If I were to guess, I think you're not setting the User-Agent header in your request, which is required by Wikimedia wikis.

How can I send a newsletter with xPages content?

I have some content displayed using computed fields inside a repeat in my xpage.
I now need to be able to send out a newsletter (by email) every week with the content of this repeat. The content can be both plain text and html
My site is also translated into different languages so I need the code to be able to specify the language and return the content in that language.
I am thinking about creating a scheduled lotusscript or java agent that somehow read the content of the repeat. is this possible? if so, some sample code to get me started would be great
edit: the content is only available to logged in users
thanks
Thomas
Use a java agent, and instead of going to the content natively, do a web page open and open the page as if in a browser, then process the result. (you could make a special version of the web page that hides all extraneous content as well if you wanted)
How is the data for the repeat evaluated? Can it be translated in to a lotusscript database.search?
If so then it would be best to forget about the actual xPage and concentrate on working out how to get the same data via LotusScript and then write your scheduled agent to loop through the document collection and generate the email that way.
Looking to the Xpage would generate a lot of extra work, you need to be authenticated as the user ( if the data in the repeat is different from one user to the next ) to get the exact same data that this particular user would see and then you have to parse the page to extract the data.
If you have a complicated enough newsletter that you want to do an Xpage and not build the html yourself in the agent, what you could do is build a single xpage that changes what's rendered based on a special query string, then in your agent get the html from a URLConnection and pass the html into the body of your email.
You could build the URL based on a view that shows documents with today's date.
I would solve this by giving the user a teaser on what to read and give them a link to the full content.
You should check out Weihang Chens (my colleague) article about rendering an xPage as Mime and sending it as a mail.
http://www.bleedyellow.com/blogs/weihang/entry/render_a_xpages_programmtically_and_send_it_as_a_mail?lang=en_us
We got this working in house and it is very convenient.
He describes 3 different approaches to the problem.

Categories

Resources