Navigation Menu

Skip to content

Commit

Permalink
have Archive.create('archive@user.email', 'password', 'ArchiveIdentif…
Browse files Browse the repository at this point in the history
…ier', '', '') working. But I still need to make file specification an option.... I need to study some xml from the archive's servers
  • Loading branch information
papyromancer committed Feb 3, 2009
1 parent f20855d commit 7bee62c
Show file tree
Hide file tree
Showing 2 changed files with 96 additions and 0 deletions.
89 changes: 89 additions & 0 deletions lib/archive.rb
@@ -0,0 +1,89 @@
require 'uri'
require 'net/http'
require 'net/ftp'
require 'rubygems'
require 'hpricot'
require 'xmlsimple'

module Archive
SourceName = 'ArchiveGem'

module EasyClassMaker

def self.included(base)
base.extend(ClassMethods)
end

module ClassMethods
# creates the attributes class variable and creates each attribute's accessor methods
def attributes(*attrs)
@@attributes = attrs
@@attributes.each { |a| attr_accessor a }
end

# read method for attributes class variable
def self.attributes; @@attributes end
end

# allows for any class that includes this to use a block to initialize
# variables instead of assigning each one seperately
#
# Example:
#
# instead of...
#
# a = Archive.new
# a.foo = 'thing'
# a.bar = 'another thing'
#
# you can ...
#
# Archive.new do |a|
# a.foo = 'thing'
# a.bar = 'another thing'
# end
def initialize
yield self if block_given?
end
end

class ArchiveItem

include EasyClassMaker

attributes :archive_identifier, :xml_files, :xml_meta

class << self
def new(archive_identifier, xml_files, xml_meta)
ArchiveItem.new do |i|
i.archive_identifier = archive_identifier
i.xml_files = xml_files
i.xml_meta = xml_meta
end
end
end
end


## Archive.create('archive@user.email', 'password', 'ArchiveIdentifier', 'files_xml', 'metadata_xml')
def self.create(archive_user, archive_password, archive_identifier, xml_files, xml_meta)

#c = ArchiveItem.new(archive_identifier, xml_files, xml_meta)

create_xml = Net::HTTP.get(URI.parse('http://www.archive.org/create.php?identifier=' + archive_identifier + '&xml=1&user=' + archive_user))

create = XmlSimple.xml_in(create_xml)

uri = URI.parse('ftp://' + create['url'].to_s)
path = uri::path

ftp = Net::FTP.new(uri.host)
ftp.login(user = archive_user, archive_password)
ftp.chdir(path)
ftp.putbinaryfile('/test.jpg')
ftp.close

response = Net::HTTP.get(URI.parse('http://www.archive.org/checkin.php?identifier=' + archive_identifier + '&xml=1&user=' + archive_user))
puts response
end
end
7 changes: 7 additions & 0 deletions test/archive_test.rb
@@ -0,0 +1,7 @@
require File.dirname(__FILE__) + '/test_helper'

class ArchiveTest < Test::Unit::TestCase
should "probably rename this file and start testing for real" do
flunk "hey buddy, you should probably rename this file and start testing for real"
end
end

0 comments on commit 7bee62c

Please sign in to comment.