AFQiitaClient 0.1.0

AFQiitaClient 0.1.0

测试已测试
语言语言 Obj-CObjective C
许可 MIT
发布最后发布2015年3月

不明 维护。



  • 作者
  • Nagase Atsushi

使用 Cocoa 操作 Qiita API 的客户端

Qiita 是一个程序员使用的,用于轻松记录和公开编程 Tips、经验和笔记的技术信息共享服务。

AFQiitaClientAFHTTPClient 的子类,与 AFNetworking 的源代码一起,可以将它添加到项目中并使用。

用法

初始化

AFQiitaClient *client = [[AFQiitaClient alloc] init];

认证

[client authenticateWithUsername:@"ngs"
                        password:@"qwerty1234!?"
                        success:success:^ {
                          NSLog(@"Success");
                        }
                        failure:^(NSError *error) {
                          NSLog(@"Error: %@", error);
                        }];

分页

AFQiitaResponse 有一个返回 NSURL 类型的实例方法的成员:`firstURL`, `prevURL`, `nextURL`, 和 `prevURL`。

[client tagsWithSuccess:^(AFQiitaResponse *response) {
                  if(response.nextURL) {
                    [client getURL:response.nextURL
                           success:^(AFQiitaResponse *response) { ... }
                           failure:^(NSError *error) { ... }];
                  } else {
                    NSLog(@"No more tags");
                  }
                }
                failure:^(NSError *error) {
                  NSLog(@"Error: %@", error);
                }];

剩余请求数和 Rate Limit 获取

[client rateLimitWithSuccess:^(NSInteger remaining, NSInteger limit){
                        NSLog(@"Success: Limted to %d, %d remaining", limit, remaining);
                      }
                      failure:^(NSError *error) {
                        NSLog(@"Error: %@", error);
                      }];

请求用户的详细信息获取

[client currentUserWithSuccess:^(AFQiitaResponse *response) {
                         AFQiitaUser *me = [response first];
                         NSLog(@"Success: Hello, my name is %@", me.name);
                       }
                       failure:^(NSError *error) {
                         NSLog(@"Error: %@", error);
                       }];

特定用户的详细信息获取

[client userWithUsername:@"yaotti@github"
                 success:^(AFQiitaResponse *response) {
                   AFQiitaUser *user = [response first];
                   NSLog(@"Success: %@ has %d followers", user.name, user.followers);
                 }
                 failure:^(NSError *error) {
                   NSLog(@"Error: %@", error);
                 }];

特定用户的投稿获取

[client itemsWithUsername:@"yaotti@github"
                  success:^(AFQiitaResponse *response) {
                    AFQiitaItem *item = nil;
                    while(item = response.next)
                      NSLog(@"Post: %@", item.title);
                  }
                  failure:^(NSError *error) {
                    NSLog(@"Error: %@", error);
                  }];

特定用户的收藏投稿获取

[client stockedItemsWithUsername:@"yaotti@github"
                         success:^(AFQiitaResponse *response) {
                           AFQiitaItem *item = nil;
                           while(item = response.next)
                             NSLog(@"Post: %@", item.title);
                         }
                         failure:^(NSError *error) {
                           NSLog(@"Error: %@", error);
                         }];

特定标签的投稿获取

[client itemsWithTag:@"Rails"
             success:^(AFQiitaResponse *response) {
               AFQiitaItem *item = nil;
               while(item = response.next)
                 NSLog(@"Post: %@", item.title);
             }
             failure:^(NSError *error) {
               NSLog(@"Error: %@", error);
             }];

标签列表获取

[client tagsWithSuccess:^(AFQiitaResponse *response) {
                  AFQiitaTag *tag = nil;
                  while(tag = response.next)
                    NSLog(@"Tag: %@", tag.name);
                }
                failure:^(NSError *error) {
                  NSLog(@"Error: %@", error);
                }];

搜索结果获取

