httsoiree 0.13.1 → 0.13.1.1

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 491c39f8ca9fcbace9d294dfc6ee776ffcd9b14b
4
- data.tar.gz: 40856244d0cc91af78cb241f7aa9cceef5b2ba52
3
+ metadata.gz: b96e1f9c5ddf1d48bf3c1e775c74b3e8ee7ae37b
4
+ data.tar.gz: c12b50e32aa15f2d29266305d9bb55d0d36a2895
5
5
  SHA512:
6
- metadata.gz: 3ef38e2ec560c2ab049369beb70093c74dc99817e9937e9d60428efce64e9b7b814ae0e065d812176a4957aea4ccd3ca76216887d063b78757ef19cb8ae19552
7
- data.tar.gz: 80bfb94747033c9b6e56f0b384d21fc909ab529ca93cbf189c2cfc0b6b2c9216198396922889104c519527129d87459b8bb0d91d5f5a42b328f51f9bd0b01171
6
+ metadata.gz: f5142045a09dedf5b7e62e898173aaf7d12ff5a0818d3d451d50bd645a7a2317f8f38d932062e5397288ef93216c8706a013109198d94f324457abca99c73cf9
7
+ data.tar.gz: 95bb1a46d509354a2b7b0233bb19d4f0bcf299de8bca27fedae2033df2b934f5da7349051bbe657547ca6a908902f2a3bb6b6b4b1790d30f8bbf20d6c7a2503e
data/README.md CHANGED
@@ -1,30 +1,34 @@
1
- # httparty
1
+ # httsoiree
2
2
 
3
- Makes http fun again!
3
+ Like HTTParty, just a little less in your face.
4
4
 
5
5
  ## Install
6
6
 
7
7
  ```
8
- gem install httparty
8
+ gem install httsoiree
9
9
  ```
10
10
 
11
11
  ## Requirements
12
12
 
13
13
  * Ruby 1.9.3 or higher
14
14
  * multi_xml
15
- * You like to party!
15
+ * You like to converse with friends, perhaps over drinks.
16
+
17
+ ## Usage
18
+
19
+ A drop-in replacement to HTTParty - you can even keep typing HTTParty. Or, if you prefer, you can HTTSoiree.
16
20
 
17
21
  ## Examples
18
22
 
19
23
  ```ruby
20
24
  # Use the class methods to get down to business quickly
21
- response = HTTParty.get('https://api.stackexchange.com/2.2/questions?site=stackoverflow')
25
+ response = HTTSoiree.get('https://api.stackexchange.com/2.2/questions?site=stackoverflow')
22
26
 
23
27
  puts response.body, response.code, response.message, response.headers.inspect
24
28
 
25
29
  # Or wrap things up in your own class
26
30
  class StackExchange
27
- include HTTParty
31
+ include HTTSoiree
28
32
  base_uri 'api.stackexchange.com'
29
33
 
30
34
  def initialize(service, page)
@@ -49,15 +53,15 @@ See the [examples directory](http://github.com/jnunemaker/httparty/tree/master/e
49
53
 
50
54
  ## Command Line Interface
51
55
 
52
- httparty also includes the executable `httparty` which can be
56
+ httsoiree also includes the executable `httsoiree` which can be
53
57
  used to query web services and examine the resulting output. By default
54
58
  it will output the response as a pretty-printed Ruby object (useful for
55
59
  grokking the structure of output). This can also be overridden to output
56
- formatted XML or JSON. Execute `httparty --help` for all the
60
+ formatted XML or JSON. Execute `httsoiree --help` for all the
57
61
  options. Below is an example of how easy it is.
58
62
 
59
63
  ```
