Objective-C: NSURLConnection POST - objective-c

What's the best way to send a POST request with NSURLConnection.
I see how the facebook-ios-sdk does it:
https://github.com/facebook/facebook-ios-sdk/blob/master/src/FBRequest.m#L298-304
https://github.com/facebook/facebook-ios-sdk/blob/master/src/FBRequest.m#L109-165
But, that seems like a lot of code. Is that how it's done? Or, is there a better way? I'd like to keep the support for posting binary data, like images & files.

Facebook's code is as complicated as it is because they're sending the data with a multipart/form-data content type. You are free to use a simpler content type, like application/octet-stream for raw binary data.

You can try http://getsharekit.com/. Using this you can share in many social networks. Also you can share in a specific network also. If you refer to the documents there you can see how to send the images from a URL.

Related

Rest API resources: composed for post but separate to get is ok?

I'm creating a set of RESTful API and I have this question: I have a resource that has some images attached and I'm creating my resources like this:
POST to /resource: create the object and save the images to the server.
GET to /resource returns the object but no the images, GET to /images returns the images.
My question is: is this compliant with REST or should I either make the resources completely separate or completely unified?
I choose this solution because when posting I for sure send the images, but I may need them or not when doing a get.
is this compliant with REST
It's fine - for instance, if you look at the way that Atom Publishing works, you'll see that when you post a media to a collection, two resources are created (the Media Resource and the Media Link Entry).
However, fine here means you are making tradeoffs. In particular, cache invalidation is more challenging when you a POST to one resource may change the representation of a different resource.
HTTP caching semantics are optimized for the common case, which is that a given request changes only the target resource; no spooky action at a distance.
That doesn't mean that this is the Right Way, but rather that you should understand that this is the way that HTTP makes easy, and in other cases you need to pay attention to the details.
POST can basically mean anything, and unlike PUT and GET (for which there is a bit more of a direct relation), POST is allowed to result in all kinds of side-effects, including the creation of 0 or more resources.
POST is basically the 'anything goes' method.

Can I hide the artwork from the received embed code when calling SoundCloud oEmbed?

Is there any way to send a parameter to /oembed so that the artwork will not be shown in the received embed code?
I am thinking about rewriting the src attribute of the iframe in the response html value, but I'd rather not resort to such a hack.
Also, is it safe to assume that the iframe src contains /track/ if (and only if) it's a track?
What I want to achieve is a player that displays artwork for all content types except track, where I want to hide it. My solution would be to look at the received src attribute and set show_artwork=false on it if it's a track.
Does this seem like a very bad idea? :)
I need this too. A while ago, it had worked while I included show_artwork=false in my oembed request.
Eg.
http://soundcloud.com/oembed?url=http%3A//soundcloud.com/xxx/xxxx&format=json&show_artwork=false&auto_play=false
However, Soundcloud seems to have made some changes to their oembed api, and now even when I specify that, the returned code has show_artwork=true specified regardless.
I think we might have to make a feature request to Soundcloud about this.
Sure, we can edit the received results, and it will work, but that definitely not a satisfactory solution.
Yes, show_artwork is a missing oembed parameter: http://developers.soundcloud.com/docs/api/reference#oembed

How to parse information from blog to iphone?

could someone point me in the right direction in how i can parse data from a blog to an iphone. E.g. You have a table view displaying the posts of the blog, you select a table cell and text content is displayed. Are there any tutorials/examples on this?
I have a bit of experience with parsing data using JSON (parsed data from database to iphone) but unsure on where to start with this?
Thanks for an help..
What you want to do is use the Wordpress API. The flow goes like this:
Make an API call. This is a subject unto itself, but typically you'd use NSHTTPRequest and NSURLConnection to make the request.
Parse the result. I forget if you get XML back; you probably do; in that case there are tons of solutions for parsing, including NSXMLParser and libxml2.
Populate UITables, etc. with the retrieved information.
The Wordpress API is not that big or complex, but it's a bigger subject than I can really get into in the context of an SO answer, so I'll just refer you to the aforelinked documentation and wish you happy reading.

