JSONAPI.h 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. //
  2. // JSONAPI.h
  3. //
  4. // @version 1.2
  5. // @author Marin Todorov (http://www.underplot.com) and contributors
  6. //
  7. // Copyright (c) 2012-2015 Marin Todorov, Underplot ltd.
  8. // This code is distributed under the terms and conditions of the MIT license.
  9. //
  10. // Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
  11. // The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
  12. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  13. //
  14. #import <Foundation/Foundation.h>
  15. #import "JSONHTTPClient.h"
  16. /////////////////////////////////////////////////////////////////////////////////////////////
  17. /**
  18. * @discussion Class for working with JSON APIs. It builds upon the JSONHTTPClient class
  19. * and facilitates making requests to the same web host. Also features helper
  20. * method for making calls to a JSON RPC service
  21. */
  22. @interface JSONAPI : NSObject
  23. /////////////////////////////////////////////////////////////////////////////////////////////
  24. /** @name Configuring the API */
  25. /**
  26. * Sets the API url
  27. * @param base the API url as a string
  28. */
  29. +(void)setAPIBaseURLWithString:(NSString*)base;
  30. /**
  31. * Sets the default content type for the requests/responses
  32. * @param ctype The content-type as a string. Some possible types,
  33. * depending on the service: application/json, text/json, x-application/javascript, etc.
  34. */
  35. +(void)setContentType:(NSString*)ctype;
  36. /////////////////////////////////////////////////////////////////////////////////////////////
  37. /** @name Making GET API requests */
  38. /**
  39. * Makes an asynchronous GET request to the API
  40. * @param path the URL path to add to the base API URL for this HTTP call
  41. * @param params the variables to pass to the API
  42. * @param completeBlock a JSONObjectBlock block to execute upon completion
  43. */
  44. +(void)getWithPath:(NSString*)path andParams:(NSDictionary*)params completion:(JSONObjectBlock)completeBlock;
  45. /////////////////////////////////////////////////////////////////////////////////////////////
  46. /** @name Making POST API requests */
  47. /**
  48. * Makes a POST request to the API
  49. * @param path the URL path to add to the base API URL for this HTTP call
  50. * @param params the variables to pass to the API
  51. * @param completeBlock a JSONObjectBlock block to execute upon completion
  52. */
  53. +(void)postWithPath:(NSString*)path andParams:(NSDictionary*)params completion:(JSONObjectBlock)completeBlock;
  54. /////////////////////////////////////////////////////////////////////////////////////////////
  55. /** @name JSON RPC methods */
  56. /**
  57. * Makes an asynchronous JSON RPC request to the API. Read more: http://www.jsonrpc.org
  58. * @param method the HTTP method name; GET or POST only
  59. * @param args the list of arguments to pass to the API
  60. * @param completeBlock JSONObjectBlock to execute upon completion
  61. */
  62. +(void)rpcWithMethodName:(NSString*)method andArguments:(NSArray*)args completion:(JSONObjectBlock)completeBlock;
  63. /** @name JSON RPC (2.0) request method */
  64. /**
  65. * Makes an asynchronous JSON RPC 2.0 request to the API. Read more: http://www.jsonrpc.org
  66. * @param method the HTTP method name; GET or POST only
  67. * @param params the params to pass to the API - an NSArray or an NSDictionary,
  68. * depending whether you're using named or unnamed parameters
  69. * @param completeBlock JSONObjectBlock to execute upon completion
  70. */
  71. +(void)rpc2WithMethodName:(NSString*)method andParams:(id)params completion:(JSONObjectBlock)completeBlock;
  72. /////////////////////////////////////////////////////////////////////////////////////////////
  73. @end