rsfhelper 0.1.0

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.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 98cc6a4053a6290b6eff1751d6290608379995c6
4
+ data.tar.gz: 8812a1d8f8d105abff13b44db7bc83571a1a2ad0
5
+ SHA512:
6
+ metadata.gz: 7459cb1c6736f182425aae17bf5d17da33d9733e51bd549803fff3ec335efdbba59a819a84bdac5225b90caaafc09f3dcfb7413c4aa348ac09ed38b8df9f7ebf
7
+ data.tar.gz: 312dd6b05708e222cb90b7db162dd0c0e8cf772d7f88e273618f882fe4413d8c36fcf7706fa71f73425def6bde70eb8f4f261fe228d761b281749d0db4963cca
Binary file
Binary file
@@ -0,0 +1,116 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ # file: rsfhelper.rb
4
+
5
+ require 'open-uri'
6
+ require 'cgi'
7
+ require 'rexml/document'
8
+
9
+ class RSFHelper
10
+ include REXML
11
+
12
+ attr_reader :doc, :result, :text
13
+ attr_accessor :package
14
+
15
+ def initialize(opts={})
16
+
17
+ o = {:hostname => nil, :package => ''}.merge(opts)
18
+
19
+ @hostname = o[:hostname]
20
+ raise 'please supply a hostname' unless @hostname
21
+ @package = o[:package]
22
+
23
+ if @package.length > 0 then
24
+ jobs_to_methods(@package)
25
+ init_content_types
26
+ end
27
+
28
+ end
29
+
30
+ def package=(s)
31
+ if s then
32
+ @package = s
33
+ jobs_to_methods(@package)
34
+ init_content_types
35
+ end
36
+ end
37
+
38
+ private
39
+
40
+ def jobs_to_methods(package)
41
+
42
+ url = "http://%s/source/%s" % [@hostname, package]
43
+
44
+ doc = Document.new(open(url, 'UserAgent' => 'ClientRscript').read)
45
+ a = XPath.match(doc.root, 'job/attribute::id')
46
+
47
+ a.each do |attr|
48
+ method_name = attr.value.to_s.gsub('-','_')
49
+ method = "def %s(param={}); query_method('%s', param); end" % [method_name, method_name]
50
+ self.instance_eval(method)
51
+ end
52
+ end
53
+
54
+ def init_content_types
55
+
56
+ @return_type = {}
57
+
58
+ xmlproc = Proc.new {
59
+ @doc = Document.new(@result.sub(/xmlns=["']http:\/\/www.w3.org\/1999\/xhtml["']/,''))
60
+ summary_node = XPath.match(@doc.root, 'summary/*')
61
+ if summary_node then
62
+ summary_node.each do |node|
63
+
64
+ if node.cdatas.length > 0 then
65
+ if node.cdatas.length == 1 then
66
+ content = node.cdatas.join.strip
67
+ else
68
+ if node.elements["@value='methods'"] then
69
+
70
+ else
71
+ content = node.cdatas.map {|x| x.to_s[/^\{.*\}$/] ? eval(x.to_s) : x.to_s}
72
+ end
73
+
74
+ end
75
+ else
76
+ content = node.text.to_s.gsub(/"/,'\"').gsub(/#/,'\#')
77
+ end
78
+
79
+
80
+ method =<<EOF
81
+ def #{node.name}()
82
+ #{content}
83
+ end
84
+ EOF
85
+ self.instance_eval(method)
86
+ end
87
+ records = XPath.match(@doc.root, 'records/*/text()')
88
+ method = "def %s(); %s; end" % [@doc.root.name, records.inspect] if records
89
+ self.instance_eval(method)
90
+ end
91
+ }
92
+
93
+ textproc = Proc.new {@text = @result}
94
+ @return_type['text/plain'] = textproc
95
+ @return_type['text/html'] = textproc
96
+ @return_type['text/xml'] = xmlproc
97
+ @return_type['application/xml'] = xmlproc
98
+ @return_type['application/rss+xml'] = xmlproc
99
+
100
+ end
101
+
102
+ def query_method(method, params={})
103
+
104
+ base_url = "http://#{@hostname}/do/#{@package}/"
105
+ param_list = params.to_a.map{|param, value| "%s=%s" % [param, CGI.escape(value)]}.join('&')
106
+
107
+ x = param_list.empty? ? '' : param_list
108
+ url = "%s%s%s" % [base_url, method.gsub('_','-'), x]
109
+
110
+ response = open(url, 'UserAgent' => 'RSFHelper')
111
+ @result = response.read
112
+ @return_type[response.content_type].call
113
+ return self
114
+ end
115
+
116
+ end
metadata ADDED
@@ -0,0 +1,67 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: rsfhelper
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - James Robertson
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain:
11
+ - |
12
+ -----BEGIN CERTIFICATE-----
13
+ MIIDljCCAn6gAwIBAgIBATANBgkqhkiG9w0BAQUFADBIMRIwEAYDVQQDDAlnZW1t
14
+ YXN0ZXIxHjAcBgoJkiaJk/IsZAEZFg5qYW1lc3JvYmVydHNvbjESMBAGCgmSJomT
15
+ 8ixkARkWAmV1MB4XDTE1MDkxNzEwMzM1MloXDTE2MDkxNjEwMzM1MlowSDESMBAG
16
+ A1UEAwwJZ2VtbWFzdGVyMR4wHAYKCZImiZPyLGQBGRYOamFtZXNyb2JlcnRzb24x
17
+ EjAQBgoJkiaJk/IsZAEZFgJldTCCASIwDQYJKoZIhvcNAQEBBQADggEPADCCAQoC
18
+ ggEBAL0xylQn5SA6mw6s/kXuVH+l/VES0Dy2zq8dOYtIig+Mg4WEPulhyb1Gh/fs
19
+ ewTB/sn0Ln6HE0sPn7WZstf1TiRSH+1rGzPsqlbpwI7hslBOqhBISzg9zqyuvqt6
20
+ MI8KFJOEDlXeFQ17feFOO7sSmvhvE9UwKMLF91dZoG5Z3HgBLSl1i2uOxj+ZFQ61
21
+ nFL6oJvawGvZb152nFEysypRS9XYyTdNfKi3gcwTjxeojSm39qkd71IqhjPenbqD
22
+ ueqKLYfat++pi/+YlQgvdCPbL5NQT/XanV/AvztHSCvoKmixljxWb9+J6IAkIGzE
23
+ 7SkMTtwIUQXNQByZ9lTfuhIg2RcCAwEAAaOBijCBhzAJBgNVHRMEAjAAMAsGA1Ud
24
+ DwQEAwIEsDAdBgNVHQ4EFgQU/PWzKNEN4uqmRsGdS0AMTpLlkywwJgYDVR0RBB8w
25
+ HYEbZ2VtbWFzdGVyQGphbWVzcm9iZXJ0c29uLmV1MCYGA1UdEgQfMB2BG2dlbW1h
26
+ c3RlckBqYW1lc3JvYmVydHNvbi5ldTANBgkqhkiG9w0BAQUFAAOCAQEAoj+e9SMC
27
+ S83wqcoVrbiQfwfiG2zysY2o1NTKoEngfPpCJUC2s+dglLKbeMT+GbFrVvi6TFE5
28
+ 4gPYbkSF5g3u0KUtqWX/2RnhPNrZcX0E+vFRv6slwZKi4HLA+qvbmA6RIUltYqOT
29
+ YRBN6ZkIG/Od7A53zpo4b6QCx6V3Ey2BYfR1WOhY3NHLshPvnMTbdTkbQzt+fdIu
30
+ pSbLc9M1FupGfQZua/dUYiJbdyDS4o7uDzUzRNtlAD+0NIf0FAd9x1CW1n0roFbh
31
+ QA0UogLaEOYeFjtOjgJBZPLMQSpMdRqTxgOFd58OvNFgIw8zvNmbTddmAkVNB20S
32
+ myPGQvlmeO3mQw==
33
+ -----END CERTIFICATE-----
34
+ date: 2015-09-17 00:00:00.000000000 Z
35
+ dependencies: []
36
+ description:
37
+ email: james@r0bertson.co.uk
38
+ executables: []
39
+ extensions: []
40
+ extra_rdoc_files: []
41
+ files:
42
+ - lib/rsfhelper.rb
43
+ homepage: https://github.com/jrobertson/rsfhelper
44
+ licenses:
45
+ - MIT
46
+ metadata: {}
47
+ post_install_message:
48
+ rdoc_options: []
49
+ require_paths:
50
+ - lib
51
+ required_ruby_version: !ruby/object:Gem::Requirement
52
+ requirements:
53
+ - - ">="
54
+ - !ruby/object:Gem::Version
55
+ version: '0'
56
+ required_rubygems_version: !ruby/object:Gem::Requirement
57
+ requirements:
58
+ - - ">="
59
+ - !ruby/object:Gem::Version
60
+ version: '0'
61
+ requirements: []
62
+ rubyforge_project:
63
+ rubygems_version: 2.4.8
64
+ signing_key:
65
+ specification_version: 4
66
+ summary: A client for conveniently sending requests to a Rack-rscript web server
67
+ test_files: []
@@ -0,0 +1 @@
1
+ +�����.OP>�WT�\�f����g�1���)�MFR�?P��حԴ���X�Q�|wp5Nj�E|� q��-e2�|