cattail 0.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/cattail.rb +60 -0
- metadata +94 -0
data/cattail.rb
ADDED
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
require 'net/https'
|
|
2
|
+
require 'nokogiri'
|
|
3
|
+
require 'net/http/post/multipart'
|
|
4
|
+
|
|
5
|
+
# This is a simple demonstration of using Ruby to upload and list
|
|
6
|
+
# files to IBMs internal cattail service. It serves as a demonstration
|
|
7
|
+
# of accessing REST-based principles
|
|
8
|
+
class Cattail
|
|
9
|
+
def initialize(user = "my_email", passwd = "change_me")
|
|
10
|
+
@user = user
|
|
11
|
+
@passwd = passwd
|
|
12
|
+
@url = URI.parse("https://cattail.boulder.ibm.com")
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
# Retrieve a list of the users files, uses basic http authentication
|
|
17
|
+
# and nokogiri to parse the xml response
|
|
18
|
+
def list
|
|
19
|
+
results = []
|
|
20
|
+
http, req = get_request("/cattail/api/#{@user}")
|
|
21
|
+
response = http.request(req)
|
|
22
|
+
xml = doc = Nokogiri::HTML(response.body)
|
|
23
|
+
xml.remove_namespaces!
|
|
24
|
+
xml.xpath('//filename').each do |file|
|
|
25
|
+
results << file.children.text
|
|
26
|
+
end
|
|
27
|
+
results
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
# Send a file using multipart form data
|
|
31
|
+
def insert(file)
|
|
32
|
+
http, req = post_request("/cattail/api/#{@user}", file)
|
|
33
|
+
response = http.request(req)
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
private
|
|
37
|
+
def request(path)
|
|
38
|
+
http = Net::HTTP.new(@url.host, @url.port)
|
|
39
|
+
http.use_ssl = true
|
|
40
|
+
http.verify_mode = OpenSSL::SSL::VERIFY_NONE
|
|
41
|
+
http
|
|
42
|
+
end
|
|
43
|
+
|
|
44
|
+
def post_request(path, file)
|
|
45
|
+
f = File.open(file)
|
|
46
|
+
http = request(path)
|
|
47
|
+
req = Net::HTTP::Post::Multipart.new path,
|
|
48
|
+
"file" => UploadIO.new(f, ""),
|
|
49
|
+
"visibility" => "PRIVATE"
|
|
50
|
+
req.basic_auth @user, @passwd
|
|
51
|
+
[http, req]
|
|
52
|
+
end
|
|
53
|
+
|
|
54
|
+
def get_request(path)
|
|
55
|
+
http = request(path)
|
|
56
|
+
req = Net::HTTP::Get.new(path)
|
|
57
|
+
req.basic_auth @user, @passwd
|
|
58
|
+
[http, req]
|
|
59
|
+
end
|
|
60
|
+
end
|
metadata
ADDED
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
|
2
|
+
name: cattail
|
|
3
|
+
version: !ruby/object:Gem::Version
|
|
4
|
+
hash: 29
|
|
5
|
+
prerelease: false
|
|
6
|
+
segments:
|
|
7
|
+
- 0
|
|
8
|
+
- 0
|
|
9
|
+
- 1
|
|
10
|
+
version: 0.0.1
|
|
11
|
+
platform: ruby
|
|
12
|
+
authors:
|
|
13
|
+
- Philip Mcmahon
|
|
14
|
+
autorequire:
|
|
15
|
+
bindir: bin
|
|
16
|
+
cert_chain: []
|
|
17
|
+
|
|
18
|
+
date: 2011-01-21 00:00:00 -07:00
|
|
19
|
+
default_executable:
|
|
20
|
+
dependencies:
|
|
21
|
+
- !ruby/object:Gem::Dependency
|
|
22
|
+
name: nokogiri
|
|
23
|
+
prerelease: false
|
|
24
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
|
25
|
+
none: false
|
|
26
|
+
requirements:
|
|
27
|
+
- - ">="
|
|
28
|
+
- !ruby/object:Gem::Version
|
|
29
|
+
hash: 3
|
|
30
|
+
segments:
|
|
31
|
+
- 0
|
|
32
|
+
version: "0"
|
|
33
|
+
type: :runtime
|
|
34
|
+
version_requirements: *id001
|
|
35
|
+
- !ruby/object:Gem::Dependency
|
|
36
|
+
name: multipart-post
|
|
37
|
+
prerelease: false
|
|
38
|
+
requirement: &id002 !ruby/object:Gem::Requirement
|
|
39
|
+
none: false
|
|
40
|
+
requirements:
|
|
41
|
+
- - ">="
|
|
42
|
+
- !ruby/object:Gem::Version
|
|
43
|
+
hash: 3
|
|
44
|
+
segments:
|
|
45
|
+
- 0
|
|
46
|
+
version: "0"
|
|
47
|
+
type: :runtime
|
|
48
|
+
version_requirements: *id002
|
|
49
|
+
description:
|
|
50
|
+
email: mcmahonp@us.ibm.com
|
|
51
|
+
executables: []
|
|
52
|
+
|
|
53
|
+
extensions: []
|
|
54
|
+
|
|
55
|
+
extra_rdoc_files: []
|
|
56
|
+
|
|
57
|
+
files:
|
|
58
|
+
- cattail.rb
|
|
59
|
+
has_rdoc: true
|
|
60
|
+
homepage: http://domino.watson.ibm.com/cambridge/research.nsf/99751d8eb5a20c1f852568db004efc90/7ea66f4eb9382eaf852573d1005cff95!OpenDocument
|
|
61
|
+
licenses: []
|
|
62
|
+
|
|
63
|
+
post_install_message:
|
|
64
|
+
rdoc_options: []
|
|
65
|
+
|
|
66
|
+
require_paths:
|
|
67
|
+
- .
|
|
68
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
|
69
|
+
none: false
|
|
70
|
+
requirements:
|
|
71
|
+
- - ">="
|
|
72
|
+
- !ruby/object:Gem::Version
|
|
73
|
+
hash: 3
|
|
74
|
+
segments:
|
|
75
|
+
- 0
|
|
76
|
+
version: "0"
|
|
77
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
78
|
+
none: false
|
|
79
|
+
requirements:
|
|
80
|
+
- - ">="
|
|
81
|
+
- !ruby/object:Gem::Version
|
|
82
|
+
hash: 3
|
|
83
|
+
segments:
|
|
84
|
+
- 0
|
|
85
|
+
version: "0"
|
|
86
|
+
requirements: []
|
|
87
|
+
|
|
88
|
+
rubyforge_project:
|
|
89
|
+
rubygems_version: 1.3.7
|
|
90
|
+
signing_key:
|
|
91
|
+
specification_version: 3
|
|
92
|
+
summary: Library that provides a simple demonstration of using REST principles to list and upload files to Cattail service.
|
|
93
|
+
test_files: []
|
|
94
|
+
|