cage 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,4 @@
1
+ *.gem
2
+ .bundle
3
+ Gemfile.lock
4
+ pkg/*
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source "http://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in cage.gemspec
4
+ gemspec
@@ -0,0 +1,75 @@
1
+ Cage
2
+ ====
3
+
4
+ *A Faraday Cage for your HTTP Interactions.*
5
+
6
+
7
+ Getting It
8
+ ----------
9
+
10
+ Once Cage hits 0.1.0, it will be released as a gem. Then you can install it
11
+ globally with `gem install cage`. Better still, add it to the `Gemfile` of your
12
+ project.
13
+
14
+ ```ruby
15
+ group :development do
16
+ gem "cage"
17
+ end
18
+ ```
19
+
20
+ Using It
21
+ --------
22
+
23
+ Running `cage` will begin a console session. Cage is like a specialized IRB, but
24
+ for HTTP interactions. Imagine that you are working on an API. [Rack::Test][rt]
25
+ is an awesome tool but when you try to use it interactively you get an
26
+ interesting display of fireworks(read: stacktraces). Cage is based on a utility
27
+ script I wrote while working on a REST API. Some days, you just want to monkey
28
+ around with your work.
29
+
30
+ When you run Cage, you're dropped into a special Pry terminal with HTTP related
31
+ commands available.
32
+
33
+ ```
34
+ [
35
+ [0] 200,
36
+ [1] {
37
+ "server" => "nginx",
38
+ "date" => "Thu, 26 Jan 2012 19:56:30 GMT",
39
+ "content-type" => "application/x-javascript; charset=UTF-8",
40
+ "transfer-encoding" => "chunked",
41
+ "connection" => "close",
42
+ "expires" => "Thu, 26 Jan 2012 19:56:31 GMT",
43
+ "cache-control" => "max-age=1"
44
+ },
45
+ [2] "{\"Definition\":\"Hackers do *not* generally use this to mean FUBAR..."
46
+ ]
47
+ ```
48
+
49
+ Configuring It
50
+ --------------
51
+
52
+ Cage will look first for a global `~/.cagerc.rb` file, then for a localr
53
+ `./cagerc.rb` in the working directory. Both are essentially instance_eval'd
54
+ into your new Cage console so anything that works in Cage will work in a config.
55
+ The global one is run first, so you can overload it with a local config. The
56
+ local config is for setting up project defaults, you can even automate your
57
+ initial authentication if you want.
58
+
59
+ Roadmap
60
+ -------
61
+
62
+ - 0.0.1 Have a working, if ugly and hacky console.
63
+
64
+ - 0.0.2 Write tests for whatever I can.
65
+
66
+ - 0.1.0 Clean up the prompt and solidify the command set. Support .cagerc files.
67
+
68
+ - 0.2.0 Use decorators to pretty print responses.
69
+
70
+ - 0.3.0 Auto detect and parse incoming body types like XML, JSON, wwwurlencode.
71
+
72
+ - 0.4.0 Make it easier to send XML, YAML, and JSON formatted bodies.
73
+
74
+ - 0.5.0 ???
75
+
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
@@ -0,0 +1,5 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "cage"
4
+ Cage::Console.start!
5
+
@@ -0,0 +1,27 @@
1
+ # -*- encoding: utf-8 -*-
2
+ $:.push File.expand_path("../lib", __FILE__)
3
+ require "cage/version"
4
+
5
+ Gem::Specification.new do |s|
6
+ s.name = "cage"
7
+ s.version = Cage::VERSION
8
+ s.authors = ["Steven! Ragnarök"]
9
+ s.email = ["steven@nuclearsandwich.com"]
10
+ s.homepage = "https://github.com/nuclearsandwich/cage"
11
+ s.summary = "A Faraday Cage for your HTTP Interactions."
12
+ s.description = <<-DESC
13
+ Curl can be a bit unfriendly, especially to developers just starting out. Cage
14
+ wraps Faraday and Pry in order to provide an attractive and helpful interface to
15
+ the web APIs in your life.
16
+ DESC
17
+
18
+ s.files = `git ls-files`.split("\n")
19
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
20
+ s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
21
+ s.require_paths = ["lib"]
22
+
23
+ s.add_development_dependency "minitest"
24
+ s.add_runtime_dependency "faraday"
25
+ s.add_runtime_dependency "pry"
26
+ s.add_runtime_dependency "awesome_print"
27
+ end
@@ -0,0 +1,6 @@
1
+ require "pry"
2
+ require "awesome_print"
3
+ require "faraday"
4
+
5
+ require "cage/version"
6
+ require "cage/console"
@@ -0,0 +1,46 @@
1
+ module Cage
2
+ class Console
3
+ CONNECTION_VARIABLES = [:scheme, :domain, :prefix, :headers]
4
+
5
+ attr_reader :connection, :last_response, *CONNECTION_VARIABLES
6
+
7
+ def initialize
8
+ @scheme = "http"
9
+ @domain = "duckduckgo.com"
10
+ @prefix = "?q="
11
+ reinitialize_connection
12
+ end
13
+
14
+ def reinitialize_connection
15
+ @connection = Faraday::Connection.new "#{scheme}://#{domain}/#{prefix}"
16
+ end
17
+
18
+ def method_missing sym, *args, &block
19
+ if sym =~ /^(?:get|post|put|delete)$/i
20
+ http sym, *args, &block
21
+ else
22
+ super
23
+ end
24
+ end
25
+
26
+ def print_response
27
+ ap [ last_response.status, last_response.headers, last_response.body ]
28
+ end
29
+
30
+ def http method, *args, &block
31
+ @last_response = connection.send method, *args, &block
32
+ print_response
33
+ end
34
+
35
+ def set convar, value
36
+ instance_variable_set :"@#{convar}", value
37
+ reinitialize_connection
38
+ value
39
+ end
40
+
41
+ def self.start!
42
+ new.pry
43
+ end
44
+ end
45
+ end
46
+
@@ -0,0 +1,3 @@
1
+ module Cage
2
+ VERSION = "0.0.1"
3
+ end
metadata ADDED
@@ -0,0 +1,106 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: cage
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Steven! Ragnarök
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-01-26 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: minitest
16
+ requirement: &10129200 !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: '0'
22
+ type: :development
23
+ prerelease: false
24
+ version_requirements: *10129200
25
+ - !ruby/object:Gem::Dependency
26
+ name: faraday
27
+ requirement: &10126820 !ruby/object:Gem::Requirement
28
+ none: false
29
+ requirements:
30
+ - - ! '>='
31
+ - !ruby/object:Gem::Version
32
+ version: '0'
33
+ type: :runtime
34
+ prerelease: false
35
+ version_requirements: *10126820
36
+ - !ruby/object:Gem::Dependency
37
+ name: pry
38
+ requirement: &10125360 !ruby/object:Gem::Requirement
39
+ none: false
40
+ requirements:
41
+ - - ! '>='
42
+ - !ruby/object:Gem::Version
43
+ version: '0'
44
+ type: :runtime
45
+ prerelease: false
46
+ version_requirements: *10125360
47
+ - !ruby/object:Gem::Dependency
48
+ name: awesome_print
49
+ requirement: &10124020 !ruby/object:Gem::Requirement
50
+ none: false
51
+ requirements:
52
+ - - ! '>='
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ type: :runtime
56
+ prerelease: false
57
+ version_requirements: *10124020
58
+ description: ! 'Curl can be a bit unfriendly, especially to developers just starting
59
+ out. Cage
60
+
61
+ wraps Faraday and Pry in order to provide an attractive and helpful interface to
62
+
63
+ the web APIs in your life.
64
+
65
+ '
66
+ email:
67
+ - steven@nuclearsandwich.com
68
+ executables:
69
+ - cage
70
+ extensions: []
71
+ extra_rdoc_files: []
72
+ files:
73
+ - .gitignore
74
+ - Gemfile
75
+ - README.md
76
+ - Rakefile
77
+ - bin/cage
78
+ - cage.gemspec
79
+ - lib/cage.rb
80
+ - lib/cage/console.rb
81
+ - lib/cage/version.rb
82
+ homepage: https://github.com/nuclearsandwich/cage
83
+ licenses: []
84
+ post_install_message:
85
+ rdoc_options: []
86
+ require_paths:
87
+ - lib
88
+ required_ruby_version: !ruby/object:Gem::Requirement
89
+ none: false
90
+ requirements:
91
+ - - ! '>='
92
+ - !ruby/object:Gem::Version
93
+ version: '0'
94
+ required_rubygems_version: !ruby/object:Gem::Requirement
95
+ none: false
96
+ requirements:
97
+ - - ! '>='
98
+ - !ruby/object:Gem::Version
99
+ version: '0'
100
+ requirements: []
101
+ rubyforge_project:
102
+ rubygems_version: 1.8.10
103
+ signing_key:
104
+ specification_version: 3
105
+ summary: A Faraday Cage for your HTTP Interactions.
106
+ test_files: []