Getting text information from the Internet into my app

I learning Objective C, and I am going to develop some apps. I have a general question: How to get text information from the Internet into your app. Say you want the current title of Yahoo News. Do I need to use some PHP, or are there Objective-C specific classes to choose from?
Help is appreciated (code as well!), just anything that can help me take te step to exploring the new possibilities!
If I understand your question, I'd say the best way to do it would be to get the HTML source from the URL of your choosing as a string, then parse it to grab an attribute such as the title. Have a look at NSString and NSXMLDocument; they both let you instantiate them from a URL.
Here's a great way to do it:
Go to Yahoo Pipes, and create your "pipe" (basically a feed of one or many different data inputs on the web).
Publish: Select a format for Yahoo to host, for example as an RSS feed or in JSON.
UIWebView can then point to your pipe's URL. (Here's a tutorial on UIWebView)
Done.
Note that you can choose to get the feed as RSS, JSON, and other formats as well. Here is an example of a pipe I set up for the National Vulnerabilities Database as RSS, and the same feed as JSON.
ASIHttpRequest Will keep you sane.

using appengine blobs for binary data in an obj-c app

I'm writing an obj-c app and would like to upload a binary file a few megs in size to my appengine server (python). I'm guessing I need to use the blob entity for this, but am unsure how to go about doing this. I've been using http requests and responses to send and receive data up to now, but they've been encoded in strings. Can someone advise how I'd go about doing the same with blobs from an obj-c app? I see some examples that involve http requests but they seem geared toward web page and I'm not terribly familiar with it. Are there any decent tutorials or walkthroughs perhaps?
I'm basically not completely sure, if I'm supposed to encode it into the http request and send it back through the response, how to get the binary data into the http string from the client and how to send it back properly from the server when downloading my binary data. I'm thinking perhaps the approach has to be totally different from what I'm used to with encoding values into my request in the param1=val&param2=val2 style format but uncertain.
Should I be using the blobstore service for this? One important note is that I've heard there is a 1 meg limit on blobs, but I have audio files 2-3 megs in size that I need to store (at the very least 1.8 megs).
I recently had to do something similar, though it was binary data over a socket connection. To the client using XML, to the server as a data stream. I ended up base64 encoding the binary data when sending it back and forth. It's a bit wordy but especially on the client side it made things easier to deal with, no special characters to worry about in my XML. I then translated it with NSData into a real binary format. I used this code to do the encoding and decoding, search for "cyrus" to find the snippet I used, there are a few that would work here.
In your case I would change your http request to a post data call rather than putting it all in the URL. If you're not sure what the difference is, have a look here.
I'm not as familiar with python, but you could try here for help on that end.
Hope that helps.
Edit - it looks like blobs are the way to go. Have a look at this link for the string/blob type as well as this link for more info on working with the blob.
There are three questions in one here:
Should you use a BLOB for binary data?
How do you post binary data, and use it from app engine
How do you retrieve binary data from app engine
I can't answer if you "should" use blobs, only you would know the answer to that, and it greatly depends upon the type of data you are trying to store, and how it will be used. Let's take an image for example (which is probably the most popular use case for this). You want users to take a photo with their phone, upload it, and then share it with other users. That's a good use of blobs, but as #slycrel suggests you'll run into limitations on record size. This can be workable, for example you could use the python image library (pil) to downsize the image.
To post binary data, see this question. It would be best to cache 2 copies, a thumbnail and a full size. This way the resizing only has to happen once, on upload. If you want to go one better, you can use the new background jobs feature of app engine to queue up the image processing for later. Either way, you'll want to return the ID of the newly created blob so you can reference it from the device without an additional http request.
To retrieve data, I think the best approach would be to treat the BLOB as it's own resource. Adjust your routes such that any given blob has a unique URL:
http://myweb/images/(thumbnail|fullsize)/<blobid>.(jpg|png|gif)
Where BLOBID is dynamic, and JPG, PNG or GIF could be used to get the particular type of image. Thumbnail or fullsize could be used to retrieve the smaller or larger version you saved when they posted it.