GithubHelp home page GithubHelp logo

lukeredpath / lrresty Goto Github PK

View Code? Open in Web Editor NEW
463.0 14.0 56.0 863 KB

Yet another Objective-C REST client library, inspired by Ruby's restclient gem.

Home Page: http://projects.lukeredpath.co.uk/resty/

Objective-C 95.37% Ruby 4.63%

lrresty's Introduction

NOTE: THIS PROJECT IS NO LONGER SUPPORTED

If you require an awesome HTTP framework for iOS or Mac, I highly recommend AFNetworking.

Resty, an Objective-C HTTP framework

Resty is a simple to use HTTP library for iOS and Mac apps, aimed at consuming RESTful web services and APIs.

It uses modern Objective-C language features like blocks to simple asynchronous requests without having to worry about threads, operation queues or repetitive delegation. It is inspired heavily by RestClient, a Ruby HTTP library.

For more information and documentation, check out the project website.

Getting started

Because Resty relies heavily on Objective-C blocks, it requires a minimum of iOS 4.0 or Mac 10.6.

Resty is distributed as a static framework for iOS and a regular framework Mac; this makes it easy to get up and running with Resty. Simply drop the framework into your project (like any other framework) and add the -ObjC and -all_load linker flags to your target. If your project builds, you should be ready to go.

To download Resty, you can either clone this project and build from scratch or grab one of the latest releases or nightly builds from the Github downloads tab.

For detailed information, check out the Resty website.

Using LRResty with ARC projects

A version of LRResty that uses Objective-C Automatic Reference Counting (ARC) is available in the arcified branch. This, like ARC, should be considered experimental. I aim to move over to ARC fully when it is production ready (but without the use of __weak to maintain iOS4 compatibility). I will aim to keep both branches in sync, feature-wise.

lrresty's People

Contributors

lukeredpath avatar rufferto avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

lrresty's Issues

POST not sending "body"

It seems there is no HTTP Body when sending a simple post (iOS 5.0.1)

NSDictionary *params = [NSMutableDictionary dictionary];
[(NSMutableDictionary *)params setObject:@"Joe Bloggs" forKey:@"name"];
[(NSMutableDictionary *)params setObject:@"[email protected]" forKey:@"email"];

[[LRResty client] post:url payload:params
withBlock:^(LRRestyResponse *response){}];

On the server side, no HTTP request body is received.

Tried both with current master and arcified branches.

build for simulator fails

