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
@@ -0,0 +1,158 @@
1
+ require 'optparse'
2
+
3
+ if ENV["SPARK_API_CONSOLE"].nil?
4
+ require 'spark_api'
5
+ else
6
+ puts "Enabling console mode for local gem"
7
+ Bundler.require(:default, "development") if defined?(Bundler)
8
+ path = File.expand_path(File.dirname(__FILE__) + "/../../../lib/")
9
+ $LOAD_PATH.unshift(path) unless $LOAD_PATH.include?(path)
10
+ require path + '/spark_api'
11
+ end
12
+
13
+ module SparkApi
14
+ module CLI
15
+ class ConsoleCLI
16
+ OPTIONS_ENV = {
17
+ :endpoint => "API_ENDPOINT",
18
+ # OAUTH2 Options
19
+ :access_uri => "ACCESS_URI",
20
+ :username=> "USERNAME",
21
+ :password=> "PASSWORD",
22
+ :client_id=> "CLIENT_ID",
23
+ :client_secret=> "CLIENT_SECRET",
24
+ # API AUTH Options
25
+ :api_key => "API_KEY",
26
+ :api_secret => "API_SECRET",
27
+ :api_user => "API_USER",
28
+ # OTHER
29
+ :debug=> "DEBUG",
30
+ :console => "SPARK_API_CONSOLE" # not a public option, meant to distinguish bin/spark_api and script/console
31
+ }
32
+
33
+ def self.execute(stdout, arguments=[])
34
+ options = setup_options(stdout,arguments)
35
+ libs = " -r irb/completion"
36
+ # Perhaps use a console_lib to store any extra methods I may want available in the cosole
37
+ libs << (options[:oauth2] ? setup_oauth2 : setup_api_auth)
38
+
39
+ bundler = (options[:console] ? "bundle exec" : "")
40
+ cmd = "#{export_env(options)} #{bundler} #{irb} #{libs} --simple-prompt"
41
+ puts "Loading spark_api gem..."
42
+ exec "#{cmd}"
43
+ end
44
+
45
+ def self.irb()
46
+ RUBY_PLATFORM =~ /(:?mswin|mingw)/ ? 'irb.bat' : 'irb'
47
+ end
48
+
49
+ private
50
+ def self.setup_options(stdout,arguments)
51
+ env_options = {
52
+ :oauth2 => false,
53
+ :endpoint => ENV[OPTIONS_ENV[:endpoint]],
54
+ # OAUTH2 Options
55
+ :access_uri => ENV[OPTIONS_ENV[:access_uri]],
56
+ :username=> ENV[OPTIONS_ENV[:username]],
57
+ :password=> ENV[OPTIONS_ENV[:password]],
58
+ :client_id=> ENV[OPTIONS_ENV[:client_id]],
59
+ :client_secret=> ENV[OPTIONS_ENV[:client_secret]],
60
+ # API AUTH Options
61
+ :api_key => ENV[OPTIONS_ENV[:api_key]],
62
+ :api_secret => ENV[OPTIONS_ENV[:api_secret]],
63
+ :api_user => ENV[OPTIONS_ENV[:api_user]],
64
+ :console => ENV[OPTIONS_ENV[:console]]
65
+ }
66
+ cli_options = {}
67
+ file_options = {}
68
+ parser = OptionParser.new do |opts|
69
+ opts.banner = <<-BANNER.gsub(/^ /,'')
70
+ #{version}
71
+ SparkApi Client Console - http://www.flexmls.com/developers/api/
72
+
73
+ Usage: #{File.basename($0)} [options]
74
+
75
+ Environment Variables: some options (as indicated below), will default to values of keys set in the environment.
76
+
77
+ Options are:
78
+ BANNER
79
+ opts.separator ""
80
+ opts.on("-o","--oauth2",
81
+ "Run the API using OAuth2 credentials. The client defaults to using the Spark API authentication mode for access. ",
82
+ "See http://www.flexmls.com/developers/api/api-services/authentication/ for more information on authentication types.",
83
+ "Default: false") { |arg| cli_options[:oauth2] = arg }
84
+ opts.on("-e","--endpoint ENDPOINT",
85
+ "URI of the API.",
86
+ "Default: ENV['#{OPTIONS_ENV[:endpoint]}']") { |arg| cli_options[:endpoint] = arg }
87
+
88
+ # OAUTH2
89
+ opts.on("--client_id CLIENT_ID",
90
+ "OAuth2 client id",
91
+ "Default: ENV['#{OPTIONS_ENV[:client_id]}']") { |arg| cli_options[:client_id] = arg }
92
+ opts.on("--client_secret CLIENT_SECRET",
93
+ "OAuth2 client secret",
94
+ "Default: ENV['#{OPTIONS_ENV[:client_secret]}']") { |arg| cli_options[:client_secret] = arg }
95
+ opts.on("-u","--username USERNAME",
96
+ "OAuth2 username",
97
+ "Default: ENV['#{OPTIONS_ENV[:username]}']") { |arg| cli_options[:username] = arg }
98
+ opts.on("-p","--password PASSWORD",
99
+ "OAuth2 password",
100
+ "Default: ENV['#{OPTIONS_ENV[:password]}']") { |arg| cli_options[:password] = arg }
101
+ opts.on("--access_uri ACCESS_URI",
102
+ "OAuth2 path for granting access to the application",
103
+ "Default: ENV['#{OPTIONS_ENV[:access_uri]}']") { |arg| cli_options[:access_uri] = arg }
104
+
105
+ # API AUTH
106
+ opts.on("--api_key API_KEY",
107
+ "Authentication key for running the api using the default api authentication",
108
+ "Default: ENV['#{OPTIONS_ENV[:api_key]}']") { |arg| cli_options[:api_key] = arg }
109
+ opts.on("--api_secret API_SECRET",
110
+ "API secret for the api key",
111
+ "Default: ENV['#{OPTIONS_ENV[:api_secret]}']") { |arg| cli_options[:api_secret] = arg }
112
+ opts.on("--api_user API_USER",
113
+ "ID of the Spark user to run the client as.",
114
+ "Default: ENV['#{OPTIONS_ENV[:api_user]}']") { |arg| cli_options[:api_user] = arg }
115
+
116
+ opts.on("-f", "--file FILE",
117
+ "Load configuration for yaml file.") { |arg| file_options = parse_file_options(arg) }
118
+ opts.on("-d", "--debug",
119
+ "Show detailed request logging information.") { |arg| cli_options[:debug] = arg }
120
+ opts.on("-v", "--version",
121
+ "Show client version.") { stdout.puts version; exit }
122
+ opts.on("-h", "--help",
123
+ "Show this help message.") { stdout.puts opts; exit }
124
+ opts.parse!(arguments)
125
+
126
+ end
127
+ options = env_options.merge(file_options.merge(cli_options))
128
+ return options
129
+ end
130
+
131
+ def self.setup_api_auth
132
+ " -r #{File.dirname(__FILE__) + '/../../lib/spark_api/cli/api_auth.rb'}"
133
+ end
134
+
135
+ def self.setup_oauth2
136
+ " -r #{File.dirname(__FILE__) + '/../../lib/spark_api/cli/oauth2.rb'}"
137
+ end
138
+
139
+ def self.export_env(options)
140
+ run_env = ""
141
+ OPTIONS_ENV.each do |k,v|
142
+ run_env << " #{v}=\"#{options[k]}\"" unless options[k].nil?
143
+ end
144
+ run_env
145
+ end
146
+
147
+ private
148
+ def self.parse_file_options(file)
149
+ yaml = SparkApi::Configuration::YamlConfig.new(file)
150
+ return {:oauth2 => yaml.oauth2}.merge(yaml.client_keys.merge(yaml.oauth2_keys))
151
+ end
152
+
153
+ def self.version
154
+ "SparkApi v#{SparkApi::VERSION}"
155
+ end
156
+ end
157
+ end
158
+ end
@@ -0,0 +1,8 @@
1
+ require File.dirname(__FILE__) + "/../cli/setup"
2
+
3
+ SparkApi.configure do |config|
4
+ config.api_key = ENV["API_KEY"]
5
+ config.api_secret = ENV["API_SECRET"]
6
+ config.api_user = ENV["API_USER"] if ENV["API_USER"]
7
+ config.endpoint = ENV["API_ENDPOINT"] if ENV["API_ENDPOINT"]
8
+ end
@@ -0,0 +1,8 @@
1
+ require File.dirname(__FILE__) + "/../cli/setup"
2
+
3
+ FlexmlsApi.configure do |config|
4
+ config.api_key = ENV["API_KEY"]
5
+ config.api_secret = ENV["API_SECRET"]
6
+ config.api_user = ENV["API_USER"] if ENV["API_USER"]
7
+ config.endpoint = ENV["API_ENDPOINT"] if ENV["API_ENDPOINT"]
8
+ end
@@ -0,0 +1,14 @@
1
+ require File.dirname(__FILE__) + "/../cli/setup"
2
+
3
+ SparkApi.configure do |config|
4
+ config.oauth2_provider = SparkApi::Authentication::OAuth2Impl::PasswordProvider.new(
5
+ :authorization_uri=> ENV["AUTH_URI"],
6
+ :access_uri => ENV["ACCESS_URI"],
7
+ :username=> ENV["USERNAME"],
8
+ :password=> ENV["PASSWORD"],
9
+ :client_id=> ENV["CLIENT_ID"],
10
+ :client_secret=> ENV["CLIENT_SECRET"]
11
+ )
12
+ config.authentication_mode = SparkApi::Authentication::OAuth2
13
+ config.endpoint = ENV["API_ENDPOINT"] if ENV["API_ENDPOINT"]
14
+ end
@@ -0,0 +1,14 @@
1
+ require File.dirname(__FILE__) + "/../cli/setup"
2
+
3
+ FlexmlsApi.configure do |config|
4
+ config.oauth2_provider = FlexmlsApi::Authentication::OAuth2Impl::PasswordProvider.new(
5
+ :authorization_uri=> ENV["AUTH_URI"],
6
+ :access_uri => ENV["ACCESS_URI"],
7
+ :username=> ENV["USERNAME"],
8
+ :password=> ENV["PASSWORD"],
9
+ :client_id=> ENV["CLIENT_ID"],
10
+ :client_secret=> ENV["CLIENT_SECRET"]
11
+ )
12
+ config.authentication_mode = FlexmlsApi::Authentication::OAuth2
13
+ config.endpoint = ENV["API_ENDPOINT"] if ENV["API_ENDPOINT"]
14
+ end
@@ -0,0 +1,47 @@
1
+ require "rubygems"
2
+ require 'pp'
3
+ require 'irb/ext/save-history'
4
+ IRB.conf[:SAVE_HISTORY] = 1000
5
+ IRB.conf[:HISTORY_FILE] = "#{ENV['HOME']}/.spark-api-history"
6
+
7
+ if ENV["SPARK_API_CONSOLE"].nil?
8
+ require 'spark_api'
9
+ else
10
+ puts "Enabling console mode for local gem"
11
+ Bundler.require(:default, "development") if defined?(Bundler)
12
+ path = File.expand_path(File.dirname(__FILE__) + "/../../../lib/")
13
+ $LOAD_PATH.unshift(path) unless $LOAD_PATH.include?(path)
14
+ require path + '/spark_api'
15
+ end
16
+
17
+ IRB.conf[:AUTO_INDENT]=true
18
+ IRB.conf[:PROMPT][:SPARK]= {
19
+ :PROMPT_I => "SparkApi:%03n:%i> ",
20
+ :PROMPT_S => "SparkApi:%03n:%i%l ",
21
+ :PROMPT_C => "SparkApi:%03n:%i* ",
22
+ :RETURN => "%s\n"
23
+ }
24
+
25
+ IRB.conf[:PROMPT_MODE] = :SPARK
26
+
27
+ path = File.expand_path(File.dirname(__FILE__) + "/../../../lib/")
28
+ $LOAD_PATH.unshift(path) unless $LOAD_PATH.include?(path)
29
+ require path + '/spark_api'
30
+
31
+ module SparkApi
32
+ def self.logger
33
+ if @logger.nil?
34
+ @logger = Logger.new(STDOUT)
35
+ @logger.level = ENV["DEBUG"].nil? ? Logger::WARN : Logger::DEBUG
36
+ end
37
+ @logger
38
+ end
39
+ end
40
+
41
+ SparkApi.logger.info("Client configured!")
42
+
43
+ include SparkApi::Models
44
+
45
+ def c
46
+ SparkApi.client
47
+ end
@@ -0,0 +1,47 @@
1
+ require "rubygems"
2
+ require 'pp'
3
+ require 'irb/ext/save-history'
4
+ IRB.conf[:SAVE_HISTORY] = 1000
5
+ IRB.conf[:HISTORY_FILE] = "#{ENV['HOME']}/.flexmls-api-history"
6
+
7
+ if ENV["FLEXMLS_API_CONSOLE"].nil?
8
+ require 'flexmls_api'
9
+ else
10
+ puts "Enabling console mode for local gem"
11
+ Bundler.require(:default, "development") if defined?(Bundler)
12
+ path = File.expand_path(File.dirname(__FILE__) + "/../../../lib/")
13
+ $LOAD_PATH.unshift(path) unless $LOAD_PATH.include?(path)
14
+ require path + '/flexmls_api'
15
+ end
16
+
17
+ IRB.conf[:AUTO_INDENT]=true
18
+ IRB.conf[:PROMPT][:FLEXMLS]= {
19
+ :PROMPT_I => "flexmlsApi:%03n:%i> ",
20
+ :PROMPT_S => "flexmlsApi:%03n:%i%l ",
21
+ :PROMPT_C => "flexmlsApi:%03n:%i* ",
22
+ :RETURN => "%s\n"
23
+ }
24
+
25
+ IRB.conf[:PROMPT_MODE] = :FLEXMLS
26
+
27
+ path = File.expand_path(File.dirname(__FILE__) + "/../../../lib/")
28
+ $LOAD_PATH.unshift(path) unless $LOAD_PATH.include?(path)
29
+ require path + '/flexmls_api'
30
+
31
+ module FlexmlsApi
32
+ def self.logger
33
+ if @logger.nil?
34
+ @logger = Logger.new(STDOUT)
35
+ @logger.level = ENV["DEBUG"].nil? ? Logger::WARN : Logger::DEBUG
36
+ end
37
+ @logger
38
+ end
39
+ end
40
+
41
+ FlexmlsApi.logger.info("Client configured!")
42
+
43
+ include FlexmlsApi::Models
44
+
45
+ def c
46
+ FlexmlsApi.client
47
+ end
@@ -0,0 +1,27 @@
1
+ module SparkApi
2
+ # =API Client
3
+ # Main class to setup and run requests on the API. A default client is accessible globally as
4
+ # SparkApi::client if the global configuration has been set as well. Otherwise, this class may
5
+ # be instanciated separately with the configuration information.
6
+ class Client
7
+ include Connection
8
+ include Authentication
9
+ include Request
10
+
11
+ attr_accessor :authenticator
12
+ attr_accessor *Configuration::VALID_OPTION_KEYS
13
+
14
+ # Constructor bootstraps the client with configuration and authorization class.
15
+ # options - see Configuration::VALID_OPTION_KEYS
16
+ # auth_klass - subclass of Authentication::BaseAuth Defaults to the original api auth system.
17
+ def initialize(options={}, auth_klass=ApiAuth)
18
+ options = SparkApi.options.merge(options)
19
+ Configuration::VALID_OPTION_KEYS.each do |key|
20
+ send("#{key}=", options[key])
21
+ end
22
+ # Instanciate the authenication class passed in.
23
+ @authenticator = authentication_mode.send("new", self)
24
+ end
25
+
26
+ end
27
+ end
@@ -0,0 +1,54 @@
1
+ module SparkApi
2
+ module Configuration
3
+
4
+ # valid configuration options
5
+ VALID_OPTION_KEYS = [:api_key, :api_secret, :api_user, :endpoint, :user_agent, :version, :ssl, :oauth2_provider, :authentication_mode].freeze
6
+ OAUTH2_KEYS = [:authorization_uri, :access_uri, :client_id, :client_secret,
7
+ # Requirements for authorization_code grant type
8
+ :redirect_uri,
9
+ # Requirements for password grant type
10
+ :username, :password
11
+ ]
12
+
13
+ require File.expand_path('../configuration/yaml', __FILE__)
14
+
15
+ DEFAULT_API_KEY = nil
16
+ DEFAULT_API_SECRET = nil
17
+ DEFAULT_API_USER = nil
18
+ DEFAULT_ENDPOINT = 'https://api.sparkapi.com'
19
+ DEFAULT_VERSION = 'v1'
20
+ DEFAULT_USER_AGENT = "Spark API Ruby Gem #{VERSION}"
21
+ DEFAULT_SSL = true
22
+ DEFAULT_OAUTH2 = nil
23
+
24
+ X_SPARK_API_USER_AGENT = "X-SparkApi-User-Agent"
25
+
26
+ attr_accessor *VALID_OPTION_KEYS
27
+ def configure
28
+ yield self
29
+ end
30
+
31
+ def self.extended(base)
32
+ base.reset_configuration
33
+ end
34
+
35
+ def options
36
+ VALID_OPTION_KEYS.inject({}) do |opt,key|
37
+ opt.merge(key => send(key))
38
+ end
39
+ end
40
+
41
+ def reset_configuration
42
+ self.api_key = DEFAULT_API_KEY
43
+ self.api_secret = DEFAULT_API_SECRET
44
+ self.api_user = DEFAULT_API_USER
45
+ self.authentication_mode = SparkApi::Authentication::ApiAuth
46
+ self.endpoint = DEFAULT_ENDPOINT
47
+ self.oauth2_provider = DEFAULT_OAUTH2
48
+ self.user_agent = DEFAULT_USER_AGENT
49
+ self.ssl = DEFAULT_SSL
50
+ self.version = DEFAULT_VERSION
51
+ self
52
+ end
53
+ end
54
+ end
@@ -0,0 +1,54 @@
1
+ module SparkApi
2
+ module Configuration
3
+
4
+ # valid configuration options
5
+ VALID_OPTION_KEYS = [:api_key, :api_secret, :api_user, :endpoint, :user_agent, :version, :ssl, :oauth2_provider, :authentication_mode].freeze
6
+ OAUTH2_KEYS = [:authorization_uri, :access_uri, :client_id, :client_secret,
7
+ # Requirements for authorization_code grant type
8
+ :redirect_uri,
9
+ # Requirements for password grant type
10
+ :username, :password
11
+ ]
12
+
13
+ require File.expand_path('../configuration/yaml', __FILE__)
14
+
15
+ DEFAULT_API_KEY = nil
16
+ DEFAULT_API_SECRET = nil
17
+ DEFAULT_API_USER = nil
18
+ DEFAULT_ENDPOINT = 'https://api.sparkapi.com'
19
+ DEFAULT_VERSION = 'v1'
20
+ DEFAULT_USER_AGENT = "Spark API Ruby Gem #{VERSION}"
21
+ DEFAULT_SSL = true #false
22
+ DEFAULT_OAUTH2 = nil
23
+
24
+ X_SPARK_API_USER_AGENT = "X-SparkApi-User-Agent"
25
+
26
+ attr_accessor *VALID_OPTION_KEYS
27
+ def configure
28
+ yield self
29
+ end
30
+
31
+ def self.extended(base)
32
+ base.reset_configuration
33
+ end
34
+
35
+ def options
36
+ VALID_OPTION_KEYS.inject({}) do |opt,key|
37
+ opt.merge(key => send(key))
38
+ end
39
+ end
40
+
41
+ def reset_configuration
42
+ self.api_key = DEFAULT_API_KEY
43
+ self.api_secret = DEFAULT_API_SECRET
44
+ self.api_user = DEFAULT_API_USER
45
+ self.authentication_mode = SparkApi::Authentication::ApiAuth
46
+ self.endpoint = DEFAULT_ENDPOINT
47
+ self.oauth2_provider = DEFAULT_OAUTH2
48
+ self.user_agent = DEFAULT_USER_AGENT
49
+ self.ssl = DEFAULT_SSL
50
+ self.version = DEFAULT_VERSION
51
+ self
52
+ end
53
+ end
54
+ end