Over a million developers have joined DZone.
{{announcement.body}}
{{announcement.title}}

Invoking the Insights for Twitter Service in Bluemix from Swift

DZone's Guide to

Invoking the Insights for Twitter Service in Bluemix from Swift

See how you can interact with Bluemix in iOS

· Mobile Zone
Free Resource

Download this comprehensive Mobile Testing Reference Guide to help prioritize which mobile devices and OSs to test against, brought to you in partnership with Sauce Labs.

"Hear the Buzz" is a sample iPhone app which finds tweets with positive or negative sentiments for certain topics via the IBM Insights for Twitter service in IBM Bluemix. Below is a short description how this service is used from Swift.

As a starting point I used the sample app from my colleague Frederic Lavigne. The sample contains a simple Node.js application which provides a REST API that basically just forwards requests to the service and adds credentials so that clients can invoke the API without having to authenticate. I used this mechanism in this simple sample but you might want to change this for production apps.

Clients can now invoke REST APIs via insights-search.mybluemix.net/api/1/messages/search?q=bluemix which returns JSON. The following code shows how I parse the JSON is Swift. There might be better ways to do this though. I haven't done much Swift development honestly.


The next screenshot shows the code how to invoke the REST API from Swift. In order to define the tweets I'm interested in I use the query language of the Twitter service.

 

Analysts agree that a mix of emulators/simulators and real devices are necessary to optimize your mobile app testing - learn more in this white paper, brought to you in partnership with Sauce Labs.

Topics:
bluemix ,ios ,swift

Published at DZone with permission of Niklas Heidloff, DZone MVB. See the original article here.

Opinions expressed by DZone contributors are their own.

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}