Module: Rapidash::HTTPClient

Defined in:
lib/rapidash/http_client.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#connectionObject



14
15
16
17
# File 'lib/rapidash/http_client.rb', line 14

def connection
  raise ConfigurationError.new "Site is required" unless site
  @connection ||= Faraday.new(site)
end

#loginObject

Returns the value of attribute login.



5
6
7
# File 'lib/rapidash/http_client.rb', line 5

def 
  @login
end

#passwordObject

Returns the value of attribute password.



5
6
7
# File 'lib/rapidash/http_client.rb', line 5

def password
  @password
end

Instance Method Details

#initialize(options = {}) ⇒ Object



8
9
10
11
12
# File 'lib/rapidash/http_client.rb', line 8

def initialize(options = {})
  [:login, :password].each do |key|
    self.send("#{key.to_s}=".to_sym, options[key])
  end
end

#process_response(response, verb, options) ⇒ Object



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

def process_response(response, verb, options)
  # "foo"[0] does not work in 1.8.7, "foo"[0,1] is required
  case response.status.to_s[0, 1]
  when "5", "4"
    error = ResponseError.new(response)
    raise error if self.class.respond_to?(:raise_error) && self.class.raise_error
    return nil
  #Handle redirects
  when "3"
    request(verb, response.headers["location"], options)
  when "2"
    return Response.new(response)
  end
end

#request(verb, url, options = {}) ⇒ Object



19
20
21
22
23
24
25
26
# File 'lib/rapidash/http_client.rb', line 19

def request(verb, url, options = {})
  url = connection.build_url(normalize_url(url), options[:params]).to_s
  response = connection.run_request verb, url, options[:body], options[:header] do |request|
    request.headers.update(:Authorization => connection.basic_auth(, password)) if  && password
  end

  process_response(response, verb, options)
end