httparty 0.24.3 → 0.24.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (56) hide show
  1. checksums.yaml +4 -4
  2. data/CONTRIBUTING.md +2 -4
  3. data/Rakefile +3 -1
  4. data/bin/httparty +32 -11
  5. data/docs/README.md +38 -4
  6. data/examples/README.md +12 -23
  7. data/examples/basic.rb +2 -2
  8. data/examples/basic_auth.rb +19 -0
  9. data/examples/cookies.rb +20 -0
  10. data/examples/crack.rb +2 -2
  11. data/examples/custom_parsers.rb +2 -2
  12. data/examples/debug_output.rb +17 -0
  13. data/examples/google.rb +2 -2
  14. data/examples/headers_and_user_agents.rb +2 -2
  15. data/examples/idn.rb +4 -3
  16. data/examples/logging.rb +2 -2
  17. data/examples/nokogiri_html_parser.rb +2 -2
  18. data/examples/party_foul_mode.rb +1 -0
  19. data/examples/peer_cert.rb +2 -2
  20. data/examples/rescue_json.rb +5 -3
  21. data/examples/stackexchange.rb +2 -2
  22. data/examples/stream_download.rb +2 -2
  23. data/examples/whoismyrep.rb +2 -2
  24. data/httparty.gemspec +2 -1
  25. data/lib/httparty/connection_adapter.rb +3 -3
  26. data/lib/httparty/cookie_hash.rb +1 -1
  27. data/lib/httparty/headers_processor.rb +4 -2
  28. data/lib/httparty/logger/curl_formatter.rb +16 -3
  29. data/lib/httparty/logger/logger.rb +2 -1
  30. data/lib/httparty/module_inheritable_attributes.rb +13 -13
  31. data/lib/httparty/net_digest_auth.rb +9 -11
  32. data/lib/httparty/parser.rb +2 -1
  33. data/lib/httparty/request/body.rb +2 -2
  34. data/lib/httparty/request/streaming_multipart_body.rb +9 -2
  35. data/lib/httparty/request.rb +29 -6
  36. data/lib/httparty/response.rb +2 -1
  37. data/lib/httparty/text_encoder.rb +1 -5
  38. data/lib/httparty/utils.rb +1 -5
  39. data/lib/httparty/version.rb +1 -1
  40. data/lib/httparty.rb +14 -15
  41. metadata +8 -18
  42. data/.github/dependabot.yml +0 -6
  43. data/.github/workflows/ci.yml +0 -24
  44. data/.rubocop.yml +0 -92
  45. data/.rubocop_todo.yml +0 -124
  46. data/Gemfile +0 -27
  47. data/Guardfile +0 -17
  48. data/cucumber.yml +0 -1
  49. data/examples/aaws.rb +0 -36
  50. data/examples/delicious.rb +0 -37
  51. data/examples/rubyurl.rb +0 -14
  52. data/examples/tripit_sign_in.rb +0 -44
  53. data/examples/twitter.rb +0 -31
  54. data/script/release +0 -42
  55. data/website/css/common.css +0 -47
  56. data/website/index.html +0 -73
