NLRMashapeClientMashape API 调用
NLRMashapeClient 基于 AFNetworking 构建,NLRMashapeClient 提供简单和方便的形式来调用你在 Mashape 选择的 APIs。
用法
以“ Ultimate Weather Forecasts”为例,这是一个免费的返回天气状况的API。登录到Mashape并拥有至少一个应用程序后,将为Mashape Key
每个应用程序获得一个,以提出对此应用程序的请求。
首先,创建NLRMashapeClient的子类,并声明单例方法,如下所示。
#import "NLRMashapeClient.h"
@interface WeatherClient : NLRMashapeClient
+ (instancetype)sharedClient;
@end
现在,应该使用正确的API名称和Mashape App Key实现单例方法。API名称是URL中位于之前的部分.p.mashape.com
。例如,如果天气API的基本网址为https://george-vustrey-weather.p.mashape.com
,则应使用george-vustrey-weather
。可以从Mashape的应用程序页面中获取应用程序密钥,然后按“获取密钥”按钮。
#import "WeatherClient.h"
@implementation WeatherClient
+ (instancetype)sharedClient
{
static dispatch_once_t once;
static id sharedInstance;
dispatch_once(&once, ^{
sharedInstance = [[self alloc] initWithAPIName:@"george-vustrey-weather" mashapeAppKey:@"THE-KEY-FOR-YOUR-APP"];
});
return sharedInstance;
}
@end
对于将使用的每个Mashape API,应该使用的一个子类/单个子类NLRMashapeClient
。
正确初始化客户端后,就可以完成配置,并且可以进行任意数量的调用,而无需设置标题,键,而仅需注意:端点和参数!
例如,如果示例GET
为https://george-vustrey-weather.p.mashape.com/api.php
,而参数为location
,则只需调用:
[[WeatherClient sharedClient]] GET:@"api.php" parameters:@{@"location" : @"Tel Aviv"} success:^(NSURLSessionDataTask *task, id responseObject) {
NSLog(@"%@", responseObject);
} failure:^(NSURLSessionDataTask *task, NSError *error) {
NSLog(@"%@", error);
}];
对于单个调用,Mashape提供的Objective-C示例要简单得多。
如果想更多地玩这个游戏,可以使用示例项目(它需要CocoaPods并在运行pod install
之前运行)。
评论
API MonitorWindows API 调用监视工具
API Monitor 是一款用来监视和显示用户应用程序和服务程序中的Windows API调用的免
API MonitorWindows API 调用监视工具
0
Google API PHP ClientGoogle API 调用
GoogleAPIPHPClient库能让你在Google+、Drive、或者你服务器上的YouTube上使用GoogleAPI。示例代码:<?php require_once 'google
Google API PHP ClientGoogle API 调用
0
API MonitorWindows API 调用监视工具
APIMonitor是一款用来监视和显示用户应用程序和服务程序中的WindowsAPI调用的免费软件。它是一个强大的工具,在跟踪调试你开发的应用程序时,可以帮助发现产生问题可能的原因。APIMonit
API MonitorWindows API 调用监视工具
0
Google API PHP ClientGoogle API 调用
Google API PHP Client 库能让你在 Google+、Drive、或者你服务器上的
Google API PHP ClientGoogle API 调用
0
XINS调用远程API规范
XINS是一项规范技术用于定义,创建和调用远程APIs。当API规范在XML文档中定义好之后,XINS将会把它们转换成包括客户端与服务端的HTML文档与Java代码.XINS将与复杂的SOAP技术竞争
XINS调用远程API规范
0
API-requestor调用 API 请求接口
利用API-requestor无需定义请求方法即可调用API请求接口,无第三方依赖。使用方法1.引入API-requestor.js<scriptsrc="API-requestor.js"&g
API-requestor调用 API 请求接口
0