fix-it:"/Users/jblues/ExpanzProjects/LRResty/Classes/Categories/NSData+Base64.m":{146:23-146:23}:";"
/Users/jblues/ExpanzProjects/LRResty/Classes/Categories/NSData+Base64.m:253:1: error: unexpected '@' in program [1]
@implementation NSData (Base64)
^
/Users/jblues/ExpanzProjects/LRResty/Classes/Categories/NSData+Base64.m:301:1: error: unexpected '@' in program [1]
@EnD
^
/Users/jblues/ExpanzProjects/LRResty/Classes/Categories/NSData+Base64.m:301:5: error: expected '}' [1]
@EnD
^
/Users/jblues/ExpanzProjects/LRResty/Classes/Categories/NSData+Base64.m:74:1: note: to match this '{'
{
^
4 errors generated.

** BUILD SUCCEEDED **

Error with Archiving in Xcode 4

In project settings "Valid Architectures" is set to "armv6 arvmv7"

error: strip /Users/krasnoukhov/app/Frameworks/LRResty/LRResty.framework.dSYM/Contents/Resources/DWARF/LRResty: /usr/bin/strip exited with 1
/usr/bin/strip: for architecture x86_64 object: /Users/krasnoukhov/app/Frameworks/LRResty/LRResty.framework.dSYM/Contents/Resources/DWARF/LRResty malformed object (section contents at offset 0 with a size of 20300, overlaps Mach-O headers at offset 0 with a size of 3248)

no DELETE

is there any particular reason theres no delete method?

Large file streaming downloads fail

When using the streaming get method to download a 2.6 gigabyte sized file, LRResty fails with out of memory errors, because it is not releasing each block of data after it is passed to the onData block. I would like to stream the data to an NSFileHandle that is opened for writing.

- (void)restyClientWillPerformRequest:(LRRestyClient *)client {
    [[NSFileManager defaultManager] createFileAtPath:[self archiveFilePath]
                                            contents:nil
                                          attributes:nil];
    self.fh = [NSFileHandle fileHandleForWritingAtPath: [self archiveFilePath]];
}

- (void)requestDataFile {
    [[LRResty client] setDelegate:self];
    [[LRResty client] get:[self archiveURL]
                                  onData:^(NSData *data, BOOL *cancel) {
                                      [fh writeData:data];
                                  } onError:^(NSError *error) {
                                      [fh closeFile];
                                  }
}

malloc: *** mmap(size=2337423360) failed (error code=12)
*** error: can't allocate region
*** set a breakpoint in malloc_error_break to debug

Building from the latest source

Building from source actually fails if done using the following command:
rake build:ios:framework
Error from the command line:

`require': no such file to load -- bundler/setup (LoadError)

Adding a single line to the Rakefile helped to fix this on my system (Mac OS X Lion)

require "ruby gems"

Add ability to cancel Request

I need the ability to cancel an upload or download on command. It looks (in my five minute perusal of the source) like it can be done by accessing the instance of NSOperationQueue residing inside of LRRestyHTTPClient. operationQueue is handed an instance of LRRestyRequest.

Two questions:

  1. It seems simple enough to just tack "cancel" methods onto LRRestyClient and LRRestyHTTPClient, so that a cancel message can be handed off to operationQueue. Is that the best way to do this?
  2. "cancelAllOperations" is the method call on NSOperationQueue. That will then pass on a cancel message to the instance of LRRestyRequest. Will LRRestyRequest be smart enough to handle this? If not, what additional work needs to be done in LRRestyRequest to handle the cancel message?

In further analysis, I see that LRRestyRequest is a child of LRURLRequestOperation, which is in turn a child of NSOperation. NSOperation has a cancel method (which is what is being called by [NSOperationQueue cancelAllOperations]. Does that intrinsically cancel everything in any of its children classes, or do I have to override it and explicitly make a call to [NSURLConnection cancel]?

I fully admit that I don't have a deep understanding of how NSOperation and NSOperationQueue work. So I apologize if I'm asking nonsensical questions. I'd just like to see how to implement this in a way that allows me to cancel a connection gracefully on command.

Any suggestions are gratefully accepted. Thank you.

Namespace categories

The suggestion is to namespace categories in LRResty to avoid the possibility of name collisions with categories from the application or other libraries.

'LRResty/LRResty.h' file not found?

Hi I am very new to iOS development and I am currently experiencing problems trying to get install LRResty.

These are the steps which I have taken:

  1. Checked out the source from github
  2. I dragged 'LRResty.xcodeproj' to my project in XCode
  3. I added ObjC and all_load linker flags
  4. Then I added #import <LRResty/LRResty.h> to AppDelegate.h

At this point I tried building but I was getting 'LRResty/LRResty.h' file not found
I also tried adding the following:

  1. LRResty to Target Dependency.

However, I am not able to get this to work. Any ideas?

Screenshot: http://imgur.com/RVAAB

Cannot detect that GET request has been canceled

From my understanding if I call cancel on a LRRestyRequest it stops the NSURLConnection and calls finish, which in turn calls the completion block. However there is no way of knowing in my completion block that the request actually got canceled.

I would think that when canceling a long GET or POST operation the completion block either:

  • should not be called (after all we explicitly force a cancel)
  • should be called but it should have a way of doing that it is called because of a cancel and not because of a finish

What do you think?

Add ability to handle errors in callbacks.

I assumed I would be able to handle errors in the callback. So, my callback might look something like what you see below.

[self.client get:resource withBlock:^(LRRestyResponse *response) {
    if(response.error) {
         // Failed for some reason
    } else {
      // Response was in the 200 range
    }
}];

The workaround for this is that I need to check the status code in every callback to determine if the request was a success or not. If the status isn't in the success range, I'd need to call [NSHTTPURLResponse localizedStringForStatusCode:[response status]] to fetch the reason.

Add Example for POSTing UIImages

RestKit allows you to post images with:

RKParams* params = [RKParams params];
RKParamsAttachment* attachment = [params setData:UIImageJPEGRepresentation([thumbnail.image fixOrientation], 0.1) MIMEType:@"image/jpeg" forParam:@"timeline[photo]"];
[[RKClient sharedClient] post:urlString params:params delegate:self];

Is there any easy way to do that with LRResty?

Copying header files during build -- necessary?

I am using the latest arcified branch as a git submodule in an iOS project. I setup my application target to depend on the iOS static library target in the LRResty project. Two header files get copied as "public headers" during the build of the static library. This ends up causing problems creating an Archive of my application.

The header files being copied are:

  • LRRestyClient+DELETE.h
  • RemoteRepositoryExample.h

These don't really look like they ought to be copied as public headers for the static library, do they? When I remove them from the Copy Headers build phase, my application archive problem goes away.

synchronus request just hangs

i.e LRRestyClient get: never get returned (all other synchronized request methods do).

build env: SL 10.6.8
xcode 4.0
target: iOS 4.3.2 (simulator, not tested in real box)

code:

  • (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
    {
    NSLog(@"%s: begin.", FUNCTION);
    LRRestyResponse * lr = [[LRResty client] get:@"http://www.google.com/ncr"];

NSLog(@"r: %@", [lr asString]);

.... (omitted)

}

get an console output like '-[UFBXMobileAppDelegate application:didFinishLaunchingWithOptions:]: begin.' and the main window does not showup.

PS. async calls work fine, except that I cannot block the thread committed the async calls, or else the async calls do not run.

No timeout callbacks received from nightly

Hello,

I'm using the very latest nightly, and struggling to get any timeout callbacks:

[[[LRResty client] get:@"http://127.0.0.1:8888/api" withBlock:^(LRRestyResponse *r) {
        NSLog(@"response");
    }] timeoutAfter:5 handleWithBlock:^(LRRestyRequest *r){
        NSLog(@"timeout");
    }];

If the service at "127.0.0.1:8888/api" is up, I see the response block executed as expected. But if I stop the service, then neither the response nor the timeout blocks are executed.

I've also tried setting a global timeout (with setGlobalTimeout:handleWithBlock:), but that block doesn't get called either.

Any ideas? I guess either my code is bad, or my expectations about how LRResty works are wrong.

Thanks folks!

Matthew

Example - missing files

Hi
While trying to compile the provided example code I'm getting an:

ExamplesViewController.m:11:9: fatal error: 'GithubCredentials.h' file not found

And indeed the "GithubCredentials.h" and "TwitterCredentials.h" files are missing. I cloned the example from the master branch.

Caching Support

I couldn't find any documentation with regards to caching support. Is that provided by the underlying HTTP connection mechanism or is there no caching support at the moment?

submitting filters in url string

Hi Luke. When I am submitting a url such as:

http://clklabvm11.aaa.bbbbbbbbbb.ca:8000/sap/opu/sdata/sap/ZCWMERCSVC/CustomerCollection?$filter=emailAddress eq '[email protected]'&$sap-client=100&$format=xml

Resty throws:

2011-09-07 00:08:49.713 CWMercDemo[2974:b603] *** Assertion failure in -[LRRestyHTTPClient requestForURL:method:payload:headers:requestDelegate:], /Users/admin/.jenkins/jobs/LRResty Nightly Builds/workspace/Classes/LRRestyHTTPClient.m:86
2011-09-07 00:08:49.715 CWMercDemo[2974:b603] *** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'LResty requires a valid HTTP(S) URL, received (null)'

I am guessing that this is due to the single-quotes in the url string? I tried to escape them with \ but the same exception is thrown... I am wondering if there is a way I can get url strings like this one work with Resty?

thanks,

steve

Building framework in Xcode 4

Okay, I'm feeling particularly stupid at this point. I've not dealt with frameworks in Xcode 4 (nor, hardly, in Xcode 3.x, for that matter), and I'm hitting a wall. I've been digging around in the docs, and starting to get a feel for Schemes. But I can't seem to get to the point where I've got a build result that gives me an LRResty.framework folder with all of the necessary components residing inside.

I don't really know/understand what is happening, so I'm pretty much stuck at this point. Has anyone here built LRResty in Xcode 4? Any thoughts or tips on what I should be doing? I've googled extensively, and I've not seen anything from anyone about building frameworks in Xcode 4. Lots about including pre-built ones. But nothing about starting from scratch.

Help!

Access Denied when downloading LRResty-iOS-0.10.dmg

When trying to download LRResty-iOS-0.10.dmg (i.e. NOT the nightly iOS build), we get an access denied error:

AccessDenied Access Denied 061052C0AD5B6E1D zXZUL+6Hd3BnIXVrXWR9HWOzqtSQtkoT0Yefxxo3N8Gd9bbSYBNitkhkitQaUB+u

Connection errors not forwarded to Delegate

Currently the URL connection errors are lost in the LRRestyClientProxyDelegate, so they can't be handled by the application.

To hand them down, a chunk of code is missing in the LRRestyClientProxyDelegate implementation:

- (void)restyRequest:(LRRestyRequest *)request didFailWithError:(NSError *)error {
    if ([responseDelegate respondsToSelector:@selector(restClient:request:didFailWithError:)]) {
        [responseDelegate restClient:restyClient request:request didFailWithError:error];
    }
}

and the LRRestyClientResponseDelegate must be extended by:

@optional
/**
 * Called if the underlying URLConnection reported an error
 * @param client    The client performing the request.
 * @param request   The request resulting in an error.
 * @param didFailWithError  The error the URLConnection reported.
 */
- (void)restClient:(LRRestyClient *)client request:(LRRestyRequest *)request didFailWithError:(NSError *)error;

Any chance to see the bugfix in the nightly build soon?

Pascal

Basic Authentication scheme uses two requests

Hi,

I'm using basic auth and it looks like LRResty isn't sending this information as a base64 encoded header, but rather it's waiting for one request to receive an authentication challenge and then sending another request with the credentials.

It looks like I might be able to get around this by supplying my own base64 routine and using attachRequestModifier. I think the header approach is much better as it is technically faster and less stress on your server (one request vs two).

I used the Auth header in HTTPRiot and this is also the approach that ASIHTTPRequest has taken. Are there any benefits to the current implementation?

linking issue with lastest MacOS LRResty build

Hi Luke. I added the nightly MacOS build to a mac project and am having some problems linking. I think this may be a human issue (me), but I am wondering if you have any tips?

XCode 4.1 on 10.7.2 11C57

valid architectures: i386 x86_64
linker flags: -ObjC -all_load

ld: warning: ignoring file /Users/i004432/Desktop/Library/osx/LRResty.framework/LRResty, missing required architecture x86_64 in file
Undefined symbols for architecture x86_64:
"OBJC_CLASS$_LRResty", referenced from:
objc-class-ref in LRRestyMacDemoAppDelegate.o
(maybe you meant: OBJC_CLASS$_LRRestyMacDemoAppDelegate)
ld: symbol(s) not found for architecture x86_64
collect2: ld returned 1 exit status

kind regards,

steve

problem linking to libLRResty.a in iOS project (Xcode 4.0.2)

I've used LRResty in a Cocoa application as a framework (LRResty.framework) and I was very pleased.

I would like to use libLRResty.a in an iOS project, but I am having trouble.

I used the rake tool to build a combined ios/iosimulator library, but made one change to the Rakefile:

  BASE_SDK = 4.3
  %  rake buid:clean
  %  rake build:combined

The build appears to work. There is one issue around the CodePilot 2.0 plugin (I am a beta tester). I don't really think this is an issue, but it might be, so I include the output below.

I am use a number of static libraries and am familiar with how to include them in my targets. In this particular case, I am also linking libOCMock.a without any difficulties.

Can you confirm that I used the correct rake command for building for iOS (device and simulator)?

I am using the following import statement:

 #import <LRResty/LRResty.h>

(Xcode actually suggests this as a completion)

When I build (for device or simulator) I get: LRResty/LRResty.h: No such file or directory.

Any suggestions?

Thanks,

jmoody

=== BEGIN CODE PILOT ISSUE ===

WARNING: skipping plug-in at path '/Users/moody/Library/Application Support/Developer/Shared/Xcode/Plug-ins/CodePilot.xcplugin' because it is not compatible with this version of Xcode.
2011-04-28 17:44:05.190 xcodebuild[74612:80f] Error loading /Users/moody/Library/Developer/Xcode/Third-Party Plug-ins/CodePilot2.xcplugin/Contents/MacOS/CodePilot2: dlopen(/Users/moody/Library/Developer/Xcode/Third-Party Plug-ins/CodePilot2.xcplugin/Contents/MacOS/CodePilot2, 265): Symbol not found: OBJC_CLASS$_IDEDocumentController
Referenced from: /Users/moody/Library/Developer/Xcode/Third-Party Plug-ins/CodePilot2.xcplugin/Contents/MacOS/CodePilot2
Expected in: flat namespace
in /Users/moody/Library/Developer/Xcode/Third-Party Plug-ins/CodePilot2.xcplugin/Contents/MacOS/CodePilot2
2011-04-28 17:44:05.190 xcodebuild[74612:80f] WARNING: Failed to load plugin at: /Users/moody/Library/Developer/Xcode/Third-Party Plug-ins/CodePilot2.xcplugin, skipping. Could not load bundle

=== END CODE PILOT ISSUE ===

Linker error and compile warnings in Xcode 4.3.2 on Lion for arcified branch

I downloaded the arcified branch of LRResty and imported the files into my Xcode project.

On build, I'm seeing these warnings :

-Implicit declaration of function 'DEFINE_SHARED_INSTANCE_USING_BLOCK' is invalid in C99
-Control reaches end of non-void function

They relate to this function in LRResty.m:

    + (LRRestyClient *)client;
    {
      DEFINE_SHARED_INSTANCE_USING_BLOCK(^{
        return [self newClient];
     });
    }

This then results in a linker error:

Undefined symbols for architecture i386:
"_DEFINE_SHARED_INSTANCE_USING_BLOCK", referenced from:
+[LRResty client] in LRResty.o
ld: symbol(s) not found for architecture i386

Have I done something wrong? Are there any prerequisites that I've missed (I can't see any documented anywhere), e.g. minimum iOS target version (mine is 4.0), frameworks to link with, etc?

The All-Seeing I post (http://allseeing-i.com/%5Brequest_release%5D) said this arcified branch is an active project. Is it?

Thanks!

Tried to obtain the web lock from a thread other than the main thread

Integration Test run through Cedar, sometimes fails with: Tried to obtain the web lock from a thread other than the main thread or the web thread. This may be a result of calling to UIKit from a secondary thread. Crashing now...

Would using Kiwi help to prevent this error?

Form encoded requests strip NSNumber values

I haven't fully tested this, so it might apply to anything that inherits from NSValue or any non-retained, non-copied value. If you send a post request with an NSNumber in the payload, it's stripped, but the request will still complete. If I convert the number to a string before sending it to post:payload:withBlock, everything works as expected.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.