data/Gemfile DELETED
@@ -1,27 +0,0 @@
1
- source 'https://rubygems.org'
2
- gemspec
3
-
4
- gem 'base64'
5
- gem 'rake'
6
- gem 'mongrel', '1.2.0.pre2'
7
- gem 'json'
8
-
9
- group :development do
10
- gem 'guard'
11
- gem 'guard-rspec'
12
- gem 'guard-bundler'
13
- end
14
-
15
- group :test do
16
- gem 'rexml'
17
- gem 'rspec', '~> 3.4'
18
- gem 'simplecov', require: false
19
- gem 'aruba'
20
- gem 'cucumber', '~> 2.3'
21
- gem 'webmock'
22
- gem 'addressable'
23
- end
24
-
25
- group :development, :test do
26
- gem 'pry'
27
- end
data/Guardfile DELETED
@@ -1,17 +0,0 @@
1
- rspec_options = {
2
- all_after_pass: false,
3
- all_on_start: false,
4
- failed_mode: :keep,
5
- cmd: 'bundle exec rspec',
6
- }
7
-
8
- guard 'rspec', rspec_options do
9
- watch(%r{^spec/.+_spec\.rb$})
10
- watch(%r{^lib/(.+)\.rb$}) { |m| "spec/#{m[1]}_spec.rb" }
11
- watch('spec/spec_helper.rb') { "spec" }
12
- end
13
-
14
- guard 'bundler' do
15
- watch('Gemfile')
16
- watch(/^.+\.gemspec/)
17
- end
data/cucumber.yml DELETED
@@ -1 +0,0 @@
1
- default: features --format progress
data/examples/aaws.rb DELETED
@@ -1,36 +0,0 @@
1
- require 'rubygems'
2
- require 'active_support'
3
- require 'active_support/core_ext/hash'
4
- require 'active_support/core_ext/string'
5
-
6
- dir = File.expand_path(File.join(File.dirname(__FILE__), '..', 'lib'))
7
- require File.join(dir, 'httparty')
8
- require 'pp'
9
- config = YAML.load(File.read(File.join(ENV['HOME'], '.aaws')))
10
-
11
- module AAWS
12
- class Book
13
- include HTTParty
14
- base_uri 'http://ecs.amazonaws.com'
15
- default_params Service: 'AWSECommerceService', Operation: 'ItemSearch', SearchIndex: 'Books'
16
-
17
- def initialize(key)
18
- @auth = { AWSAccessKeyId: key }
19
- end
20
-
21
- def search(options = {})
22
- raise ArgumentError, 'You must search for something' if options[:query].blank?
23
-
24
- # amazon uses nasty camelized query params
25
- options[:query] = options[:query]
26
- .reverse_merge(@auth)
27
- .transform_keys { |k| k.to_s.camelize }
28
-
29
- # make a request and return the items (NOTE: this doesn't handle errors at this point)
30
- self.class.get('/onca/xml', options)['ItemSearchResponse']['Items']
31
- end
32
- end
33
- end
34
-
35
- aaws = AAWS::Book.new(config[:access_key])
36
- pp aaws.search(query: { title: 'Ruby On Rails' })
@@ -1,37 +0,0 @@
1
- dir = File.expand_path(File.join(File.dirname(__FILE__), '..', 'lib'))
2
- require File.join(dir, 'httparty')
3
- require 'pp'
4
- config = YAML.load(File.read(File.join(ENV['HOME'], '.delicious')))
5
-
6
- class Delicious
7
- include HTTParty
8
- base_uri 'https://api.del.icio.us/v1'
9
-
10
- def initialize(u, p)
11
- @auth = { username: u, password: p }
12
- end
13
-
14
- # query params that filter the posts are:
15
- # tag (optional). Filter by this tag.
16
- # dt (optional). Filter by this date (CCYY-MM-DDThh:mm:ssZ).
17
- # url (optional). Filter by this url.
18
- # ie: posts(query: {tag: 'ruby'})
19
- def posts(options = {})
20
- options.merge!({ basic_auth: @auth })
21
- self.class.get('/posts/get', options)
22
- end
23
-
24
- # query params that filter the posts are:
25
- # tag (optional). Filter by this tag.
26
- # count (optional). Number of items to retrieve (Default:15, Maximum:100).
27
- def recent(options = {})
28
- options.merge!({ basic_auth: @auth })
29
- self.class.get('/posts/recent', options)
30
- end
31
- end
32
-
33
- delicious = Delicious.new(config['username'], config['password'])
34
- pp delicious.posts(query: { tag: 'ruby' })
35
- pp delicious.recent
36
-
37
- delicious.recent['posts']['post'].each { |post| puts post['href'] }
data/examples/rubyurl.rb DELETED
@@ -1,14 +0,0 @@
1
- dir = File.expand_path(File.join(File.dirname(__FILE__), '..', 'lib'))
2
- require File.join(dir, 'httparty')
3
- require 'pp'
4
-
5
- class Rubyurl
6
- include HTTParty
7
- base_uri 'rubyurl.com'
8
-
9
- def self.shorten(website_url)
10
- post('/api/links.json', query: { link: { website_url: website_url } })
11
- end
12
- end
13
-
14
- pp Rubyurl.shorten('http://istwitterdown.com/')
@@ -1,44 +0,0 @@
1
- dir = File.expand_path(File.join(File.dirname(__FILE__), '..', 'lib'))
2
- require File.join(dir, 'httparty')
3
-
4
- class TripIt
5
- include HTTParty
6
- base_uri 'https://www.tripit.com'
7
- debug_output
8
-
9
- def initialize(email, password)
10
- @email = email
11
- get_response = self.class.get('/account/login')
12
- get_response_cookie = parse_cookie(get_response)
13
-
14
- post_response = self.class.post(
15
- '/account/login',
16
- body: {
17
- login_email_address: email,
18
- login_password: password
19
- },
20
- headers: {'Cookie' => get_response_cookie.to_cookie_string }
21
- )
22
-
23
- @cookie = parse_cookie(post_response)
24
- end
25
-
26
- def account_settings
27
- self.class.get('/account/edit', headers: { 'Cookie' => @cookie.to_cookie_string })
28
- end
29
-
30
- def logged_in?
31
- account_settings.include? "You're logged in as #{@email}"
32
- end
33
-
34
- private
35
-
36
- def parse_cookie(resp)
37
- cookie_hash = CookieHash.new
38
- resp.get_fields('Set-Cookie').each { |c| cookie_hash.add_cookies(c) }
39
- cookie_hash
40
- end
41
- end
42
-
43
- tripit = TripIt.new('email', 'password')
44
- puts "Logged in: #{tripit.logged_in?}"
data/examples/twitter.rb DELETED
@@ -1,31 +0,0 @@
1
- dir = File.expand_path(File.join(File.dirname(__FILE__), '..', 'lib'))
2
- require File.join(dir, 'httparty')
3
- require 'pp'
4
- config = YAML.load(File.read(File.join(ENV['HOME'], '.twitter')))
5
-
6
- class Twitter
7
- include HTTParty
8
- base_uri 'twitter.com'
9
-
10
- def initialize(u, p)
11
- @auth = {username: u, password: p}
12
- end
13
-
14
- # which can be :friends, :user or :public
15
- # options[:query] can be things like since, since_id, count, etc.
16
- def timeline(which = :friends, options = {})
17
- options.merge!({ basic_auth: @auth })
18
- self.class.get("/statuses/#{which}_timeline.json", options)
19
- end
20
-
21
- def post(text)
22
- options = { query: { status: text }, basic_auth: @auth }
23
- self.class.post('/statuses/update.json', options)
24
- end
25
- end
26
-
27
- twitter = Twitter.new(config['email'], config['password'])
28
- pp twitter.timeline
29
- # pp twitter.timeline(:friends, query: {since_id: 868482746})
30
- # pp twitter.timeline(:friends, query: 'since_id=868482746')
31
- # pp twitter.post('this is a test of 0.2.0')
data/script/release DELETED
@@ -1,42 +0,0 @@
1
- #!/bin/sh
2
- #/ Usage: release
3
- #/
4
- #/ Tag the version in the repo and push the gem.
5
- #/
6
-
7
- set -e
8
- cd $(dirname "$0")/..
9
-
10
- [ "$1" = "--help" -o "$1" = "-h" -o "$1" = "help" ] && {
11
- grep '^#/' <"$0"| cut -c4-
12
- exit 0
13
- }
14
-
15
- gem_name=httparty
16
-
17
- # Build a new gem archive.
18
- rm -rf $gem_name-*.gem
19
- gem build -q $gem_name.gemspec
20
-
21
- # Make sure we're on the main branch.
22
- (git branch | grep -q '* main') || {
23
- echo "Only release from the main branch."
24
- exit 1
25
- }
26
-
27
- # Figure out what version we're releasing.
28
- tag=v`ls $gem_name-*.gem | sed "s/^$gem_name-\(.*\)\.gem$/\1/"`
29
-
30
- echo "Releasing $tag"
31
-
32
- # Make sure we haven't released this version before.
33
- git fetch -t origin
34
-
35
- (git tag -l | grep -q "$tag") && {
36
- echo "Whoops, there's already a '${tag}' tag."
37
- exit 1
38
- }
39
-
40
- # Tag it and bag it.
41
- gem push $gem_name-*.gem && git tag "$tag" &&
42
- git push origin main && git push origin "$tag"
@@ -1,47 +0,0 @@
1
- @media screen, projection {
2
- /*
3
- Copyright (c) 2007, Yahoo! Inc. All rights reserved.
4
- Code licensed under the BSD License:
5
- http://developer.yahoo.net/yui/license.txt
6
- version: 2.2.0
7
- */
8
- body {font:13px arial,helvetica,clean,sans-serif;*font-size:small;*font:x-small;}table {font-size:inherit;font:100%;}select, input, textarea {font:99% arial,helvetica,clean,sans-serif;}pre, code {font:115% monospace;*font-size:100%;}body * {line-height:1.22em;}
9
- body,div,dl,dt,dd,ul,ol,li,h1,h2,h3,h4,h5,h6,pre,form,fieldset,input,textarea,p,blockquote,th,td{margin:0;padding:0;}table{border-collapse:collapse;border-spacing:0;}fieldset,img{border:0;}address,caption,cite,code,dfn,em,strong,th,var{font-style:normal;font-weight:normal;}/*ol,ul {list-style:none;}*/caption,th {text-align:left;}h1,h2,h3,h4,h5,h6{font-size:100%;font-weight:normal;}q:before,q:after{content:'';}abbr,acronym {border:0;}
10
- /* end of yahoo reset and fonts */
11
-
12
- body {color:#333; background:#4b1a1a; line-height:1.3;}
13
- p {margin:0 0 20px;}
14
- a {color:#4b1a1a;}
15
- a:hover {text-decoration:none;}
16
- strong {font-weight:bold;}
17
- em {font-style:italics;}
18
- h1,h2,h3,h4,h5,h6 {font-weight:bold;}
19
- h1 {font-size:197%; margin:30px 0; color:#4b1a1a;}
20
- h2 {font-size:174%; margin:20px 0; color:#b8111a;}
21
- h3 {font-size:152%; margin:10px 0;}
22
- h4 {font-size:129%; margin:10px 0;}
23
- pre {background:#eee; margin:0 0 20px; padding:20px; border:1px solid #ccc; font-size:100%; overflow:auto;}
24
- code {font-size:100%; margin:0; padding:0;}
25
- ul, ol {margin:10px 0 10px 25px;}
26
- ol li {margin:0 0 10px;}
27
-
28
-
29
-
30
-
31
-
32
- div#wrapper {background:#fff; width:560px; margin:0 auto; padding:20px; border:10px solid #bc8c46; border-width:0 10px;}
33
- div#header {position:relative; border-bottom:1px dotted; margin:0 0 10px; padding:0 0 10px;}
34
- div#header p {margin:0; padding:0;}
35
- div#header h1 {margin:0; padding:0;}
36
- ul#nav {position:absolute; top:0; right:0; list-style:none; margin:0; padding:0;}
37
- ul#nav li {display:inline; padding:0 0 0 5px;}
38
- ul#nav li a {}
39
- div#content {}
40
- div#footer {margin:40px 0 0; border-top:1px dotted; padding:10px 0 0;}
41
-
42
-
43
-
44
-
45
-
46
-
47
- }
data/website/index.html DELETED
@@ -1,73 +0,0 @@
1
- <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
2
- <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
3
- <head>
4
- <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
5
- <title>HTTParty by John Nunemaker</title>
6
- <link rel="stylesheet" href="css/common.css" type="text/css" />
7
- </head>
8
- <body>
9
-
10
- <div id="wrapper">
11
- <div id="header">
12
- <h1>HTTParty</h1>
13
- <p>Tonight we're gonna HTTParty like it's 1999!</p>
14
-
15
- <ul id="nav">
16
- <li><a href="rdoc/">Docs</a></li>
17
- <li><a href="http://github.com/jnunemaker/httparty">Github</a></li>
18
- <li><a href="http://rubyforge.org/projects/httparty/">Rubyforge</a></li>
19
- </ul>
20
- </div>
21
-
22
- <div id="content">
23
- <h2>Install</h2>
24
- <pre><code>$ sudo gem install httparty</code></pre>
25
-
26
- <h2>Some Quick Examples</h2>
27
-
28
- <p>The following is a simple example of wrapping Twitter's API for posting updates.</p>
29
-
30
- <pre><code>class Twitter
31
- include HTTParty
32
- base_uri 'twitter.com'
33
- basic_auth 'username', 'password'
34
- end
35
-
36
- Twitter.post('/statuses/update.json', query: {status: "It's an HTTParty and everyone is invited!"})</code></pre>
37
-
38
- <p>That is really it! The object returned is a ruby hash that is decoded from Twitter's json response. JSON parsing is used because of the .json extension in the path of the request. You can also explicitly set a format (see the examples). </p>
39
-
40
- <p>That works and all but what if you don't want to embed your username and password in the class? Below is an example to fix that:</p>
41
-
42
- <pre><code>class Twitter
43
- include HTTParty
44
- base_uri 'twitter.com'
45
-
46
- def initialize(u, p)
47
- @auth = {username: u, password: p}
48
- end
49
-
50
- def post(text)
51
- options = { query: {status: text}, basic_auth: @auth }
52
- self.class.post('/statuses/update.json', options)
53
- end
54
- end
55
-
56
- Twitter.new('username', 'password').post("It's an HTTParty and everyone is invited!")</code></pre>
57
-
58
- <p><strong>More Examples:</strong> There are <a href="http://github.com/jnunemaker/httparty/tree/master/examples/">several examples in the gem itself</a>.</p>
59
-
60
- <h2>Support</h2>
61
- <p>Conversations welcome in the <a href="http://groups.google.com/group/httparty-gem">google group</a> and bugs/features over at <a href="http://github.com/jnunemaker/httparty">Github</a>.</p>
62
-
63
-
64
- </div>
65
-
66
- <div id="footer">
67
- <p>Created by <a href="http://addictedtonew.com/about/">John Nunemaker</a> |
68
- <a href="http://orderedlist.com/">Hire Me at Ordered List</a></p>
69
- </div>
70
- </div>
71
-
72
- </body>
73
- </html>