Skip to content

Commit

Permalink
added tweet function example
Browse files Browse the repository at this point in the history
  • Loading branch information
typester committed Nov 8, 2010
1 parent dbcce3d commit cb16f10
Show file tree
Hide file tree
Showing 6 changed files with 256 additions and 12 deletions.
151 changes: 141 additions & 10 deletions resources/RootView.xib
@@ -1,17 +1,18 @@
<?xml version="1.0" encoding="UTF-8"?>
<archive type="com.apple.InterfaceBuilder3.CocoaTouch.XIB" version="7.10">
<data>
<int key="IBDocument.SystemTarget">1024</int>
<int key="IBDocument.SystemTarget">1056</int>
<string key="IBDocument.SystemVersion">10F569</string>
<string key="IBDocument.InterfaceBuilderVersion">804</string>
<string key="IBDocument.InterfaceBuilderVersion">823</string>
<string key="IBDocument.AppKitVersion">1038.29</string>
<string key="IBDocument.HIToolboxVersion">461.00</string>
<object class="NSMutableDictionary" key="IBDocument.PluginVersions">
<string key="NS.key.0">com.apple.InterfaceBuilder.IBCocoaTouchPlugin</string>
<string key="NS.object.0">123</string>
<string key="NS.object.0">132</string>
</object>
<object class="NSMutableArray" key="IBDocument.EditedObjectIDs">
<bool key="EncodedWithXMLCoder">YES</bool>
<integer value="1"/>
</object>
<object class="NSArray" key="IBDocument.PluginDependencies">
<bool key="EncodedWithXMLCoder">YES</bool>
Expand All @@ -37,7 +38,7 @@
<string key="targetRuntimeIdentifier">IBCocoaTouchFramework</string>
</object>
<object class="IBUIView" id="191373211">
<nil key="NSNextResponder"/>
<reference key="NSNextResponder"/>
<int key="NSvFlags">274</int>
<object class="NSMutableArray" key="NSSubviews">
<bool key="EncodedWithXMLCoder">YES</bool>
Expand Down Expand Up @@ -113,6 +114,53 @@
</object>
<reference key="IBUINormalTitleShadowColor" ref="799240176"/>
</object>
<object class="IBUIButton" id="20793561">
<reference key="NSNextResponder" ref="191373211"/>
<int key="NSvFlags">292</int>
<string key="NSFrame">{{228, 122}, {72, 37}}</string>
<reference key="NSSuperview" ref="191373211"/>
<bool key="IBUIOpaque">NO</bool>
<string key="targetRuntimeIdentifier">IBCocoaTouchFramework</string>
<int key="IBUIContentHorizontalAlignment">0</int>
<int key="IBUIContentVerticalAlignment">0</int>
<object class="NSFont" key="IBUIFont">
<string key="NSName">Helvetica-Bold</string>
<double key="NSSize">15</double>
<int key="NSfFlags">16</int>
</object>
<int key="IBUIButtonType">1</int>
<string key="IBUINormalTitle">tweet</string>
<reference key="IBUIHighlightedTitleColor" ref="914061868"/>
<object class="NSColor" key="IBUINormalTitleColor">
<int key="NSColorSpace">1</int>
<bytes key="NSRGB">MC4xOTYwNzg0MzQ2IDAuMzA5ODAzOTMyOSAwLjUyMTU2ODY1NgA</bytes>
</object>
<reference key="IBUINormalTitleShadowColor" ref="799240176"/>
</object>
<object class="IBUITextField" id="929623836">
<reference key="NSNextResponder" ref="191373211"/>
<int key="NSvFlags">292</int>
<string key="NSFrame">{{20, 125}, {200, 31}}</string>
<reference key="NSSuperview" ref="191373211"/>
<bool key="IBUIOpaque">NO</bool>
<bool key="IBUIClipsSubviews">YES</bool>
<string key="targetRuntimeIdentifier">IBCocoaTouchFramework</string>
<int key="IBUIContentVerticalAlignment">0</int>
<string key="IBUIText"/>
<int key="IBUIBorderStyle">3</int>
<object class="NSColor" key="IBUITextColor">
<int key="NSColorSpace">3</int>
<bytes key="NSWhite">MAA</bytes>
<object class="NSColorSpace" key="NSCustomColorSpace" id="435572509">
<int key="NSID">2</int>
</object>
</object>
<bool key="IBUIAdjustsFontSizeToFit">YES</bool>
<float key="IBUIMinimumFontSize">17</float>
<object class="IBUITextInputTraits" key="IBUITextInputTraits">
<string key="targetRuntimeIdentifier">IBCocoaTouchFramework</string>
</object>
</object>
<object class="IBUIView" id="1064435681">
<reference key="NSNextResponder" ref="191373211"/>
<int key="NSvFlags">-2147483356</int>
Expand All @@ -135,14 +183,13 @@
<object class="NSColor" key="IBUIBackgroundColor" id="82119440">
<int key="NSColorSpace">3</int>
<bytes key="NSWhite">MQA</bytes>
<object class="NSColorSpace" key="NSCustomColorSpace">
<int key="NSID">2</int>
</object>
<reference key="NSCustomColorSpace" ref="435572509"/>
</object>
<string key="targetRuntimeIdentifier">IBCocoaTouchFramework</string>
</object>
</object>
<string key="NSFrameSize">{320, 416}</string>
<reference key="NSSuperview"/>
<reference key="IBUIBackgroundColor" ref="82119440"/>
<object class="IBUISimulatedStatusBarMetrics" key="IBUISimulatedStatusBarMetrics"/>
<object class="IBUISimulatedNavigationBarMetrics" key="IBUISimulatedTopBarMetrics">
Expand Down Expand Up @@ -212,6 +259,31 @@
</object>
<int key="connectionID">15</int>
</object>
<object class="IBConnectionRecord">
<object class="IBCocoaTouchOutletConnection" key="connection">
<string key="label">tweetButton</string>
<reference key="source" ref="372490531"/>
<reference key="destination" ref="20793561"/>
</object>
<int key="connectionID">18</int>
</object>
<object class="IBConnectionRecord">
<object class="IBCocoaTouchOutletConnection" key="connection">
<string key="label">tweetField</string>
<reference key="source" ref="372490531"/>
<reference key="destination" ref="929623836"/>
</object>
<int key="connectionID">19</int>
</object>
<object class="IBConnectionRecord">
<object class="IBCocoaTouchEventConnection" key="connection">
<string key="label">onPushTweetButton:</string>
<reference key="source" ref="20793561"/>
<reference key="destination" ref="372490531"/>
<int key="IBEventType">7</int>
</object>
<int key="connectionID">20</int>
</object>
</object>
<object class="IBMutableOrderedSet" key="objectRecords">
<object class="NSArray" key="orderedObjects">
Expand All @@ -231,6 +303,8 @@
<reference ref="834072399"/>
<reference ref="65253808"/>
<reference ref="1064435681"/>
<reference ref="929623836"/>
<reference ref="20793561"/>
</object>
<reference key="parent" ref="0"/>
</object>
Expand Down Expand Up @@ -274,6 +348,16 @@
<reference key="object" ref="615818260"/>
<reference key="parent" ref="1064435681"/>
</object>
<object class="IBObjectRecord">
<int key="objectID">16</int>
<reference key="object" ref="20793561"/>
<reference key="parent" ref="191373211"/>
</object>
<object class="IBObjectRecord">
<int key="objectID">17</int>
<reference key="object" ref="929623836"/>
<reference key="parent" ref="191373211"/>
</object>
</object>
</object>
<object class="NSMutableDictionary" key="flattenedProperties">
Expand All @@ -286,6 +370,10 @@
<string>1.IBPluginDependency</string>
<string>10.IBPluginDependency</string>
<string>11.IBPluginDependency</string>
<string>16.IBPluginDependency</string>
<string>16.IBViewBoundsToFrameTransform</string>
<string>17.IBPluginDependency</string>
<string>17.IBViewBoundsToFrameTransform</string>
<string>4.IBPluginDependency</string>
<string>4.IBViewBoundsToFrameTransform</string>
<string>5.IBPluginDependency</string>
Expand All @@ -302,6 +390,14 @@
<string>com.apple.InterfaceBuilder.IBCocoaTouchPlugin</string>
<string>com.apple.InterfaceBuilder.IBCocoaTouchPlugin</string>
<string>com.apple.InterfaceBuilder.IBCocoaTouchPlugin</string>
<object class="NSAffineTransform">
<bytes key="NSTransformStruct">AUNkAABDiAAAA</bytes>
</object>
<string>com.apple.InterfaceBuilder.IBCocoaTouchPlugin</string>
<object class="NSAffineTransform">
<bytes key="NSTransformStruct">AUGgAABDiYAAA</bytes>
</object>
<string>com.apple.InterfaceBuilder.IBCocoaTouchPlugin</string>
<object class="NSAffineTransform">
<bytes key="NSTransformStruct">P4AAAL+AAABDCwAAw0MAAA</bytes>
</object>
Expand Down Expand Up @@ -331,11 +427,25 @@
</object>
</object>
<nil key="sourceID"/>
<int key="maxID">15</int>
<int key="maxID">20</int>
</object>
<object class="IBClassDescriber" key="IBDocument.Classes">
<object class="NSMutableArray" key="referencedPartialClassDescriptions">
<bool key="EncodedWithXMLCoder">YES</bool>
<object class="IBPartialClassDescription">
<string key="className">NSObject</string>
<object class="IBClassDescriptionSource" key="sourceIdentifier">
<string key="majorKey">IBProjectSource</string>
<string key="minorKey">src/JSON/NSObject+SBJSON.h</string>
</object>
</object>
<object class="IBPartialClassDescription">
<string key="className">NSObject</string>
<object class="IBClassDescriptionSource" key="sourceIdentifier">
<string key="majorKey">IBProjectSource</string>
<string key="minorKey">src/JSON/SBJsonWriter.h</string>
</object>
</object>
<object class="IBPartialClassDescription">
<string key="className">RootViewController</string>
<string key="superclassName">UIViewController</string>
Expand All @@ -345,11 +455,13 @@
<bool key="EncodedWithXMLCoder">YES</bool>
<string>onPushHomeTimelineButton:</string>
<string>onPushSigninButton:</string>
<string>onPushTweetButton:</string>
</object>
<object class="NSMutableArray" key="dict.values">
<bool key="EncodedWithXMLCoder">YES</bool>
<string>id</string>
<string>id</string>
<string>id</string>
</object>
</object>
<object class="NSMutableDictionary" key="actionInfosByName">
Expand All @@ -358,6 +470,7 @@
<bool key="EncodedWithXMLCoder">YES</bool>
<string>onPushHomeTimelineButton:</string>
<string>onPushSigninButton:</string>
<string>onPushTweetButton:</string>
</object>
<object class="NSMutableArray" key="dict.values">
<bool key="EncodedWithXMLCoder">YES</bool>
Expand All @@ -369,6 +482,10 @@
<string key="name">onPushSigninButton:</string>
<string key="candidateClassName">id</string>
</object>
<object class="IBActionInfo">
<string key="name">onPushTweetButton:</string>
<string key="candidateClassName">id</string>
</object>
</object>
</object>
<object class="NSMutableDictionary" key="outlets">
Expand All @@ -379,13 +496,17 @@
<string>loadingView</string>
<string>signinButton</string>
<string>statusLabel</string>
<string>tweetButton</string>
<string>tweetField</string>
</object>
<object class="NSMutableArray" key="dict.values">
<bool key="EncodedWithXMLCoder">YES</bool>
<string>UIButton</string>
<string>UIView</string>
<string>UIButton</string>
<string>UILabel</string>
<string>UIButton</string>
<string>UITextField</string>
</object>
</object>
<object class="NSMutableDictionary" key="toOneOutletInfosByName">
Expand All @@ -396,6 +517,8 @@
<string>loadingView</string>
<string>signinButton</string>
<string>statusLabel</string>
<string>tweetButton</string>
<string>tweetField</string>
</object>
<object class="NSMutableArray" key="dict.values">
<bool key="EncodedWithXMLCoder">YES</bool>
Expand All @@ -415,6 +538,14 @@
<string key="name">statusLabel</string>
<string key="candidateClassName">UILabel</string>
</object>
<object class="IBToOneOutletInfo">
<string key="name">tweetButton</string>
<string key="candidateClassName">UIButton</string>
</object>
<object class="IBToOneOutletInfo">
<string key="name">tweetField</string>
<string key="candidateClassName">UITextField</string>
</object>
</object>
</object>
<object class="IBClassDescriptionSource" key="sourceIdentifier">
Expand All @@ -428,7 +559,7 @@
<string key="IBDocument.TargetRuntimeIdentifier">IBCocoaTouchFramework</string>
<object class="NSMutableDictionary" key="IBDocument.PluginDeclaredDependencyDefaults">
<string key="NS.key.0">com.apple.InterfaceBuilder.CocoaTouchPlugin.iPhoneOS</string>
<integer value="1024" key="NS.object.0"/>
<integer value="1056" key="NS.object.0"/>
</object>
<object class="NSMutableDictionary" key="IBDocument.PluginDeclaredDevelopmentDependencies">
<string key="NS.key.0">com.apple.InterfaceBuilder.CocoaTouchPlugin.InterfaceBuilder3</string>
Expand All @@ -437,6 +568,6 @@
<bool key="IBDocument.PluginDeclaredDependenciesTrackSystemTargetVersion">YES</bool>
<string key="IBDocument.LastKnownRelativeProjectPath">../twitter-oauth-example.xcodeproj</string>
<int key="IBDocument.defaultPropertyAccessControl">3</int>
<string key="IBCocoaTouchPluginVersion">123</string>
<string key="IBCocoaTouchPluginVersion">132</string>
</data>
</archive>
1 change: 1 addition & 0 deletions src/OAuth.h
Expand Up @@ -22,5 +22,6 @@
+(NSString*)getAuthHeaderForMethod:(NSString*)method URL:(NSString*)url params:(NSDictionary*)params;

