readonly_party 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,19 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
18
+ vendor
19
+ bin/httparty
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in read_only_party.gemspec
4
+ gemspec
data/LICENSE ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2012 Expected Behavior
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,53 @@
1
+ # ReadonlyParty
2
+
3
+ An HTTParty where the resources never change, the points are made up,
4
+ and everyboday wins.
5
+
6
+ This is meant to be used in the same way as HTTParty and uses it under
7
+ the covers. Except, when the ReadonlyParty module is included in a
8
+ class, it explicitly disallows post, put, delete, and patch methods
9
+ from being called on that class.
10
+
11
+ ## Installation
12
+
13
+ Add this line to your application's Gemfile:
14
+
15
+ gem 'read_only_party'
16
+
17
+ And then execute:
18
+
19
+ $ bundle
20
+
21
+ Or install it yourself as:
22
+
23
+ $ gem install read_only_party
24
+
25
+ ## Usage
26
+
27
+ ```ruby
28
+ class ThingThatShouldOnlyRead
29
+ include ReadonlyParty
30
+ end
31
+
32
+ ThingThatShouldOnlyRead.get("http://www.example.com") #=> some response
33
+ ThingThatShouldOnlyRead.head("http://www.example.com") #=> some response
34
+ ThingThatShouldOnlyRead.options("http://www.example.com") #=> some response
35
+
36
+ ThingThatShouldOnlyRead.put("http://www.example.com") #=> HTTPMethodDisallowedException
37
+ ThingThatShouldOnlyRead.post("http://www.example.com") #=> HTTPMethodDisallowedException
38
+ ThingThatShouldOnlyRead.delete("http://www.example.com") #=> HTTPMethodDisallowedException
39
+ ```
40
+
41
+ ## Contributing
42
+
43
+ 1. Fork it
44
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
45
+ 3. Commit your changes (`git commit -am 'Added some feature'`)
46
+ 4. Push to the branch (`git push origin my-new-feature`)
47
+ 5. Create new Pull Request
48
+
49
+ ## Meta
50
+
51
+ Maintained by Expected Behavior
52
+
53
+ Released under the MIT license. http://github.com/expected-behavior/readonly_party
@@ -0,0 +1,2 @@
1
+ #!/usr/bin/env rake
2
+ require "bundler/gem_tasks"
@@ -0,0 +1,30 @@
1
+ require "readonly_party/version"
2
+ require "httparty"
3
+
4
+ class HTTPMethodDisallowedException < StandardError; end
5
+
6
+ module ReadonlyParty
7
+ module ClassMethods
8
+ def post(*args)
9
+ raise HTTPMethodDisallowedException.new
10
+ end
11
+
12
+ def put(*args)
13
+ raise HTTPMethodDisallowedException.new
14
+ end
15
+
16
+ def delete(*args)
17
+ raise HTTPMethodDisallowedException.new
18
+ end
19
+
20
+ # Technically, HTTParty doesn't do patch yet. Enable... in the FUTURE!
21
+ # def patch(*args)
22
+ # raise HTTPMethodDisallowedException.new
23
+ # end
24
+ end
25
+
26
+ def self.included(base)
27
+ base.send(:include, HTTParty)
28
+ base.send(:extend, ClassMethods)
29
+ end
30
+ end
@@ -0,0 +1,3 @@
1
+ module ReadonlyParty
2
+ VERSION = "1.0.0"
3
+ end
@@ -0,0 +1,23 @@
1
+ # -*- encoding: utf-8 -*-
2
+ $LOAD_PATH.push(File.expand_path "../lib", __FILE__)
3
+ require "readonly_party/version"
4
+
5
+ Gem::Specification.new do |gem|
6
+ gem.authors = ["Joel Meador"]
7
+ gem.email = ["joel@expectedbehavior.com"]
8
+ gem.description = %q{This is meant to be used in the same way as HTTParty and uses it under the covers. Except, when the ReadonlyParty module is included in a class, it explicitly disallows post, put, delete, and patch methods from being called on that class.}
9
+ gem.summary = %q{An HTTParty where the resources never change, the points are made up, and everyboday wins.}
10
+ gem.homepage = "http://www.expectedbehavior.com"
11
+
12
+ gem.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
13
+ gem.files = `git ls-files`.split("\n")
14
+ gem.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
15
+ gem.name = "readonly_party"
16
+ gem.require_paths = ["lib"]
17
+ gem.version = ReadonlyParty::VERSION
18
+
19
+ gem.add_dependency "httparty"
20
+
21
+ gem.add_development_dependency "minitest"
22
+ gem.add_development_dependency "webmock"
23
+ end
@@ -0,0 +1,62 @@
1
+ require "minitest/autorun"
2
+ require "webmock/minitest"
3
+
4
+ require "readonly_party"
5
+
6
+ class ReadonlyPartyObject; include ReadonlyParty; end
7
+
8
+ class ReadonlyPartyTest < MiniTest::Unit::TestCase
9
+ describe "a boring party where everyone reads but no one writes" do
10
+
11
+ describe "readers" do
12
+ it "can get" do
13
+ stub_request(:get, /http:\/\/www.example.com/).to_return(:status => 200)
14
+ assert ReadonlyPartyObject.get("http://www.example.com")
15
+ end
16
+
17
+ it "can head" do
18
+ stub_request(:head, /http:\/\/www.example.com/).to_return(:status => 200)
19
+ assert ReadonlyPartyObject.head("http://www.example.com")
20
+ end
21
+
22
+ it "can options" do
23
+ stub_request(:options, /http:\/\/www.example.com/).to_return(:status => 200)
24
+ assert ReadonlyPartyObject.options("http://www.example.com")
25
+ end
26
+
27
+ # FUTURE!
28
+ # it "can trace" do
29
+ # stub_request(:options, /http:\/\/www.example.com/).to_return(:status => 200)
30
+ # assert ReadonlyPartyObject.trace("http://www.example.com")
31
+ # end
32
+ end
33
+
34
+ describe "writers" do
35
+ it "cannot post" do
36
+ assert_raises(HTTPMethodDisallowedException) {
37
+ ReadonlyPartyObject.post("http://www.example.com")
38
+ }
39
+ end
40
+
41
+ it "cannot put" do
42
+ assert_raises(HTTPMethodDisallowedException) {
43
+ ReadonlyPartyObject.put("http://www.example.com")
44
+ }
45
+ end
46
+
47
+ it "cannot delete" do
48
+ assert_raises(HTTPMethodDisallowedException) {
49
+ ReadonlyPartyObject.delete("http://www.example.com")
50
+ }
51
+ end
52
+
53
+ # FUTURE!
54
+ # it "cannot patch" do
55
+ # assert_raises(HTTPMethodDisallowedException) {
56
+ # ReadonlyPartyObject.patch("http://www.example.com")
57
+ # }
58
+ # end
59
+ end
60
+
61
+ end
62
+ end
metadata ADDED
@@ -0,0 +1,117 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: readonly_party
3
+ version: !ruby/object:Gem::Version
4
+ hash: 23
5
+ prerelease:
6
+ segments:
7
+ - 1
8
+ - 0
9
+ - 0
10
+ version: 1.0.0
11
+ platform: ruby
12
+ authors:
13
+ - Joel Meador
14
+ autorequire:
15
+ bindir: bin
16
+ cert_chain: []
17
+
18
+ date: 2012-02-16 00:00:00 -05:00
19
+ default_executable:
20
+ dependencies:
21
+ - !ruby/object:Gem::Dependency
22
+ name: httparty
23
+ prerelease: false
24
+ requirement: &id001 !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ">="
28
+ - !ruby/object:Gem::Version
29
+ hash: 3
30
+ segments:
31
+ - 0
32
+ version: "0"
33
+ type: :runtime
34
+ version_requirements: *id001
35
+ - !ruby/object:Gem::Dependency
36
+ name: minitest
37
+ prerelease: false
38
+ requirement: &id002 !ruby/object:Gem::Requirement
39
+ none: false
40
+ requirements:
41
+ - - ">="
42
+ - !ruby/object:Gem::Version
43
+ hash: 3
44
+ segments:
45
+ - 0
46
+ version: "0"
47
+ type: :development
48
+ version_requirements: *id002
49
+ - !ruby/object:Gem::Dependency
50
+ name: webmock
51
+ prerelease: false
52
+ requirement: &id003 !ruby/object:Gem::Requirement
53
+ none: false
54
+ requirements:
55
+ - - ">="
56
+ - !ruby/object:Gem::Version
57
+ hash: 3
58
+ segments:
59
+ - 0
60
+ version: "0"
61
+ type: :development
62
+ version_requirements: *id003
63
+ description: This is meant to be used in the same way as HTTParty and uses it under the covers. Except, when the ReadonlyParty module is included in a class, it explicitly disallows post, put, delete, and patch methods from being called on that class.
64
+ email:
65
+ - joel@expectedbehavior.com
66
+ executables: []
67
+
68
+ extensions: []
69
+
70
+ extra_rdoc_files: []
71
+
72
+ files:
73
+ - .gitignore
74
+ - Gemfile
75
+ - LICENSE
76
+ - README.md
77
+ - Rakefile
78
+ - lib/readonly_party.rb
79
+ - lib/readonly_party/version.rb
80
+ - readonly_party.gemspec
81
+ - test/readonly_party_test.rb
82
+ has_rdoc: true
83
+ homepage: http://www.expectedbehavior.com
84
+ licenses: []
85
+
86
+ post_install_message:
87
+ rdoc_options: []
88
+
89
+ require_paths:
90
+ - lib
91
+ required_ruby_version: !ruby/object:Gem::Requirement
92
+ none: false
93
+ requirements:
94
+ - - ">="
95
+ - !ruby/object:Gem::Version
96
+ hash: 3
97
+ segments:
98
+ - 0
99
+ version: "0"
100
+ required_rubygems_version: !ruby/object:Gem::Requirement
101
+ none: false
102
+ requirements:
103
+ - - ">="
104
+ - !ruby/object:Gem::Version
105
+ hash: 3
106
+ segments:
107
+ - 0
108
+ version: "0"
109
+ requirements: []
110
+
111
+ rubyforge_project:
112
+ rubygems_version: 1.5.3
113
+ signing_key:
114
+ specification_version: 3
115
+ summary: An HTTParty where the resources never change, the points are made up, and everyboday wins.
116
+ test_files:
117
+ - test/readonly_party_test.rb