ipp_quickbase_devkit 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (239) hide show
  1. data/LICENSE +87 -0
  2. data/README.rdoc +112 -0
  3. data/doc/QuickBaseClient.rb.htm +1896 -0
  4. data/doc/ReleaseNotes.txt +43 -0
  5. data/doc/qbc.makeCSVFile.qbc +4 -0
  6. data/doc/qbc.makeCSVFile.rb +4 -0
  7. data/doc/quickbase_adapter.rb.htm +399 -0
  8. data/examples/cookbookfiles/QuickBaseAPICookbook.html +2590 -0
  9. data/examples/cookbookfiles/addChangeRemoveUserRole.rb +21 -0
  10. data/examples/cookbookfiles/addOrEditRecord.rb +10 -0
  11. data/examples/cookbookfiles/application_object.rb +55 -0
  12. data/examples/cookbookfiles/applyRubyFormulas.rb +10 -0
  13. data/examples/cookbookfiles/average.rb +27 -0
  14. data/examples/cookbookfiles/backupApplication.rb +8 -0
  15. data/examples/cookbookfiles/cacheSchemas.rb +53 -0
  16. data/examples/cookbookfiles/calculateRunningTotals.rb +11 -0
  17. data/examples/cookbookfiles/copyrecords.rb +73 -0
  18. data/examples/cookbookfiles/count.rb +26 -0
  19. data/examples/cookbookfiles/createRecordNavigatorHTML.rb +42 -0
  20. data/examples/cookbookfiles/createReportDashboard.rb +35 -0
  21. data/examples/cookbookfiles/createTable.rb +12 -0
  22. data/examples/cookbookfiles/deviation.rb +25 -0
  23. data/examples/cookbookfiles/downloadCookbook.rb +97 -0
  24. data/examples/cookbookfiles/downloadFile.rb +10 -0
  25. data/examples/cookbookfiles/downloadFilesToFolder.rb +81 -0
  26. data/examples/cookbookfiles/downloadToTextFile.rb +64 -0
  27. data/examples/cookbookfiles/dumpSchema.rb +11 -0
  28. data/examples/cookbookfiles/duplicateRecord.rb +8 -0
  29. data/examples/cookbookfiles/dynamicMethods.rb +33 -0
  30. data/examples/cookbookfiles/editRecords.rb +15 -0
  31. data/examples/cookbookfiles/findJohnsLast10Records.rb +17 -0
  32. data/examples/cookbookfiles/findRubyRecords.rb +17 -0
  33. data/examples/cookbookfiles/formatCurrency.rb +24 -0
  34. data/examples/cookbookfiles/formatDate.rb +10 -0
  35. data/examples/cookbookfiles/formatDuration.rb +27 -0
  36. data/examples/cookbookfiles/formatPercent.rb +24 -0
  37. data/examples/cookbookfiles/getAllValuesForFields.rb +18 -0
  38. data/examples/cookbookfiles/getAppDTMInfo.rb +29 -0
  39. data/examples/cookbookfiles/getApplicationVariable.rb +5 -0
  40. data/examples/cookbookfiles/getChildTableDBID.rb +11 -0
  41. data/examples/cookbookfiles/getColumnListForReport.rb +6 -0
  42. data/examples/cookbookfiles/getFieldChoices.rb +13 -0
  43. data/examples/cookbookfiles/getFieldIDs.rb +6 -0
  44. data/examples/cookbookfiles/getFieldNames.rb +6 -0
  45. data/examples/cookbookfiles/getLastModTime.rb +8 -0
  46. data/examples/cookbookfiles/getLastRecModTime.rb +8 -0
  47. data/examples/cookbookfiles/getNumRecords.rb +8 -0
  48. data/examples/cookbookfiles/getNumTables.rb +4 -0
  49. data/examples/cookbookfiles/getRecord.rb +5 -0
  50. data/examples/cookbookfiles/getRecordDisplayURL.rb +13 -0
  51. data/examples/cookbookfiles/getRecordsAddedToday.rb +20 -0
  52. data/examples/cookbookfiles/getRecordsAsJSON.rb +6 -0
  53. data/examples/cookbookfiles/getReportNames.rb +25 -0
  54. data/examples/cookbookfiles/getRoleInfo.rb +48 -0
  55. data/examples/cookbookfiles/getServerStatus.rb +11 -0
  56. data/examples/cookbookfiles/getSortListForReport.rb +6 -0
  57. data/examples/cookbookfiles/getTableIDs.rb +6 -0
  58. data/examples/cookbookfiles/getTableName.rb +8 -0
  59. data/examples/cookbookfiles/getTableNames.rb +25 -0
  60. data/examples/cookbookfiles/getTimeCreated.rb +8 -0
  61. data/examples/cookbookfiles/getTimeInMilliseconds.rb +5 -0
  62. data/examples/cookbookfiles/getUserInfo.rb +26 -0
  63. data/examples/cookbookfiles/getUserRole.rb +15 -0
  64. data/examples/cookbookfiles/intranet.rb +101 -0
  65. data/examples/cookbookfiles/isAverageField.rb +17 -0
  66. data/examples/cookbookfiles/isDbidString.rb +8 -0
  67. data/examples/cookbookfiles/isTotalField.rb +16 -0
  68. data/examples/cookbookfiles/iterateDBPages.rb +8 -0
  69. data/examples/cookbookfiles/iterateFilteredRecords.rb +12 -0
  70. data/examples/cookbookfiles/iterateJoinRecords.rb +68 -0
  71. data/examples/cookbookfiles/iterateRecordInfos.rb +8 -0
  72. data/examples/cookbookfiles/iterateRecords.rb +23 -0
  73. data/examples/cookbookfiles/iterateSummaryRecords.rb +13 -0
  74. data/examples/cookbookfiles/iterateUnionRecords.rb +38 -0
  75. data/examples/cookbookfiles/listAccessibleApplications.rb +6 -0
  76. data/examples/cookbookfiles/logRequestAndResponseXML.rb +8 -0
  77. data/examples/cookbookfiles/lookupFieldPropertyByName.rb +62 -0
  78. data/examples/cookbookfiles/lookupFieldTypeByName.rb +10 -0
  79. data/examples/cookbookfiles/makeCSVFile.rb +4 -0
  80. data/examples/cookbookfiles/makeSlideShow.rb +42 -0
  81. data/examples/cookbookfiles/makerecs.rb +64 -0
  82. data/examples/cookbookfiles/max.rb +26 -0
  83. data/examples/cookbookfiles/min.rb +26 -0
  84. data/examples/cookbookfiles/percent.rb +29 -0
  85. data/examples/cookbookfiles/printChildElements.rb +54 -0
  86. data/examples/cookbookfiles/printNewRecords.rb +12 -0
  87. data/examples/cookbookfiles/processRESTRequest.rb +21 -0
  88. data/examples/cookbookfiles/provisionAndInviteNewUser.rb +13 -0
  89. data/examples/cookbookfiles/purgeRecords.rb +15 -0
  90. data/examples/cookbookfiles/quickbase_adapter.rb.htm +397 -0
  91. data/examples/cookbookfiles/quickbase_record_finder.zip +0 -0
  92. data/examples/cookbookfiles/recordAndFieldIterator.rb +24 -0
  93. data/examples/cookbookfiles/runImport.rb +9 -0
  94. data/examples/cookbookfiles/runQuickBaseTwitterConnector.rb +41 -0
  95. data/examples/cookbookfiles/sendToQuickBase.rb +33 -0
  96. data/examples/cookbookfiles/setDBvar.rb +6 -0
  97. data/examples/cookbookfiles/showRequestAndResponseXML.rb +8 -0
  98. data/examples/cookbookfiles/sqlQuery.rb +11 -0
  99. data/examples/cookbookfiles/stopOnError.rb +10 -0
  100. data/examples/cookbookfiles/sum.rb +26 -0
  101. data/examples/cookbookfiles/twitterFromQuickBase.rb +42 -0
  102. data/examples/cookbookfiles/twitterWithQuickBase.rb +36 -0
  103. data/examples/cookbookfiles/uploadCSVData.rb +20 -0
  104. data/examples/cookbookfiles/uploadExcelData.rb +22 -0
  105. data/examples/cookbookfiles/uploadFileEveryHour.rb +18 -0
  106. data/examples/cookbookfiles/uploadFileIntoNewRecord.rb +8 -0
  107. data/examples/cookbookfiles/uploadFilesFromFolder.exe +0 -0
  108. data/examples/cookbookfiles/uploadFilesFromFolder.rb +69 -0
  109. data/examples/cookbookfiles/useCompanyURL.rb +12 -0
  110. data/examples/cookbookfiles/userRoles.rb +49 -0
  111. data/examples/cookbookfiles/watchCommunityForum.rb +5 -0
  112. data/examples/cookbookfiles/wikifyTable.rb +29 -0
  113. data/examples/cookbookfiles/xmlShortcuts.rb +33 -0
  114. data/examples/pmp/app/controllers/application.rb +7 -0
  115. data/examples/pmp/app/controllers/contacts_controller.rb +8 -0
  116. data/examples/pmp/app/controllers/document_library_controller.rb +2 -0
  117. data/examples/pmp/app/controllers/issues_controller.rb +5 -0
  118. data/examples/pmp/app/controllers/projects_controller.rb +22 -0
  119. data/examples/pmp/app/controllers/resources_controller.rb +2 -0
  120. data/examples/pmp/app/controllers/tasks_controller.rb +13 -0
  121. data/examples/pmp/app/controllers/time_cards_controller.rb +5 -0
  122. data/examples/pmp/app/helpers/application_helper.rb +3 -0
  123. data/examples/pmp/app/helpers/contacts_helper.rb +2 -0
  124. data/examples/pmp/app/helpers/document_library_helper.rb +2 -0
  125. data/examples/pmp/app/helpers/issues_helper.rb +2 -0
  126. data/examples/pmp/app/helpers/projects_helper.rb +2 -0
  127. data/examples/pmp/app/helpers/resources_helper.rb +2 -0
  128. data/examples/pmp/app/helpers/tasks_helper.rb +2 -0
  129. data/examples/pmp/app/helpers/time_cards_helper.rb +2 -0
  130. data/examples/pmp/app/models/contacts.rb +26 -0
  131. data/examples/pmp/app/models/document_library.rb +2 -0
  132. data/examples/pmp/app/models/issues.rb +6 -0
  133. data/examples/pmp/app/models/projects.rb +26 -0
  134. data/examples/pmp/app/models/resources.rb +2 -0
  135. data/examples/pmp/app/models/tasks.rb +12 -0
  136. data/examples/pmp/app/models/time_cards.rb +7 -0
  137. data/examples/pmp/app/schemas/contacts.xml +1 -0
  138. data/examples/pmp/app/schemas/document_library.xml +1 -0
  139. data/examples/pmp/app/schemas/issues.xml +1 -0
  140. data/examples/pmp/app/schemas/pmp.xml +1 -0
  141. data/examples/pmp/app/schemas/projects.xml +1 -0
  142. data/examples/pmp/app/schemas/readme.txt +8 -0
  143. data/examples/pmp/app/schemas/resources.xml +1 -0
  144. data/examples/pmp/app/schemas/tasks.xml +1 -0
  145. data/examples/pmp/app/schemas/time_cards.xml +1 -0
  146. data/examples/pmp/app/views/contacts/companies.rhtml +31 -0
  147. data/examples/pmp/app/views/contacts/project_contacts.rhtml +31 -0
  148. data/examples/pmp/app/views/issues/filter_issues.rhtml +26 -0
  149. data/examples/pmp/app/views/layouts/application.rhtml +56 -0
  150. data/examples/pmp/app/views/projects/all_projects.rhtml +33 -0
  151. data/examples/pmp/app/views/projects/home.rhtml +11 -0
  152. data/examples/pmp/app/views/projects/my_open_projects.rhtml +27 -0
  153. data/examples/pmp/app/views/projects/open_projects.rhtml +44 -0
  154. data/examples/pmp/app/views/projects/project_sorted_by_company.rhtml +40 -0
  155. data/examples/pmp/app/views/projects/projects_sorted_by_priority.rhtml +30 -0
  156. data/examples/pmp/app/views/projects/updated_projects.rhtml +0 -0
  157. data/examples/pmp/app/views/tasks/all_tasks.rhtml +27 -0
  158. data/examples/pmp/app/views/tasks/search.rhtml +23 -0
  159. data/examples/pmp/app/views/tasks/search2.rhtml +23 -0
  160. data/examples/pmp/app/views/tasks/search3.rhtml +23 -0
  161. data/examples/pmp/app/views/time_cards/summary.rhtml +38 -0
  162. data/examples/pmp/config/boot.rb +45 -0
  163. data/examples/pmp/config/database.yml +30 -0
  164. data/examples/pmp/config/environment.rb +60 -0
  165. data/examples/pmp/config/environments/development.rb +21 -0
  166. data/examples/pmp/config/environments/production.rb +18 -0
  167. data/examples/pmp/config/environments/test.rb +19 -0
  168. data/examples/pmp/config/routes.rb +23 -0
  169. data/examples/pmp/db/migrate/001_create_projects.rb +10 -0
  170. data/examples/pmp/db/migrate/002_create_tasks.rb +10 -0
  171. data/examples/pmp/db/migrate/003_create_issues.rb +10 -0
  172. data/examples/pmp/db/migrate/004_create_document_libraries.rb +10 -0
  173. data/examples/pmp/db/migrate/005_create_resources.rb +10 -0
  174. data/examples/pmp/db/migrate/006_create_time_cards.rb +10 -0
  175. data/examples/pmp/db/migrate/007_create_contacts.rb +10 -0
  176. data/examples/pmp/public/404.html +30 -0
  177. data/examples/pmp/public/500.html +30 -0
  178. data/examples/pmp/public/app.index.html +277 -0
  179. data/examples/pmp/public/dispatch.cgi +10 -0
  180. data/examples/pmp/public/dispatch.fcgi +24 -0
  181. data/examples/pmp/public/dispatch.rb +10 -0
  182. data/examples/pmp/public/favicon.ico +0 -0
  183. data/examples/pmp/public/images/rails.png +0 -0
  184. data/examples/pmp/public/javascripts/application.js +2 -0
  185. data/examples/pmp/public/javascripts/controls.js +833 -0
  186. data/examples/pmp/public/javascripts/dragdrop.js +942 -0
  187. data/examples/pmp/public/javascripts/effects.js +1088 -0
  188. data/examples/pmp/public/javascripts/prototype.js +2515 -0
  189. data/examples/pmp/public/robots.txt +1 -0
  190. data/examples/pmp/test/fixtures/contacts.yml +5 -0
  191. data/examples/pmp/test/fixtures/document_libraries.yml +5 -0
  192. data/examples/pmp/test/fixtures/issues.yml +5 -0
  193. data/examples/pmp/test/fixtures/projects.yml +5 -0
  194. data/examples/pmp/test/fixtures/resources.yml +5 -0
  195. data/examples/pmp/test/fixtures/tasks.yml +5 -0
  196. data/examples/pmp/test/fixtures/time_cards.yml +5 -0
  197. data/examples/pmp/test/functional/contacts_controller_test.rb +18 -0
  198. data/examples/pmp/test/functional/document_library_controller_test.rb +18 -0
  199. data/examples/pmp/test/functional/issues_controller_test.rb +18 -0
  200. data/examples/pmp/test/functional/projects_controller_test.rb +18 -0
  201. data/examples/pmp/test/functional/resources_controller_test.rb +18 -0
  202. data/examples/pmp/test/functional/tasks_controller_test.rb +18 -0
  203. data/examples/pmp/test/functional/time_cards_controller_test.rb +18 -0
  204. data/examples/pmp/test/test_helper.rb +28 -0
  205. data/examples/pmp/test/unit/contacts_test.rb +10 -0
  206. data/examples/pmp/test/unit/document_library_test.rb +10 -0
  207. data/examples/pmp/test/unit/issues_test.rb +10 -0
  208. data/examples/pmp/test/unit/projects_test.rb +10 -0
  209. data/examples/pmp/test/unit/resources_test.rb +10 -0
  210. data/examples/pmp/test/unit/tasks_test.rb +10 -0
  211. data/examples/pmp/test/unit/time_cards_test.rb +10 -0
  212. data/lib/QuickBaseClient.rb +5054 -0
  213. data/lib/QuickBaseCommandLineClient.rb +401 -0
  214. data/lib/QuickBaseContactsAppBuilder.rb +419 -0
  215. data/lib/QuickBaseEmailer.rb +334 -0
  216. data/lib/QuickBaseEventNotifier.rb +592 -0
  217. data/lib/QuickBaseMisc.rb +96 -0
  218. data/lib/QuickBaseObjects.rb +566 -0
  219. data/lib/QuickBaseRSSGenerator.rb +286 -0
  220. data/lib/QuickBaseTextData.rb +545 -0
  221. data/lib/QuickBaseTwitterConnector.rb +300 -0
  222. data/lib/QuickBaseWebClient.rb +126 -0
  223. data/lib/WorkPlaceClient.rb +45 -0
  224. data/lib/qbc.makeCSVFile.qbc +4 -0
  225. data/lib/qbc.makeCSVFile.rb +17 -0
  226. data/lib/quickbase_adapter.rb +320 -0
  227. data/lib/runFieldEntryDialog.rb +151 -0
  228. data/lib/runOfflineFieldEntryDialog.rb +203 -0
  229. data/rakefile +100 -0
  230. data/test/run_tests.bat +7 -0
  231. data/test/spec_all_tests.rb +13 -0
  232. data/test/spec_smoke_tests.rb +58 -0
  233. data/test/spec_workplace_addrecord_test.rb +46 -0
  234. data/test/spec_workplace_base_test.rb +57 -0
  235. data/test/spec_workplace_editrecord_test.rb +38 -0
  236. data/test/spec_workplace_json_test.rb +38 -0
  237. data/test/spec_workplace_objects_test.rb +39 -0
  238. data/test/spec_workplace_smoke_tests.rb +45 -0
  239. metadata +353 -0
