Class: GDocsMigration::Migration
- Inherits:
-
Object
- Object
- GDocsMigration::Migration
- Defined in:
- lib/gdocs-migration/migration.rb
Instance Method Summary collapse
- #fetch ⇒ Object
-
#initialize(from, to) ⇒ Migration
constructor
A new instance of Migration.
- #login ⇒ Object
- #migrate ⇒ Object
Constructor Details
#initialize(from, to) ⇒ Migration
Returns a new instance of Migration.
28 29 30 31 32 33 34 |
# File 'lib/gdocs-migration/migration.rb', line 28 def initialize(from, to) @documents = [] @from = from @to = to @from_client = GData::Client::DocList.new @to_client = GData::Client::DocList.new end |
Instance Method Details
#fetch ⇒ Object
48 49 50 51 52 53 54 55 56 57 58 59 60 61 |
# File 'lib/gdocs-migration/migration.rb', line 48 def fetch puts "Fetching all documents from #{@from}:" feed = @from_client.get("http://docs.google.com/feeds/documents/private/full/").to_xml feed.elements.each('entry') do |entry| type = entry.elements['category[@scheme = "http://schemas.google.com/g/2005#kind"]'].attributes['label'] document = GDocsMigration::Model::Document.new type document.title = entry.elements['title'].text puts "Fetched #{document.type} #{document.title}" end puts "" end |
#login ⇒ Object
63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 |
# File 'lib/gdocs-migration/migration.rb', line 63 def login begin from_pass = ask("Password for #{@from}:") { |q| q.echo = "*" } @from_client.clientlogin(@from, from_pass) puts "Successfully logged in to #{@from}";puts "" to_pass = ask("Password for #{@to}:") { |q| q.echo ="*" } @to_client.clientlogin(@to, to_pass) puts "Successfully logged in to #{@to}";puts "" rescue GData::Client::AuthorizationError puts("Oops, something went wrong while logging you in. Check the credentials");exit rescue GData::Client::CaptchaError puts("There was an error with loggin you in, try to login to Google Docs in your browser and then try again.");exit rescue SocketError puts("Cannot connect to the Google Docs service, are you connected to the internet?");exit end end |
#migrate ⇒ Object
36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/gdocs-migration/migration.rb', line 36 def migrate puts "";puts "**************************" puts "GDocs Migration started...";puts "" login fetch puts "";puts "Migration complete" puts "";puts "**************************" end |