module RestCore::ClientOauth1
Public Instance Methods
data_json()
click to toggle source
# File lib/rest-core/client_oauth1.rb, line 34 def data_json Json.encode(data.merge('sig' => calculate_sig)) end
data_json=(json)
click to toggle source
# File lib/rest-core/client_oauth1.rb, line 38 def data_json= json self.data = check_sig_and_return_data(Json.decode(json)) rescue Json.const_get(:ParseError) self.data = nil end
oauth_callback()
click to toggle source
# File lib/rest-core/client_oauth1.rb, line 56 def oauth_callback data['oauth_callback'] if data.kind_of?(Hash) end
oauth_callback=(uri)
click to toggle source
# File lib/rest-core/client_oauth1.rb, line 59 def oauth_callback= uri data['oauth_callback'] = uri if data.kind_of?(Hash) end
oauth_token()
click to toggle source
# File lib/rest-core/client_oauth1.rb, line 44 def oauth_token data['oauth_token'] if data.kind_of?(Hash) end
oauth_token=(token)
click to toggle source
# File lib/rest-core/client_oauth1.rb, line 47 def oauth_token= token data['oauth_token'] = token if data.kind_of?(Hash) end
oauth_token_secret()
click to toggle source
# File lib/rest-core/client_oauth1.rb, line 50 def oauth_token_secret data['oauth_token_secret'] if data.kind_of?(Hash) end
oauth_token_secret=(secret)
click to toggle source
# File lib/rest-core/client_oauth1.rb, line 53 def oauth_token_secret= secret data['oauth_token_secret'] = secret if data.kind_of?(Hash) end
Private Instance Methods
calculate_sig(hash=data)
click to toggle source
# File lib/rest-core/client_oauth1.rb, line 73 def calculate_sig hash=data base = hash.reject{ |(k, _)| k == 'sig' }.sort.map{ |(k, v)| "#{Middleware.escape(k.to_s)}=#{Middleware.escape(v.to_s)}" }.join('&') Digest::MD5.hexdigest("#{Middleware.escape(consumer_secret)}&#{base}") end
check_sig_and_return_data(hash)
click to toggle source
# File lib/rest-core/client_oauth1.rb, line 68 def check_sig_and_return_data hash hash if consumer_secret && hash.kind_of?(Hash) && calculate_sig(hash) == hash['sig'] end
default_data()
click to toggle source
# File lib/rest-core/client_oauth1.rb, line 64 def default_data {} end