Class: ActiveRecord::Remote::Client
- Inherits:
-
Object
- Object
- ActiveRecord::Remote::Client
- Defined in:
- lib/active_record/remote/client.rb
Instance Attribute Summary collapse
-
#action ⇒ Object
Returns the value of attribute action.
Class Method Summary collapse
- .content_type(content_type) ⇒ Object
- .host(host) ⇒ Object
- .read_timeout(read_timeout) ⇒ Object
- .secure(secure) ⇒ Object
Instance Method Summary collapse
- #complete_request_url ⇒ Object
- #endpoint_path ⇒ Object
- #formatted_action ⇒ Object
- #formatted_path ⇒ Object
- #http ⇒ Object
- #http_protocol ⇒ Object
-
#initialize(action) ⇒ Client
constructor
A new instance of Client.
- #request(request_body) ⇒ Object
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
#action ⇒ Object
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_url ⇒ Object
43 44 45 |
# File 'lib/active_record/remote/client.rb', line 43 def complete_request_url "#{http_protocol}://#{host}#{formatted_path}" end |
#endpoint_path ⇒ Object
51 52 53 |
# File 'lib/active_record/remote/client.rb', line 51 def endpoint_path # define in subclass end |
#formatted_action ⇒ Object
35 36 37 |
# File 'lib/active_record/remote/client.rb', line 35 def formatted_action action end |
#formatted_path ⇒ Object
39 40 41 |
# File 'lib/active_record/remote/client.rb', line 39 def formatted_path "/#{endpoint_path}/#{formatted_action}" end |
#http ⇒ Object
31 32 33 |
# File 'lib/active_record/remote/client.rb', line 31 def http @http ||= Net::HTTP.new(host) end |
#http_protocol ⇒ Object
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 |