• This repository has been archived on 17/Aug/2019
  • Stars
    star
    124
  • Rank 288,207 (Top 6 %)
  • Language
    Objective-C
  • License
    MIT License
  • Created almost 13 years ago
  • Updated over 8 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

YToolkit includes a base64 lib, a handy cocoa categories lib, and an oauth 1.0 & 2.0 lib

YToolkit for Cocoa

What's new

2012-10-10 Added a binary ytoolkit.framework, which contains armv6, armv7 and armv7s arch lib https://github.com/downloads/sprhawk/ytoolkit/ytoolkit.framework.zip

What it includes

At the moment , the YToolkit includes a base64 lib (implemented in C, with NSData/NSString catetories), a handy cocoa categories lib, an oauth 1.0 & 2.0 lib (implemented in C function but using Cocoa object arguments, with NSMutableURLRequest & ASIHTTPRequest categories).

Besides, a demo for YToolkit is available from ytoolkitdemo (which is including demos for signing in & retrieving basic data from Twitter, Facebook, Douban, Sina Weibo, QQ Weibo, etc).

Why implementing again?

  • I have used some OAuth implementation for iOS, such as OAuthConsumer, OAuthCore, each of them has its pros and cons.

    About one year and a half ago I started to learn iPhone development, I wanted to make a client for douban.com. Then I tried OAuthConsumer, after some hard work, I got OAuthConsumer working. However, OAuthConsumer handles network with NSURLConnection internally. If I want to use the ASIHTTPRequest, it just can't help. Besides, OAuthConsumer simply handles error according to OATicket object is nil or non-nil ( it assumes returned format is form-url-encoded), programmers cannot get the real reason why it can't work.

    Then I turned to use OAuthCore. It is simply a C function, which generates a OAuth 1.0 Authorization Header, one can integrate it with any HTTP handling libs. But OAuthCore only generate OAuth 1.0 spec Authorization without an optional realm value, which may be required by a OAuth provider.

    So, I decide to re-implement it: OAuth 1.0 and 2.0 (draft 22), following the spec as strictly as I could.

  • A base64 implementation is just for fun at the beginning. When I finished the code, I had a profiling among NSData+Base64 (along with OAuthCore), josefsson's base64 (which is now a GNU CoreUtils implementation) and libb64. The NSData+Base64 is the slowest, and my implementation is the fastest (On Macbook pro and an iPod 3G). Although on a Mac, my implementation is not much faster than josefsson's base64 and libb64, on an iPod, it is faster enough (both on a Mac and iPod, tested for a nearly 1.5MB png file). (You can check the benchmark result, or run the benchmark yourself in ytoolkitdemo)

What can I do with it?

  • The ytoolkit generates ybase64.a, ybase64additions.a, yoauth.a, yoauthadditions.a, and ytoolkit.framework (statically linked faked framework. Thanks to the ios-Universal-Framework project). You can either use the lib(s) , or the framework alone. Just add ytoolkit project as a dependencies of your project, and link the libs. All required headers will be generated under {BUILT_PRODUCTS_DIR}/usr/local/include, you should add this path into your header search path (See how ytoolkitdemo does). If you want to use the framework, just link against it, all required headers are just bundled in it. add

    -ObjC -all_load

    linker flags into your project

  • You can only use its base64 lib, the core is a pure C implementation, with NSString/NSData categories, which is handy under Cocoa foundation. Just as:
    NSString * base64encoded = [data base64String];