@@ -0,0 +1,300 @@
1
+ #--#####################################################################
2
+ # Copyright (c) 2009 Gareth Lewis and Intuit, Inc.
3
+ #
4
+ # All rights reserved. This program and the accompanying materials
5
+ # are made available under the terms of the Eclipse Public License v1.0
6
+ # which accompanies this distribution, and is available at
7
+ # http://www.opensource.org/licenses/eclipse-1.0.php
8
+ #
9
+ # Contributors:
10
+ # Gareth Lewis - Initial contribution.
11
+ # Intuit Partner Platform.
12
+ #++#####################################################################
13
+
14
+ require 'rubygems'
15
+ gem 'twitter4r', '>=0.3.0'
16
+ require 'twitter'
17
+
18
+ require 'QuickBaseClient'
19
+
20
+ module QuickBase
21
+
22
+ class TwitterConnector
23
+
24
+ #----------------------------------------------------------------
25
+ def initialize(options = {:get_friends_twitter_status => true,:get_direct_messages => true})
26
+ @options = options
27
+ [quickbase_username,quickbase_password,twitter_username,twitter_password].each{|option|
28
+ @options[option] ||= get_input(option)
29
+ }
30
+ get_connection_type
31
+ find_or_create_twitter_databases if get_quickbase_client
32
+ run if get_twitter_client
33
+ end
34
+
35
+ private
36
+
37
+ #----------------------------------------------------------------
38
+ def get_input(string)
39
+ ret = ""
40
+ while ret.length == 0
41
+ print "Please enter the #{string} to use for this session: "
42
+ ret = gets.chop
43
+ end
44
+ ret
45
+ end
46
+
47
+ #----------------------------------------------------------------
48
+ def get_quickbase_client
49
+ begin
50
+ @qbc = QuickBase::Client.new(@options[quickbase_username],@options[quickbase_password])
51
+ #@qbc.printRequestsAndResponses=true
52
+ rescue StandardError => error
53
+ puts "Error accessing QuickBase. Please check your username and password. (#{error})"
54
+ @qbc= nil
55
+ end
56
+ @qbc
57
+ end
58
+
59
+ #----------------------------------------------------------------
60
+ def get_twitter_client
61
+ begin
62
+ @tc = Twitter::Client.new(:login => @options[twitter_username],:password => @options[twitter_password])
63
+ rescue StandardError => error
64
+ puts "Error accessing Twitter. Please check your username and password. (#{error})"
65
+ @tc= nil
66
+ end
67
+ @tc
68
+ end
69
+
70
+ #----------------------------------------------------------------
71
+ def get_connection_type
72
+ puts "\n\nPlease enter a number to select the connection type:\n\n"
73
+ puts "1 - Send Twitter messages to QuickBase."
74
+ puts "2 - Send QuickBase messages to Twitter."
75
+ puts "3 - Exchange messages between QuickBase and Twitter."
76
+ puts "4 - Send automated replies from QuickBase to Twitter."
77
+ puts "5 - All the above.\n\n"
78
+ @options[connection_type] = ""
79
+ while !["1","2","3","4","5"].include?(@options[connection_type])
80
+ @options[connection_type] = gets.chop
81
+ end
82
+ puts "\n\n"
83
+ end
84
+
85
+ #----------------------------------------------------------------
86
+ def find_or_create_twitter_databases
87
+ message_database = "Twitter messages: #{@options[quickbase_username]} - #{@options[twitter_username]}"
88
+ @messages_dbid = @qbc.findDBByName(message_database)
89
+ if @messages_dbid.nil?
90
+ begin
91
+ @messages_dbid = @qbc.createDatabase(message_database, "Messages exchanged between QuickBase (#{@options['QuickBase username']}) and Twitter (#{@options['Twitter username']})." )
92
+ @qbc.addField(@messages_dbid, message_type, "text")
93
+ @qbc.addField(@messages_dbid, twitter_username, "text")
94
+ @qbc.addField(@messages_dbid, received_from_twitter, "text")
95
+ @qbc.addField(@messages_dbid, keyword, "text")
96
+ @qbc.addField(@messages_dbid, send_to_twitter, "text")
97
+ @qbc.addField(@messages_dbid, sent_to_twitter, "checkbox")
98
+ rescue StandardError => error
99
+ puts "Error creating Twitter messages database in QuickBase. (#{error})"
100
+ end
101
+ end
102
+ @qbc.getSchema(@messages_dbid)
103
+ @messages_dbid = @qbc.lookupChdbid(message_database)
104
+ @qbc.getSchema(@messages_dbid)
105
+ @fieldIDs = {}
106
+ @qbc.getFieldNames.each{|name|@fieldIDs[name]=@qbc.lookupFieldIDByName(name)}
107
+ end
108
+
109
+ #----------------------------------------------------------------
110
+ def run
111
+ @lastCheckTime = (Time.now-60)
112
+ loop {
113
+ nextCheckTime = Time.now
114
+ if ["1","3","5"].include?(@options[connection_type])
115
+ if @options[:get_my_twitter_status]
116
+ get_my_twitter_status
117
+ sleep(60)
118
+ end
119
+ if @options[:get_friends_twitter_status]
120
+ get_friends_twitter_status
121
+ sleep(60)
122
+ end
123
+ if @options[:get_direct_messages]
124
+ get_direct_messages
125
+ sleep(60)
126
+ end
127
+ end
128
+ if ["2","3","5"].include?(@options[connection_type])
129
+ send_messages_to_twitter
130
+ sleep(60)
131
+ end
132
+ if ["4","5"].include?(@options[connection_type])
133
+ get_direct_messages
134
+ sleep(60)
135
+ end
136
+
137
+ @lastCheckTime = nextCheckTime
138
+ }
139
+ end
140
+
141
+ #----------------------------------------------------------------
142
+ def get_my_twitter_status
143
+ get_twitter_status(:me)
144
+ end
145
+
146
+ #----------------------------------------------------------------
147
+ def get_friends_twitter_status
148
+ get_twitter_status(:friends)
149
+ end
150
+
151
+ #----------------------------------------------------------------
152
+ def get_public_twitter_status
153
+ get_twitter_status(:public)
154
+ end
155
+
156
+ #----------------------------------------------------------------
157
+ def get_twitter_status(who,twitter_options = {})
158
+ twitter_options["since"] ||= @lastCheckTime
159
+ puts "Getting '#{who}' Twitter Status since #{twitter_options["since"]}."
160
+ begin
161
+ @tc.timeline_for(who,twitter_options) {|status|
162
+ @qbc.clearFieldValuePairList
163
+ @qbc.addFieldValuePair(twitter_username,nil,nil,status.user.screen_name)
164
+ @qbc.addFieldValuePair(received_from_twitter,nil,nil,status.text)
165
+ @qbc.addFieldValuePair(message_type,nil,nil,"status")
166
+ @qbc.addRecord(@messages_dbid,@qbc.fvlist)
167
+ puts "Twitter status added to QuickBase: #{status.user.screen_name}: #{status.text}"
168
+ }
169
+ rescue Twitter::RESTError => error
170
+ #puts "Twitter exception handling timeline_for request: #{error}"
171
+ rescue StandardError => error
172
+ puts "Exception handling timeline_for request: #{error}"
173
+ end
174
+ end
175
+
176
+ #----------------------------------------------------------------
177
+ def get_direct_messages(twitter_options = {})
178
+ twitter_options["since"] ||= @lastCheckTime
179
+ puts "Getting Direct Messages from Twitter since #{twitter_options["since"]}."
180
+ begin
181
+ received_messages = @tc.messages(:received,twitter_options)
182
+ if received_messages
183
+ received_messages.each{|message|
184
+ if message.created_at > @lastCheckTime
185
+ sentAutomatedReply = false
186
+ if ["4","5"].include?(@options[connection_type])
187
+ if message.text[-1,1] == ':'
188
+ sentAutomatedReply = sendAutomatedReplyFromQuickBase(message.text,message.sender.screen_name)
189
+ else
190
+ sentAutomatedReply = processRESTRequest(message.text,message.sender.screen_name)
191
+ end
192
+ end
193
+ if !sentAutomatedReply
194
+ @qbc.clearFieldValuePairList
195
+ @qbc.addFieldValuePair(twitter_username,nil,nil,message.sender.screen_name)
196
+ @qbc.addFieldValuePair(received_from_twitter,nil,nil,message.text)
197
+ @qbc.addFieldValuePair(message_type,nil,nil,"message")
198
+ @qbc.addRecord(@messages_dbid,@qbc.fvlist)
199
+ puts "Twitter Direct Message added to QuickBase: #{message.sender.screen_name}: #{message.text}"
200
+ end
201
+ end
202
+ }
203
+ end
204
+ rescue Twitter::RESTError => error
205
+ puts "Twitter exception handling Twitter::Client.messages request: #{error}"
206
+ rescue StandardError => error
207
+ puts "Exception handling Twitter::Client.messages request: #{error}"
208
+ end
209
+ end
210
+
211
+ #----------------------------------------------------------------
212
+ def send_messages_to_twitter
213
+ timeToCompare = Misc.time_in_milliseconds(@lastCheckTime)
214
+ puts "Sending messages from QuickBase to Twitter added since #{@lastCheckTime}."
215
+ @qbc.iterateRecords(@messages_dbid,[date_created,record_ID,send_to_twitter,twitter_username],"{'1'.OAF.'today'}AND{'#{@fieldIDs[send_to_twitter]}'.XEX.''}AND{'#{@fieldIDs[sent_to_twitter]}'.XEX.'1'}"){|new_quickbase_record|
216
+ if new_quickbase_record[date_created].to_i > timeToCompare
217
+ begin
218
+ msgType = ""
219
+ recipient = ""
220
+ if new_quickbase_record[twitter_username]
221
+ msgType = "Direct Message"
222
+ recipient = new_quickbase_record[twitter_username].dup
223
+ Twitter::Message.create(:text => new_quickbase_record[send_to_twitter].dup,:recipient => new_quickbase_record[twitter_username].dup,:client => @tc)
224
+ else
225
+ msgType = "Status"
226
+ Twitter::Status.create(:text => new_quickbase_record[send_to_twitter].dup,:client => @tc)
227
+ end
228
+ @qbc.clearFieldValuePairList
229
+ @qbc.addFieldValuePair(sent_to_twitter,nil,nil,"1")
230
+ @qbc.editRecord(@messages_dbid,new_quickbase_record[record_ID],@qbc.fvlist)
231
+ puts "#{msgType} sent from QuickBase to Twitter: #{recipient} #{new_quickbase_record[send_to_twitter].dup}"
232
+ rescue Twitter::RESTError => error
233
+ puts "Twitter exception handling #{msgType}.create request: #{error}"
234
+ rescue StandardError => error
235
+ puts "Exception handling #{msgType}.create request: #{error}"
236
+ end
237
+ end
238
+ }
239
+ end
240
+
241
+ #-------------------------------------------------------------------------------------------------
242
+ def sendAutomatedReplyFromQuickBase(requestString, sendTo)
243
+ sent = false
244
+ @qbc.iterateRecords(@messages_dbid,[send_to_twitter],"{'#{@fieldIDs[keyword]}'.EX.'#{requestString}'}AND{'#{@fieldIDs[send_to_twitter]}'.XEX.''}"){|quickbase_record|
245
+ begin
246
+ response = "#{requestString}: #{quickbase_record[send_to_twitter].dup}"
247
+ Twitter::Message.create(:text => response,:recipient => sendTo,:client => @tc)
248
+ puts "Automated Direct Message sent to #{sendTo}: #{response}"
249
+ sent = true
250
+ rescue Twitter::RESTError => error
251
+ puts "Twitter exception handling Twitter::Message.create request: #{error}"
252
+ rescue StandardError => error
253
+ puts "Exception handling Twitter::Message.create request: #{error}"
254
+ end
255
+ }
256
+ sent
257
+ end
258
+
259
+ #----------------------------------------------------------------
260
+ def processRESTRequest(requestString, sendTo)
261
+ sent = false
262
+ reply = @qbc.processRESTRequest(requestString)
263
+ response = "#{requestString}: #{reply}"
264
+ begin
265
+ Twitter::Message.create(:text => response,:recipient => sendTo,:client => @tc)
266
+ puts "Automated Direct Message sent to #{sendTo}: #{response}"
267
+ sent = true
268
+ rescue Twitter::RESTError => error
269
+ puts "Twitter exception handling Twitter::Message.create request: #{error}"
270
+ rescue StandardError => error
271
+ puts "Exception handling Twitter::Message.create request: #{error}"
272
+ end
273
+ sent
274
+ end
275
+
276
+ #----------------------------------------------------------------
277
+ def quickbase_username() "Quickbase username" end
278
+ def quickbase_password() "Quickbase password" end
279
+ def twitter_username() "Twitter username" end
280
+ def twitter_password() "Twitter password" end
281
+ def connection_type() "Connection type" end
282
+ def message_type() "Message type" end
283
+ def keyword() "Keyword" end
284
+ def received_from_twitter() "Received from Twitter" end
285
+ def send_to_twitter() "Send to Twitter" end
286
+ def sent_to_twitter() "Sent?" end
287
+ def record_ID() "Record ID#" end
288
+ def date_created() "Date Created" end
289
+
290
+ end
291
+
292
+ end
293
+
294
+ def testQuickBaseTwitterConnector()
295
+ QuickBase::TwitterConnector.new
296
+ end
297
+
298
+ #testQuickBaseTwitterConnector
299
+
300
+
@@ -0,0 +1,126 @@
1
+ #--#####################################################################
2
+ # Copyright (c) 2009 Gareth Lewis and Intuit, Inc.
3
+ #
4
+ # All rights reserved. This program and the accompanying materials
5
+ # are made available under the terms of the Eclipse Public License v1.0
6
+ # which accompanies this distribution, and is available at
7
+ # http://www.opensource.org/licenses/eclipse-1.0.php
8
+ #
9
+ # Contributors:
10
+ # Gareth Lewis - Initial contribution.
11
+ # Intuit Partner Platform.
12
+ #++#####################################################################
13
+
14
+ require 'QuickBaseCommandlineClient'
15
+
16
+ module QuickBase
17
+
18
+ # class WebClient: a web server that responds to requests to run command files
19
+ # present on the local machine. This extends QuickBase via URLs on web pages.
20
+ #
21
+ # e.g. if there is an 'uploadSpreadsheet.qbc' command file next to this QuickBaseClient.rb
22
+ # file on your machine, it can be run from a web page by starting 'WebClient.new' on your
23
+ # machine and placing 'http://127.0.0.1:2358/qbc/uploadSpreadsheet.qbc' in a link on the
24
+ # web page.
25
+ #
26
+ # Any request that does not include "/qbc/" will shut down the server.
27
+ class WebClient < CommandLineClient
28
+
29
+ attr_reader :runNow, :running, :ipAddress, :port, :thread
30
+
31
+ def initialize( runNow = true, ipAddress = 'localhost', port = 2358 )
32
+ super()
33
+ @runNow = runNow
34
+ @doStop = @running = false
35
+ if @runNow
36
+ start( ipAddress, port )
37
+ else
38
+ @ipAddress, @port = ipAddress, port
39
+ end
40
+ end
41
+
42
+ def stop()
43
+ if @running and @thread
44
+ puts "------ #{Time.now} ------"
45
+ puts "------ Web client stopped ------"
46
+ Thread.kill( @thread )
47
+ @doStop = @running = @thread = nil
48
+ end
49
+ end
50
+
51
+ def start( ipAddress = 'localhost', port = 2358 )
52
+
53
+ stop if @running
54
+ @ipAddress, @port = ipAddress, port
55
+
56
+ @thread = Thread.new {
57
+
58
+ begin
59
+ server = TCPServer.new( ipAddress, port )
60
+ @running = true
61
+
62
+ puts "------ #{Time.now} ------"
63
+ puts "------ Web client started on #{ipAddress}:#{port} ------"
64
+
65
+ while ( session = server.accept )
66
+
67
+ request = session.gets
68
+
69
+ puts "------ #{Time.now} ------"
70
+ puts "Request: #{request}"
71
+
72
+ if request.include?( " /qbc/" )
73
+ commandFile = ""
74
+ requestParts = request.split( " " )
75
+ requestParts.each{ |requestPart|
76
+ if requestPart.include?( "/qbc/" )
77
+ commandFile = requestPart.split( "/" ).last
78
+ end
79
+ }
80
+ if commandFile.length > 1 and FileTest.readable?( commandFile )
81
+ puts "------ Attempting to run '#{commandFile}'."
82
+ run( commandFile )
83
+ puts "------ Finished running command file '#{commandFile}'."
84
+ session.print "HTTP/1.1 200/OK\r\nContent-type: text/html\r\n\r\n"
85
+ session.print "<html><head><META HTTP-EQUIV=\"Pragma\" CONTENT=\"no-cache\"></META></head><body><h1>"
86
+ session.print "Finished running command file '#{commandFile}'.<br>Please press the browser's Back button"
87
+ session.print "</h1></body></html>\r\n"
88
+ else
89
+ puts "------ '#{commandFile}' is not a valid command file."
90
+ session.print "HTTP/1.1 200/OK\r\nContent-type: text/html\r\n\r\n"
91
+ session.print "<html><head><META HTTP-EQUIV=\"Pragma\" CONTENT=\"no-cache\"></META></head><body><h1>'#{commandFile}' is not a valid command file.</h1></body></html>\r\n"
92
+ end
93
+ session.close
94
+ elsif not request.include?( "GET /favicon.ico " )
95
+ session.print "HTTP/1.1 200/OK\r\nContent-type: text/html\r\n\r\n"
96
+ session.print "<html><head><META HTTP-EQUIV=\"Pragma\" CONTENT=\"no-cache\"></META></head><body><h1>Invalid request.</h1></body></html>\r\n"
97
+ session.close
98
+ stop()
99
+ end
100
+ end
101
+ rescue StandardError => e
102
+ puts "Error: #{e}"
103
+ end
104
+ }
105
+ @thread.join
106
+ @running
107
+ end
108
+
109
+ end #class WebClient -------------------------------------
110
+
111
+ end #module QuickBase ---------------------------------------------
112
+
113
+ # Run a command line client as a local web server that runs command files.
114
+ # e.g. ruby QuickBaseWebClient.rb runwebclient
115
+ if __FILE__ == $0 and ARGV.length > 0
116
+ if ARGV[0] == "runwebclient"
117
+ ARGV.shift
118
+ if ARGV.length > 1
119
+ qbwc = QuickBase::WebClient.new( true, ARGV[0], ARGV[1] )
120
+ elsif ARGV.length > 0
121
+ qbwc = QuickBase::WebClient.new( true, ARGV[0] )
122
+ else
123
+ qbwc = QuickBase::WebClient.new( true )
124
+ end
125
+ end
126
+ end
@@ -0,0 +1,45 @@
1
+ #--#####################################################################
2
+ # Copyright (c) 2009 Gareth Lewis and Intuit, Inc.
3
+ #
4
+ # All rights reserved. This program and the accompanying materials
5
+ # are made available under the terms of the Eclipse Public License v1.0
6
+ # which accompanies this distribution, and is available at
7
+ # http://www.opensource.org/licenses/eclipse-1.0.php
8
+ #
9
+ # Contributors:
10
+ # Gareth Lewis - Initial contribution.
11
+ # Intuit Partner Platform.
12
+ #++#####################################################################
13
+
14
+ require 'QuickBaseClient'
15
+
16
+ module QuickBase
17
+ # Client that defaults the host to workplace.intuit.com
18
+ class WorkPlaceClient < Client
19
+ def initialize(username=nil,password=nil,appname=nil,useSSL=true,printRequestsAndResponses=false,
20
+ stopOnError=false,showTrace=false,apptoken=nil,debugHTTPConnection=false,proxy_options = nil)
21
+ super(username,password,appname,useSSL,printRequestsAndResponses,stopOnError,showTrace,"workplace",apptoken,debugHTTPConnection,"intuit",proxy_options)
22
+ end
23
+ def WorkPlaceClient.init(options)
24
+ options ||= {}
25
+ options["useSSL"] ||= true
26
+ options["printRequestsAndResponses"] ||= false
27
+ options["stopOnError"] ||= false
28
+ options["showTrace"] ||= false
29
+ options["debugHTTPConnection"] ||= false
30
+ options["proxy_options"] ||= nil
31
+ instance = WorkPlaceClient.new( options["username"],
32
+ options["password"],
33
+ options["appname"],
34
+ options["useSSL"],
35
+ options["printRequestsAndResponses"],
36
+ options["stopOnError"],
37
+ options["showTrace"],
38
+ options["apptoken"],
39
+ options["debugHTTPConnection"],
40
+ options["proxy_options"])
41
+ end
42
+ end
43
+ end
44
+
45
+