[client itemsWithSearchString:@"Hackathon"
                      stocked:NO
                      success:^(AFQiitaResponse *response) {
                        AFQiitaItem *item = nil;
                        while(item = response.next)
                          NSLog(@"Post: %@", item.title);
                      }
                      failure:^(NSError *error) {
                        NSLog(@"Error: %@", error);
                      }];

最新投稿的获取

[client recentItemsWithSuccess:^(AFQiitaResponse *response) {
                         AFQiitaItem *item = nil;
                         while(item = response.next)
                           NSLog(@"Post: %@", item.title);
                       }
                       failure:^(NSError *error) {
                         NSLog(@"Error: %@", error);
                       }];

自己收藏投稿的获取

[client stockedItemsWithSuccess:^(AFQiitaResponse *response) {
                          AFQiitaItem *item = nil;
                          while(item = response.next)
                            NSLog(@"Post: %@", item.title);
                        }
                        failure:^(NSError *error) {
                          NSLog(@"Error: %@", error);
                        }];

投稿的执行

AFQiitaItem *item = [[AFQiitaItem alloc]
                      initWithTitle:@"テスト!"
                      body:@"[AFQiitaClient](http://github.com/ngs/AFQiitaClient) から投稿テスト"];

[item addTag:[AFQiitaTag tagWithName:@"iOS"
                            versions:@"5.1.1", @"6.0", nil]];

[item setTweet:YES]; // Posts URL to Twitter
[item setGist:YES];  // Share code blocks on Gist

[client createItem:item
           success:success:^(AFQiitaResponse *response) {
             AFQiitaItem *createdItem = [response first];
             NSLog(@"Success! UUID is %@", createdItem.uuid);
           }
           failure:^(NSError *error) {
             NSLog(@"Error: %@", error);
           }];

投稿的更新

AFQiitaItem *item = ...; // Received from API

[item setTitle:@"テスト!(追記アリ)"];
[item setBody:@"[AFQiitaClient](http://github.com/ngs/AFQiitaClient) から投稿テスト\n\n##追記 (2012/10/13)\n\n* 非公開にしてみた"];

[item removeTag:[item.tags objectAtIndex:2]];
[item addTag:[AFQiitaTag tagWithName:@"Rails"]];

[item publicize]; // 限定公開のものを public に変更のみ可能

[client updateItem:item
           success:success:^(AFQiitaResponse *response) {
             AFQiitaItem *updatedItem = [response first];
             NSLog(@"Success! Updated at %@", updatedItem.updatedAt);
           }
           failure:^(NSError *error) {
             NSLog(@"Error: %@", error);
           }];

投稿的删除

[client deleteItem:item // Alias for deleteItemWithUUID:(NSString *)uuid
           success:success:^(AFQiitaResponse *response) {
             NSLog(@"Successfully deleted");
           }
           failure:^(NSError *error) {
             NSLog(@"Error: %@", error);
           }];

特定の投稿取得

[client itemWithUUID:@"1a43e55e7209c8f3c565"
             success:success:^ {
             AFQiitaItem *item = [response first];
               NSLog(@"Success: Title is %@, posted by %@ at %@",
                 item.title, item.user.name, item.createdAt);
             }
             failure:^(NSError *error) {
               NSLog(@"Error: %@", error);
             }];

投稿のストック

[client stockItem:item // Alias for stockItemWithUUID:(NSString *)uuid
          success:success:^ {
            NSLog(@"Successfully stocked");
          }
          failure:^(NSError *error) {
            NSLog(@"Error: %@", error);
          }];

投稿のストック解除

[client unstockItem:item // Alias for unstockItemWithUUID:(NSString *)uuid
            success:success:^ {
              NSLog(@"Successfully unstocked");
            }
            failure:^(NSError *error) {
              NSLog(@"Error: %@", error);
            }];

連絡先

Nagase Atsushi

@ngs

ライセンス

AFQiitaClient 以 MIT 许可证分发。有关详细信息,请参阅 LICENSE 文件。