2012年3月4日日曜日

TWRequest Class Reference

TWRequest Class

TWRequest(Twitter Framework)は in iOS 5.0以降で動作する。

TWRequestオブジェクトは、Twitterの操作とユーザ認証のためのHTTPリクエストを含んでいる。
・URL 識別
・HTTP メソッド(GET, POST or DELETE)
・要求ごとの問い合わせパラメータのセット
・分割POST
詳細はTwittter APIドキュメントを参照のこと。
メソッド initWithURL:parameters:requestMethod: は、新しいTWRequestオブジェクトを生成しする。
メソッド addMultiPartData:withName:type: は分割POTSTの本体を定義する。
メソッド performRequestWithHandler: ハンドラーに定義された要求を実行する。あるいは, 代わりにsignedURLRequest メソッドで NSURLConnection オブジェクトで処理する。
もし、Twitterの承認が必要な場合は、アカウントを登録をACAccountオブジェクトで実施する。

ーーーーーーーーーーーーーーーーーーーーーーーーーー

Initializing Requests
– initWithURL:parameters:requestMethod:

Accessing Properties
account
requestMethod
URL
parameters
– addMultiPartData:withName:type:

Sending Requests
– performRequestWithHandler:
– signedURLRequest

ーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーー



プロパティ

ーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーー

account
  オーソライズが要求されるリクエストで使用するアカウント情報(オプション)
@property(nonatomic, retain) ACAccount *account
    据えてのTwitterへの要求がオーソライズを必要とするわけではない。デフォルト値nil

parameters
  この要求のためのパラメータ(読み取り専用)
 @property(nonatomic, readonly) NSDictionary *parameters
    これらはHTTPリクエストのための問い合わせパラメータであり、Twitter API ドキュメントに従って記述する。

requestMethod
  この要求のためのメソッド
 @property(nonatomic, readonly) TWRequestMethod requestMethod
このプロパティは、 HTTPリクエストのメソッドとして定義さる。取りうる値は“TWRequestMethod.”で記述される。

URL
この要求のためのURL
@property(nonatomic, readonly) NSURL *URL
このプロパティは、HTTPリクエストのためのURLを意味する。取りうる値はTwitter API ドキュメントに記載されている。


ーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーー
インスタンスメソッド
ーーーーーーーーーーーーーーーーーーー
 addMultiPartData:withName:type:
この要求の分割ポストの本体の名前を定義する。

- (void)addMultiPartData:(NSData *)data withName:(NSString *)name type:(NSString *)type

パラーメタ
data
分割ポストの本体のデータ
name
分割ポストの本体の名前
type
分割ポストの本体の型
ーーーーーーーーーーーーーーーーーーーーー
 initWithURL:parameters:requestMethod:
  プロパティで指定された内容で新しいオブジェクトを初期化する。

 - (id)initWithURL:(NSURL *)url parameters:(NSDictionary *)parameters requestMethod:(TWRequestMethod)requestMethod

パラメータ
url
このHTTPリクエストのためのURL
parameters
このHTTPリクエストのためのパラメータ
request. requestMethod
HTTリクエストで使用するメソッド
Return Value
新しい初期化オブジェクト

ーーーーーーーーーーーーーーーーーーーーー

performRequestWithHandler: 
Performs the request and when done calls the specified handler. - (void)performRequestWithHandler:(TWRequestHandler)handler Parameters handler The handler to call when the request is done. The parameters to this handler are described in TWRequestHandler. This handler is not guaranteed to be called on any particular thread. Availability Available in iOS 5.0 and later. Declared In TWRequest.h signedURLRequest Returns an authorized request that can be sent using an NSURLConnection object. - (NSURLRequest *)signedURLRequest Return Value An OAuth compatible NSURLRequest object that allows an application to act on behalf of the user while keeping the user’s password private. Availability Available in iOS 5.0 and later. Declared In TWRequest.h Constants TWRequestMethod Indicates the method used in the request. enum TWRequestMethod { TWRequestMethodGET, TWRequestMethodPOST, TWRequestMethodDELETE }; typedef enum TWRequestMethod TWRequestMethod; Constants TWRequestMethodGET Requests a representation of the specified resource. Available in iOS 5.0 and later. Declared in TWRequest.h. TWRequestMethodPOST Submits data to be processed. Available in iOS 5.0 and later. Declared in TWRequest.h. TWRequestMethodDELETE Deletes the specified resource. Available in iOS 5.0 and later. Declared in TWRequest.h. Discussion Use this constant to set the requestMethod property. TWRequestHandler The callback handler for a Twitter request. typedef void(^TWRequestHandler)(NSData *responseData, NSHTTPURLResponse *urlResponse, NSError *error); Discussion The parameters to this handler are: responseData The data returned by the Twitter request. urlResponse The URL response returned by the Twitter request that includes the HTTP response codes. error An error sending the Twitter request if it occurs. Refer to Twitter API Documentation for possible values of these parameters. Availability Available in iOS 5.0 and later. Declared In TWRequest.h

参考:
    iOS5のTwitter APIを使って実装してみる          
     TwitterFrameworkの利用

0 件のコメント:

コメントを投稿