zipper 0.1.0 → 0.1.1

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 (3) hide show
  1. data/lib/tasks/zipper.rake +8 -0
  2. data/lib/zipper.rb +144 -111
  3. metadata +4 -3
@@ -0,0 +1,8 @@
1
+ namespace :zipper do
2
+ desc "Zipper API Testing"
3
+ task :test => :environment do
4
+
5
+ Zipper.run
6
+
7
+ end
8
+ end
data/lib/zipper.rb CHANGED
@@ -1,121 +1,154 @@
1
1
  require 'pocket'
2
- require 'singleton'
3
2
 
4
- class Zipper
5
- include Singleton
3
+ module Zipper
4
+ DEFAULT_PORT = 3001
5
+ DEFAULT_ROOT = "http://localhost:#{DEFAULT_PORT}/"
6
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
- }
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
- # merge passed in options with default options
51
- _options = _options.merge(options)
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
- _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
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.0
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: &70234267340940 !ruby/object:Gem::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: *70234267340940
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