agentx 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,94 @@
1
+
2
+ module AgentX
3
+
4
+ class Session
5
+ attr_reader :history, :jar
6
+
7
+ def initialize(base_url=nil, opts={})
8
+ @history = History.new
9
+ path = File.join(AgentX.root, opts[:cookie_store] || 'cookies.sqlite')
10
+ @jar = HTTP::CookieJar.new(store: :mozilla, filename: path)
11
+ @base_url = base_url
12
+ @headers = {}
13
+ end
14
+
15
+ DEFAULT_PORT = { 'http' => 80, 'https' => 443 }
16
+
17
+ def base_url
18
+ if url = URI(@base_url || (history.last && history.last.request.url))
19
+ if url.port != DEFAULT_PORT[url.scheme]
20
+ "#{url.scheme}://#{url.host}:#{url.port}"
21
+ else
22
+ "#{url.scheme}://#{url.host}"
23
+ end
24
+ end
25
+ end
26
+
27
+ def relative_base_url
28
+ if history.last
29
+ uri = URI(history.last.request.full_url)
30
+ path = uri.path.split('/')
31
+ path.pop
32
+
33
+ URI.join(uri, path.empty? ? '/' : path.join)
34
+ else
35
+ base_url
36
+ end
37
+ end
38
+
39
+ def headers(headers={})
40
+ headers.each { |k,v| set_header(k, v) }
41
+ @headers
42
+ end
43
+
44
+ def [](url, params={})
45
+ Request.new(self, url, params)
46
+ end
47
+
48
+ def inspect
49
+ "(Session)"
50
+ end
51
+
52
+ private
53
+
54
+ HEADER_MAP = {
55
+ accept: 'Accept',
56
+ accept_charset: 'Accept-Charset',
57
+ accept_encoding: 'Accept-Encoding',
58
+ accept_language: 'Accept-Language',
59
+ accept_datetime: 'Accept-Datetime',
60
+ authorization: 'Authorization',
61
+ cache_control: 'Cache-Control',
62
+ connection: 'Connection',
63
+ cookie: 'Cookie',
64
+ content_length: 'Content-Length',
65
+ date: 'Date',
66
+ expect: 'Expect',
67
+ from: 'From',
68
+ host: 'Host',
69
+ if_match: 'If-Match',
70
+ if_modified_since: 'If-Modified-Since',
71
+ if_none_match: 'If-None-Match',
72
+ if_range: 'If-Range',
73
+ if_unmodified_since: 'If-Unmodified-Since',
74
+ max_forwards: 'Max-Forwards',
75
+ origin: 'Origin',
76
+ pragma: 'Pragma',
77
+ proxy_authorization: 'Proxy-Authorization',
78
+ range: 'Range',
79
+ referer: 'Referer',
80
+ referrer: 'Referer',
81
+ te: 'TE',
82
+ user_agent: 'User-Agent',
83
+ upgrade: 'Upgrade',
84
+ via: 'Via',
85
+ warning: 'Warning'
86
+ }
87
+
88
+ def set_header(k, v)
89
+ @headers[HEADER_MAP[k] || k.to_s] = v
90
+ end
91
+ end
92
+
93
+ end
94
+
@@ -0,0 +1,5 @@
1
+
2
+ module AgentX
3
+ VERSION = "0.0.2"
4
+ end
5
+
@@ -0,0 +1,65 @@
1
+
2
+ module AgentX
3
+
4
+ class XML
5
+ def initialize(xml)
6
+ if xml.kind_of?(String)
7
+ @xml = Nokogiri::XML(xml)
8
+ else
9
+ @xml = xml
10
+ end
11
+ end
12
+
13
+ def to_xml
14
+ @xml.to_xml
15
+ end
16
+
17
+ def first(selector)
18
+ (e = @xml.css(selector).first) && XML.new(e)
19
+ end
20
+
21
+ def all(selector)
22
+ @xml.css(selector).map { |e| XML.new(e) }
23
+ end
24
+
25
+ def parent
26
+ XML.new(@xml.parent)
27
+ end
28
+
29
+ def children
30
+ @xml.children.map { |e| XML.new(e) }
31
+ end
32
+
33
+ def next
34
+ XML.new(@xml.next)
35
+ end
36
+
37
+ def previous
38
+ XML.new(@xml.previous)
39
+ end
40
+
41
+ def attributes
42
+ h = {}
43
+ @xml.attribute_nodes.each { |n| h[n.name] = n.value }
44
+ h
45
+ end
46
+
47
+ def [](attr)
48
+ @xml[attr.to_s]
49
+ end
50
+
51
+ def to_s
52
+ to_xml
53
+ end
54
+
55
+ def inspect
56
+ to_xml
57
+ end
58
+
59
+ def to_nokogiri
60
+ @xml
61
+ end
62
+ end
63
+
64
+ end
65
+
metadata ADDED
@@ -0,0 +1,173 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: agentx
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.2
5
+ platform: ruby
6
+ authors:
7
+ - Eric K Idema
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2016-02-03 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.6'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.6'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: ethon
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: http-cookie
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :runtime
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: nokogiri
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :runtime
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: listen
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ type: :runtime
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ">="
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
97
+ - !ruby/object:Gem::Dependency
98
+ name: oj
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - ">="
102
+ - !ruby/object:Gem::Version
103
+ version: '0'
104
+ type: :runtime
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - ">="
109
+ - !ruby/object:Gem::Version
110
+ version: '0'
111
+ - !ruby/object:Gem::Dependency
112
+ name: sqlite3
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - ">="
116
+ - !ruby/object:Gem::Version
117
+ version: '0'
118
+ type: :runtime
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - ">="
123
+ - !ruby/object:Gem::Version
124
+ version: '0'
125
+ description: A tool for doing things on the Internet.
126
+ email:
127
+ - eki@vying.org
128
+ executables:
129
+ - agentx
130
+ extensions: []
131
+ extra_rdoc_files: []
132
+ files:
133
+ - ".gitignore"
134
+ - Gemfile
135
+ - README
136
+ - Rakefile
137
+ - agentx.gemspec
138
+ - bin/agentx
139
+ - config.example
140
+ - lib/agentx.rb
141
+ - lib/agentx/cache.rb
142
+ - lib/agentx/console.rb
143
+ - lib/agentx/history.rb
144
+ - lib/agentx/html.rb
145
+ - lib/agentx/request.rb
146
+ - lib/agentx/response.rb
147
+ - lib/agentx/session.rb
148
+ - lib/agentx/version.rb
149
+ - lib/agentx/xml.rb
150
+ homepage: https://github.com/eki/agentx
151
+ licenses: []
152
+ metadata: {}
153
+ post_install_message:
154
+ rdoc_options: []
155
+ require_paths:
156
+ - lib
157
+ required_ruby_version: !ruby/object:Gem::Requirement
158
+ requirements:
159
+ - - ">="
160
+ - !ruby/object:Gem::Version
161
+ version: '0'
162
+ required_rubygems_version: !ruby/object:Gem::Requirement
163
+ requirements:
164
+ - - ">="
165
+ - !ruby/object:Gem::Version
166
+ version: '0'
167
+ requirements: []
168
+ rubyforge_project:
169
+ rubygems_version: 2.4.5.1
170
+ signing_key:
171
+ specification_version: 4
172
+ summary: A tool for doing things on the Internet.
173
+ test_files: []