60
- httparty "https://api.stackexchange.com/2.2/questions?site=stackoverflow"
64
+ httsoiree "https://api.stackexchange.com/2.2/questions?site=stackoverflow"
61
65
  ```
62
66
 
63
67
  ## Help and Docs
data/bin/httsoiree ADDED
@@ -0,0 +1,117 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "optparse"
4
+ require "pp"
5
+
6
+ $:.unshift(File.join(File.dirname(__FILE__), "/../lib"))
7
+ require "httparty"
8
+
9
+ opts = {
10
+ action: :get,
11
+ headers: {},
12
+ verbose: false
13
+ }
14
+
15
+ OptionParser.new do |o|
16
+ o.banner = "USAGE: #{$0} [options] [url]"
17
+
18
+ o.on("-f",
19
+ "--format [FORMAT]",
20
+ "Output format to use instead of pretty-print ruby: " +
21
+ "plain, csv, json or xml") do |f|
22
+ opts[:output_format] = f.downcase.to_sym
23
+ end
24
+
25
+ o.on("-a",
26
+ "--action [ACTION]",
27
+ "HTTP action: get (default), post, put, delete, head, or options") do |a|
28
+ opts[:action] = a.downcase.to_sym
29
+ end
30
+
31
+ o.on("-d",
32
+ "--data [BODY]",
33
+ "Data to put in request body (prefix with '@' for file)") do |d|
34
+ if d =~ /^@/
35
+ opts[:body] = open(d[1..-1]).read
36
+ else
37
+ opts[:body] = d
38
+ end
39
+ end
40
+
41
+ o.on("-H", "--header [NAME:VALUE]", "Additional HTTP headers in NAME:VALUE form") do |h|
42
+ abort "Invalid header specification, should be Name:Value" unless h =~ /.+:.+/
43
+ name, value = h.split(':')
44
+ opts[:headers][name.strip] = value.strip
45
+ end
46
+
47
+ o.on("-v", "--verbose", "If set, print verbose output") do |v|
48
+ opts[:verbose] = true
49
+ end
50
+
51
+ o.on("-u", "--user [CREDS]", "Use basic authentication. Value should be user:password") do |u|
52
+ abort "Invalid credentials format. Must be user:password" unless u =~ /.*:.+/
53
+ user, password = u.split(':')
54
+ opts[:basic_auth] = { username: user, password: password }
55
+ end
56
+
57
+ o.on("-r", "--response-code", "Command fails if response code >= 400") do
58
+ opts[:response_code] = true
59
+ end
60
+
61
+ o.on("-h", "--help", "Show help documentation") do |h|
62
+ puts o
63
+ exit
64
+ end
65
+ end.parse!
66
+
67
+
68
+ if ARGV.empty?
69
+ STDERR.puts "You need to provide a URL"
70
+ STDERR.puts "USAGE: #{$0} [options] [url]"
71
+ end
72
+
73
+ def dump_headers(response)
74
+ resp_type = Net::HTTPResponse::CODE_TO_OBJ[response.code.to_s]
75
+ puts "#{response.code} #{resp_type.to_s.sub(/^Net::HTTP/, '')}"
76
+ response.headers.each do |n,v|
77
+ puts "#{n}: #{v}"
78
+ end
79
+ puts
80
+ end
81
+
82
+ if opts[:verbose]
83
+ puts "#{opts[:action].to_s.upcase} #{ARGV.first}"
84
+ opts[:headers].each do |n,v|
85
+ puts "#{n}: #{v}"
86
+ end
87
+ puts
88
+ end
89
+
90
+ response = HTTParty.send(opts[:action], ARGV.first, opts)
91
+ if opts[:output_format].nil?
92
+ dump_headers(response) if opts[:verbose]
93
+ pp response
94
+ else
95
+ print_format = opts[:output_format]
96
+ dump_headers(response) if opts[:verbose]
97
+
98
+ case opts[:output_format]
99
+ when :json
100
+ begin
101
+ require 'json'
102
+ puts JSON.pretty_generate(response.delegate)
103
+ rescue LoadError
104
+ puts YAML.dump(response.delegate)
105
+ end
106
+ when :xml
107
+ require 'rexml/document'
108
+ REXML::Document.new(response.body).write(STDOUT, 2)
109
+ puts
110
+ when :csv
111
+ require 'csv'
112
+ puts CSV.parse(response.body).map{|row| row.to_s }
113
+ else
114
+ puts response
115
+ end
116
+ end
117
+ exit false if opts[:response_code] && response.code >= 400
@@ -3,13 +3,13 @@ $:.push File.expand_path("../lib", __FILE__)
3
3
  require "httparty/version"
4
4
 
5
5
  Gem::Specification.new do |s|
6
- s.name = "httparty"
6
+ s.name = "httsoiree"
7
7
  s.version = HTTParty::VERSION
8
8
  s.platform = Gem::Platform::RUBY
9
9
  s.licenses = ['MIT']
10
- s.authors = ["John Nunemaker", "Sandro Turriate"]
10
+ s.authors = ["John Nunemaker", "Sandro Turriate", "Kristján Pétursson"]
11
11
  s.email = ["nunemaker@gmail.com"]
12
- s.homepage = "http://jnunemaker.github.com/httparty"
12
+ s.homepage = "https://github.com/kristjan/httsoiree"
13
13
  s.summary = %q{Makes http fun! Also, makes consuming restful web services dead easy.}
14
14
  s.description = %q{Makes http fun! Also, makes consuming restful web services dead easy.}
15
15
 
@@ -1,3 +1,3 @@
1
1
  module HTTParty
2
- VERSION = "0.13.1"
2
+ VERSION = "0.13.1.1"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: httsoiree
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.13.1
4
+ version: 0.13.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - John Nunemaker
@@ -45,6 +45,7 @@ email:
45
45
  - nunemaker@gmail.com
46
46
  executables:
47
47
  - httparty
48
+ - httsoiree
48
49
  extensions: []
49
50
  extra_rdoc_files: []
50
51
  files:
@@ -57,6 +58,7 @@ files:
57
58
  - README.md
58
59
  - Rakefile
59
60
  - bin/httparty
61
+ - bin/httsoiree
60
62
  - cucumber.yml
61
63
  - examples/aaws.rb
62
64
  - examples/basic.rb
@@ -86,7 +88,7 @@ files:
86
88
  - features/supports_read_timeout_option.feature
87
89
  - features/supports_redirection.feature
88
90
  - features/supports_timeout_option.feature
89
- - httparty.gemspec
91
+ - httsoiree.gemspec
90
92
  - lib/httparty.rb
91
93
  - lib/httparty/connection_adapter.rb
92
94
  - lib/httparty/cookie_hash.rb
@@ -140,7 +142,7 @@ files:
140
142
  - spec/support/stub_response.rb
141
143
  - website/css/common.css
142
144
  - website/index.html
143
- homepage: http://jnunemaker.github.com/httparty
145
+ homepage: https://github.com/kristjan/httsoiree
144
146
  licenses:
145
147
  - MIT
146
148
  metadata: {}