Last active
December 14, 2015 07:19
-
-
Save posaunehm/5049593 to your computer and use it in GitHub Desktop.
youroom2string ruby script.name.rb userid pass roomID threadID
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/usr/bin/ruby | |
| # -*- coding: utf-8 -*- | |
| require 'rubygems' | |
| require 'oauth' | |
| require "rexml/document" | |
| class YouroomContent | |
| def initialize (content, author, created_at, children) | |
| @content = content | |
| @author = author | |
| @created_at = created_at | |
| @children = children | |
| end | |
| attr_reader :content, :author, :created_at, :children | |
| def string_for_print | |
| ret = Array.new | |
| ret.push "user: #{author}" | |
| content.each_line{ |line| | |
| ret.push line | |
| } | |
| children_ret = Array.new | |
| children.each{ |child| | |
| child.string_for_print.each{|line| | |
| children_ret.push "\t#{line}" | |
| } | |
| } | |
| ret.concat children_ret | |
| return ret | |
| end | |
| end | |
| def extract_entry entry | |
| content = entry.elements['content'].text | |
| author = entry.elements['participation/name'].text | |
| created_at = entry.elements['created-at'].text | |
| children = Array.new | |
| entry.elements.each('children/child'){|child| | |
| unless(child === nil) | |
| children.push extract_entry child | |
| end | |
| } | |
| return YouroomContent.new(content,author,created_at,children) | |
| end | |
| def extract_contents doc | |
| extract_entry doc.elements['entry'] | |
| end | |
| def get_youroom_access_token (user, pass) | |
| key = 'your_consumer_key' | |
| secret = 'your_consumer_secret' | |
| # get access token using XAuth | |
| # ref:https://gist.github.com/maraigue/304123 | |
| consumer = OAuth::Consumer.new(key, secret, :site => "https://www.youroom.in/") | |
| access_token = consumer.get_access_token(nil, {}, { | |
| :x_auth_mode => "client_auth", | |
| :x_auth_username => user, | |
| :x_auth_password => pass, | |
| }) | |
| return access_token | |
| end | |
| def get_room_timeline_contents (access_token, roomid, threadid) | |
| res = access_token.get("https://www.youroom.in/r/#{roomid}/entries/#{threadid}/?format=xml") | |
| doc = REXML::Document.new res.body | |
| content_root = extract_contents doc | |
| content_root.string_for_print.each { |line| | |
| puts line | |
| } | |
| end | |
| user = ARGV[0] | |
| pass = ARGV[1] | |
| roomid = ARGV[2] | |
| threadid = ARGV[3] | |
| token = get_youroom_access_token user, pass | |
| get_room_timeline_contents token, roomid, threadid |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment