httparty 0.15.6 → 0.18.1
Sign up to get free protection for your applications and to get access to all the features.
Potentially problematic release.
This version of httparty might be problematic. Click here for more details.
- checksums.yaml +5 -5
- data/.editorconfig +18 -0
- data/.gitignore +1 -0
- data/.rubocop_todo.yml +1 -1
- data/.travis.yml +7 -5
- data/Changelog.md +78 -0
- data/Gemfile +5 -0
- data/README.md +4 -2
- data/docs/README.md +3 -3
- data/examples/README.md +25 -11
- data/examples/body_stream.rb +14 -0
- data/examples/custom_parsers.rb +4 -0
- data/examples/headers_and_user_agents.rb +7 -3
- data/examples/logging.rb +3 -3
- data/examples/microsoft_graph.rb +52 -0
- data/examples/multipart.rb +22 -0
- data/examples/peer_cert.rb +9 -0
- data/examples/stream_download.rb +8 -2
- data/httparty.gemspec +2 -2
- data/lib/httparty.rb +48 -21
- data/lib/httparty/connection_adapter.rb +56 -15
- data/lib/httparty/cookie_hash.rb +8 -8
- data/lib/httparty/hash_conversions.rb +26 -12
- data/lib/httparty/headers_processor.rb +30 -0
- data/lib/httparty/logger/apache_formatter.rb +29 -6
- data/lib/httparty/logger/curl_formatter.rb +4 -4
- data/lib/httparty/logger/logger.rb +3 -1
- data/lib/httparty/logger/logstash_formatter.rb +59 -0
- data/lib/httparty/module_inheritable_attributes.rb +3 -3
- data/lib/httparty/net_digest_auth.rb +6 -5
- data/lib/httparty/parser.rb +12 -10
- data/lib/httparty/request.rb +38 -85
- data/lib/httparty/request/body.rb +84 -0
- data/lib/httparty/request/multipart_boundary.rb +11 -0
- data/lib/httparty/response.rb +54 -5
- data/lib/httparty/response/headers.rb +2 -2
- data/lib/httparty/response_fragment.rb +19 -0
- data/lib/httparty/text_encoder.rb +70 -0
- data/lib/httparty/utils.rb +11 -0
- data/lib/httparty/version.rb +1 -1
- data/website/css/common.css +1 -1
- metadata +31 -98
- data/features/basic_authentication.feature +0 -20
- data/features/command_line.feature +0 -95
- data/features/deals_with_http_error_codes.feature +0 -26
- data/features/digest_authentication.feature +0 -30
- data/features/handles_compressed_responses.feature +0 -27
- data/features/handles_multiple_formats.feature +0 -57
- data/features/steps/env.rb +0 -27
- data/features/steps/httparty_response_steps.rb +0 -56
- data/features/steps/httparty_steps.rb +0 -43
- data/features/steps/mongrel_helper.rb +0 -127
- data/features/steps/remote_service_steps.rb +0 -92
- data/features/supports_read_timeout_option.feature +0 -13
- data/features/supports_redirection.feature +0 -22
- data/features/supports_timeout_option.feature +0 -13
- data/spec/fixtures/delicious.xml +0 -23
- data/spec/fixtures/empty.xml +0 -0
- data/spec/fixtures/google.html +0 -3
- data/spec/fixtures/ssl/generate.sh +0 -29
- data/spec/fixtures/ssl/generated/bogushost.crt +0 -13
- data/spec/fixtures/ssl/generated/ca.crt +0 -16
- data/spec/fixtures/ssl/generated/ca.key +0 -15
- data/spec/fixtures/ssl/generated/selfsigned.crt +0 -14
- data/spec/fixtures/ssl/generated/server.crt +0 -13
- data/spec/fixtures/ssl/generated/server.key +0 -15
- data/spec/fixtures/ssl/openssl-exts.cnf +0 -9
- data/spec/fixtures/twitter.csv +0 -2
- data/spec/fixtures/twitter.json +0 -1
- data/spec/fixtures/twitter.xml +0 -403
- data/spec/fixtures/undefined_method_add_node_for_nil.xml +0 -2
- data/spec/httparty/connection_adapter_spec.rb +0 -495
- data/spec/httparty/cookie_hash_spec.rb +0 -100
- data/spec/httparty/exception_spec.rb +0 -45
- data/spec/httparty/hash_conversions_spec.rb +0 -49
- data/spec/httparty/logger/apache_formatter_spec.rb +0 -41
- data/spec/httparty/logger/curl_formatter_spec.rb +0 -119
- data/spec/httparty/logger/logger_spec.rb +0 -38
- data/spec/httparty/net_digest_auth_spec.rb +0 -268
- data/spec/httparty/parser_spec.rb +0 -190
- data/spec/httparty/request_spec.rb +0 -1279
- data/spec/httparty/response_spec.rb +0 -347
- data/spec/httparty/ssl_spec.rb +0 -74
- data/spec/httparty_spec.rb +0 -878
- data/spec/spec_helper.rb +0 -51
- data/spec/support/ssl_test_helper.rb +0 -47
- data/spec/support/ssl_test_server.rb +0 -80
- data/spec/support/stub_response.rb +0 -49
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 21274d1c09f3460352bc2aaf0cc00e6c0f9fb76eae45bc6dd0a65748c8d29463
|
4
|
+
data.tar.gz: c6900248181afef6fdf36381d4e33365345073a5a00f73498ac3e89259838f14
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 116978b76182751905d115a80ac0e350637564cad3c8d2bf8938ffcac99ff0e782bd810aa9889db3218ad147d38632c75fd85521682d22d7bb654de8cf1d0352
|
7
|
+
data.tar.gz: 2048e308a2d88288f9ab373f1472acd9955aeb7870c2a8cbfc128d0b71ace183bc7011a20f2f20ce7c2e37e400b4c9c6a3b695fc6dc36144e583a7151fc4a5e1
|
data/.editorconfig
ADDED
@@ -0,0 +1,18 @@
|
|
1
|
+
; This file is for unifying the coding style for different editors and IDEs.
|
2
|
+
; More information at http://EditorConfig.org
|
3
|
+
|
4
|
+
root = true
|
5
|
+
[*]
|
6
|
+
end_of_line = lf
|
7
|
+
trim_trailing_whitespace = true
|
8
|
+
|
9
|
+
[**.rb]
|
10
|
+
indent_size = 2
|
11
|
+
indent_style = spaces
|
12
|
+
insert_final_newline = true
|
13
|
+
|
14
|
+
[**.xml]
|
15
|
+
trim_trailing_whitespace = false
|
16
|
+
|
17
|
+
[**.html]
|
18
|
+
trim_trailing_whitespace = false
|
data/.gitignore
CHANGED
data/.rubocop_todo.yml
CHANGED
data/.travis.yml
CHANGED
@@ -1,9 +1,11 @@
|
|
1
1
|
language: ruby
|
2
2
|
rvm:
|
3
3
|
- 2.0.0
|
4
|
-
- 2.1.
|
5
|
-
- 2.2.
|
6
|
-
- 2.3.
|
7
|
-
- 2.4.
|
4
|
+
- 2.1.10
|
5
|
+
- 2.2.10
|
6
|
+
- 2.3.8
|
7
|
+
- 2.4.5
|
8
|
+
- 2.5.3
|
9
|
+
- 2.6.1
|
8
10
|
bundler_args: --without development
|
9
|
-
before_install: gem install bundler
|
11
|
+
before_install: gem install bundler -v '< 2'
|
data/Changelog.md
CHANGED
@@ -1,3 +1,81 @@
|
|
1
|
+
## 0.18.1
|
2
|
+
|
3
|
+
* [Rename cop Lint/HandleExceptions to Lint/SuppressedException](https://github.com/jnunemaker/httparty/pull/699).
|
4
|
+
* [Encode keys in query params](https://github.com/jnunemaker/httparty/pull/698).
|
5
|
+
* [Fixed SSL doc example](https://github.com/jnunemaker/httparty/pull/692).
|
6
|
+
* [Add a build status badge](https://github.com/jnunemaker/httparty/pull/701).
|
7
|
+
|
8
|
+
|
9
|
+
## 0.18.0
|
10
|
+
|
11
|
+
* [Support gzip/deflate transfer encoding when explicit headers are set](https://github.com/jnunemaker/httparty/pull/678).
|
12
|
+
* [Support edge case cookie format with a blank attribute](https://github.com/jnunemaker/httparty/pull/685).
|
13
|
+
|
14
|
+
## 0.17.3
|
15
|
+
|
16
|
+
0.17.2 is broken https://github.com/jnunemaker/httparty/issues/681
|
17
|
+
|
18
|
+
## 0.17.2
|
19
|
+
|
20
|
+
* [Add Response#nil? deprecetion warning](https://github.com/jnunemaker/httparty/pull/680)
|
21
|
+
|
22
|
+
## 0.17.1
|
23
|
+
|
24
|
+
* [Pass options to dynamic block headers](https://github.com/jnunemaker/httparty/pull/661)
|
25
|
+
* [Normalize urls with URI adapter to allow International Domain Names support](https://github.com/jnunemaker/httparty/pull/668)
|
26
|
+
* [Add max_retries support](https://github.com/jnunemaker/httparty/pull/660)
|
27
|
+
* [Minize gem size by removing test files](https://github.com/jnunemaker/httparty/pull/658)
|
28
|
+
|
29
|
+
## 0.17.0
|
30
|
+
|
31
|
+
* [Fix encoding of streamed chunk](https://github.com/jnunemaker/httparty/pull/644)
|
32
|
+
* [Avoid modifying frozen strings](https://github.com/jnunemaker/httparty/pull/649)
|
33
|
+
* [Expose .connection on fragment block param](https://github.com/jnunemaker/httparty/pull/648)
|
34
|
+
* [Add support for `Net::HTTP#write_timeout` method (Ruby 2.6.0)](https://github.com/jnunemaker/httparty/pull/647)
|
35
|
+
|
36
|
+
## 0.16.4
|
37
|
+
* [Add support for Ruby 2.6](https://github.com/jnunemaker/httparty/pull/636)
|
38
|
+
* [Fix a few multipart issues](https://github.com/jnunemaker/httparty/pull/626)
|
39
|
+
* [Improve a memory usage for https requests](https://github.com/jnunemaker/httparty/pull/625)
|
40
|
+
* [Add response code to streamed body](https://github.com/jnunemaker/httparty/pull/588)
|
41
|
+
|
42
|
+
## 0.16.3
|
43
|
+
* [Add Logstash-compatible formatter](https://github.com/jnunemaker/httparty/pull/612)
|
44
|
+
* [Add support for headers specified with symbols](https://github.com/jnunemaker/httparty/pull/622)
|
45
|
+
* [Fix response object marshalling](https://github.com/jnunemaker/httparty/pull/618)
|
46
|
+
* [Add ability to send multipart, without passing file](https://github.com/jnunemaker/httparty/pull/615)
|
47
|
+
* [Fix detection of content_type for multipart payload](https://github.com/jnunemaker/httparty/pull/616)
|
48
|
+
* [Process dynamic headers before making actual request](https://github.com/jnunemaker/httparty/pull/606)
|
49
|
+
* [Fix multipart uploads with ActionDispatch::Http::UploadedFile TempFile by using original_filename](https://github.com/jnunemaker/httparty/pull/598)
|
50
|
+
* [Added support for lock and unlock http requests](https://github.com/jnunemaker/httparty/pull/596)
|
51
|
+
|
52
|
+
## 0.16.2
|
53
|
+
|
54
|
+
* [Support ActionDispatch::Http::UploadedFile again](https://github.com/jnunemaker/httparty/pull/585)
|
55
|
+
|
56
|
+
## 0.16.1
|
57
|
+
|
58
|
+
* [Parse content with application/hal+json content type as JSON](https://github.com/jnunemaker/httparty/pull/573)
|
59
|
+
* [Convert objects to string when concatenating in multipart stuff](https://github.com/jnunemaker/httparty/pull/575)
|
60
|
+
* [Fix multipart to set its header even when other headers are provided](https://github.com/jnunemaker/httparty/pull/576)
|
61
|
+
|
62
|
+
## 0.16.0
|
63
|
+
|
64
|
+
* [Add multipart support](https://github.com/jnunemaker/httparty/pull/569)
|
65
|
+
|
66
|
+
## 0.15.7
|
67
|
+
|
68
|
+
Fixed
|
69
|
+
|
70
|
+
* [Add Response#pretty_print | Restore documented behavior](https://github.com/jnunemaker/httparty/pull/570)
|
71
|
+
* [Add ability to parse response from JSONAPI ](https://github.com/jnunemaker/httparty/pull/553)
|
72
|
+
|
73
|
+
## 0.15.6
|
74
|
+
|
75
|
+
Fixed
|
76
|
+
|
77
|
+
* [Encoding and content type stuff](https://github.com/jnunemaker/httparty/pull/543)
|
78
|
+
|
1
79
|
## 0.15.5
|
2
80
|
|
3
81
|
Fixed
|
data/Gemfile
CHANGED
data/README.md
CHANGED
@@ -1,6 +1,8 @@
|
|
1
1
|
# httparty
|
2
2
|
|
3
|
-
|
3
|
+
[![Build Status](https://travis-ci.org/jnunemaker/httparty.svg?branch=master)](https://travis-ci.org/jnunemaker/httparty)
|
4
|
+
|
5
|
+
Makes http fun again! Ain't no party like a httparty, because a httparty don't stop.
|
4
6
|
|
5
7
|
## Install
|
6
8
|
|
@@ -64,7 +66,7 @@ httparty "https://api.stackexchange.com/2.2/questions?site=stackoverflow"
|
|
64
66
|
|
65
67
|
* [Docs](https://github.com/jnunemaker/httparty/tree/master/docs)
|
66
68
|
* https://groups.google.com/forum/#!forum/httparty-gem
|
67
|
-
*
|
69
|
+
* https://www.rubydoc.info/github/jnunemaker/httparty
|
68
70
|
* http://stackoverflow.com/questions/tagged/httparty
|
69
71
|
|
70
72
|
## Contributing
|
data/docs/README.md
CHANGED
@@ -9,7 +9,7 @@ Makes http fun again!
|
|
9
9
|
## Parsing JSON
|
10
10
|
If the response Content Type is `application/json`, HTTParty will parse the response and return Ruby objects such as a hash or array. The default behavior for parsing JSON will return keys as strings. This can be supressed with the `format` option. To get hash keys as symbols:
|
11
11
|
|
12
|
-
```
|
12
|
+
```ruby
|
13
13
|
response = HTTParty.get('http://example.com', format: :plain)
|
14
14
|
JSON.parse response, symbolize_names: true
|
15
15
|
```
|
@@ -79,7 +79,7 @@ class Client
|
|
79
79
|
base_uri "https://example.com"
|
80
80
|
|
81
81
|
def self.fetch
|
82
|
-
get("/resources", pem:
|
82
|
+
get("/resources", pem: File.read("#{File.expand_path('.')}/path/to/certs/cert.pem"), pem_password: "123456")
|
83
83
|
end
|
84
84
|
end
|
85
85
|
```
|
@@ -103,4 +103,4 @@ class Client
|
|
103
103
|
# get("resources", verify_peer: false)
|
104
104
|
end
|
105
105
|
end
|
106
|
-
```
|
106
|
+
```
|
data/examples/README.md
CHANGED
@@ -13,22 +13,22 @@
|
|
13
13
|
* Creates a custom parser for XML using crack gem
|
14
14
|
* Uses `get` request
|
15
15
|
|
16
|
-
* [Create HTML Nokogiri parser](nokogiri_html_parser.rb)
|
16
|
+
* [Create HTML Nokogiri parser](nokogiri_html_parser.rb)
|
17
17
|
* Adds Html as a format
|
18
18
|
* passed the body of request to Nokogiri
|
19
|
-
|
19
|
+
|
20
20
|
* [More Custom Parsers](custom_parsers.rb)
|
21
21
|
* Create an additional parser for atom or make it the ONLY parser
|
22
|
-
|
22
|
+
|
23
23
|
* [Basic Auth, Delicious](delicious.rb)
|
24
24
|
* Basic Auth, shows how to merge those into options
|
25
25
|
* Uses `get` requests
|
26
|
-
|
26
|
+
|
27
27
|
* [Passing Headers, User Agent](headers_and_user_agents.rb)
|
28
28
|
* Use the class method of Httparty
|
29
29
|
* Pass the User-Agent in the headers
|
30
30
|
* Uses `get` requests
|
31
|
-
|
31
|
+
|
32
32
|
* [Basic Post Request](basic.rb)
|
33
33
|
* Httparty included into poro class
|
34
34
|
* Uses `post` requests
|
@@ -36,7 +36,7 @@
|
|
36
36
|
* [Access Rubyurl Shortener](rubyurl.rb)
|
37
37
|
* Httparty included into poro class
|
38
38
|
* Uses `post` requests
|
39
|
-
|
39
|
+
|
40
40
|
* [Add a custom log file](logging.rb)
|
41
41
|
* create a log file and have httparty log requests
|
42
42
|
|
@@ -44,23 +44,23 @@
|
|
44
44
|
* Httparty included into poro class
|
45
45
|
* Creates methods for different endpoints
|
46
46
|
* Uses `get` requests
|
47
|
-
|
47
|
+
|
48
48
|
* [Accessing Tripit](tripit_sign_in.rb)
|
49
49
|
* Httparty included into poro class
|
50
50
|
* Example of using `debug_output` to see headers/urls passed
|
51
51
|
* Getting and using Cookies
|
52
52
|
* Uses `get` requests
|
53
|
-
|
53
|
+
|
54
54
|
* [Accessing Twitter](twitter.rb)
|
55
55
|
* Httparty included into poro class
|
56
56
|
* Basic Auth
|
57
|
-
* Loads settings from a config file
|
57
|
+
* Loads settings from a config file
|
58
58
|
* Uses `get` requests
|
59
59
|
* Uses `post` requests
|
60
|
-
|
60
|
+
|
61
61
|
* [Accessing WhoIsMyRep](whoismyrep.rb)
|
62
62
|
* Httparty included into poro class
|
63
|
-
* Uses `get` requests
|
63
|
+
* Uses `get` requests
|
64
64
|
* Two ways to pass params to get, inline on the url or in query hash
|
65
65
|
|
66
66
|
* [Rescue Json Error](rescue_json.rb)
|
@@ -70,3 +70,17 @@
|
|
70
70
|
* Uses `get` requests
|
71
71
|
* Uses `stream_body` mode
|
72
72
|
* Download file without using the memory
|
73
|
+
|
74
|
+
* [Microsoft graph](microsoft_graph.rb)
|
75
|
+
* Basic Auth
|
76
|
+
* Uses `post` requests
|
77
|
+
* Uses multipart
|
78
|
+
|
79
|
+
* [Multipart](multipart.rb)
|
80
|
+
* Multipart data upload _(with and without file)_
|
81
|
+
|
82
|
+
* [Uploading File](body_stream.rb)
|
83
|
+
* Uses `body_stream` to upload file
|
84
|
+
|
85
|
+
* [Accessing x509 Peer Certificate](peer_cert.rb)
|
86
|
+
* Provides access to the server's TLS certificate
|
@@ -0,0 +1,14 @@
|
|
1
|
+
# To upload file to a server use :body_stream
|
2
|
+
|
3
|
+
HTTParty.put(
|
4
|
+
'http://localhost:3000/train',
|
5
|
+
body_stream: File.open('sample_configs/config_train_server_md.yml', 'r')
|
6
|
+
)
|
7
|
+
|
8
|
+
|
9
|
+
# Actually, it works with any IO object
|
10
|
+
|
11
|
+
HTTParty.put(
|
12
|
+
'http://localhost:3000/train',
|
13
|
+
body_stream: StringIO.new('foo')
|
14
|
+
)
|
data/examples/custom_parsers.rb
CHANGED
@@ -1,6 +1,10 @@
|
|
1
1
|
# To send custom user agents to identify your application to a web service (or mask as a specific browser for testing), send "User-Agent" as a hash to headers as shown below.
|
2
2
|
|
3
|
-
|
3
|
+
dir = File.expand_path(File.join(File.dirname(__FILE__), '..', 'lib'))
|
4
|
+
require File.join(dir, 'httparty')
|
5
|
+
require 'pp'
|
4
6
|
|
5
|
-
|
6
|
-
|
7
|
+
response = HTTParty.get('http://example.com', {
|
8
|
+
headers: {"User-Agent" => "Httparty"},
|
9
|
+
debug_output: STDOUT, # To show that User-Agent is Httparty
|
10
|
+
})
|
data/examples/logging.rb
CHANGED
@@ -3,7 +3,7 @@ require File.join(dir, 'httparty')
|
|
3
3
|
require 'logger'
|
4
4
|
require 'pp'
|
5
5
|
|
6
|
-
my_logger = Logger.new
|
6
|
+
my_logger = Logger.new STDOUT
|
7
7
|
|
8
8
|
my_logger.info "Logging can be used on the main HTTParty class. It logs redirects too."
|
9
9
|
HTTParty.get "http://google.com", logger: my_logger
|
@@ -14,7 +14,7 @@ my_logger.info "It can be used also on a custom class."
|
|
14
14
|
|
15
15
|
class Google
|
16
16
|
include HTTParty
|
17
|
-
logger ::Logger.new
|
17
|
+
logger ::Logger.new STDOUT
|
18
18
|
end
|
19
19
|
|
20
20
|
Google.get "http://google.com"
|
@@ -30,7 +30,7 @@ my_logger.info '*' * 70
|
|
30
30
|
my_logger.info "These configs are also available on custom classes."
|
31
31
|
class Google
|
32
32
|
include HTTParty
|
33
|
-
logger ::Logger.new(
|
33
|
+
logger ::Logger.new(STDOUT), :debug, :curl
|
34
34
|
end
|
35
35
|
|
36
36
|
Google.get "http://google.com"
|
@@ -0,0 +1,52 @@
|
|
1
|
+
require 'httparty'
|
2
|
+
|
3
|
+
class MicrosoftGraph
|
4
|
+
MS_BASE_URL = "https://login.microsoftonline.com".freeze
|
5
|
+
TOKEN_REQUEST_PATH = "oauth2/v2.0/token".freeze
|
6
|
+
|
7
|
+
def initialize(tenant_id)
|
8
|
+
@tenant_id = tenant_id
|
9
|
+
end
|
10
|
+
|
11
|
+
# Make a request to the Microsoft Graph API, for instance https://graph.microsoft.com/v1.0/users
|
12
|
+
def request(url)
|
13
|
+
return false unless (token = bearer_token)
|
14
|
+
|
15
|
+
response = HTTParty.get(
|
16
|
+
url,
|
17
|
+
headers: {
|
18
|
+
Authorization: "Bearer #{token}"
|
19
|
+
}
|
20
|
+
)
|
21
|
+
|
22
|
+
return false unless response.code == 200
|
23
|
+
|
24
|
+
return JSON.parse(response.body)
|
25
|
+
end
|
26
|
+
|
27
|
+
private
|
28
|
+
|
29
|
+
# A post to the Microsoft Graph to get a bearer token for the specified tenant. In this example
|
30
|
+
# our Rails application has already been given permission to request these tokens by the admin of
|
31
|
+
# the specified tenant_id.
|
32
|
+
#
|
33
|
+
# See here for more information https://developer.microsoft.com/en-us/graph/docs/concepts/auth_v2_service
|
34
|
+
#
|
35
|
+
# This request also makes use of the multipart/form-data post body.
|
36
|
+
def bearer_token
|
37
|
+
response = HTTParty.post(
|
38
|
+
"#{MS_BASE_URL}/#{@tenant_id}/#{TOKEN_REQUEST_PATH}",
|
39
|
+
multipart: true,
|
40
|
+
body: {
|
41
|
+
client_id: Rails.application.credentials[Rails.env.to_sym][:microsoft_client_id],
|
42
|
+
client_secret: Rails.application.credentials[Rails.env.to_sym][:microsoft_client_secret],
|
43
|
+
scope: 'https://graph.microsoft.com/.default',
|
44
|
+
grant_type: 'client_credentials'
|
45
|
+
}
|
46
|
+
)
|
47
|
+
|
48
|
+
return false unless response.code == 200
|
49
|
+
|
50
|
+
JSON.parse(response.body)['access_token']
|
51
|
+
end
|
52
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
# If you are uploading file in params, multipart will used as content-type automatically
|
2
|
+
|
3
|
+
HTTParty.post(
|
4
|
+
'http://localhost:3000/user',
|
5
|
+
body: {
|
6
|
+
name: 'Foo Bar',
|
7
|
+
email: 'example@email.com',
|
8
|
+
avatar: File.open('/full/path/to/avatar.jpg')
|
9
|
+
}
|
10
|
+
)
|
11
|
+
|
12
|
+
|
13
|
+
# However, you can force it yourself
|
14
|
+
|
15
|
+
HTTParty.post(
|
16
|
+
'http://localhost:3000/user',
|
17
|
+
multipart: true,
|
18
|
+
body: {
|
19
|
+
name: 'Foo Bar',
|
20
|
+
email: 'example@email.com'
|
21
|
+
}
|
22
|
+
)
|
@@ -0,0 +1,9 @@
|
|
1
|
+
dir = File.expand_path(File.join(File.dirname(__FILE__), '..', 'lib'))
|
2
|
+
require File.join(dir, 'httparty')
|
3
|
+
|
4
|
+
peer_cert = nil
|
5
|
+
HTTParty.get("https://www.example.com") do |fragment|
|
6
|
+
peer_cert ||= fragment.connection.peer_cert
|
7
|
+
end
|
8
|
+
|
9
|
+
puts "The server's certificate expires #{peer_cert.not_after}"
|
data/examples/stream_download.rb
CHANGED
@@ -9,8 +9,14 @@ url = "https://cdn.kernel.org/pub/linux/kernel/v4.x/#{filename}"
|
|
9
9
|
|
10
10
|
File.open(filename, "w") do |file|
|
11
11
|
response = HTTParty.get(url, stream_body: true) do |fragment|
|
12
|
-
|
13
|
-
|
12
|
+
if [301, 302].include?(fragment.code)
|
13
|
+
print "skip writing for redirect"
|
14
|
+
elsif fragment.code == 200
|
15
|
+
print "."
|
16
|
+
file.write(fragment)
|
17
|
+
else
|
18
|
+
raise StandardError, "Non-success status code while streaming #{fragment.code}"
|
19
|
+
end
|
14
20
|
end
|
15
21
|
end
|
16
22
|
puts
|