zipper 0.1.0 → 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/tasks/zipper.rake +8 -0
- data/lib/zipper.rb +144 -111
- metadata +4 -3
data/lib/zipper.rb
CHANGED
@@ -1,121 +1,154 @@
|
|
1
1
|
require 'pocket'
|
2
|
-
require 'singleton'
|
3
2
|
|
4
|
-
|
5
|
-
|
3
|
+
module Zipper
|
4
|
+
DEFAULT_PORT = 3001
|
5
|
+
DEFAULT_ROOT = "http://localhost:#{DEFAULT_PORT}/"
|
6
6
|
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
7
|
+
class << self
|
8
|
+
|
9
|
+
attr_accessor :port
|
10
|
+
attr_accessor :root
|
11
|
+
attr_accessor :files
|
12
|
+
attr_accessor :users
|
13
|
+
|
14
|
+
def port
|
15
|
+
@port || DEFAULT_PORT
|
16
|
+
end
|
17
|
+
|
18
|
+
def root
|
19
|
+
@root || DEFAULT_ROOT
|
20
|
+
end
|
21
|
+
|
22
|
+
def files
|
23
|
+
@files || []
|
24
|
+
end
|
25
|
+
|
26
|
+
def users
|
27
|
+
@users || (raise "must have an array of users set in config/initializers/zipper.rb")
|
28
|
+
end
|
29
|
+
|
30
|
+
|
31
|
+
def run
|
32
|
+
system "rails s --environment=test --port=#{self.instance.port} -d"
|
33
|
+
system "rake db:test:purge"
|
34
|
+
system "rake db:test:load"
|
35
|
+
pid = File.read("tmp/pids/server.pid")
|
36
|
+
|
37
|
+
self.files.each do |file|
|
38
|
+
system "ruby test/zipper/#{file}.rb"
|
39
|
+
end
|
40
|
+
|
41
|
+
system "kill -s 9 " + pid
|
42
|
+
end
|
43
|
+
|
44
|
+
|
45
|
+
|
46
|
+
def test(url = "", options = {})
|
47
|
+
|
48
|
+
|
49
|
+
# inferences
|
50
|
+
_URI = URI.parse(url)
|
51
|
+
_URL = _URI.host ? url : File.join(self.root, url)
|
52
|
+
_URI = _URI.host ? _URI : URI.parse(_URL)
|
53
|
+
_resource = _URI.path ? _URI.path.gsub(/(^\/|\/.*$)/i,"") : "resource"
|
54
|
+
_action = _URI.path ? _URI.path.gsub(/(^.*\/)/i,"") : "action on"
|
55
|
+
_title = _action.capitalize + " " + _resource.capitalize
|
56
|
+
_key = _title.downcase.gsub(/ /i, "-").downcase
|
57
|
+
|
58
|
+
|
59
|
+
# defaults
|
60
|
+
_options = {
|
61
|
+
:resource => _resource,
|
62
|
+
:title => _title,
|
63
|
+
:key => _key,
|
64
|
+
:method => :get,
|
65
|
+
:data => nil,
|
66
|
+
:status => 200,
|
67
|
+
:username => nil,
|
68
|
+
:password => nil,
|
69
|
+
:use_ssl => false
|
70
|
+
}
|
48
71
|
|
49
72
|
|
50
|
-
|
51
|
-
|
73
|
+
# merge passed in options with default options
|
74
|
+
_options = _options.merge(options)
|
75
|
+
|
76
|
+
if _options[:user]
|
77
|
+
uid = _options[:user]
|
78
|
+
user = (self.users)[uid]
|
79
|
+
raise ":user does not exist" unless user
|
80
|
+
_un = user[:username]
|
81
|
+
_pw = user[:password]
|
82
|
+
end
|
52
83
|
|
53
84
|
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
85
|
+
_result = Pocket.make_request(_URL, {
|
86
|
+
:method => _options[:method],
|
87
|
+
:username => _un || _options[:username],
|
88
|
+
:password => _pw || _options[:password],
|
89
|
+
:use_ssl => _options[:use_ssl],
|
90
|
+
:data => _options[:data]
|
91
|
+
})
|
92
|
+
|
93
|
+
|
94
|
+
|
95
|
+
|
96
|
+
|
97
|
+
|
98
|
+
# create example
|
99
|
+
# _curl_string = []
|
100
|
+
# _curl_string << "curl"
|
101
|
+
#
|
102
|
+
# if _options[:username] && _options[:password]
|
103
|
+
# _curl_string << _options[:username] + ":" + _options[:password]
|
104
|
+
# end
|
105
|
+
#
|
106
|
+
# _curl_string << '-H "Accept: application/json" -H "Content-Type: application/json"'
|
107
|
+
#
|
108
|
+
# if _options[:data]
|
109
|
+
# _curl_string << "-d '" + _options[:data] + "'"
|
110
|
+
# end
|
111
|
+
#
|
112
|
+
# if _options[:method] && _options[:method] != "GET"
|
113
|
+
# _curl_string << "-X $method"
|
114
|
+
# end
|
115
|
+
#
|
116
|
+
# _curl_string << "$docs_base_url/$api_url";
|
117
|
+
# _curl_string << "\n"
|
118
|
+
|
119
|
+
|
120
|
+
|
121
|
+
|
122
|
+
# create doc json
|
123
|
+
# doc = {
|
124
|
+
# :resource => _options[:resource],
|
125
|
+
# :title => _options[:title],
|
126
|
+
# :key => _options[:key],
|
127
|
+
# :method => _options[:method],
|
128
|
+
# :url => _options[:url],
|
129
|
+
# :request_body => _options[:data],
|
130
|
+
# :status => _options[:status],
|
131
|
+
# :response_body => _result.to_json,
|
132
|
+
# :example => _curl_string.join(" ")
|
133
|
+
# }
|
134
|
+
#
|
135
|
+
# # write to docs file
|
136
|
+
# file_path = Rails.root.join("docs/zipper_api.json")
|
137
|
+
# current_json_string = File.open( file_path , "rb" ).read
|
138
|
+
#
|
139
|
+
# docs_json = []
|
140
|
+
# begin
|
141
|
+
# docs_json = JSON.parse current_json_string
|
142
|
+
# rescue
|
143
|
+
# docs_json = []
|
144
|
+
# end
|
145
|
+
#
|
146
|
+
# docs_json << doc_json
|
147
|
+
# File.open( file_path , 'a' ) {|f| f.write( docs_json ) }
|
148
|
+
|
149
|
+
_result
|
150
|
+
|
151
|
+
end
|
119
152
|
|
120
153
|
end
|
121
154
|
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: zipper
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.1
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -15,7 +15,7 @@ date: 2011-11-24 00:00:00.000000000Z
|
|
15
15
|
dependencies:
|
16
16
|
- !ruby/object:Gem::Dependency
|
17
17
|
name: pocket
|
18
|
-
requirement: &
|
18
|
+
requirement: &70253888156380 !ruby/object:Gem::Requirement
|
19
19
|
none: false
|
20
20
|
requirements:
|
21
21
|
- - ! '>='
|
@@ -23,13 +23,14 @@ dependencies:
|
|
23
23
|
version: '0'
|
24
24
|
type: :runtime
|
25
25
|
prerelease: false
|
26
|
-
version_requirements: *
|
26
|
+
version_requirements: *70253888156380
|
27
27
|
description: API Testing Done Right
|
28
28
|
email: atomkirk@gmail.com
|
29
29
|
executables: []
|
30
30
|
extensions: []
|
31
31
|
extra_rdoc_files: []
|
32
32
|
files:
|
33
|
+
- lib/tasks/zipper.rake
|
33
34
|
- lib/zipper.rb
|
34
35
|
- MIT-LICENSE
|
35
36
|
- Rakefile
|