spark_api 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (257) hide show
  1. data/History.txt +139 -0
  2. data/LICENSE +14 -0
  3. data/README.md +153 -0
  4. data/Rakefile +18 -0
  5. data/VERSION +1 -0
  6. data/bin/spark_api +8 -0
  7. data/bin/spark_api~ +8 -0
  8. data/lib/spark_api.rb +46 -0
  9. data/lib/spark_api/authentication.rb +55 -0
  10. data/lib/spark_api/authentication/api_auth.rb +104 -0
  11. data/lib/spark_api/authentication/api_auth.rb~ +104 -0
  12. data/lib/spark_api/authentication/base_auth.rb +47 -0
  13. data/lib/spark_api/authentication/base_auth.rb~ +47 -0
  14. data/lib/spark_api/authentication/oauth2.rb +198 -0
  15. data/lib/spark_api/authentication/oauth2.rb~ +199 -0
  16. data/lib/spark_api/authentication/oauth2_impl/grant_type_base.rb +87 -0
  17. data/lib/spark_api/authentication/oauth2_impl/grant_type_base.rb~ +87 -0
  18. data/lib/spark_api/authentication/oauth2_impl/grant_type_code.rb +48 -0
  19. data/lib/spark_api/authentication/oauth2_impl/grant_type_code.rb~ +49 -0
  20. data/lib/spark_api/authentication/oauth2_impl/grant_type_password.rb +44 -0
  21. data/lib/spark_api/authentication/oauth2_impl/grant_type_password.rb~ +45 -0
  22. data/lib/spark_api/authentication/oauth2_impl/grant_type_refresh.rb +35 -0
  23. data/lib/spark_api/authentication/oauth2_impl/grant_type_refresh.rb~ +36 -0
  24. data/lib/spark_api/authentication/oauth2_impl/middleware.rb +38 -0
  25. data/lib/spark_api/authentication/oauth2_impl/middleware.rb~ +39 -0
  26. data/lib/spark_api/authentication/oauth2_impl/password_provider.rb +24 -0
  27. data/lib/spark_api/authentication/oauth2_impl/password_provider.rb~ +25 -0
  28. data/lib/spark_api/cli.rb +158 -0
  29. data/lib/spark_api/cli.rb~ +158 -0
  30. data/lib/spark_api/cli/api_auth.rb +8 -0
  31. data/lib/spark_api/cli/api_auth.rb~ +8 -0
  32. data/lib/spark_api/cli/oauth2.rb +14 -0
  33. data/lib/spark_api/cli/oauth2.rb~ +14 -0
  34. data/lib/spark_api/cli/setup.rb +47 -0
  35. data/lib/spark_api/cli/setup.rb~ +47 -0
  36. data/lib/spark_api/client.rb +27 -0
  37. data/lib/spark_api/configuration.rb +54 -0
  38. data/lib/spark_api/configuration.rb~ +54 -0
  39. data/lib/spark_api/configuration/yaml.rb +101 -0
  40. data/lib/spark_api/configuration/yaml.rb~ +101 -0
  41. data/lib/spark_api/connection.rb +42 -0
  42. data/lib/spark_api/faraday.rb +64 -0
  43. data/lib/spark_api/faraday.rb~ +64 -0
  44. data/lib/spark_api/models.rb +33 -0
  45. data/lib/spark_api/models.rb~ +33 -0
  46. data/lib/spark_api/models/account.rb +115 -0
  47. data/lib/spark_api/models/account.rb~ +115 -0
  48. data/lib/spark_api/models/base.rb +118 -0
  49. data/lib/spark_api/models/base.rb~ +118 -0
  50. data/lib/spark_api/models/connect_prefs.rb +10 -0
  51. data/lib/spark_api/models/connect_prefs.rb~ +10 -0
  52. data/lib/spark_api/models/constraint.rb +16 -0
  53. data/lib/spark_api/models/constraint.rb~ +16 -0
  54. data/lib/spark_api/models/contact.rb +49 -0
  55. data/lib/spark_api/models/contact.rb~ +49 -0
  56. data/lib/spark_api/models/custom_fields.rb +12 -0
  57. data/lib/spark_api/models/custom_fields.rb~ +12 -0
  58. data/lib/spark_api/models/document.rb +11 -0
  59. data/lib/spark_api/models/document.rb~ +11 -0
  60. data/lib/spark_api/models/finders.rb +45 -0
  61. data/lib/spark_api/models/finders.rb~ +45 -0
  62. data/lib/spark_api/models/idx_link.rb +47 -0
  63. data/lib/spark_api/models/idx_link.rb~ +47 -0
  64. data/lib/spark_api/models/listing.rb +197 -0
  65. data/lib/spark_api/models/listing.rb~ +197 -0
  66. data/lib/spark_api/models/listing_cart.rb +72 -0
  67. data/lib/spark_api/models/listing_cart.rb~ +72 -0
  68. data/lib/spark_api/models/market_statistics.rb +33 -0
  69. data/lib/spark_api/models/market_statistics.rb~ +33 -0
  70. data/lib/spark_api/models/message.rb +21 -0
  71. data/lib/spark_api/models/message.rb~ +21 -0
  72. data/lib/spark_api/models/note.rb +41 -0
  73. data/lib/spark_api/models/note.rb~ +41 -0
  74. data/lib/spark_api/models/notification.rb +42 -0
  75. data/lib/spark_api/models/notification.rb~ +42 -0
  76. data/lib/spark_api/models/open_house.rb +24 -0
  77. data/lib/spark_api/models/open_house.rb~ +24 -0
  78. data/lib/spark_api/models/photo.rb +70 -0
  79. data/lib/spark_api/models/photo.rb~ +70 -0
  80. data/lib/spark_api/models/property_types.rb +7 -0
  81. data/lib/spark_api/models/property_types.rb~ +7 -0
  82. data/lib/spark_api/models/saved_search.rb +16 -0
  83. data/lib/spark_api/models/saved_search.rb~ +16 -0
  84. data/lib/spark_api/models/shared_listing.rb +35 -0
  85. data/lib/spark_api/models/shared_listing.rb~ +35 -0
  86. data/lib/spark_api/models/standard_fields.rb +50 -0
  87. data/lib/spark_api/models/standard_fields.rb~ +50 -0
  88. data/lib/spark_api/models/subresource.rb +19 -0
  89. data/lib/spark_api/models/subresource.rb~ +19 -0
  90. data/lib/spark_api/models/system_info.rb +14 -0
  91. data/lib/spark_api/models/system_info.rb~ +14 -0
  92. data/lib/spark_api/models/tour_of_home.rb +24 -0
  93. data/lib/spark_api/models/tour_of_home.rb~ +24 -0
  94. data/lib/spark_api/models/video.rb +16 -0
  95. data/lib/spark_api/models/video.rb~ +16 -0
  96. data/lib/spark_api/models/virtual_tour.rb +18 -0
  97. data/lib/spark_api/models/virtual_tour.rb~ +18 -0
  98. data/lib/spark_api/multi_client.rb +59 -0
  99. data/lib/spark_api/multi_client.rb~ +59 -0
  100. data/lib/spark_api/paginate.rb +109 -0
  101. data/lib/spark_api/paginate.rb~ +109 -0
  102. data/lib/spark_api/primary_array.rb +29 -0
  103. data/lib/spark_api/primary_array.rb~ +29 -0
  104. data/lib/spark_api/request.rb +96 -0
  105. data/lib/spark_api/request.rb~ +96 -0
  106. data/lib/spark_api/response.rb +70 -0
  107. data/lib/spark_api/response.rb~ +70 -0
  108. data/lib/spark_api/version.rb +4 -0
  109. data/lib/spark_api/version.rb~ +4 -0
  110. data/script/console +6 -0
  111. data/script/console~ +6 -0
  112. data/script/example.rb +27 -0
  113. data/script/example.rb~ +27 -0
  114. data/spec/fixtures/accounts/all.json +160 -0
  115. data/spec/fixtures/accounts/my.json +74 -0
  116. data/spec/fixtures/accounts/my_portal.json +20 -0
  117. data/spec/fixtures/accounts/my_put.json +5 -0
  118. data/spec/fixtures/accounts/my_save.json +5 -0
  119. data/spec/fixtures/accounts/office.json +142 -0
  120. data/spec/fixtures/accounts/password_save.json +6 -0
  121. data/spec/fixtures/authentication_failure.json +7 -0
  122. data/spec/fixtures/base.json +13 -0
  123. data/spec/fixtures/contacts/contacts.json +28 -0
  124. data/spec/fixtures/contacts/my.json +19 -0
  125. data/spec/fixtures/contacts/new.json +11 -0
  126. data/spec/fixtures/contacts/new_empty.json +8 -0
  127. data/spec/fixtures/contacts/new_notify.json +11 -0
  128. data/spec/fixtures/contacts/post.json +10 -0
  129. data/spec/fixtures/contacts/tags.json +11 -0
  130. data/spec/fixtures/count.json +10 -0
  131. data/spec/fixtures/empty.json +3 -0
  132. data/spec/fixtures/errors/expired.json +7 -0
  133. data/spec/fixtures/errors/failure.json +5 -0
  134. data/spec/fixtures/errors/failure_with_constraint.json +17 -0
  135. data/spec/fixtures/errors/failure_with_msg.json +7 -0
  136. data/spec/fixtures/generic_delete.json +1 -0
  137. data/spec/fixtures/generic_failure.json +5 -0
  138. data/spec/fixtures/listing_carts/add_listing.json +13 -0
  139. data/spec/fixtures/listing_carts/add_listing_post.json +5 -0
  140. data/spec/fixtures/listing_carts/empty.json +5 -0
  141. data/spec/fixtures/listing_carts/listing_cart.json +19 -0
  142. data/spec/fixtures/listing_carts/new.json +12 -0
  143. data/spec/fixtures/listing_carts/post.json +10 -0
  144. data/spec/fixtures/listing_carts/remove_listing.json +13 -0
  145. data/spec/fixtures/listings/constraints.json +18 -0
  146. data/spec/fixtures/listings/constraints_with_pagination.json +24 -0
  147. data/spec/fixtures/listings/document_index.json +19 -0
  148. data/spec/fixtures/listings/multiple.json +69 -0
  149. data/spec/fixtures/listings/no_subresources.json +38 -0
  150. data/spec/fixtures/listings/open_houses.json +21 -0
  151. data/spec/fixtures/listings/photos/index.json +469 -0
  152. data/spec/fixtures/listings/photos/new.json +12 -0
  153. data/spec/fixtures/listings/photos/post.json +20 -0
  154. data/spec/fixtures/listings/put.json +5 -0
  155. data/spec/fixtures/listings/put_expiration_date.json +5 -0
  156. data/spec/fixtures/listings/saved_search.json +17 -0
  157. data/spec/fixtures/listings/shared_listing_get.json +14 -0
  158. data/spec/fixtures/listings/shared_listing_new.json +9 -0
  159. data/spec/fixtures/listings/shared_listing_post.json +10 -0
  160. data/spec/fixtures/listings/tour_of_homes.json +23 -0
  161. data/spec/fixtures/listings/videos_index.json +18 -0
  162. data/spec/fixtures/listings/virtual_tours_index.json +42 -0
  163. data/spec/fixtures/listings/with_documents.json +52 -0
  164. data/spec/fixtures/listings/with_permissions.json +44 -0
  165. data/spec/fixtures/listings/with_photos.json +110 -0
  166. data/spec/fixtures/listings/with_supplement.json +39 -0
  167. data/spec/fixtures/listings/with_videos.json +54 -0
  168. data/spec/fixtures/listings/with_vtour.json +48 -0
  169. data/spec/fixtures/logo_fbs.png +0 -0
  170. data/spec/fixtures/messages/new.json +14 -0
  171. data/spec/fixtures/messages/new_empty.json +7 -0
  172. data/spec/fixtures/messages/new_with_recipients.json +15 -0
  173. data/spec/fixtures/messages/post.json +5 -0
  174. data/spec/fixtures/notes/add.json +11 -0
  175. data/spec/fixtures/notes/agent_shared.json +11 -0
  176. data/spec/fixtures/notes/agent_shared_empty.json +7 -0
  177. data/spec/fixtures/notes/new.json +5 -0
  178. data/spec/fixtures/notifications/mark_read.json +1 -0
  179. data/spec/fixtures/notifications/new.json +8 -0
  180. data/spec/fixtures/notifications/new_empty.json +7 -0
  181. data/spec/fixtures/notifications/notifications.json +43 -0
  182. data/spec/fixtures/notifications/post.json +10 -0
  183. data/spec/fixtures/notifications/unread.json +10 -0
  184. data/spec/fixtures/oauth2/access.json +3 -0
  185. data/spec/fixtures/oauth2/access_with_old_refresh.json +5 -0
  186. data/spec/fixtures/oauth2/access_with_refresh.json +5 -0
  187. data/spec/fixtures/oauth2/authorization_code_body.json +7 -0
  188. data/spec/fixtures/oauth2/error.json +3 -0
  189. data/spec/fixtures/oauth2/password_body.json +7 -0
  190. data/spec/fixtures/oauth2/refresh_body.json +7 -0
  191. data/spec/fixtures/oauth2_error.json +3 -0
  192. data/spec/fixtures/property_types/property_types.json +31 -0
  193. data/spec/fixtures/session.json +10 -0
  194. data/spec/fixtures/standardfields/city.json +1031 -0
  195. data/spec/fixtures/standardfields/nearby.json +53 -0
  196. data/spec/fixtures/standardfields/standardfields.json +188 -0
  197. data/spec/fixtures/standardfields/stateorprovince.json +36 -0
  198. data/spec/fixtures/success.json +5 -0
  199. data/spec/json_helper.rb +76 -0
  200. data/spec/mock_helper.rb +124 -0
  201. data/spec/oauth2_helper.rb +68 -0
  202. data/spec/spec_helper.rb +48 -0
  203. data/spec/unit/flexmls_api_spec.rb~ +23 -0
  204. data/spec/unit/spark_api/authentication/api_auth_spec.rb +169 -0
  205. data/spec/unit/spark_api/authentication/api_auth_spec.rb~ +169 -0
  206. data/spec/unit/spark_api/authentication/base_auth_spec.rb +10 -0
  207. data/spec/unit/spark_api/authentication/base_auth_spec.rb~ +10 -0
  208. data/spec/unit/spark_api/authentication/oauth2_impl/grant_type_base_spec.rb +10 -0
  209. data/spec/unit/spark_api/authentication/oauth2_impl/grant_type_base_spec.rb~ +10 -0
  210. data/spec/unit/spark_api/authentication/oauth2_spec.rb +205 -0
  211. data/spec/unit/spark_api/authentication/oauth2_spec.rb~ +205 -0
  212. data/spec/unit/spark_api/authentication_spec.rb +38 -0
  213. data/spec/unit/spark_api/authentication_spec.rb~ +38 -0
  214. data/spec/unit/spark_api/configuration/yaml_spec.rb +72 -0
  215. data/spec/unit/spark_api/configuration/yaml_spec.rb~ +72 -0
  216. data/spec/unit/spark_api/configuration_spec.rb +122 -0
  217. data/spec/unit/spark_api/configuration_spec.rb~ +122 -0
  218. data/spec/unit/spark_api/faraday_spec.rb +90 -0
  219. data/spec/unit/spark_api/faraday_spec.rb~ +90 -0
  220. data/spec/unit/spark_api/models/account_spec.rb +176 -0
  221. data/spec/unit/spark_api/models/base_spec.rb +106 -0
  222. data/spec/unit/spark_api/models/connect_prefs_spec.rb +9 -0
  223. data/spec/unit/spark_api/models/constraint_spec.rb +19 -0
  224. data/spec/unit/spark_api/models/contact_spec.rb +108 -0
  225. data/spec/unit/spark_api/models/contact_spec.rb~ +108 -0
  226. data/spec/unit/spark_api/models/document_spec.rb +32 -0
  227. data/spec/unit/spark_api/models/listing_cart_spec.rb +127 -0
  228. data/spec/unit/spark_api/models/listing_cart_spec.rb~ +127 -0
  229. data/spec/unit/spark_api/models/listing_spec.rb +320 -0
  230. data/spec/unit/spark_api/models/listing_spec.rb~ +320 -0
  231. data/spec/unit/spark_api/models/message_spec.rb +47 -0
  232. data/spec/unit/spark_api/models/message_spec.rb~ +47 -0
  233. data/spec/unit/spark_api/models/note_spec.rb +63 -0
  234. data/spec/unit/spark_api/models/note_spec.rb~ +63 -0
  235. data/spec/unit/spark_api/models/notification_spec.rb +62 -0
  236. data/spec/unit/spark_api/models/notification_spec.rb~ +62 -0
  237. data/spec/unit/spark_api/models/open_house_spec.rb +39 -0
  238. data/spec/unit/spark_api/models/photo_spec.rb +92 -0
  239. data/spec/unit/spark_api/models/property_types_spec.rb +33 -0
  240. data/spec/unit/spark_api/models/saved_search_spec.rb +40 -0
  241. data/spec/unit/spark_api/models/shared_listing_spec.rb +45 -0
  242. data/spec/unit/spark_api/models/shared_listing_spec.rb~ +45 -0
  243. data/spec/unit/spark_api/models/standard_fields_spec.rb +60 -0
  244. data/spec/unit/spark_api/models/system_info_spec.rb +83 -0
  245. data/spec/unit/spark_api/models/tour_of_home_spec.rb +44 -0
  246. data/spec/unit/spark_api/models/video_spec.rb +36 -0
  247. data/spec/unit/spark_api/models/virtual_tour_spec.rb +44 -0
  248. data/spec/unit/spark_api/multi_client_spec.rb +56 -0
  249. data/spec/unit/spark_api/multi_client_spec.rb~ +56 -0
  250. data/spec/unit/spark_api/paginate_spec.rb +224 -0
  251. data/spec/unit/spark_api/paginate_spec.rb~ +224 -0
  252. data/spec/unit/spark_api/primary_array_spec.rb +41 -0
  253. data/spec/unit/spark_api/primary_array_spec.rb~ +41 -0
  254. data/spec/unit/spark_api/request_spec.rb +344 -0
  255. data/spec/unit/spark_api/request_spec.rb~ +344 -0
  256. data/spec/unit/spark_api_spec.rb +23 -0
  257. metadata +725 -0
