JSONAPI.h 4.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. //
  2. // JSONAPI.h
  3. //
  4. // @version 1.0.0
  5. // @author Marin Todorov, http://www.touch-code-magazine.com
  6. //
  7. // Copyright (c) 2012-2014 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. // The MIT License in plain English: http://www.touch-code-magazine.com/JSONModel/MITLicense
  15. #import <Foundation/Foundation.h>
  16. #import "JSONHTTPClient.h"
  17. /////////////////////////////////////////////////////////////////////////////////////////////
  18. /**
  19. * @discussion Class for working with JSON APIs. It builds upon the JSONHTTPClient class
  20. * and facilitates making requests to the same web host. Also features helper
  21. * method for making calls to a JSON RPC service
  22. */
  23. @interface JSONAPI : NSObject
  24. /////////////////////////////////////////////////////////////////////////////////////////////
  25. /** @name Configuring the API */
  26. /**
  27. * Sets the API url
  28. * @param base the API url as a string
  29. */
  30. +(void)setAPIBaseURLWithString:(NSString*)base;
  31. /**
  32. * Sets the default content type for the requests/responses
  33. * @param ctype The content-type as a string. Some possible types,
  34. * depending on the service: application/json, text/json, x-application/javascript, etc.
  35. */
  36. +(void)setContentType:(NSString*)ctype;
  37. /////////////////////////////////////////////////////////////////////////////////////////////
  38. /** @name Making GET API requests */
  39. /**
  40. * Makes an asynchronious GET request to the API
  41. * @param path the URL path to add to the base API URL for this HTTP call
  42. * @param params the variables to pass to the API
  43. * @param completeBlock a JSONObjectBlock block to execute upon completion
  44. */
  45. +(void)getWithPath:(NSString*)path andParams:(NSDictionary*)params completion:(JSONObjectBlock)completeBlock;
  46. /////////////////////////////////////////////////////////////////////////////////////////////
  47. /** @name Making POST API requests */
  48. /**
  49. * Makes a POST request to the API
  50. * @param path the URL path to add to the base API URL for this HTTP call
  51. * @param params the variables to pass to the API
  52. * @param completeBlock a JSONObjectBlock block to execute upon completion
  53. */
  54. +(void)postWithPath:(NSString*)path andParams:(NSDictionary*)params completion:(JSONObjectBlock)completeBlock;
  55. /////////////////////////////////////////////////////////////////////////////////////////////
  56. /** @name JSON RPC methods */
  57. /**
  58. * Makes an asynchronious JSON RPC request to the API. Read more: http://www.jsonrpc.org
  59. * @param method the HTTP method name; GET or POST only
  60. * @param args the list of arguments to pass to the API
  61. * @param completeBlock JSONObjectBlock to execute upon completion
  62. */
  63. +(void)rpcWithMethodName:(NSString*)method andArguments:(NSArray*)args completion:(JSONObjectBlock)completeBlock;
  64. /** @name JSON RPC (2.0) request method */
  65. /**
  66. * Makes an asynchronious JSON RPC 2.0 request to the API. Read more: http://www.jsonrpc.org
  67. * @param method the HTTP method name; GET or POST only
  68. * @param params the params to pass to the API - an NSArray or an NSDictionary,
  69. * depending whether you're using named or unnamed parameters
  70. * @param completeBlock JSONObjectBlock to execute upon completion
  71. */
  72. +(void)rpc2WithMethodName:(NSString*)method andParams:(id)params completion:(JSONObjectBlock)completeBlock;
  73. /////////////////////////////////////////////////////////////////////////////////////////////
  74. @end