├── .gitignore ├── Gemfile ├── bin └── curly ├── curly.gemspec └── README.md /.gitignore: -------------------------------------------------------------------------------- 1 | Gemfile.lock 2 | -------------------------------------------------------------------------------- /Gemfile: -------------------------------------------------------------------------------- 1 | source :rubygems 2 | gemspec -------------------------------------------------------------------------------- /bin/curly: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env ruby 2 | 3 | require 'json' 4 | 5 | argString = '' 6 | 7 | ARGV.each do |a| 8 | if a == '--json' 9 | argString += ' -H "Content-Type: application/json"' 10 | elsif a.match /^-/ 11 | argString += " #{a}" 12 | else 13 | argString += " \"#{a}\"" 14 | end 15 | end 16 | 17 | cmd = "curl -i #{argString}" 18 | 19 | result = `#{cmd}` 20 | 21 | result.split(/\n/).each do |line| 22 | if line.match /^[{\[].*[}\]]$/ 23 | jj JSON.parse line 24 | else 25 | puts line 26 | end 27 | end 28 | 29 | -------------------------------------------------------------------------------- /curly.gemspec: -------------------------------------------------------------------------------- 1 | # -*- encoding: utf-8 -*- 2 | 3 | Gem::Specification.new do |gem| 4 | gem.authors = ["Aaron Parecki"] 5 | gem.email = ["aaron@parecki.com"] 6 | gem.description = gem.summary = "A wrapper for curl which pretty-prints JSON output" 7 | gem.homepage = "https://github.com/aaronpk/curly" 8 | 9 | gem.executables = ['curly'] 10 | gem.files = `git ls-files | grep -v myapp`.split("\n") 11 | gem.name = "curly" 12 | gem.require_paths = ["lib"] 13 | gem.version = '0.1.0' 14 | gem.add_dependency 'json' 15 | end 16 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | curly 2 | ===== 3 | 4 | curly: A replacement for `curl` which pretty-prints JSON output 5 | 6 | Installation 7 | ------------ 8 | 9 | ``` 10 | gem install curly 11 | ``` 12 | 13 | Then you'll have a new command available, `curly` which can be used in place of `curl`. 14 | 15 | 16 | Usage 17 | ----- 18 | 19 | Use this like you would normally use `curl`. By default this script adds the `-i` flag which includes the HTTP headers in the output, which is useful when debugging REST services that return different HTTP codes depending on the response. 20 | 21 | Any command line arguments you pass to this script will be handed off to cURL. 22 | 23 | 24 | Example 25 | ------- 26 | 27 | `curly -d "foo=bar" http://example.com/` 28 | 29 | `curly https://graph.facebook.com/19292868552` 30 | 31 | ``` 32 | % Total % Received % Xferd Average Speed Time Time Time Current 33 | Dload Upload Total Spent Left Speed 34 | 100 786 100 786 0 0 2259 0 --:--:-- --:--:-- --:--:-- 3144 35 | HTTP/1.1 200 OK 36 | Access-Control-Allow-Origin: * 37 | Cache-Control: private, no-cache, no-store, must-revalidate 38 | Content-Type: text/javascript; charset=UTF-8 39 | ETag: "04806e95d2cf191a0e231f2559757767da774bf7" 40 | Expires: Sat, 01 Jan 2000 00:00:00 GMT 41 | Pragma: no-cache 42 | X-FB-Rev: 579367 43 | X-FB-Debug: 8mgUjMq1LsuQS8tjNekLjIOR9uzgIrtkNadqxJGqyFQ= 44 | Date: Sat, 23 Jun 2012 19:44:38 GMT 45 | Connection: keep-alive 46 | Content-Length: 786 47 | 48 | { 49 | "id": "19292868552", 50 | "name": "Facebook Platform", 51 | "picture": "http://profile.ak.fbcdn.net/hprofile-ak-ash2/276791_19292868552_1958181823_s.jpg", 52 | "link": "http://www.facebook.com/platform", 53 | "likes": 4781431, 54 | "cover": { 55 | "cover_id": "10150835335278553", 56 | "source": "http://sphotos.xx.fbcdn.net/hphotos-ash3/s720x720/547890_10150835335278553_344659408_n.jpg", 57 | "offset_y": 32 58 | }, 59 | "category": "Product/service", 60 | "is_published": true, 61 | "website": "http://developers.facebook.com", 62 | "username": "platform", 63 | "founded": "2007", 64 | "company_overview": "Facebook Platform enables anyone to build social apps on Facebook and the web.", 65 | "mission": "To make the web more open and social.", 66 | "about": "We're building the social web. Get the latest here: developers.facebook.com ", 67 | "were_here_count": 1, 68 | "talking_about_count": 20095 69 | } 70 | ``` 71 | --------------------------------------------------------------------------------