or

    NSData * base64decode = [base64encodedString base64ToData];
  • You can use some cocoa additions, such as:

    • Parsing a URL string into component: scheme, host, relative, query, fragment. (similar functionalities than NSURL supplies is not working sometimes.
    • Handling escaped/unscaped URLs
    • Generating a URL's query from a dictionary's key/value pair, or get the parameters from a URL's query string
    • Adding duplicated key/value paires: when a key is existed, the addition will add a NSCountedSet object to contains the values
  • You can use OAuth 1.0 and 2.0 (draft 22) lib or their Cocoa additions

    • If you are using NSMutableURLRequest of ASIHTTPRequest, just use the related additions
    • If you are using other request lib, just use yoauth lib to generate an oauth authorization header (OAuth 1.0) or an oauth parameters (OAuth 2.0), and set them as spec accordingly.
    • With NSMutableURLRequest:
  NSMutableURLRequest * request = [NSMutableURLRequest requestWithURL:[NSURL URLWithString:@"http://www.douban.com/service/auth/request_token"]];
  
  // "old version of oauth.py (Douban is using) requires an 'OAuth realm=' format pattern
  // So, the realm should be specified (even @"")
  [request prepareOAuthv1RequestUsingConsumerKey:kDoubanConsumerKey
                               consumerSecretKey:kDoubanConsumerSecretKey
                                           token:nil
                                     tokenSecret:nil
                                           realm:kDoubanRealm
                                        verifier:nil
                                        callback:nil];
  [NSURLConnection connectionWithRequest:request delegate:self];
  NSURL * url = [NSURL URLWithString:@"http://api.douban.com/people/%40me/miniblog?alt=json"];
  ASIHTTPRequest * request = [ASIHTTPRequest requestWithURL:url];
  request.delegate = self;
  [request prepareOAuthv1RequestUsingConsumerKey:kDoubanConsumerKey
                               consumerSecretKey:kDoubanConsumerSecretKey
                                           token:self.accesstoken
                                     tokenSecret:self.tokensecret
                                           realm:kDoubanRealm];
  [request startAsynchronous];
  • Just see the ytoolkitdemo for usage example of most popular sites
  • new Objective-C literials which was available only in iOS6, the literials category could add the new feature to iOS below iOS SDK 6, so you can use:
   NSArray * a = @[obj1, obj2, obj3];
   id obj = a[0]; // this literial need a new method which is only available under iOS 6, the literial category added the missing methods to array/dictionary.

License

The ytoolkit is distributed under MIT license

Hope this is useful for you.

这里面有什么?

一个快速的base64编码(纯C,及NSData/NSString的category),可以看项目页面的README和代码库里的benchmark,或者在ytoolkitdemo里跑profile

一个cocoa附加库(包括词典到URL query,URL query到词典,URL分解为scheme, host, relative path, query, fragment,包括一个可以放置重复key-value的DuplicatableDictionary),

一个完善的OAuthv1库(C函数实现,但使用cocoa对象作参数)及相对应的NSMutableURLRequest和ASIHTTPRequest的扩展,

一个OAuthv2库(结构同OAuthv1,但是由于OAuthv2比较简单,所以并没有什么代码)及OAuthv2 HTTP-MAC的扩展的实现(由于没有相应的服务器,所以没有测试)

ytoolkitdemo里包含了下列服务的登录和获取数据的demo:

Twitter(OAuthv1),

Facebook(OAuthv2),

豆瓣 (OAuthv1),

新浪微博(OAuth及OAuth 2都跑通了)

QQ微博(OAuthv1)

demo地址是 https://github.com/sprhawk/ytoolkitdemo

ytoolkit 使用MIT协议发布

More Repositories

1

nrf51822-macosx-build-scripts

nrf51822 build scripts under MacOSX
40
star
2

Python4iOS

A CPython build script for iOS
Shell
28
star
3

ytoolkitdemo

Demos for ytoolkit
Shell
24
star
4

MyGist

保存自己的小代码片断
Python
9
star
5

nrf51822-first-fw

learning
C
8
star
6

Passbook

A Passbook toolkit
Python
5
star
7

AudioDemo-ios

Objective-C
5
star
8

douban.fm-download-chrome-extension

Douban.fm的歌曲下载插件
JavaScript
5
star
9

sketch-plugin-logitech-craft

A plugin that connects Sketch to Logitech Craft keyboard
JavaScript
3
star
10

dcs_scripts

Lua
3
star
11

libftdi

mirror to libftdi (http://www.intra2net.com/en/developer/libftdi/repository.php)
C
3
star
12

DoubanBackup

备份自己的豆瓣数据的工具
Python
2
star
13

cerbero-pitivi

cerbero repo for building Pitivi on MacOS
Python
2
star
14

OgreWikiTutorialFramework_iOS

an iOS fix for OgreWikiTutorialFramework
C++
2
star
15

sensors.py

Inertial Navigation Sensors
Python
2
star
16

build-ffmpeg-ios

Build script of FFmpeg for iOS
Shell
2
star
17

QRUrl

Chrome Plugin for making QRCode for a URL
JavaScript
2
star
18

flutter_photos_library

A simple plugin to demo how to interact with iOS PhotosKit API
Objective-C
2
star
19

armv7to7s

C
1
star
20

esc-rs

Rust
1
star
21

WalkLogDemo

test for location manager
Objective-C
1
star
22

build-opencore-amr-ios

Build OpenCore AMR for iOS
Shell
1
star
23

dangerous-prototypes-open-hardware

Automatically exported from code.google.com/p/dangerous-prototypes-open-hardware
Eagle
1
star
24

sprhawk.github.com

Github Pages
1
star
25

HTTPRequestWrapper

a wrapper protocol to other real http request classes
Objective-C
1
star
26

vagrant-puppet-deploy-drupal

Puppet
1
star
27

leaf-rv1126

1
star
28

vagran-puppet-deploy-flask

Puppet
1
star
29

MosquittoCenter

a Mosquitto Client
D
1
star
30

godot_crash_demo

GAP
1
star
31

rust-cross-compile-armv7

Rust
1
star