Class: Geostats::HTTP

Inherits:
Object
  • Object
show all
Defined in:
lib/geostats/http.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#password=(value) ⇒ Object (writeonly)

Sets the attribute password

Parameters:

  • value

    the value to set the attribute password to.



5
6
7
# File 'lib/geostats/http.rb', line 5

def password=(value)
  @password = value
end

#username=(value) ⇒ Object (writeonly)

Sets the attribute username

Parameters:

  • value

    the value to set the attribute username to.



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

.instanceObject



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.(username, password)
  self.instance.username = username
  self.instance.password = password
  self.instance.
end

.logoutObject



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

#loginObject

Raises:

  • (ArgumentError)


29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/geostats/http.rb', line 29

def 
  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

#logoutObject



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