zipper 0.1.0

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 (5) hide show
  1. data/MIT-LICENSE +20 -0
  2. data/README.md +89 -0
  3. data/Rakefile +8 -0
  4. data/lib/zipper.rb +122 -0
  5. metadata +61 -0
data/MIT-LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright 2011 Adam Kirk, Mysterious Trousers, LLC
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,89 @@
1
+ # Pocket
2
+
3
+ A curl gem that doesn't suck.
4
+
5
+ ### Installation
6
+
7
+ In your Gemfile, add this line:
8
+
9
+ gem "pocket"
10
+
11
+
12
+ ### Options & Defaults
13
+
14
+ Here are the possible options. Whatever you pass in will merge with and overwrite these defaults. The :headers options will merge as well, so if you don't want those default headers, you'll
15
+ need to pass in a :headers option that overwrites (e.g. 'Content-Type') with nil.
16
+
17
+ # defaults
18
+ _options = {
19
+ :method => :get,
20
+ :username => nil,
21
+ :password => nil,
22
+ :use_ssl => false,
23
+ :data => nil,
24
+ :headers => {
25
+ "Content-Type" => "application/json",
26
+ "Accept" => "application/json",
27
+ }
28
+ }
29
+
30
+ ### Example Usage
31
+
32
+ (testing off http://button.herokuapp.com)
33
+
34
+ Simple get:
35
+
36
+ response = Pocket.make_request("http://button.herokuapp.com/stitches")
37
+
38
+ Simple post:
39
+
40
+ response = Pocket.make_request("http://button.herokuapp.com/stitches", {
41
+ :method => :post,
42
+ :data => {
43
+ :stitch => {
44
+ :thread_color => "blue",
45
+ :length => 2
46
+ }
47
+ }
48
+ })
49
+
50
+ Simple put:
51
+
52
+ response = Pocket.make_request("http://button.herokuapp.com/stitches/" + stitch["id"].to_s, {
53
+ :method => :put,
54
+ :data => {
55
+ :stitch => {
56
+ :thread_color => "blue",
57
+ :length => 3
58
+ }
59
+ }
60
+ })
61
+
62
+
63
+ Simple delete:
64
+
65
+ response = Pocket.make_request("http://button.herokuapp.com/stitches/" + stitch["id"].to_s, {
66
+ :method => :delete,
67
+ })
68
+
69
+ Get with authentication:
70
+
71
+ response = Pocket.make_request("http://button.herokuapp.com/needles", {
72
+ :username => "username",
73
+ :password => "password"
74
+ })
75
+
76
+ Post with authentication:
77
+
78
+ response = Pocket.make_request("http://button.herokuapp.com/needles", {
79
+ :method => :post,
80
+ :data => {
81
+ :needle => {
82
+ :sharpness => 7,
83
+ :length => 2
84
+ }
85
+ },
86
+ :username => "username",
87
+ :password => "password"
88
+ })
89
+
data/Rakefile ADDED
@@ -0,0 +1,8 @@
1
+ require 'rake/testtask'
2
+
3
+ Rake::TestTask.new do |t|
4
+ t.libs << 'test'
5
+ end
6
+
7
+ desc "Run tests"
8
+ task :default => :test
data/lib/zipper.rb ADDED
@@ -0,0 +1,122 @@
1
+ require 'pocket'
2
+ require 'singleton'
3
+
4
+ class Zipper
5
+ include Singleton
6
+
7
+ def initialize
8
+ @root_url = "http://localhost:3000/"
9
+ end
10
+
11
+ def self.root_url=(root_url)
12
+ self.instance.root_url = root_url
13
+ end
14
+
15
+ def root_url=(root_url)
16
+ @root_url = root_url
17
+ end
18
+
19
+ def self.run(url = "", options = {})
20
+ self.instance.run(url, options)
21
+ end
22
+
23
+ def run(url, options)
24
+
25
+
26
+ # inferences
27
+ _URI = URI.parse(url)
28
+ _URL = _URI.host ? url : File.join(@root_url, url)
29
+ _URI = _URI.host ? _URI : URI.parse(_URL)
30
+ _resource = _URI.path ? _URI.path.gsub(/(^\/|\/.*$)/i,"") : "resource"
31
+ _action = _URI.path ? _URI.path.gsub(/(^.*\/)/i,"") : "action on"
32
+ _title = _action.capitalize + " " + _resource.capitalize
33
+ _key = _title.downcase.gsub(/ /i, "-").downcase
34
+
35
+
36
+ # defaults
37
+ _options = {
38
+ :resource => _resource,
39
+ :title => _title,
40
+ :key => _key,
41
+ :method => :get,
42
+ :data => nil,
43
+ :status => 200,
44
+ :username => nil,
45
+ :password => nil,
46
+ :use_ssl => false
47
+ }
48
+
49
+
50
+ # merge passed in options with default options
51
+ _options = _options.merge(options)
52
+
53
+
54
+ _result = Pocket.make_request(_URL, {
55
+ :method => _options[:method],
56
+ :username => _options[:username],
57
+ :password => _options[:password],
58
+ :use_ssl => _options[:use_ssl],
59
+ :data => _options[:data]
60
+ })
61
+
62
+
63
+
64
+
65
+
66
+
67
+ # create example
68
+ # _curl_string = []
69
+ # _curl_string << "curl"
70
+ #
71
+ # if _options[:username] && _options[:password]
72
+ # _curl_string << _options[:username] + ":" + _options[:password]
73
+ # end
74
+ #
75
+ # _curl_string << '-H "Accept: application/json" -H "Content-Type: application/json"'
76
+ #
77
+ # if _options[:data]
78
+ # _curl_string << "-d '" + _options[:data] + "'"
79
+ # end
80
+ #
81
+ # if _options[:method] && _options[:method] != "GET"
82
+ # _curl_string << "-X $method"
83
+ # end
84
+ #
85
+ # _curl_string << "$docs_base_url/$api_url";
86
+ # _curl_string << "\n"
87
+
88
+
89
+
90
+
91
+ # create doc json
92
+ # doc = {
93
+ # :resource => _options[:resource],
94
+ # :title => _options[:title],
95
+ # :key => _options[:key],
96
+ # :method => _options[:method],
97
+ # :url => _options[:url],
98
+ # :request_body => _options[:data],
99
+ # :status => _options[:status],
100
+ # :response_body => _result.to_json,
101
+ # :example => _curl_string.join(" ")
102
+ # }
103
+ #
104
+ # # write to docs file
105
+ # file_path = Rails.root.join("docs/zipper_api.json")
106
+ # current_json_string = File.open( file_path , "rb" ).read
107
+ #
108
+ # docs_json = []
109
+ # begin
110
+ # docs_json = JSON.parse current_json_string
111
+ # rescue
112
+ # docs_json = []
113
+ # end
114
+ #
115
+ # docs_json << doc_json
116
+ # File.open( file_path , 'a' ) {|f| f.write( docs_json ) }
117
+
118
+ _result
119
+
120
+ end
121
+
122
+ end
metadata ADDED
@@ -0,0 +1,61 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: zipper
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Adam Kirk
9
+ - Parker Wightman
10
+ - Mysterious Trousers, LLC
11
+ autorequire:
12
+ bindir: bin
13
+ cert_chain: []
14
+ date: 2011-11-24 00:00:00.000000000Z
15
+ dependencies:
16
+ - !ruby/object:Gem::Dependency
17
+ name: pocket
18
+ requirement: &70234267340940 !ruby/object:Gem::Requirement
19
+ none: false
20
+ requirements:
21
+ - - ! '>='
22
+ - !ruby/object:Gem::Version
23
+ version: '0'
24
+ type: :runtime
25
+ prerelease: false
26
+ version_requirements: *70234267340940
27
+ description: API Testing Done Right
28
+ email: atomkirk@gmail.com
29
+ executables: []
30
+ extensions: []
31
+ extra_rdoc_files: []
32
+ files:
33
+ - lib/zipper.rb
34
+ - MIT-LICENSE
35
+ - Rakefile
36
+ - README.md
37
+ homepage: http://mysterioustrousers.com/
38
+ licenses: []
39
+ post_install_message:
40
+ rdoc_options: []
41
+ require_paths:
42
+ - lib
43
+ required_ruby_version: !ruby/object:Gem::Requirement
44
+ none: false
45
+ requirements:
46
+ - - ! '>='
47
+ - !ruby/object:Gem::Version
48
+ version: '0'
49
+ required_rubygems_version: !ruby/object:Gem::Requirement
50
+ none: false
51
+ requirements:
52
+ - - ! '>='
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ requirements: []
56
+ rubyforge_project:
57
+ rubygems_version: 1.8.15
58
+ signing_key:
59
+ specification_version: 3
60
+ summary: API Testing Done Right
61
+ test_files: []