data/History.txt ADDED
@@ -0,0 +1,139 @@
1
+ == v0.7.1 2011-10-13
2
+ * Updated connection dependencies
3
+ * Added messaging model
4
+ * ExpirationDate editable for Listing
5
+ == v0.7.0 2011-10-03
6
+ * Major changes to results object returned from the client (and models). Results are no longer allowed to be nil, and Array is decorated with non result response information.
7
+ * Finished listing photo uploads
8
+ * ListPrice save operation for listings
9
+ * Listing contraints processing
10
+ == v0.6.7 2011-09-02
11
+ * YAML key management
12
+ == v0.6.6 2011-08-30
13
+ * Added methods for returning street, region, and full address for a listing
14
+ == v0.6.5 2011-08-02
15
+ * Fixed some recursive gemspec issues from jewler by removing jeweler and going with some of our own custom rake tasks.
16
+ == v0.6.4 2011-08-02
17
+ * added public method for the listing carts service specified
18
+ * added spec for portal listing cart method
19
+ == v0.6.3 2011-08-02
20
+ * Fix gemspec error on CLI launch (bundler)
21
+ == v0.6.2 2011-07-29
22
+ * Added command to make irb sessions rocktastic
23
+ == v0.6.1 2011-07-14
24
+ * Fixed request headers to match api expectations
25
+ * OAuth2 grant types redesign
26
+ * "provided" saved searches
27
+ * Portal account saving
28
+ == v0.5.9 2011-07-12
29
+ * Modify Collect to handle FixNums in the case of pagination=count to my/office listings
30
+ == v0.5.8 2011-07-08
31
+ * Add finders to SharedListing model
32
+ * fixed log message
33
+ == v0.5.7 2011-07-07
34
+ * Add /my/contact support
35
+ == v0.5.6 2011-07-07
36
+ * More build woes.
37
+ == v0.5.5 2011-07-07
38
+ == v0.5.4 2011-07-01
39
+ * Added the add listing methods to the cart instance.
40
+ * Added the remove listing methods to the cart instance.
41
+ * Accounts service by office changes
42
+ == v0.5.3 2011-06-28
43
+ * API error handling bugfix to log decent messages
44
+ * Fixed the OAuth flow.
45
+ * Provide primary image types
46
+ == v0.5.2 2011-06-23
47
+ == v0.5.1 2011-06-03
48
+ * Upgraded dependencies to latest releases.
49
+ * Added put / delete functionality.
50
+ * Make method_missing and respond_to? methods match the expected behavior and add specs to define those behaviors.
51
+ * Properly escape uri paths when making requests.
52
+ * SavedSearch resource.
53
+ == v0.4.6 2011-05-13
54
+ * Added notify option to contacts
55
+ * Implementation of listing cart resource.
56
+ * Pass JSON instead of a querystring for the OAuth POST body
57
+ * API-101 client implementation for sharedlistings service.
58
+ * Added multiclient support
59
+ * Change client from sending credentials as request parameters to post data
60
+ == v0.4.5 2011-05-06
61
+ * Restrict lists larger than 1,000 scroll items
62
+ * Fixed logging of oauth2 errors, removed redundant access_token from parameters.
63
+ == v0.4.4 2011-05-06
64
+ * Need to skip spec/reports for CI builds (oops).
65
+ == v0.4.3 2011-05-05
66
+ * Fixed semi important issue with timeout settings.
67
+ == v0.4.2 2011-05-03
68
+ * Fixed some nasty session timeout issues that were reported.
69
+ * Raise proper exceptions for oauth grant errors.
70
+ == v0.4.1 2011-04-11
71
+ * Removed unnecessary finders from property type model
72
+ * OAuth2 implementation and general auth redesign
73
+ * Upgraded ruby version supported.
74
+ * Add finders to Contact model
75
+ * Adds an inspect to make debug info easier to read
76
+ * Standard field support for _expanding and nearby
77
+ == v0.3.9 2011-04-01
78
+ * Added notes model and specs
79
+ * Added a primary_logo method to the system info class
80
+ * Change owner param to arguments hash
81
+ * Add finders
82
+ == v0.3.8 2011-03-24
83
+ * Interface change! Remove api user calls that are all over the place.
84
+ * Fix for empty count response.
85
+ * Parse date and times for tour
86
+ == v0.3.7 2011-03-11
87
+ * Fix catch miss.
88
+ * Added tour of homes model.
89
+ == v0.3.6 2011-03-08
90
+ * Added account model Also moved finders to a module.
91
+ == v0.3.5 2011-03-08
92
+ * changing units on API request logging
93
+ == v0.3.4 2011-02-08
94
+ * Fixed escaping special characters in the client. This needs to happen after signing.
95
+ == v0.3.3 2011-01-28
96
+ * Add session features to the api client.
97
+ * Remove redundant debug log call
98
+ == v0.3.2 2011-01-28
99
+ * CustomFields class added
100
+ == v0.3.1 2011-01-27
101
+ * Prep work for rubygems
102
+ * doc corrections
103
+ == v0.3.0 2011-01-17
104
+ * Added license for release.
105
+ == v0.2.9 2011-01-12
106
+ * misc project cleanup
107
+ == v0.2.8 2011-01-10
108
+ * Fixed client to use http for all requests (except for session auth) by default. Added :ssl option to enable https for all traffic.
109
+ * Fixed client connection and resets.
110
+ == v0.2.7 2011-01-10
111
+ * Build troubles
112
+ == v0.2.6 2011-01-10
113
+ == v0.2.5 2011-01-10
114
+ == v0.2.4 2011-01-10
115
+ == v0.2.3 2011-01-10
116
+ * Handy startup script picking keys from the environment.
117
+ == v0.2.2 2010-12-29
118
+ * per_page setting for the client models.
119
+ * Pagination support for the Spark api client
120
+ * Added branded? and unbranded? instance methods to Video
121
+ * Added document model
122
+ * Added virtual tours model
123
+ * Added videos model
124
+ * Contact model and saving
125
+ * Added `find_by_cart_id' method to Listing model
126
+ * allow finder to pass thru options
127
+ * Implemented Listing.find(:all, ...)
128
+ == v0.2.1 2010-12-29
129
+ * fixed some error code issues.
130
+ * corrected default endpoint to include the URL scheme
131
+ == v0.2.0 2010-12-27
132
+ * new gemspec
133
+ * Session caching
134
+ * Major overhaul on the models for code reuse
135
+ * added Photo.find_by_listing_key
136
+ == v0.1.1 2010-12-23
137
+ * IDX link and market stat models.
138
+ == v0.1.0 2010-12-13
139
+ * Initial usable release with request interface and models
data/LICENSE ADDED
@@ -0,0 +1,14 @@
1
+ Copyright 2011 Financial Business Systems, Inc.
2
+
3
+ Licensed under the Apache License, Version 2.0 (the "License");
4
+ you may not use this file except in compliance with the License.
5
+ You may obtain a copy of the License at
6
+
7
+ http://www.apache.org/licenses/LICENSE-2.0
8
+
9
+ Unless required by applicable law or agreed to in writing, software
10
+ distributed under the License is distributed on an "AS IS" BASIS,
11
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ See the License for the specific language governing permissions and
13
+ limitations under the License.
14
+
data/README.md ADDED
@@ -0,0 +1,153 @@
1
+ Spark API
2
+ =====================
3
+ A Ruby wrapper for the Spark REST API. Loosely based on ActiveResource to provide models to interact with remote services.
4
+
5
+
6
+ Documentation
7
+ -------------
8
+ For full information on the API, see [http://sparkplatform.com/docs/overview/api](http://sparkplatform.com/docs/overview/api)
9
+
10
+
11
+ Installation
12
+ ---------
13
+ gem install spark_api
14
+
15
+ Usage Examples
16
+ ------------------------
17
+
18
+ #### Ruby Script
19
+ # initialize the gem with your key/secret
20
+ # api_key and _api_secret are the only required settings
21
+ # other options and their defaults:
22
+ # - endpoint: 'https://api.sparkapi.com'
23
+ # - version: 'v1'
24
+ # - ssl: false
25
+ # - user_agent: 'Spark API Ruby Gem'
26
+ SparkApi.configure do |config|
27
+ config.endpoint = 'https://developers.sparkapi.com'
28
+ config.api_key = 'my_api_key'
29
+ config.api_secret = 'my_api_secret'
30
+ end
31
+
32
+ # mixin the models so you can use them without prefix
33
+ include SparkApi::Models
34
+
35
+ # Grab your listings!
36
+ my_listings = Listing.my()
37
+
38
+
39
+ #### Interactive Console
40
+ Included in the gem is a simple setup script to run the client in IRB. To use it, first create the file called _.spark_api_testing_ filling in the credentials for your account.
41
+
42
+ API_USER="12345678901234567890123456" # 26-digit identifier of an API user
43
+ API_ENDPOINT="https://developers.sparkapi.com"
44
+ API_KEY="my_api_key"
45
+ API_SECRET="my_api_secret"
46
+
47
+ export API_USER API_ENDPOINT API_KEY API_SECRET
48
+
49
+ Now, to run with this setup, run the following from the command line:
50
+
51
+ > source .spark_api_testing
52
+ > spark_api
53
+ SparkApi> SparkApi.client.get '/my/account'
54
+
55
+ You can also provide these options from the command line, see "spark_api -h" for more information
56
+
57
+
58
+ Authentication Types
59
+ --------------
60
+ Authentication is handled transparently by the request framework in the gem, so you should never need to manually make an authentication request. More than one mode of authentication is supported, so the client needs to be configured accordingly.
61
+
62
+ #### API Authentication (Default)
63
+ Usually supplied for a single user, this authentication mode is the simplest, and is setup as the default. The example usage above demonstrates how to get started using this authentication mode.
64
+
65
+ #### OAuth2 Authentication
66
+ Authentication mode the separates application and user authentication. This mode requires further setup which is described in _lib/spark_api/authentication/oauth2.rb_
67
+
68
+ Error Codes
69
+ ---------------------
70
+ <table>
71
+ <thead>
72
+ <tr>
73
+ <th>HTTP Code</th>
74
+ <th>Spark API Error Code</th>
75
+ <th>Exception Raised</th>
76
+ <th>Description</th>
77
+ </tr>
78
+ </thead>
79
+ <tbody>
80
+ <tr>
81
+ <td><tt>401</tt></td>
82
+ <td><tt>1000</tt></td>
83
+ <td><tt></tt></td>
84
+ <td>Invalid API Key and/or Request signed improperly</td>
85
+ </tr>
86
+ <tr>
87
+ <td><tt>401</tt></td>
88
+ <td><tt>1010</tt></td>
89
+ <td><tt></tt></td>
90
+ <td>API key is disabled</td>
91
+ </tr>
92
+ <tr>
93
+ <td><tt>403</tt></td>
94
+ <td><tt>1015</tt></td>
95
+ <td><tt></tt></td>
96
+ <td><tt>ApiUser</tt> must be supplied, or the provided key does not have access to the supplied user</td>
97
+ </tr>
98
+ <tr>
99
+ <td><tt>401</tt></td>
100
+ <td><tt>1020</tt></td>
101
+ <td><tt></tt></td>
102
+ <td>Session token has expired</td>
103
+ </tr>
104
+ <tr>
105
+ <td><tt>403</tt></td>
106
+ <td><tt>1030</tt></td>
107
+ <td><tt></tt></td>
108
+ <td>SSL required for this type of request</td>
109
+ </tr>
110
+ <tr>
111
+ <td><tt>400</tt></td>
112
+ <td><tt>1035</tt></td>
113
+ <td><tt></tt></td>
114
+ <td>POST data not supplied as valid JSON. Issued if the <tt>Content-Type</tt> header is not <tt>application/json/</tt> and/or if the POST data is not in valid JSON format.</td>
115
+ </tr>
116
+ <tr>
117
+ <td><tt>400</tt></td>
118
+ <td><tt>1040</tt></td>
119
+ <td><tt></tt></td>
120
+ <td>The <tt>_filter</tt> syntax was invalid or a specified field to search on does not exist</td>
121
+ </tr>
122
+ <tr>
123
+ <td><tt>400</tt></td>
124
+ <td><tt>1050</tt></td>
125
+ <td><tt></tt></td>
126
+ <td>(message varies) A required parameter was not provided</td>
127
+ </tr>
128
+ <tr>
129
+ <td><tt>400</tt></td>
130
+ <td><tt>1053</tt></td>
131
+ <td><tt></tt></td>
132
+ <td>(message varies) A parameter was provided but does not adhere to constraints</td>
133
+ </tr>
134
+ <tr>
135
+ <td><tt>409</tt></td>
136
+ <td><tt>1055</tt></td>
137
+ <td><tt></tt></td>
138
+ <td>(message varies)Issued when a write is requested that will conflict with existing data. For example, adding a new contact with an e-mail that already exists.</td>
139
+ </tr>
140
+ <tr>
141
+ <td><tt>403</tt></td>
142
+ <td><tt>1500</tt></td>
143
+ <td><tt></tt></td>
144
+ <td>The resource is not available at the current API key's service level. For example, this error applies if a user attempts to access the IDX Links API via a free API key. </td>
145
+ </tr>
146
+ <tr>
147
+ <td><tt>503</tt></td>
148
+ <td><tt>1550</tt></td>
149
+ <td><tt></tt></td>
150
+ <td>Over rate limit</td>
151
+ </tbody>
152
+ </table>
153
+
data/Rakefile ADDED
@@ -0,0 +1,18 @@
1
+ require "rubygems"
2
+ require 'rubygems/user_interaction'
3
+ require 'flexmls_gems/tasks'
4
+ require 'flexmls_gems/tasks/spec'
5
+ require 'flexmls_gems/tasks/rdoc'
6
+
7
+ desc "Run all the tests"
8
+ task :default => :spec
9
+
10
+ desc "Generate (and test) supported Spark API paths and methods"
11
+ RSpec::Core::RakeTask.new(:api_support) do |t|
12
+ t.rspec_opts = ["--require spec/formatters/api_support_formatter",
13
+ "--format ApiSupportFormatter",
14
+ "--color",
15
+ "--tag support"]
16
+ t.pattern = 'spec/unit/spark_api/models/**/*_spec.rb'
17
+ t.verbose = false
18
+ end
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 1.0.0
data/bin/spark_api ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env ruby
2
+ # File: bin/spark_api
3
+
4
+ require File.dirname(__FILE__) + '/../lib/spark_api/cli'
5
+
6
+ SparkApi::CLI::ConsoleCLI.execute(STDOUT, ARGV)
7
+
8
+
data/bin/spark_api~ ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env ruby
2
+ # File: bin/flexmls_api
3
+
4
+ require File.dirname(__FILE__) + '/../lib/flexmls_api/cli'
5
+
6
+ FlexmlsApi::CLI::ConsoleCLI.execute(STDOUT, ARGV)
7
+
8
+
data/lib/spark_api.rb ADDED
@@ -0,0 +1,46 @@
1
+ require 'rubygems'
2
+ require 'json'
3
+ require 'logger'
4
+
5
+ require 'spark_api/version'
6
+ require 'spark_api/configuration'
7
+ require 'spark_api/multi_client'
8
+ require 'spark_api/authentication'
9
+ require 'spark_api/response'
10
+ require 'spark_api/paginate'
11
+ require 'spark_api/request'
12
+ require 'spark_api/connection'
13
+ require 'spark_api/client'
14
+ require 'spark_api/faraday'
15
+ require 'spark_api/primary_array'
16
+ require 'spark_api/models'
17
+
18
+ module SparkApi
19
+ extend Configuration
20
+ extend MultiClient
21
+
22
+ #:nocov:
23
+ def self.logger
24
+ if @logger.nil?
25
+ @logger = Logger.new(STDOUT)
26
+ @logger.level = Logger::INFO
27
+ end
28
+ @logger
29
+ end
30
+ #:nocov:
31
+
32
+ def self.client(opts={})
33
+ Thread.current[:spark_api_client] ||= SparkApi::Client.new(opts)
34
+ end
35
+
36
+ def self.method_missing(method, *args, &block)
37
+ return super unless (client.respond_to?(method))
38
+ client.send(method, *args, &block)
39
+ end
40
+
41
+ def self.reset
42
+ reset_configuration
43
+ Thread.current[:spark_api_client] = nil
44
+ end
45
+
46
+ end
@@ -0,0 +1,55 @@
1
+
2
+ require 'openssl'
3
+ require 'faraday'
4
+ require 'faraday_middleware'
5
+ require 'yajl'
6
+ require 'date'
7
+
8
+ require 'spark_api/authentication/base_auth'
9
+ require 'spark_api/authentication/api_auth'
10
+ require 'spark_api/authentication/oauth2'
11
+
12
+ module SparkApi
13
+ # =Authentication
14
+ # Mixin module for handling client authentication and reauthentication to the spark api. Makes
15
+ # use of the configured authentication mode (API Auth by default).
16
+ module Authentication
17
+
18
+ # Main authentication step. Run before any api request unless the user session exists and is
19
+ # still valid.
20
+ #
21
+ # *returns*
22
+ # The user session object when authentication succeeds
23
+ # *raises*
24
+ # SparkApi::ClientError when authentication fails
25
+ def authenticate
26
+ start_time = Time.now
27
+ request_time = Time.now - start_time
28
+ new_session = @authenticator.authenticate
29
+ SparkApi.logger.info("[#{(request_time * 1000).to_i}ms]")
30
+ SparkApi.logger.debug("Session: #{new_session.inspect}")
31
+ new_session
32
+ end
33
+
34
+ # Test to see if there is an active session
35
+ def authenticated?
36
+ @authenticator.authenticated?
37
+ end
38
+
39
+ # Delete the current session
40
+ def logout
41
+ SparkApi.logger.info("Logging out.")
42
+ @authenticator.logout
43
+ end
44
+
45
+ # Fetch the active session object
46
+ def session
47
+ @authenticator.session
48
+ end
49
+ # Save the active session object
50
+ def session=(active_session)
51
+ @authenticator.session=active_session
52
+ end
53
+
54
+ end
55
+ end