Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

Twitter 1.1 API (now required), %-encoding bugfix #110

Open
wants to merge 1 commit into from

1 participant

@bome

Changes for the Twitter 1.1 API (1.0 is disabled by Twitter!)

  • remove (some) XML references. 1.1 does not support XML anymore!
  • update twitter domain to 1.1
  • removed LibXML files
  • moderate documentation updates, fix compiler warning in MGTwitterXMLParser.h

Note: not all REST commands have been tested for 1.1 compliance.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Jul 1, 2013
  1. @bome
This page is out of date. Refresh to see the latest.
View
36 MGTwitterEngine.m
@@ -8,15 +8,10 @@
#import "MGTwitterEngine.h"
#import "MGTwitterHTTPURLConnection.h"
-#import "OAuthConsumer.h"
+#import "OAMutableURLRequest.h"
#import "NSData+Base64.h"
-#ifndef USE_LIBXML
-// if you wish to use LibXML, add USE_LIBXML=1 to "Precompiler Macros" in Project Info for all targets
-# define USE_LIBXML 0
-#endif
-
#if YAJL_AVAILABLE
#define API_FORMAT @"json"
@@ -30,25 +25,12 @@
#import "MGTwitterTouchJSONParser.h"
#else
- #define API_FORMAT @"xml"
-
- #if USE_LIBXML
- #import "MGTwitterStatusesLibXMLParser.h"
- #import "MGTwitterMessagesLibXMLParser.h"
- #import "MGTwitterUsersLibXMLParser.h"
- #import "MGTwitterMiscLibXMLParser.h"
- #import "MGTwitterSocialGraphLibXMLParser.h"
- #else
- #import "MGTwitterStatusesParser.h"
- #import "MGTwitterUsersParser.h"
- #import "MGTwitterMessagesParser.h"
- #import "MGTwitterMiscParser.h"
- #import "MGTwitterSocialGraphParser.h"
- #import "MGTwitterUserListsParser.h"
- #endif
+
+#error "Need to define either YAJL_AVAILABLE or TOUCHJSON_AVAILABLE in MGTwitterEngineGlobalHeader.h!"
+
#endif
-#define TWITTER_DOMAIN @"api.twitter.com/1"
+#define TWITTER_DOMAIN @"api.twitter.com/1.1"
#if YAJL_AVAILABLE || TOUCHJSON_AVAILABLE
#define TWITTER_SEARCH_DOMAIN @"search.twitter.com"
@@ -415,7 +397,7 @@ - (NSString *)_encodeString:(NSString *)string
NSString *result = (NSString *)CFURLCreateStringByAddingPercentEscapes(NULL,
(CFStringRef)string,
NULL,
- (CFStringRef)@";/?:@&=$+{}<>,",
+ (CFStringRef)@"!*'();:@&=+$,/?%#[]",
kCFStringEncodingUTF8);
return [result autorelease];
}
@@ -653,7 +635,7 @@ - (NSMutableURLRequest *)_baseRequestWithMethod:(NSString *)method
[self _encodeString:_username], [self _encodeString:_password],
domain, fullPath];
#endif
-
+
NSURL *finalURL = [NSURL URLWithString:urlString];
if (!finalURL) {
return nil;
@@ -888,7 +870,7 @@ - (void)parsingSucceededForRequest:(NSString *)identifier
withParsedObjects:(NSArray *)parsedObjects
{
// Forward appropriate message to _delegate, depending on responseType.
- NSLog(@"here at parsingSucceededForRequest");
+ //NSLog(@"here at parsingSucceededForRequest");
switch (responseType) {
case MGTwitterStatuses:
case MGTwitterStatus:
@@ -1270,6 +1252,8 @@ - (NSString *)sendUpdate:(NSString *)status inReplyTo:(MGTwitterEngineID)updateI
NSMutableDictionary *params = [NSMutableDictionary dictionaryWithCapacity:0];
[params setObject:trimmedText forKey:@"status"];
+ //$$fb added this per Twitter documentation
+ [params setObject:@"true" forKey:@"include_entities"];
if (updateID > 0) {
[params setObject:[NSString stringWithFormat:@"%llu", updateID] forKey:@"in_reply_to_status_id"];
}
View
50 MGTwitterLibXMLParser.h
@@ -1,50 +0,0 @@
-//
-// MGTwitterLibXMLParser.h
-// MGTwitterEngine
-//
-// Created by Matt Gemmell on 18/02/2008.
-// Copyright 2008 Instinctive Code.
-//
-
-#import "MGTwitterEngineGlobalHeader.h"
-#include <libxml/xmlreader.h>
-
-#import "MGTwitterParserDelegate.h"
-
-@interface MGTwitterLibXMLParser : NSObject {
- __weak NSObject <MGTwitterParserDelegate> *delegate; // weak ref
- NSString *identifier;
- MGTwitterRequestType requestType;
- MGTwitterResponseType responseType;
- NSURL *URL;
- NSData *xml;
- NSMutableArray *parsedObjects;
-
- xmlTextReaderPtr _reader;
-}
-
-+ (id)parserWithXML:(NSData *)theXML delegate:(NSObject *)theDelegate
-connectionIdentifier:(NSString *)identifier requestType:(MGTwitterRequestType)reqType
- responseType:(MGTwitterResponseType)respType URL:(NSURL *)URL;
-- (id)initWithXML:(NSData *)theXML delegate:(NSObject *)theDelegate
-connectionIdentifier:(NSString *)identifier requestType:(MGTwitterRequestType)reqType
- responseType:(MGTwitterResponseType)respType URL:(NSURL *)URL;
-
-- (void)parse;
-
-// subclass utilities
-- (xmlChar *)_nodeValue;
-- (NSString *)_nodeValueAsString;
-- (NSDate *)_nodeValueAsDate;
-- (NSNumber *)_nodeValueAsInt;
-- (NSNumber *)_nodeValueAsBool;
-- (NSDictionary *)_statusDictionaryForNodeWithName:(const xmlChar *)parentNodeName;
-- (NSDictionary *)_userDictionaryForNodeWithName:(const xmlChar *)parentNodeName;
-- (NSDictionary *)_hashDictionaryForNodeWithName:(const xmlChar *)parentNodeName;
-
-// delegate callbacks
-- (void)_parsingDidEnd;
-- (void)_parsingErrorOccurred:(NSError *)parseError;
-
-
-@end
View
374 MGTwitterLibXMLParser.m
@@ -1,374 +0,0 @@
-//
-// MGTwitterLibXMLParser.m
-// MGTwitterEngine
-//
-// Created by Matt Gemmell on 18/02/2008.
-// Copyright 2008 Instinctive Code.
-//
-// Major portions derived from BSTweetParser by Brent Simmons
-// <http://inessential.com/?comments=1&postid=3489>
-
-#import "MGTwitterLibXMLParser.h"
-
-
-@implementation MGTwitterLibXMLParser
-
-
-#pragma mark Creation and Destruction
-
-
-+ (id)parserWithXML:(NSData *)theXML delegate:(NSObject *)theDelegate
-connectionIdentifier:(NSString *)identifier requestType:(MGTwitterRequestType)reqType
- responseType:(MGTwitterResponseType)respType URL:(NSURL *)URL
-{
- id parser = [[self alloc] initWithXML:theXML
- delegate:theDelegate
- connectionIdentifier:identifier
- requestType:reqType
- responseType:respType
- URL:URL];
-
- return [parser autorelease];
-}
-
-
-- (id)initWithXML:(NSData *)theXML delegate:(NSObject *)theDelegate
-connectionIdentifier:(NSString *)theIdentifier requestType:(MGTwitterRequestType)reqType
- responseType:(MGTwitterResponseType)respType URL:(NSURL *)theURL
-{
- if ((self = [super init]))
- {
- xml = [theXML retain];
- identifier = [theIdentifier retain];
- requestType = reqType;
- responseType = respType;
- URL = [theURL retain];
- delegate = theDelegate;
- parsedObjects = [[NSMutableArray alloc] initWithCapacity:0];
-
- // setup the xml reader
- _reader = xmlReaderForMemory([xml bytes], (int)[xml length], [[URL absoluteString] UTF8String], nil, XML_PARSE_NOBLANKS | XML_PARSE_NOCDATA | XML_PARSE_NOERROR | XML_PARSE_NOWARNING);
- if (! _reader)
- {
- return nil;
- }
-
- // run the parser and create parsedObjects
- [self parse];
-
- // free the xml reader used for parsing
- xmlFree(_reader);
-
- // notify the delegate that parsing completed
- [self _parsingDidEnd];
- }
-
- return self;
-}
-
-
-- (void)dealloc
-{
- [parsedObjects release];
- [xml release];
- [identifier release];
- [URL release];
-
- delegate = nil;
- [super dealloc];
-}
-
-- (void)parse
-{
- // empty implementation -- override in subclasses
-}
-
-#pragma mark Subclass utilities
-
-// get the value from the current node
-- (xmlChar *)_nodeValue
-{
- if (xmlTextReaderIsEmptyElement(_reader))
- {
- return nil;
- }
-
- xmlChar *result = nil;
- int nodeType = xmlTextReaderNodeType(_reader);
- while (nodeType != XML_READER_TYPE_END_ELEMENT)
- {
- if (nodeType == XML_READER_TYPE_TEXT)
- {
- result = xmlTextReaderValue(_reader);
- }
-
- // advance reader
- int readerResult = xmlTextReaderRead(_reader);
- if (readerResult != 1)
- {
- break;
- }
- nodeType = xmlTextReaderNodeType(_reader);
- }
-
- //NSLog(@"node: %25s = %s", xmlTextReaderConstName(_reader), result);
-
- return result;
-}
-
-- (NSString *)_nodeValueAsString
-{
- xmlChar *nodeValue = [self _nodeValue];
- if (! nodeValue)
- {
- return nil;
- }
-
- NSMutableString *value = [NSMutableString stringWithUTF8String:(const char *)nodeValue];
- xmlFree(nodeValue);
-
- // convert HTML entities back into UTF-8
- [value replaceOccurrencesOfString:@"&gt;" withString:@">" options:NSCaseInsensitiveSearch range:NSMakeRange(0, [value length])];
- [value replaceOccurrencesOfString:@"&lt;" withString:@"<" options:NSCaseInsensitiveSearch range:NSMakeRange(0, [value length])];
-
- NSString *result = [NSString stringWithString:value];
- return result;
-}
-
-- (NSDate *)_nodeValueAsDate
-{
- xmlChar *nodeValue = [self _nodeValue];
- if (! nodeValue)
- {
- return nil;
- }
-
- struct tm theTime;
- strptime((char *)nodeValue, "%a %b %d %H:%M:%S +0000 %Y", &theTime);
- xmlFree(nodeValue);
- time_t epochTime = timegm(&theTime);
- return [NSDate dateWithTimeIntervalSince1970:epochTime];
-}
-
-- (NSNumber *)_nodeValueAsInt
-{
- xmlChar *nodeValue = [self _nodeValue];
- if (! nodeValue)
- {
- return nil;
- }
-
- NSString *intString = [NSString stringWithUTF8String:(const char *)nodeValue];
- xmlFree(nodeValue);
- return [NSNumber numberWithLongLong:[intString longLongValue]];
-}
-
-- (NSNumber *)_nodeValueAsBool
-{
- xmlChar *nodeValue = [self _nodeValue];
- if (! nodeValue)
- {
- return nil;
- }
-
- NSString *boolString = [NSString stringWithUTF8String:(const char *)nodeValue];
- xmlFree(nodeValue);
- return [NSNumber numberWithBool:[boolString isEqualToString:@"true"]];
-}
-
-- (NSDictionary *)_statusDictionaryForNodeWithName:(const xmlChar *)parentNodeName
-{
- if (xmlTextReaderIsEmptyElement(_reader))
- return nil;
- NSMutableDictionary *dictionary = [NSMutableDictionary dictionary];
-
- int readerResult = xmlTextReaderRead(_reader);
- if (readerResult != 1)
- return nil;
- int nodeType = xmlTextReaderNodeType(_reader);
- const xmlChar *name = xmlTextReaderConstName(_reader);
- while (! (nodeType == XML_READER_TYPE_END_ELEMENT && xmlStrEqual(parentNodeName, name)))
- {
- if (nodeType == XML_READER_TYPE_ELEMENT)
- {
- if (xmlStrEqual(name, BAD_CAST "user"))
- {
- // "user" is the name of a sub-dictionary in each <status> item
- [dictionary setObject:[self _userDictionaryForNodeWithName:name] forKey:@"user"];
- }
- else if (xmlStrEqual(name, BAD_CAST "id") || xmlStrEqual(name, BAD_CAST "in_reply_to_user_id") || xmlStrEqual(name, BAD_CAST "in_reply_to_status_id"))
- {
- // process element as an integer
- NSNumber *number = [self _nodeValueAsInt];
- if (number)
- {
- [dictionary setObject:number forKey:[NSString stringWithUTF8String:(const char *)name]];
- }
- }
- else if (xmlStrEqual(name, BAD_CAST "created_at"))
- {
- // process element as a date
- NSDate *date = [self _nodeValueAsDate];
- if (date)
- {
- [dictionary setObject:date forKey:[NSString stringWithUTF8String:(const char *)name]];
- }
- }
- else if (xmlStrEqual(name, BAD_CAST "truncated") || xmlStrEqual(name, BAD_CAST "favorited"))
- {
- // process element as a boolean
- NSNumber *number = [self _nodeValueAsBool];
- if (number)
- {
- [dictionary setObject:number forKey:[NSString stringWithUTF8String:(const char *)name]];
- }
- }
- else if (xmlStrEqual(name, BAD_CAST "retweeted_status"))
- {
- [dictionary setObject:[self _statusDictionaryForNodeWithName:name] forKey:[NSString stringWithUTF8String:(const char *)name]];
- }
- else
- {
- // process element as a string
- NSString *string = [self _nodeValueAsString];
- if (string)
- {
- [dictionary setObject:string forKey:[NSString stringWithUTF8String:(const char *)name]];
- }
- }
- }
-
- // advance reader
- readerResult = xmlTextReaderRead(_reader);
- if (readerResult != 1)
- break;
- nodeType = xmlTextReaderNodeType(_reader);
- name = xmlTextReaderConstName(_reader);
- }
-
- // save the request type in the tweet
- [dictionary setObject:[NSNumber numberWithInt:requestType] forKey:TWITTER_SOURCE_REQUEST_TYPE];
-
- return dictionary;
-}
-
-- (NSDictionary *)_userDictionaryForNodeWithName:(const xmlChar *)parentNodeName
-{
- if (xmlTextReaderIsEmptyElement(_reader))
- return nil;
- NSMutableDictionary *dictionary = [NSMutableDictionary dictionary];
-
- int readerResult = xmlTextReaderRead(_reader);
- if (readerResult != 1)
- return nil;
- int nodeType = xmlTextReaderNodeType(_reader);
- const xmlChar *name = xmlTextReaderConstName(_reader);
- while (! (nodeType == XML_READER_TYPE_END_ELEMENT && xmlStrEqual(parentNodeName, name)))
- {
- if (nodeType == XML_READER_TYPE_ELEMENT)
- {
- if (xmlStrEqual(name, BAD_CAST "id") || xmlStrEqual(name, BAD_CAST "followers_count")
- || xmlStrEqual(name, BAD_CAST "friends_count") || xmlStrEqual(name, BAD_CAST "favourites_count")
- || xmlStrEqual(name, BAD_CAST "statuses_count"))
- {
- // process element as an integer
- NSNumber *number = [self _nodeValueAsInt];
- if (number)
- {
- [dictionary setObject:number forKey:[NSString stringWithUTF8String:(const char *)name]];
- }
- }
- else if (xmlStrEqual(name, BAD_CAST "protected"))
- {
- // process element as a boolean
- NSNumber *number = [self _nodeValueAsBool];
- if (number)
- {
- [dictionary setObject:number forKey:[NSString stringWithUTF8String:(const char *)name]];
- }
- }
- else
- {
- // process element as a string
- NSString *s = [self _nodeValueAsString];
- if (s)
- {
- [dictionary setObject:s forKey:[NSString stringWithUTF8String:(const char *)name]];
- }
- }
- }
-
- // advance reader
- readerResult = xmlTextReaderRead(_reader);
- if (readerResult != 1)
- break;
- nodeType = xmlTextReaderNodeType(_reader);
- name = xmlTextReaderConstName(_reader);
- }
-
- return dictionary;
-}
-
-- (NSDictionary *)_hashDictionaryForNodeWithName:(const xmlChar *)parentNodeName
-{
- if (xmlTextReaderIsEmptyElement(_reader))
- return nil;
- NSMutableDictionary *dictionary = [NSMutableDictionary dictionary];
-
- int readerResult = xmlTextReaderRead(_reader);
- if (readerResult != 1)
- return nil;
- int nodeType = xmlTextReaderNodeType(_reader);
- const xmlChar *name = xmlTextReaderConstName(_reader);
- while (! (nodeType == XML_READER_TYPE_END_ELEMENT && xmlStrEqual(parentNodeName, name)))
- {
- if (nodeType == XML_READER_TYPE_ELEMENT)
- {
- if (xmlStrEqual(name, BAD_CAST "hourly-limit") || xmlStrEqual(name, BAD_CAST "remaining-hits")
- || xmlStrEqual(name, BAD_CAST "reset-time-in-seconds"))
- {
- // process element as an integer
- NSNumber *number = [self _nodeValueAsInt];
- if (number)
- {
- [dictionary setObject:number forKey:[NSString stringWithUTF8String:(const char *)name]];
- }
- }
- else
- {
- // process element as a string
- NSString *s = [self _nodeValueAsString];
- if (s)
- {
- [dictionary setObject:s forKey:[NSString stringWithUTF8String:(const char *)name]];
- }
- }
- }
-
- // advance reader
- readerResult = xmlTextReaderRead(_reader);
- if (readerResult != 1)
- break;
- nodeType = xmlTextReaderNodeType(_reader);
- name = xmlTextReaderConstName(_reader);
- }
-
- return dictionary;
-}
-
-
-#pragma mark Delegate callbacks
-
-- (void)_parsingDidEnd
-{
- //NSLog(@"Parsing complete: %@", parsedObjects);
- [delegate parsingSucceededForRequest:identifier ofResponseType:responseType withParsedObjects:parsedObjects];
-}
-
-- (void)_parsingErrorOccurred:(NSError *)parseError
-{
- //NSLog(@"Parsing error occurred: %@", parseError);
- [delegate parsingFailedForRequest:identifier ofResponseType:responseType withError:parseError];
-}
-
-@end
View
17 MGTwitterMessagesLibXMLParser.h
@@ -1,17 +0,0 @@
-//
-// MGTwitterMessagesLibXMLParser.h
-// MGTwitterEngine
-//
-// Created by Matt Gemmell on 11/02/2008.
-// Copyright 2008 Instinctive Code.
-//
-
-#import "MGTwitterEngineGlobalHeader.h"
-
-#import "MGTwitterLibXMLParser.h"
-
-@interface MGTwitterMessagesLibXMLParser : MGTwitterLibXMLParser {
-
-}
-
-@end
View
114 MGTwitterMessagesLibXMLParser.m
@@ -1,114 +0,0 @@
-//
-// MGTwitterMessagesLibXMLParser.m
-// MGTwitterEngine
-//
-// Created by Matt Gemmell on 11/02/2008.
-// Copyright 2008 Instinctive Code.
-//
-
-#import "MGTwitterMessagesLibXMLParser.h"
-
-
-@implementation MGTwitterMessagesLibXMLParser
-
-- (NSDictionary *)_directMessageDictionaryForNodeWithName:(const xmlChar *)parentNodeName {
- if (xmlTextReaderIsEmptyElement(_reader))
- return nil;
- NSMutableDictionary *dictionary = [NSMutableDictionary dictionary];
-
- int readerResult = xmlTextReaderRead(_reader);
- if (readerResult != 1)
- return nil;
- int nodeType = xmlTextReaderNodeType(_reader);
- const xmlChar *name = xmlTextReaderConstName(_reader);
- while (! (nodeType == XML_READER_TYPE_END_ELEMENT && xmlStrEqual(parentNodeName, name)))
- {
- if (nodeType == XML_READER_TYPE_ELEMENT)
- {
- if (xmlStrEqual(name, BAD_CAST "sender") || xmlStrEqual(name, BAD_CAST "recipient"))
- {
- // "user" is the name of a sub-dictionary in each <status> item
- [dictionary setObject:[self _userDictionaryForNodeWithName:name] forKey:[NSString stringWithUTF8String:(const char *)name]];
- }
- else if (xmlStrEqual(name, BAD_CAST "id") || xmlStrEqual(name, BAD_CAST "sender_id") || xmlStrEqual(name, BAD_CAST "recipient_id"))
- {
- // process element as an integer
- NSNumber *number = [self _nodeValueAsInt];
- if (number)
- {
- [dictionary setObject:number forKey:[NSString stringWithUTF8String:(const char *)name]];
- }
- }
- else if (xmlStrEqual(name, BAD_CAST "created_at"))
- {
- // process element as a date
- NSDate *date = [self _nodeValueAsDate];
- if (date)
- {
- [dictionary setObject:date forKey:[NSString stringWithUTF8String:(const char *)name]];
- }
- }
- else if (xmlStrEqual(name, BAD_CAST "protected"))
- {
- // process element as a boolean
- NSNumber *number = [self _nodeValueAsBool];
- if (number)
- {
- [dictionary setObject:number forKey:[NSString stringWithUTF8String:(const char *)name]];
- }
- }
- else
- {
- // process element as a string
- NSString *string = [self _nodeValueAsString];
- if (string)
- {
- [dictionary setObject:string forKey:[NSString stringWithUTF8String:(const char *)name]];
- }
- }
- }
-
- // advance reader
- readerResult = xmlTextReaderRead(_reader);
- if (readerResult != 1)
- break;
- nodeType = xmlTextReaderNodeType(_reader);
- name = xmlTextReaderConstName(_reader);
- }
-
- // save the request type in the tweet
- [dictionary setObject:[NSNumber numberWithInt:requestType] forKey:TWITTER_SOURCE_REQUEST_TYPE];
-
- return dictionary;
-}
-
-
-- (void)parse
-{
- int readerResult = xmlTextReaderRead(_reader);
- if (readerResult != 1)
- return;
- int nodeType = xmlTextReaderNodeType(_reader);
- const xmlChar *name = xmlTextReaderConstName(_reader);
- while (! (nodeType == XML_READER_TYPE_END_ELEMENT && xmlStrEqual(BAD_CAST "direct-messages", name)))
- {
- if (nodeType == XML_READER_TYPE_ELEMENT)
- {
- if (xmlStrEqual(name, BAD_CAST "direct_message"))
- {
- [parsedObjects addObject:[self _directMessageDictionaryForNodeWithName:BAD_CAST "direct_message"]];
- }
- }
-
- // advance reader
- readerResult = xmlTextReaderRead(_reader);
- if (readerResult != 1)
- {
- break;
- }
- nodeType = xmlTextReaderNodeType(_reader);
- name = xmlTextReaderConstName(_reader);
- }
-}
-
-@end
View
17 MGTwitterMiscLibXMLParser.h
@@ -1,17 +0,0 @@
-//
-// MGTwitterMiscLibXMLParser.h
-// MGTwitterEngine
-//
-// Created by Matt Gemmell on 11/02/2008.
-// Copyright 2008 Instinctive Code.
-//
-
-#import "MGTwitterEngineGlobalHeader.h"
-
-#import "MGTwitterLibXMLParser.h"
-
-@interface MGTwitterMiscLibXMLParser : MGTwitterLibXMLParser {
-
-}
-
-@end
View
54 MGTwitterMiscLibXMLParser.m
@@ -1,54 +0,0 @@
-//
-// MGTwitterMiscLibXMLParser.m
-// MGTwitterEngine
-//
-// Created by Matt Gemmell on 11/02/2008.
-// Copyright 2008 Instinctive Code.
-//
-
-#import "MGTwitterMiscLibXMLParser.h"
-
-
-@implementation MGTwitterMiscLibXMLParser
-
-- (void)parse
-{
- int readerResult = xmlTextReaderRead(_reader);
- if (readerResult != 1)
- return;
-
- int nodeType = xmlTextReaderNodeType(_reader);
- const xmlChar *name = xmlTextReaderConstName(_reader);
- while (! (nodeType == XML_READER_TYPE_END_ELEMENT))
- {
- if (nodeType == XML_READER_TYPE_ELEMENT)
- {
- if (xmlStrEqual(name, BAD_CAST "hash"))
- {
- [parsedObjects addObject:[self _hashDictionaryForNodeWithName:name]];
- }
- else
- {
- // process element as a string -- API calls like friendships/exists.xml just return <friends>false</friends> or <friends>true</friends>
- NSString *string = [self _nodeValueAsString];
- if (string)
- {
- NSMutableDictionary *dictionary = [NSMutableDictionary dictionary];
- [dictionary setObject:string forKey:[NSString stringWithUTF8String:(const char *)name]];
- [parsedObjects addObject:dictionary];
- }
- }
- }
-
- // advance reader
- readerResult = xmlTextReaderRead(_reader);
- if (readerResult != 1)
- {
- break;
- }
- nodeType = xmlTextReaderNodeType(_reader);
- name = xmlTextReaderConstName(_reader);
- }
-}
-
-@end
View
19 MGTwitterSocialGraphLibXMLParser.h
@@ -1,19 +0,0 @@
-//
-// MGTwitterSocialGraphLibXMLParser.h
-// MGTwitterEngine
-//
-// Created by Robert McGovern on 2010/03/20.
-// Copyright 2010 Tarasis. All rights reserved.
-//
-
-#import "MGTwitterEngineGlobalHeader.h"
-
-#import "MGTwitterLibXMLParser.h"
-
-@interface MGTwitterSocialGraphLibXMLParser : MGTwitterLibXMLParser {
- NSMutableArray * twitterIDs;
-}
-
-- (NSDictionary *)_socialGraphDictionaryForNodeWithName:(const xmlChar *)parentNodeName;
-
-@end
View
99 MGTwitterSocialGraphLibXMLParser.m
@@ -1,99 +0,0 @@
-//
-// MGTwitterSocialGraphLibXMLParser.m
-// MGTwitterEngine
-//
-// Created by Robert McGovern on 2010/03/20.
-// Copyright 2010 Tarasis. All rights reserved.
-//
-
-#import "MGTwitterSocialGraphLibXMLParser.h"
-
-
-@implementation MGTwitterSocialGraphLibXMLParser
-- (void)parse
-{
- int readerResult = xmlTextReaderRead(_reader);
- if (readerResult != 1)
- return;
-
- int nodeType = xmlTextReaderNodeType(_reader);
- const xmlChar *name = xmlTextReaderConstName(_reader);
-
- NSMutableDictionary *dictionary = [NSMutableDictionary dictionary];
-
- while (! (nodeType == XML_READER_TYPE_END_ELEMENT))
- {
- //NSLog(@"name is: %@", [NSString stringWithUTF8String:(const char *)name]);
- if (nodeType == XML_READER_TYPE_ELEMENT)
- {
- if (xmlStrEqual(name, BAD_CAST "ids"))
- {
- [dictionary addEntriesFromDictionary:[self _socialGraphDictionaryForNodeWithName:name]];
- }
- else if (xmlStrEqual(BAD_CAST "previous_cursor", name) || xmlStrEqual(BAD_CAST "next_cursor", name))
- {
- // process element as a string -- API calls like friendships/exists.xml just return <friends>false</friends> or <friends>true</friends>
- NSString *string = [self _nodeValueAsString];
- if (string)
- {
- [dictionary setObject:string forKey:[NSString stringWithUTF8String:(const char *)name]];
- }
- }
-
- }
-
- // advance reader
- readerResult = xmlTextReaderRead(_reader);
- if (readerResult != 1)
- {
- break;
- }
- nodeType = xmlTextReaderNodeType(_reader);
- name = xmlTextReaderConstName(_reader);
- }
-
- [dictionary setObject:[NSNumber numberWithInt:requestType] forKey:TWITTER_SOURCE_REQUEST_TYPE];
- [parsedObjects addObject:dictionary];
-}
-
-- (NSDictionary *)_socialGraphDictionaryForNodeWithName:(const xmlChar *)parentNodeName
-{
- if (xmlTextReaderIsEmptyElement(_reader))
- return nil;
- NSMutableDictionary *dictionary = [NSMutableDictionary dictionary];
- twitterIDs = [NSMutableArray arrayWithCapacity:0];
-
- int readerResult = xmlTextReaderRead(_reader);
- if (readerResult != 1)
- return nil;
- int nodeType = xmlTextReaderNodeType(_reader);
- const xmlChar *name = xmlTextReaderConstName(_reader);
- while (! (nodeType == XML_READER_TYPE_END_ELEMENT && xmlStrEqual(parentNodeName, name)))
- {
- if (nodeType == XML_READER_TYPE_ELEMENT)
- {
- //NSLog(@" name is: %@", [NSString stringWithUTF8String:(const char *)name]);
- // process element as an integer
- NSNumber *number = [self _nodeValueAsInt];
- if (number)
- {
- //[dictionary setObject:number forKey:[NSString stringWithUTF8String:(const char *)name]];
- [twitterIDs addObject:number];
- }
- }
-
- // advance reader
- readerResult = xmlTextReaderRead(_reader);
- if (readerResult != 1)
- break;
- nodeType = xmlTextReaderNodeType(_reader);
- name = xmlTextReaderConstName(_reader);
- }
-
- [dictionary setObject:twitterIDs forKey:[NSString stringWithUTF8String:(const char *)name]];
-
- return dictionary;
-}
-
-
-@end
View
17 MGTwitterStatusesLibXMLParser.h
@@ -1,17 +0,0 @@
-//
-// MGTwitterStatusesLibXMLParser.h
-// MGTwitterEngine
-//
-// Created by Matt Gemmell on 11/02/2008.
-// Copyright 2008 Instinctive Code.
-//
-
-#import "MGTwitterEngineGlobalHeader.h"
-
-#import "MGTwitterLibXMLParser.h"
-
-@interface MGTwitterStatusesLibXMLParser : MGTwitterLibXMLParser {
-
-}
-
-@end
View
43 MGTwitterStatusesLibXMLParser.m
@@ -1,43 +0,0 @@
-//
-// MGTwitterStatusesLibXMLParser.m
-// MGTwitterEngine
-//
-// Created by Matt Gemmell on 11/02/2008.
-// Copyright 2008 Instinctive Code.
-//
-
-#import "MGTwitterStatusesLibXMLParser.h"
-
-
-@implementation MGTwitterStatusesLibXMLParser
-
-
-- (void)parse
-{
- int readerResult = xmlTextReaderRead(_reader);
- if (readerResult != 1)
- return;
- int nodeType = xmlTextReaderNodeType(_reader);
- const xmlChar *name = xmlTextReaderConstName(_reader);
- while (! (nodeType == XML_READER_TYPE_END_ELEMENT && xmlStrEqual(BAD_CAST "statuses", name)))
- {
- if (nodeType == XML_READER_TYPE_ELEMENT)
- {
- if (xmlStrEqual(name, BAD_CAST "status"))
- {
- [parsedObjects addObject:[self _statusDictionaryForNodeWithName:name]];
- }
- }
-
- // advance reader
- readerResult = xmlTextReaderRead(_reader);
- if (readerResult != 1)
- {
- break;
- }
- nodeType = xmlTextReaderNodeType(_reader);
- name = xmlTextReaderConstName(_reader);
- }
-}
-
-@end
View
17 MGTwitterUsersLibXMLParser.h
@@ -1,17 +0,0 @@
-//
-// MGTwitterUsersLibXMLParser.h
-// MGTwitterEngine
-//
-// Created by Matt Gemmell on 11/02/2008.
-// Copyright 2008 Instinctive Code.
-//
-
-#import "MGTwitterEngineGlobalHeader.h"
-
-#import "MGTwitterLibXMLParser.h"
-
-@interface MGTwitterUsersLibXMLParser : MGTwitterLibXMLParser {
-
-}
-
-@end
View
42 MGTwitterUsersLibXMLParser.m
@@ -1,42 +0,0 @@
-//
-// MGTwitterUsersLibXMLParser.m
-// MGTwitterEngine
-//
-// Created by Matt Gemmell on 11/02/2008.
-// Copyright 2008 Instinctive Code.
-//
-
-#import "MGTwitterUsersLibXMLParser.h"
-
-
-@implementation MGTwitterUsersLibXMLParser
-
-- (void)parse
-{
- int readerResult = xmlTextReaderRead(_reader);
- if (readerResult != 1)
- return;
- int nodeType = xmlTextReaderNodeType(_reader);
- const xmlChar *name = xmlTextReaderConstName(_reader);
- while (! (nodeType == XML_READER_TYPE_END_ELEMENT && xmlStrEqual(BAD_CAST "users", name)))
- {
- if (nodeType == XML_READER_TYPE_ELEMENT)
- {
- if (xmlStrEqual(name, BAD_CAST "user"))
- {
- [parsedObjects addObject:[self _userDictionaryForNodeWithName:name]];
- }
- }
-
- // advance reader
- readerResult = xmlTextReaderRead(_reader);
- if (readerResult != 1)
- {
- break;
- }
- nodeType = xmlTextReaderNodeType(_reader);
- name = xmlTextReaderConstName(_reader);
- }
-}
-
-@end
View
2  MGTwitterXMLParser.h
@@ -9,7 +9,7 @@
#import "MGTwitterEngineGlobalHeader.h"
#import "MGTwitterParserDelegate.h"
-@interface MGTwitterXMLParser : NSObject {
+@interface MGTwitterXMLParser : NSObject <NSXMLParserDelegate> {
__weak NSObject <MGTwitterParserDelegate> *delegate; // weak ref
NSString *identifier;
MGTwitterRequestType requestType;
View
21 README.txt
@@ -30,21 +30,20 @@ Using MGTwitterEngine is easy. The basic steps are:
4. Go ahead and use MGTwitterEngine! Just instantiate the object and set the relevant username and password (as AppController does in the demo project), and then go ahead and call some of the Twitter API methods - you can see a full list of them in the MGTwitterEngine.h header file, which also includes a link to the Twitter API documentation online.
-A note about XML parsing
-========================
-
-You may wish to use the LibXML parser rather than the NSXMLParser, since LibXML can be faster and has a smaller memory footprint.
-
-In this case, you make need to make the following changes to your project:
+A note about JSON parsing
+=========================
-1. Set USE_LIBXML to 1, near the top of the MGTwitterEngine.m file.
+For the required JSON support, you need to use either YAJL or TouchJSON (http://github.com/TouchCode/TouchJSON).
+Set either of the following definitions to 1 in MGTwitterEngineGlobalHeader.h:
+#define YAJL_AVAILABLE 0
+#define TOUCHJSON_AVAILABLE 0
-2. Add libxml2.dylib in Other Frameworks. You'll find the library in:
- /usr/lib/libxml2.dylib
-
-3. Add "/usr/include/libxml2" as a Header Search Path in your Project Settings.
+A note about Twitter 1.1
+========================
+The implementation has not been fully updated to Twitter's 1.1 API. Most REST functions
+will work, YMWV.
A note about using MGTwitterEngine on the iPhone
Something went wrong with that request. Please try again.