Class: Geostats::HTTP
- Inherits:
-
Object
- Object
- Geostats::HTTP
- Defined in:
- lib/geostats/http.rb
Instance Attribute Summary collapse
-
#password ⇒ Object
writeonly
Sets the attribute password.
-
#username ⇒ Object
writeonly
Sets the attribute username.
Class Method Summary collapse
- .get(path) ⇒ Object
- .instance ⇒ Object
- .login(username, password) ⇒ Object
- .logout ⇒ Object
- .post(path, data = {}) ⇒ Object
Instance Method Summary collapse
Instance Attribute Details
#password=(value) ⇒ Object (writeonly)
Sets the attribute password
5 6 7 |
# File 'lib/geostats/http.rb', line 5 def password=(value) @password = value end |
#username=(value) ⇒ Object (writeonly)
Sets the attribute username
5 6 7 |
# File 'lib/geostats/http.rb', line 5 def username=(value) @username = value end |
Class Method Details
.get(path) ⇒ Object
21 22 23 |
# File 'lib/geostats/http.rb', line 21 def self.get(path) self.instance.get(path) end |
.instance ⇒ Object
7 8 9 |
# File 'lib/geostats/http.rb', line 7 def self.instance @instance ||= new end |
.login(username, password) ⇒ Object
11 12 13 14 15 |
# File 'lib/geostats/http.rb', line 11 def self.login(username, password) self.instance.username = username self.instance.password = password self.instance.login end |
.logout ⇒ Object
17 18 19 |
# File 'lib/geostats/http.rb', line 17 def self.logout self.instance.logout end |
.post(path, data = {}) ⇒ Object
25 26 27 |
# File 'lib/geostats/http.rb', line 25 def self.post(path, data={}) self.instance.post(path, data) end |
Instance Method Details
#get(path) ⇒ Object
48 49 50 51 52 53 |
# File 'lib/geostats/http.rb', line 48 def get(path) header = default_header header["Cookie"] = @cookie if @cookie http.get(path, header) end |
#login ⇒ Object
29 30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/geostats/http.rb', line 29 def login raise ArgumentError, "Missing username" unless @username raise ArgumentError, "Missing password" unless @password resp, data = post("/login/default.aspx", { "ctl00$ContentBody$myUsername" => @username, "ctl00$ContentBody$myPassword" => @password, "ctl00$ContentBody$Button1" => "Login", "ctl00$ContentBody$cookie" => "on" }) @cookie = resp.response["set-cookie"] end |
#logout ⇒ Object
43 44 45 46 |
# File 'lib/geostats/http.rb', line 43 def logout get("/login/default.aspx?RESET=Y") @cookie = nil end |
#post(path, data = {}) ⇒ Object
55 56 57 58 59 60 61 62 63 64 |
# File 'lib/geostats/http.rb', line 55 def post(path, data={}) (path).each do |key, value| data[key] = value end header = default_header header["Cookie"] = @cookie if @cookie http.post(path, data.map { |k,v| "#{k}=#{v}" }.join("&"), header) end |