Class: ActiveRecord::Remote::Client

Inherits:
Object
  • Object
show all
Defined in:
lib/active_record/remote/client.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(action) ⇒ Client

Returns a new instance of Client.



11
12
13
# File 'lib/active_record/remote/client.rb', line 11

def initialize(action)
  @action = action
end

Instance Attribute Details

#actionObject

Returns the value of attribute action.



9
10
11
# File 'lib/active_record/remote/client.rb', line 9

def action
  @action
end

Class Method Details

.content_type(content_type) ⇒ Object



15
16
17
# File 'lib/active_record/remote/client.rb', line 15

def self.content_type(content_type)
  self.content_type = content_type
end

.host(host) ⇒ Object



19
20
21
# File 'lib/active_record/remote/client.rb', line 19

def self.host(host)
  self.host = host
end

.read_timeout(read_timeout) ⇒ Object



23
24
25
# File 'lib/active_record/remote/client.rb', line 23

def self.read_timeout(read_timeout)
  self.read_timeout = read_timeout
end

.secure(secure) ⇒ Object



27
28
29
# File 'lib/active_record/remote/client.rb', line 27

def self.secure(secure)
  self.secure = secure
end

Instance Method Details

#complete_request_urlObject



43
44
45
# File 'lib/active_record/remote/client.rb', line 43

def complete_request_url
  "#{http_protocol}://#{host}#{formatted_path}"
end

#endpoint_pathObject



51
52
53
# File 'lib/active_record/remote/client.rb', line 51

def endpoint_path
  # define in subclass
end

#formatted_actionObject



35
36
37
# File 'lib/active_record/remote/client.rb', line 35

def formatted_action
  action
end

#formatted_pathObject



39
40
41
# File 'lib/active_record/remote/client.rb', line 39

def formatted_path
  "/#{endpoint_path}/#{formatted_action}"
end

#httpObject



31
32
33
# File 'lib/active_record/remote/client.rb', line 31

def http
  @http ||= Net::HTTP.new(host)
end

#http_protocolObject



47
48
49
# File 'lib/active_record/remote/client.rb', line 47

def http_protocol
  secure ? "https" : "http"
end

#request(request_body) ⇒ Object



55
56
57
58
59
60
61
62
63
64
65
66
# File 'lib/active_record/remote/client.rb', line 55

def request(request_body)
  request              = Net::HTTP::Post.new(formatted_path)
  request.body         = request_body
  request.content_type = content_type
  if secure
    http.use_ssl     = true
    http.verify_mode = OpenSSL::SSL::VERIFY_NONE
  end
  request.add_field("SOAPAction", "") if api_type == :soap
  http.read_timeout = read_timeout    if read_timeout
  http.request(request)
end