+(BOOL)getHomeTimelineParams:(NSDictionary*)params onComplete:(void (^)(OAuth*))callback;
+(BOOL)tweetParams:(NSDictionary*)params onComplete:(void (^)(OAuth*))callback;

@end
47 changes: 47 additions & 0 deletions src/OAuth.m
Expand Up @@ -204,6 +204,53 @@ +(BOOL)getHomeTimelineParams:(NSDictionary*)params onComplete:(void (^)(OAuth*))
return YES;
}

+(BOOL)tweetParams:(NSDictionary*)params onComplete:(void (^)(OAuth*))callback {
NSString* url = @"http://api.twitter.com/1/statuses/update.json";

dispatch_queue_t mq = dispatch_get_main_queue();
dispatch_queue_t q = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0);

dispatch_async(q, ^{
OAuth* api = [OAuth oauth];
CURL* curl = curl_init(api);
CURLcode res = 0;

struct curl_slist* slist = NULL;
slist = curl_slist_append(slist, "Expect:");
slist = curl_slist_append(slist, "Content-Type: application/x-www-form-urlencoded");
slist = curl_slist_append(slist, [[OAuth getAuthHeaderForMethod:@"POST" URL:url params:params] UTF8String]);
curl_easy_setopt(curl, CURLOPT_HTTPHEADER, slist);

NSString* content = [NSString stringWithFormat:@"status=%@", [[params objectForKey:@"status"] URLEncodedString]];
LOG(@"content: %@", content);

curl_easy_setopt(curl, CURLOPT_URL, [url UTF8String]);
curl_easy_setopt(curl, CURLOPT_POST, 1);
curl_easy_setopt(curl, CURLOPT_POSTFIELDS, [content UTF8String]);
curl_easy_setopt(curl, CURLOPT_POSTFIELDSIZE, strlen([content UTF8String]));

res = curl_easy_perform(curl);

if (0 != res) {
api.error = [NSString stringWithUTF8String:curl_easy_strerror(res)];
}
else {
NSString* content = [[NSString alloc] initWithData:api.readBuf
encoding:NSUTF8StringEncoding];
api.content = content;
[content release];
}

curl_easy_cleanup(curl);

dispatch_async(mq, ^{
callback(api);
});
});

