rquest 1.0.3 → 1.0.4

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: ccb87b11c4a5df2002cc9ead2028f0297ffc3a12
4
- data.tar.gz: bdb349435190c34cafe4de1c75e263b87192885c
3
+ metadata.gz: f8e9c105156c55e454ce83def1bf7b510cda4852
4
+ data.tar.gz: da15cb62c55daadfd472b2e1ccf8de93520c33ce
5
5
  SHA512:
6
- metadata.gz: 7865e3f64395107ee24687bd802182a785a8c79fb03a4a4cbf434fad0becdca5835c79d9fafabd3d08a8c4edd5e7f13645aac9f291264209efa1cd68a7855cd1
7
- data.tar.gz: 075e5f4fcaa8247faeab5348f2406d46fe851d3b71201f5d41f85ef5d01e569585ff74db8f1423ad46afeed097331b03c6aeae97caca7b04be8d52941d0875f7
6
+ metadata.gz: 5168e5cf92da783751c71f3795452e59acc2f120be97f97bbdb1f14b0b3eec7508c26dd3073601b946827ec0840873b61bc6e50ee615aa6469a60504b56b57cf
7
+ data.tar.gz: f214c7fdeeb10623726432bd0805dfbe933b64405d8db49591e9ac40fa3152ad70ec82a9c0017b432ca9ab726a4aa31d730a30a006dc4b4f3ad3077cb903ebe3
data/README.md CHANGED
@@ -4,7 +4,7 @@ A helper library to easily define restful web requests in ruby.
4
4
 
5
5
  Bassically I am tiered of constantly relooking up NET HTTP blog post to try and remember how to say override the default headers or attatch a file as a multipart post request. Also there are things about the ruby request generation process I felt I could improve such as, autodetecting the need for ssl from the URI and providing a clean DSL for request definition, as well as cleaner file attatchment.
6
6
 
7
- RQuest makes it easy to build request and gives you full control over every aspect of the request. I modeled it after the chrome extension postman. Everything you can do with postman you can do with RQuest and it follows the same intuitive work flow.
7
+ Rquest makes it easy to build request and gives you full control over every aspect of the request. I modeled it after the chrome extension postman. Everything you can do with postman you can do with Rquest and it follows the same intuitive work flow.
8
8
 
9
9
  In addition Rquest is an object that can handle a full session request cycle. You can say log in have the authentication cookies set by the server and then proceed to parse your dashboard.
10
10
 
@@ -29,7 +29,7 @@ Or install it yourself as:
29
29
  Its basic setup involves setting the uri and action. Its send method will execute the rquest and return the body. You can access the full request object and the response time if you need them.
30
30
 
31
31
  ```ruby
32
- rquest = RQuest.new({verb: :get, uri: "https://google.com"})
32
+ rquest = Rquest.new({verb: :get, uri: "https://google.com"})
33
33
  response_body = rquest.send
34
34
  response_time = rquest.last_response_time
35
35
  response_object = rquest.last_response
@@ -38,7 +38,7 @@ response_object = rquest.last_response
38
38
  You can easily combine query params with the uri and the settings hash
39
39
 
40
40
  ```ruby
41
- rquest = RQuest.new({verb: :get, uri: "https://google.com?q=testing", q_params: {token: "foo"}})
41
+ rquest = Rquest.new({verb: :get, uri: "https://google.com?q=testing", q_params: {token: "foo"}})
42
42
  ```
43
43
 
44
44
  This will result in a request with a URI of http://google.com?q=testing&token=foo behind the sceens
@@ -55,7 +55,14 @@ https.use_ssl = true
55
55
  All controlled from the same settings hash with the payload key
56
56
 
57
57
  ```ruby
58
- rquest = RQuest.new({verb: :post, uri: "https://google.com", payload: {a_field: "stuff", another_field: "more stuff"} })
58
+ rquest = Rquest.new({verb: :post, uri: "https://google.com", payload: {a_field: "stuff", another_field: "more stuff"} })
59
+ rquest.send
60
+ ```
61
+
62
+ The default body style is key=value&other_key=other_value however you can set it to a json body if you need like so
63
+
64
+ ```ruby
65
+ rquest = Rquest.new({verb: :post, uri: "https://google.com", payload: {a_field: "stuff", another_field: "more stuff"}, form_type: :json })
59
66
  rquest.send
60
67
  ```
61
68
 
@@ -68,7 +75,7 @@ Just pass file objects into the files key and everything will be handled for you
68
75
  ```ruby
