Class: Capybara::HTTPClientJson::Driver
- Inherits:
-
Json::Driver::Base
- Object
- Json::Driver::Base
- Capybara::HTTPClientJson::Driver
- Defined in:
- lib/capybara/httpclient_json/driver.rb
Instance Attribute Summary collapse
-
#app ⇒ Object
readonly
Returns the value of attribute app.
-
#cookies ⇒ Object
readonly
Returns the value of attribute cookies.
-
#current_url ⇒ Object
readonly
Returns the value of attribute current_url.
-
#options ⇒ Object
readonly
Returns the value of attribute options.
-
#response ⇒ Object
readonly
Returns the value of attribute response.
Instance Method Summary collapse
- #body ⇒ Object
- #client ⇒ Object
- #delete(url, params = {}, headers = {}) ⇒ Object
- #get(url, params = {}, headers = {}) ⇒ Object (also: #visit)
-
#initialize(app, options = {}) ⇒ Driver
constructor
A new instance of Driver.
- #json ⇒ Object
- #needs_server? ⇒ Boolean
- #patch(url, json, headers = {}) ⇒ Object
- #post(url, json, headers = {}) ⇒ Object
- #put(url, json, headers = {}) ⇒ Object
- #raw_json ⇒ Object (also: #source, #html)
- #reset! ⇒ Object
- #response_headers ⇒ Object
- #status_code ⇒ Object
Constructor Details
#initialize(app, options = {}) ⇒ Driver
Returns a new instance of Driver.
22 23 24 25 26 |
# File 'lib/capybara/httpclient_json/driver.rb', line 22 def initialize(app, = {}) @app, @options = app, { :follow_redirect => true }.merge() @rack_server = Capybara::Server.new(@app) @rack_server.boot if Capybara.run_server end |
Instance Attribute Details
#app ⇒ Object (readonly)
Returns the value of attribute app.
4 5 6 |
# File 'lib/capybara/httpclient_json/driver.rb', line 4 def app @app end |
#cookies ⇒ Object (readonly)
Returns the value of attribute cookies.
4 5 6 |
# File 'lib/capybara/httpclient_json/driver.rb', line 4 def @cookies end |
#current_url ⇒ Object (readonly)
Returns the value of attribute current_url.
4 5 6 |
# File 'lib/capybara/httpclient_json/driver.rb', line 4 def current_url @current_url end |
#options ⇒ Object (readonly)
Returns the value of attribute options.
4 5 6 |
# File 'lib/capybara/httpclient_json/driver.rb', line 4 def @options end |
#response ⇒ Object (readonly)
Returns the value of attribute response.
4 5 6 |
# File 'lib/capybara/httpclient_json/driver.rb', line 4 def response @response end |
Instance Method Details
#body ⇒ Object
38 39 40 |
# File 'lib/capybara/httpclient_json/driver.rb', line 38 def body MultiJson.load(source) || {} end |
#client ⇒ Object
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 |
# File 'lib/capybara/httpclient_json/driver.rb', line 6 def client unless @client @client = HTTPClient.new @client.follow_redirect_count = 5 + 1 # allows 5 redirection @client.ssl_config.verify_mode = OpenSSL::SSL::VERIFY_NONE # hack for redirect def @client.redirect_uri_callback_to_keep_new_uri(uri, res) new_uri = default_redirect_uri_callback(uri, res) @new_uri = new_uri end @client.redirect_uri_callback = @client.method(:redirect_uri_callback_to_keep_new_uri) end @client end |
#delete(url, params = {}, headers = {}) ⇒ Object
73 74 75 |
# File 'lib/capybara/httpclient_json/driver.rb', line 73 def delete(url, params = {}, headers = {}) process :delete, url, params, headers end |
#get(url, params = {}, headers = {}) ⇒ Object Also known as: visit
50 51 52 |
# File 'lib/capybara/httpclient_json/driver.rb', line 50 def get(url, params = {}, headers = {}) process :get, url, params, headers, [:follow_redirect] end |
#json ⇒ Object
42 43 44 |
# File 'lib/capybara/httpclient_json/driver.rb', line 42 def json MultiJson.load(source) || {} end |
#needs_server? ⇒ Boolean
93 94 95 |
# File 'lib/capybara/httpclient_json/driver.rb', line 93 def needs_server? true end |
#patch(url, json, headers = {}) ⇒ Object
61 62 63 64 65 |
# File 'lib/capybara/httpclient_json/driver.rb', line 61 def patch(url, json, headers = {}) json = MultiJson.dump(json) unless json.is_a?(String) headers['Content-Type'] = "application/json; charset=#{json.encoding.to_s.downcase}" process :patch, url, json, headers, [:follow_redirect] end |
#post(url, json, headers = {}) ⇒ Object
55 56 57 58 59 |
# File 'lib/capybara/httpclient_json/driver.rb', line 55 def post(url, json, headers = {}) json = MultiJson.dump(json) unless json.is_a?(String) headers['Content-Type'] = "application/json; charset=#{json.encoding.to_s.downcase}" process :post, url, json, headers, [:follow_redirect] end |
#put(url, json, headers = {}) ⇒ Object
67 68 69 70 71 |
# File 'lib/capybara/httpclient_json/driver.rb', line 67 def put(url, json, headers = {}) json = MultiJson.dump(json) unless json.is_a?(String) headers['Content-Type'] = "application/json; charset=#{json.encoding.to_s.downcase}" process :put, url, json, headers end |
#raw_json ⇒ Object Also known as: source, html
32 33 34 |
# File 'lib/capybara/httpclient_json/driver.rb', line 32 def raw_json response.body end |
#reset! ⇒ Object
97 98 99 |
# File 'lib/capybara/httpclient_json/driver.rb', line 97 def reset! @client = nil end |
#response_headers ⇒ Object
46 47 48 |
# File 'lib/capybara/httpclient_json/driver.rb', line 46 def response_headers response.headers end |
#status_code ⇒ Object
28 29 30 |
# File 'lib/capybara/httpclient_json/driver.rb', line 28 def status_code response.code end |