return YES;
}

+(NSString*)getAuthHeaderForMethod:(NSString*)method URL:(NSString*)url params:(NSDictionary*)params {
NSNumber* epoch = [NSNumber numberWithInt:(int)[[NSDate date] timeIntervalSince1970]];

Expand Down
5 changes: 5 additions & 0 deletions src/RootViewController.h
Expand Up @@ -3,16 +3,21 @@
@interface RootViewController : UIViewController {
UIButton* signinButton_;
UIButton* homeTimelineButton_;
UITextField* tweetField_;
UIButton* tweetButton_;
UILabel* statusLabel_;
UIView* loadingView_;
}

@property (nonatomic, retain) IBOutlet UIButton* signinButton;
@property (nonatomic, retain) IBOutlet UIButton* homeTimelineButton;
@property (nonatomic, retain) IBOutlet UITextField* tweetField;
@property (nonatomic, retain) IBOutlet UIButton* tweetButton;
@property (nonatomic, retain) IBOutlet UILabel* statusLabel;
@property (nonatomic, retain) IBOutlet UIView* loadingView;

-(IBAction)onPushSigninButton:(id)sender;
-(IBAction)onPushHomeTimelineButton:(id)sender;
-(IBAction)onPushTweetButton:(id)sender;

@end

0 comments on commit cb16f10

Please sign in to comment.