Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add json serialization support #7

Open
appoxy opened this issue Oct 12, 2010 · 0 comments
Open

Add json serialization support #7

appoxy opened this issue Oct 12, 2010 · 0 comments

Comments

@appoxy
Copy link

appoxy commented Oct 12, 2010

eg:

OAuth::RequestToken.class_eval do
def to_json(*a)

puts 'to_json called in RequestToken'

    {
            'json_class'   => self.class.name,
            'data'         => instance_values
    }.to_json(*a)
end

end

OAuth::RequestToken.instance_eval do

def json_create(o)
    consumer = OAuth::Consumer.new(o['data']['consumer']['key'], o['data']['consumer']['secret'], o['data']['consumer']['options'])
    OAuth::RequestToken.from_hash(consumer, o['data']['params'].update({:oauth_token=>o['data']['params']['oauth_token'], :oauth_token_secret=>o['data']['params']['oauth_token_secret']}))
end

end

OAuth::AccessToken.class_eval do
def to_json(*a)

puts 'to_json called in RequestToken'

    {
            'json_class'   => self.class.name,
            'data'         => instance_values
    }.to_json(*a)
end

end

OAuth::AccessToken.instance_eval do

def json_create(o)
    consumer = OAuth::Consumer.new(o['data']['consumer']['key'], o['data']['consumer']['secret'], o['data']['consumer']['options'])
    OAuth::AccessToken.from_hash(consumer, o['data']['params'].update({:oauth_token=>o['data']['params']['oauth_token'], :oauth_token_secret=>o['data']['params']['oauth_token_secret']}))
end

end

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

0 participants