mirror of
https://github.com/jnunemaker/httparty
synced 2023-03-27 23:23:07 -04:00
Merge pull request #449 from IcaliaLabs/ssl-docs
Adds docs directory with SSL configuration help
This commit is contained in:
commit
2e08aacb96
2 changed files with 101 additions and 0 deletions
|
@ -62,6 +62,7 @@ httparty "https://api.stackexchange.com/2.2/questions?site=stackoverflow"
|
|||
|
||||
## Help and Docs
|
||||
|
||||
* [Docs](docs/)
|
||||
* https://groups.google.com/forum/#!forum/httparty-gem
|
||||
* http://rdoc.info/projects/jnunemaker/httparty
|
||||
* http://stackoverflow.com/questions/tagged/httparty
|
||||
|
|
100
docs/README.md
Normal file
100
docs/README.md
Normal file
|
@ -0,0 +1,100 @@
|
|||
# httparty
|
||||
|
||||
Makes http fun again!
|
||||
|
||||
## Table of contents
|
||||
- [Working with SSL](#working-with-ssl)
|
||||
|
||||
## Working with SSL
|
||||
|
||||
You can use this guide to work with SSL certificates.
|
||||
|
||||
#### Using `pem` option
|
||||
|
||||
```ruby
|
||||
# Use this example if you are using a pem file
|
||||
|
||||
class Client
|
||||
include HTTParty
|
||||
|
||||
base_uri "https://example.com"
|
||||
pem File.read("#{File.expand_path('.')}/path/to/certs/cert.pem"), "123456"
|
||||
|
||||
end
|
||||
```
|
||||
|
||||
#### Using `pkcs12` option
|
||||
|
||||
```ruby
|
||||
# Use this example if you are using a pkcs12 file
|
||||
|
||||
class Client
|
||||
include HTTParty
|
||||
|
||||
base_uri "https://example.com"
|
||||
pkcs12 File.read("#{File.expand_path('.')}/path/to/certs/cert.p12"), "123456"
|
||||
|
||||
end
|
||||
```
|
||||
|
||||
#### Using `ssl_ca_file` option
|
||||
|
||||
```ruby
|
||||
# Use this example if you are using a pkcs12 file
|
||||
|
||||
class Client
|
||||
include HTTParty
|
||||
|
||||
base_uri "https://example.com"
|
||||
ssl_ca_file "#{File.expand_path('.')}/path/to/certs/cert.pem"
|
||||
|
||||
end
|
||||
```
|
||||
|
||||
#### Using `ssl_ca_path` option
|
||||
|
||||
```ruby
|
||||
# Use this example if you are using a pkcs12 file
|
||||
|
||||
class Client
|
||||
include HTTParty
|
||||
|
||||
base_uri "https://example.com"
|
||||
ssl_ca_path '/path/to/certs'
|
||||
end
|
||||
```
|
||||
|
||||
You can also include this options with the call:
|
||||
|
||||
```ruby
|
||||
class Client
|
||||
include HTTParty
|
||||
|
||||
base_uri "https://example.com"
|
||||
|
||||
def self.fetch
|
||||
get("/resources", pem: (File.read("#{File.expand_path('.')}/path/to/certs/cert.pem"), "123456")
|
||||
end
|
||||
end
|
||||
```
|
||||
|
||||
### Avoid SSL verification
|
||||
|
||||
In some cases you may want to skip SSL verification, because the entity that issue the certificate is not a valid one, but you still want to work with it. You can achieve this through:
|
||||
|
||||
```ruby
|
||||
#Skips SSL certificate verification
|
||||
|
||||
class Client
|
||||
include HTTParty
|
||||
|
||||
base_uri "https://example.com"
|
||||
pem File.read("#{File.expand_path('.')}/path/to/certs/cert.pem"), "123456"
|
||||
|
||||
def self.fetch
|
||||
get("/resources", verify: false)
|
||||
# You can also use something like:
|
||||
# get("resources", verify_peer: false)
|
||||
end
|
||||
end
|
||||
```
|
Loading…
Reference in a new issue