69
76
  f1 = File.open("path/to/file.txt")
70
77
  f2 = File.open("path/to/file.jpg")
71
- rquest = RQuest.new({verb: :get, uri: "https://google.com", payload: {a_field: "stuff", another_field: "more stuff"}, files: {file_field_1: f1, file_field_2: f2} })
78
+ rquest = Rquest.new({verb: :get, uri: "https://google.com", payload: {a_field: "stuff", another_field: "more stuff"}, files: {file_field_1: f1, file_field_2: f2} })
72
79
  rquest.send
73
80
  ```
74
81
 
@@ -79,7 +86,7 @@ Rquest is built to behave like a fresh incognito browser. Every time you apply s
79
86
  Simply call update to change what you need before the next send like so. New settings will be merged so they will either override old ones ore creat new ones. Any non specified setting will remain untouched from the last request.
80
87
 
81
88
  ```ruby
82
- rquest = RQuest.new({verb: :get, uri: "https://google.com?q=testing", q_params: {token: "foo"}})
89
+ rquest = Rquest.new({verb: :get, uri: "https://google.com?q=testing", q_params: {token: "foo"}})
83
90
  rquest.send
84
91
  rquest.update({q_params: {q: "other search value"}}
85
92
  rquest.send
@@ -100,13 +107,13 @@ time_it_took = first_query[:response_time]
100
107
  You can set cookies for a request by adding them to the settings[:cookies] like
101
108
 
102
109
  ```ruby
103
- rquest = RQuest.new({verb: :get, uri: "https://google.com", payload: {a_field: "stuff", another_field: "more stuff"}, cookies: {"MySpecialCookie" => "SomeSuperSecretValue"} })
110
+ rquest = Rquest.new({verb: :get, uri: "https://google.com", payload: {a_field: "stuff", another_field: "more stuff"}, cookies: {"MySpecialCookie" => "SomeSuperSecretValue"} })
104
111
  ```
105
112
 
106
113
  Any response will add/merge any cookies in the "Set-Cookie" header of the response to your next request
107
114
 
108
115
  ```ruby
109
- rquest = RQuest.new({verb: :post, uri: "https://somesite.com/sessions", payload: {username: "foobar", password: "SuperSecret"}})
116
+ rquest = Rquest.new({verb: :post, uri: "https://somesite.com/sessions", payload: {username: "foobar", password: "SuperSecret"}})
110
117
  rquest.send
111
118
  ```
112
119
  If this authenticates correctly then the server will send the right Set-Cookie so then you can do something like.
@@ -4,6 +4,7 @@ require 'mimemagic'
4
4
  require 'benchmark'
5
5
  require "rquest/core_overrides"
6
6
  require "rquest/requestor"
7
+ require 'json'
7
8
 
8
9
  module Rquest
9
10
  class << self
@@ -9,6 +9,7 @@ module Rquest
9
9
  def update( settings={} )
10
10
  @settings ||= {}
11
11
  @settings = @settings.merge( settings )
12
+ @settings[:form_type] ||= :http
12
13
  apply_default_settings
13
14
  merge_settings
14
15
  @verb = @settings[:verb].to_sym
@@ -116,7 +117,11 @@ module Rquest
116
117
  unless @files.any?
117
118
  klass = Rquest::client_class_for_verb( @verb )
118
119
  @http_request_client = klass.send(:new, uri_path)
119
- @http_request_client.set_form_data( @settings[:payload] )
120
+ if @settings[:form_type] == :http
121
+ @http_request_client.set_form_data( @settings[:payload] )
122
+ elsif @settings[:form_type] == :json
123
+ @http_request_client.body = @settings[:payload].to_json
124
+ end
120
125
  else
121
126
  klass = Rquest::client_class_for_verb( @verb, true )
122
127
  multi_part_params = @settings[:payload].merge( @files )
@@ -1,3 +1,3 @@
1
1
  module Rquest
2
- VERSION = "1.0.3"
2
+ VERSION = "1.0.4"
3
3
  end
Binary file
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rquest
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.3
4
+ version: 1.0.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - The Tyrel Corporation
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2015-03-27 00:00:00.000000000 Z
11
+ date: 2015-04-24 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -137,6 +137,7 @@ files:
137
137
  - rquest-1.0.0.gem
138
138
  - rquest-1.0.1.gem
139
139
  - rquest-1.0.2.gem
140
+ - rquest-1.0.3.gem
140
141
  - rquest.gemspec
141
142
  homepage: https://github.com/thetyrelcorporation/rquest
142
143
  licenses: