On Sunday, December 16, 2012 7:45:57 PM UTC-8, rubyrookie
wrote:>
> I want to take some elements from json string from
> facebook
{"algorithm":"HMAC-SHA256","expires":1355720400,"issued_at":1355715753,"oauth_token":"AAAAAChvQA2sBAClBE0B40nw7YqrAuYNhOZCYJ4sZAMSZC8VFZAz81s2mndYbS7t2DxTzFkQ88FmXsyBzznuQUuu1p2htZBav5KQmD3ICIcwZDZD","user":{"country":"us","locale":"en_US","age":{"min":21}},"user_id":"527477320"}
> and put them in a active record .
>
> Can anyone help me a good way to do it?
>
> Code->
>
>
>
>
> class ApplicationController < ActionController::Base
> before_filter :check_uri
>
> protect_from_forgery
>
> def check_uri
> @signed_request_json = decode_data(params[:signed_request]).to_json
> end
>
> def base64_url_decode str
> encoded_str =
str.gsub(''-'',''+'').gsub(''_'',''/'')
> encoded_str += ''='' while !(encoded_str.size % 4).zero?
> Base64.decode64(encoded_str)
> end
>
> def decode_data str
> encoded_sig, payload = str.split(''.'')
> data = ActiveSupport::JSON.decode base64_url_decode(payload)
> end
>
> end
>
>
>
--
You received this message because you are subscribed to the Google Groups
"Ruby on Rails: Talk" group.
To post to this group, send email to
rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-talk+unsubscribe@googlegroups.com.
To view this discussion on the web visit
https://groups.google.com/d/msg/rubyonrails-talk/-/v9X2xXklKUIJ.
For more options, visit https://groups.google.com/groups/opt_out.