1 <?xml version=
"1.0" encoding=
"iso-8859-1"?>
3 PUBLIC
"-//W3C//DTD XHTML 1.0 Transitional//EN"
4 "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
6 <html xmlns=
"http://www.w3.org/1999/xhtml" xml:
lang=
"en" lang=
"en">
8 <title>Class: SlingshotSyncController
</title>
9 <meta http-equiv=
"Content-Type" content=
"text/html; charset=iso-8859-1" />
10 <meta http-equiv=
"Content-Script-Type" content=
"text/javascript" />
11 <link rel=
"stylesheet" href=
".././rdoc-style.css" type=
"text/css" media=
"screen" />
12 <script type=
"text/javascript">
15 function popupCode( url ) {
16 window.open(url,
"Code",
"resizable=yes,scrollbars=yes,toolbar=no,status=no,height=150,width=400")
19 function toggleCode( id ) {
20 if ( document.getElementById )
21 elem = document.getElementById( id );
22 else if ( document.all )
23 elem = eval(
"document.all." + id );
27 elemStyle = elem.style;
29 if ( elemStyle.display !=
"block" ) {
30 elemStyle.display =
"block"
32 elemStyle.display =
"none"
38 // Make codeblocks hidden by default
39 document.writeln(
"<style type=\"text/css\
">div.method-source-code { display: none }</style>" )
49 <div id=
"classHeader">
50 <table class=
"header-table">
51 <tr class=
"top-aligned-row">
52 <td><strong>Class
</strong></td>
53 <td class=
"class-name-in-header">SlingshotSyncController
</td>
55 <tr class=
"top-aligned-row">
56 <td><strong>In:
</strong></td>
58 <a href=
"../files/app/controllers/slingshot_sync_controller_rb.html">
59 app/controllers/slingshot_sync_controller.rb
65 <tr class=
"top-aligned-row">
66 <td><strong>Parent:
</strong></td>
73 <!-- banner header -->
75 <div id=
"bodyContent">
79 <div id=
"contextContent">
81 <div id=
"description">
83 Copyright
© 2007 Joyent Inc.
86 THE SOFTWARE IS PROVIDED
"AS IS
", WITHOUT WARRANTY OF ANY KIND,
87 EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
88 MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
89 NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
90 DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
91 OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
92 USE OR OTHER DEALINGS IN THE SOFTWARE.
100 <div id=
"method-list">
101 <h3 class=
"section-bar">Methods
</h3>
103 <div class=
"name-list">
104 <a href=
"#M000031">aggregate_data
</a>
105 <a href=
"#M000032">download_file
</a>
106 <a href=
"#M000033">require_http_authentication
</a>
115 <h3 class=
"section-bar">Included Modules
</h3>
117 <div id=
"includes-list">
118 <span class=
"include-name"><a href=
"AuthenticatedSystem.html">AuthenticatedSystem
</a></span>
131 <!-- if method_list -->
133 <h3 class=
"section-bar">Public Instance methods
</h3>
135 <div id=
"method-M000031" class=
"method-detail">
136 <a name=
"M000031"></a>
138 <div class=
"method-heading">
139 <a href=
"#M000031" class=
"method-signature">
140 <span class=
"method-name">aggregate_data
</span><span class=
"method-args">()
</span>
144 <div class=
"method-description">
146 Here is where the bulk of your efffort will go in the down sync portion You
147 are tasked with creating an array of arrays that will define all the data
148 which will be available for a particular user while running in offline
149 mode. This example is simply aggregating all the information for a
150 particular
‘organization
’ but you can embed whatever logic that
151 you need here to send down data with much more fine grained permissions.
152 You could also, perhaps, delete all the database data from a particular
153 client if they are no longer allowed access to your service.
155 <p><a class=
"source-toggle" href=
"#"
156 onclick=
"toggleCode('M000031-source');return false;">[Source]
</a></p>
157 <div class=
"method-source-code" id=
"M000031-source">
159 <span class=
"ruby-comment cmt"># File app/controllers/slingshot_sync_controller.rb, line
23</span>
160 23:
<span class=
"ruby-keyword kw">def
</span> <span class=
"ruby-identifier">aggregate_data
</span>
161 24:
<span class=
"ruby-identifier">model
</span> = [
<span class=
"ruby-identifier">current_user
</span>]
162 25:
<span class=
"ruby-identifier">model
</span> <span class=
"ruby-operator">+=
</span> <span class=
"ruby-constant">Song
</span>.
<span class=
"ruby-identifier">find
</span>(
<span class=
"ruby-identifier">:all
</span>,
<span class=
"ruby-identifier">:conditions
</span> =
<span class=
"ruby-operator">></span> [
<span class=
"ruby-value str">"user_id = ?
"</span>,
<span class=
"ruby-identifier">current_user
</span>.
<span class=
"ruby-identifier">id
</span>])
163 26:
<span class=
"ruby-identifier">model
</span> <span class=
"ruby-operator">+=
</span> <span class=
"ruby-constant">Show
</span>.
<span class=
"ruby-identifier">find
</span>(
<span class=
"ruby-identifier">:all
</span>,
<span class=
"ruby-identifier">:conditions
</span> =
<span class=
"ruby-operator">></span> [
<span class=
"ruby-value str">"user_id = ?
"</span>,
<span class=
"ruby-identifier">current_user
</span>.
<span class=
"ruby-identifier">id
</span>])
164 27:
<span class=
"ruby-identifier">current_user
</span>.
<span class=
"ruby-identifier">shows
</span>.
<span class=
"ruby-identifier">each
</span> <span class=
"ruby-keyword kw">do
</span> <span class=
"ruby-operator">|
</span><span class=
"ruby-identifier">s
</span><span class=
"ruby-operator">|
</span>
165 28:
<span class=
"ruby-identifier">model
</span> <span class=
"ruby-operator">+=
</span> <span class=
"ruby-identifier">s
</span>.
<span class=
"ruby-identifier">usages
</span>
166 29:
<span class=
"ruby-keyword kw">end
</span>
167 30:
<span class=
"ruby-identifier">puts
</span> <span class=
"ruby-identifier">model
</span>.
<span class=
"ruby-identifier">inspect
</span>
168 31:
<span class=
"ruby-identifier">model
</span>
169 32:
<span class=
"ruby-keyword kw">end
</span>
175 <div id=
"method-M000032" class=
"method-detail">
176 <a name=
"M000032"></a>
178 <div class=
"method-heading">
179 <a href=
"#M000032" class=
"method-signature">
180 <span class=
"method-name">download_file
</span><span class=
"method-args">()
</span>
184 <div class=
"method-description">
186 Not required, but a good place to have a helper method to download a file
187 using http auth so that you can easily sync down files. When sync happens,
188 you
’re going to have a user requesting info without having an active
191 <p><a class=
"source-toggle" href=
"#"
192 onclick=
"toggleCode('M000032-source');return false;">[Source]
</a></p>
193 <div class=
"method-source-code" id=
"M000032-source">
195 <span class=
"ruby-comment cmt"># File app/controllers/slingshot_sync_controller.rb, line
39</span>
196 39:
<span class=
"ruby-keyword kw">def
</span> <span class=
"ruby-identifier">download_file
</span>
197 40:
<span class=
"ruby-comment cmt"># Example
</span>
198 41:
<span class=
"ruby-comment cmt"># @joyent_file = JoyentFile.restricted_find(params[:id])
</span>
199 42:
<span class=
"ruby-comment cmt"># send_joyent_file(@joyent_file, true)
</span>
200 43:
<span class=
"ruby-comment cmt"># rescue ActiveRecord::RecordNotFound
</span>
201 44:
<span class=
"ruby-comment cmt"># redirect_to files_index_url
</span>
202 45:
<span class=
"ruby-keyword kw">end
</span>
208 <div id=
"method-M000033" class=
"method-detail">
209 <a name=
"M000033"></a>
211 <div class=
"method-heading">
212 <a href=
"#M000033" class=
"method-signature">
213 <span class=
"method-name">require_http_authentication
</span><span class=
"method-args">()
</span>
217 <div class=
"method-description">
218 <p><a class=
"source-toggle" href=
"#"
219 onclick=
"toggleCode('M000033-source');return false;">[Source]
</a></p>
220 <div class=
"method-source-code" id=
"M000033-source">
222 <span class=
"ruby-comment cmt"># File app/controllers/slingshot_sync_controller.rb, line
48</span>
223 48:
<span class=
"ruby-keyword kw">def
</span> <span class=
"ruby-identifier">require_http_authentication
</span>
224 49:
<span class=
"ruby-comment cmt"># Use this to hook into your authentication
</span>
226 51:
<span class=
"ruby-keyword kw">unless
</span> (
<span class=
"ruby-identifier">auth
</span> = (
<span class=
"ruby-identifier">request
</span>.
<span class=
"ruby-identifier">env
</span>[
<span class=
"ruby-value str">'X-HTTP_AUTHORIZATION'
</span>]
<span class=
"ruby-operator">||
</span> <span class=
"ruby-identifier">request
</span>.
<span class=
"ruby-identifier">env
</span>[
<span class=
"ruby-value str">'HTTP_AUTHORIZATION'
</span>])).
<span class=
"ruby-identifier">nil?
</span>
227 52:
<span class=
"ruby-identifier">auth
</span> =
<span class=
"ruby-identifier">auth
</span>.
<span class=
"ruby-identifier">split
</span>
228 53:
<span class=
"ruby-identifier">user
</span>,
<span class=
"ruby-identifier">password
</span> =
<span class=
"ruby-constant">Base64
</span>.
<span class=
"ruby-identifier">decode64
</span>(
<span class=
"ruby-identifier">auth
</span>[
<span class=
"ruby-value">1</span>]).
<span class=
"ruby-identifier">split
</span>(
<span class=
"ruby-value str">':'
</span>)[
<span class=
"ruby-value">0</span><span class=
"ruby-operator">..
</span><span class=
"ruby-value">1</span>]
229 54:
<span class=
"ruby-keyword kw">self
</span>.
<span class=
"ruby-identifier">current_user
</span> =
<span class=
"ruby-constant">User
</span>.
<span class=
"ruby-identifier">authenticate
</span>(
<span class=
"ruby-identifier">user
</span>,
<span class=
"ruby-identifier">password
</span>)
230 55:
<span class=
"ruby-keyword kw">if
</span> <span class=
"ruby-identifier">logged_in?
</span>
231 56:
<span class=
"ruby-keyword kw">return
</span> <span class=
"ruby-keyword kw">true
</span>
232 57:
<span class=
"ruby-keyword kw">end
</span>
233 58:
<span class=
"ruby-keyword kw">end
</span>
234 59:
<span class=
"ruby-ivar">@response
</span>.
<span class=
"ruby-identifier">headers
</span>[
<span class=
"ruby-value str">"Status
"</span>] =
<span class=
"ruby-value str">"Unauthorized
"</span>
235 60:
<span class=
"ruby-ivar">@response
</span>.
<span class=
"ruby-identifier">headers
</span>[
<span class=
"ruby-value str">"WWW-Authenticate
"</span>] =
<span class=
"ruby-value str">"Basic realm=\
"Offline Sync from Joyent\
""</span>
236 61:
<span class=
"ruby-identifier">render
</span> <span class=
"ruby-identifier">:text
</span> =
<span class=
"ruby-operator">></span> <span class=
"ruby-value str">'You must log in to access your Sync'
</span>,
<span class=
"ruby-identifier">:status
</span> =
<span class=
"ruby-operator">></span> <span class=
"ruby-value">401</span>
237 62:
<span class=
"ruby-keyword kw">end
</span>
250 <div id=
"validator-badges">
251 <p><small><a href=
"http://validator.w3.org/check/referer">[Validate]
</a></small></p>