bixby-common 0.3.8

Sign up to get free protection for your applications and to get access to all the features.
Files changed (36) hide show
  1. data/.document +5 -0
  2. data/Gemfile +40 -0
  3. data/Gemfile.lock +147 -0
  4. data/Rakefile +58 -0
  5. data/VERSION +1 -0
  6. data/bixby-common.gemspec +135 -0
  7. data/lib/bixby-common.rb +1 -0
  8. data/lib/bixby_common/api/json_request.rb +36 -0
  9. data/lib/bixby_common/api/json_response.rb +83 -0
  10. data/lib/bixby_common/bixby.rb +23 -0
  11. data/lib/bixby_common/command_response.rb +80 -0
  12. data/lib/bixby_common/command_spec.rb +138 -0
  13. data/lib/bixby_common/exception/bundle_not_found.rb +5 -0
  14. data/lib/bixby_common/exception/command_exception.rb +13 -0
  15. data/lib/bixby_common/exception/command_not_found.rb +5 -0
  16. data/lib/bixby_common/exception/encryption_error.rb +5 -0
  17. data/lib/bixby_common/util/crypto_util.rb +130 -0
  18. data/lib/bixby_common/util/debug.rb +19 -0
  19. data/lib/bixby_common/util/hashify.rb +16 -0
  20. data/lib/bixby_common/util/http_client.rb +64 -0
  21. data/lib/bixby_common/util/jsonify.rb +27 -0
  22. data/lib/bixby_common/util/log.rb +50 -0
  23. data/lib/bixby_common.rb +24 -0
  24. data/test/bixby_common_test.rb +18 -0
  25. data/test/command_response_test.rb +48 -0
  26. data/test/command_spec_test.rb +98 -0
  27. data/test/helper.rb +34 -0
  28. data/test/support/repo/vendor/test_bundle/bin/cat +2 -0
  29. data/test/support/repo/vendor/test_bundle/bin/cat.json +3 -0
  30. data/test/support/repo/vendor/test_bundle/bin/echo +2 -0
  31. data/test/support/repo/vendor/test_bundle/digest +20 -0
  32. data/test/support/repo/vendor/test_bundle/manifest.json +0 -0
  33. data/test/util/http_client_test.rb +58 -0
  34. data/test/util/jsonify_test.rb +36 -0
  35. data/test/util/log_test.rb +26 -0
  36. metadata +450 -0
data/test/helper.rb ADDED
@@ -0,0 +1,34 @@
1
+ require 'rubygems'
2
+ require 'bundler'
3
+ begin
4
+ Bundler.setup(:default, :development)
5
+ rescue Bundler::BundlerError => e
6
+ $stderr.puts e.message
7
+ $stderr.puts "Run `bundle install` to install missing gems"
8
+ exit e.status_code
9
+ end
10
+
11
+ require 'test_guard'
12
+ TestGuard.load_simplecov()
13
+
14
+ begin
15
+ require 'curb'
16
+ require 'curb_threadpool'
17
+ rescue LoadError
18
+ end
19
+
20
+ begin
21
+ require 'httpclient'
22
+ rescue LoadError
23
+ end
24
+
25
+ require 'webmock'
26
+ require 'mocha/setup'
27
+
28
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
29
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
30
+ require 'bixby_common'
31
+
32
+ Dir.glob(File.dirname(__FILE__) + "/../lib/**/*.rb").each{ |f| require f }
33
+
34
+ MiniTest::Unit.autorun
@@ -0,0 +1,2 @@
1
+ #!/bin/bash
2
+ cat -
@@ -0,0 +1,3 @@
1
+ {
2
+ "name": "cat"
3
+ }
@@ -0,0 +1,2 @@
1
+ #!/bin/sh
2
+ echo hi
@@ -0,0 +1,20 @@
1
+ {
2
+ "digest":"8980372485fc6bcd287e481ab1e15710e2b63c68db75085c2d24386ced272ca4",
3
+ "files":[
4
+ {
5
+ "file":"bin/cat",
6
+ "digest":"6d14ab63802f3ef51bdc16db1cfeb6df93167fe7a2aa09a6c737293d42c118b2"
7
+ },
8
+ {
9
+ "file":"bin/cat.json",
10
+ "digest":"1d1f4247f1412aa595c3df27226ebe808dfa8c72c1edc3ebbee452401153503b"
11
+ },
12
+ {
13
+ "file":"bin/echo",
14
+ "digest":"299001868fb8c02fd431c336c6d058f5558c5dff5b5af5e6fe04b870a6a9cbba"
15
+ },
16
+ {
17
+ "file":"manifest.json",
18
+ "digest":"e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855"
19
+ }
20
+ ]}
@@ -0,0 +1,58 @@
1
+
2
+ require 'helper'
3
+
4
+ module Bixby
5
+ module Test
6
+
7
+ class TestHttpClient < MiniTest::Unit::TestCase
8
+
9
+ include WebMock::API
10
+
11
+ def teardown
12
+ WebMock.reset!
13
+ end
14
+
15
+ class Foo
16
+ include Bixby::HttpClient
17
+ end
18
+
19
+ def test_http_get
20
+ stub_request(:get, "http://www.google.com/").
21
+ to_return(:status => 200, :body => "foobar", :headers => {})
22
+ body = Foo.new.http_get("http://www.google.com")
23
+ assert_equal "foobar", body
24
+ end
25
+
26
+ def test_http_post
27
+ stub_request(:post, "http://www.google.com/").
28
+ with(:body => "foo=bar").
29
+ to_return(:status => 200, :body => "foobar", :headers => {})
30
+ body = Foo.new.http_post("http://www.google.com", {:foo => "bar"})
31
+ assert_equal "foobar", body
32
+ end
33
+
34
+ def test_http_post_json
35
+ # string bodies should pass through directly
36
+ stub_request(:post, "http://www.google.com/").
37
+ with(:body => "{\"foo\":\"bar\"}").
38
+ to_return(:status => 200, :body => "foobar", :headers => {})
39
+ body = Foo.new.http_post("http://www.google.com", MultiJson.dump({:foo => "bar"}))
40
+ assert_equal "foobar", body
41
+ end
42
+
43
+ def test_http_post_download
44
+ stub_request(:post, "http://www.google.com/").
45
+ with(:body => "fooey").
46
+ to_return(:status => 200, :body => "baznab", :headers => {})
47
+
48
+ tmp = Tempfile.new("bc-post-")
49
+ body = Foo.new.http_post_download("http://www.google.com", "fooey", tmp.path)
50
+
51
+ s = File.read(tmp.path)
52
+ assert_equal "baznab", s
53
+ end
54
+
55
+ end # TestHttpClient
56
+
57
+ end # Test
58
+ end # Bixby
@@ -0,0 +1,36 @@
1
+
2
+ require 'helper'
3
+
4
+ module Bixby
5
+ module Test
6
+
7
+ class TestJsonify < MiniTest::Unit::TestCase
8
+
9
+ def test_to_json
10
+ j = JFoo.new
11
+ j.bar = "baz"
12
+ json = j.to_json
13
+ assert json
14
+ assert_equal '{"bar":"baz"}', json
15
+ end
16
+
17
+ def test_from_json
18
+ j1 = JFoo.new
19
+ j1.bar = "baz"
20
+
21
+ j2 = JFoo.from_json(j1.to_json)
22
+ assert_equal "baz", j2.bar
23
+
24
+ j3 = JFoo.from_json('{"bar":"baz"}')
25
+ assert_equal "baz", j3.bar
26
+ end
27
+
28
+ end # Jsonify
29
+
30
+ class JFoo
31
+ include Jsonify
32
+ attr_accessor :bar
33
+ end
34
+
35
+ end # Test
36
+ end # Bixby
@@ -0,0 +1,26 @@
1
+
2
+ require 'helper'
3
+
4
+ module Bixby
5
+ module Test
6
+
7
+ class TestLog < MiniTest::Unit::TestCase
8
+
9
+ def test_setup_logger
10
+ ENV["BIXBY_DEBUG"] = "1"
11
+ Bixby::Log.setup_logger
12
+ assert_equal 0, Logging::Logger.root.level # debug
13
+
14
+ ENV.delete("BIXBY_DEBUG")
15
+ Bixby::Log.setup_logger
16
+ assert_equal 2, Logging::Logger.root.level # warn
17
+
18
+ ENV.delete("BIXBY_DEBUG")
19
+ Bixby::Log.setup_logger(:info)
20
+ assert_equal 1, Logging::Logger.root.level # info
21
+ end
22
+
23
+ end # TestLog
24
+
25
+ end # Test
26
+ end # Bixby
metadata ADDED
@@ -0,0 +1,450 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: bixby-common
3
+ version: !ruby/object:Gem::Version
4
+ prerelease:
5
+ version: 0.3.8
6
+ platform: ruby
7
+ authors:
8
+ - Chetan Sarva
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2013-03-23 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: multi_json
16
+ prerelease: false
17
+ requirement: !ruby/object:Gem::Requirement
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: '0'
22
+ none: false
23
+ type: :runtime
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ requirements:
26
+ - - ! '>='
27
+ - !ruby/object:Gem::Version
28
+ version: '0'
29
+ none: false
30
+ - !ruby/object:Gem::Dependency
31
+ name: httpi
32
+ prerelease: false
33
+ requirement: !ruby/object:Gem::Requirement
34
+ requirements:
35
+ - - ! '>='
36
+ - !ruby/object:Gem::Version
37
+ version: '0'
38
+ none: false
39
+ type: :runtime
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ requirements:
42
+ - - ! '>='
43
+ - !ruby/object:Gem::Version
44
+ version: '0'
45
+ none: false
46
+ - !ruby/object:Gem::Dependency
47
+ name: logging
48
+ prerelease: false
49
+ requirement: !ruby/object:Gem::Requirement
50
+ requirements:
51
+ - - ! '>='
52
+ - !ruby/object:Gem::Version
53
+ version: '0'
54
+ none: false
55
+ type: :runtime
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ requirements:
58
+ - - ! '>='
59
+ - !ruby/object:Gem::Version
60
+ version: '0'
61
+ none: false
62
+ - !ruby/object:Gem::Dependency
63
+ name: yard
64
+ prerelease: false
65
+ requirement: !ruby/object:Gem::Requirement
66
+ requirements:
67
+ - - ~>
68
+ - !ruby/object:Gem::Version
69
+ version: '0.8'
70
+ none: false
71
+ type: :development
72
+ version_requirements: !ruby/object:Gem::Requirement
73
+ requirements:
74
+ - - ~>
75
+ - !ruby/object:Gem::Version
76
+ version: '0.8'
77
+ none: false
78
+ - !ruby/object:Gem::Dependency
79
+ name: bundler
80
+ prerelease: false
81
+ requirement: !ruby/object:Gem::Requirement
82
+ requirements:
83
+ - - ~>
84
+ - !ruby/object:Gem::Version
85
+ version: '1.1'
86
+ none: false
87
+ type: :development
88
+ version_requirements: !ruby/object:Gem::Requirement
89
+ requirements:
90
+ - - ~>
91
+ - !ruby/object:Gem::Version
92
+ version: '1.1'
93
+ none: false
94
+ - !ruby/object:Gem::Dependency
95
+ name: jeweler
96
+ prerelease: false
97
+ requirement: !ruby/object:Gem::Requirement
98
+ requirements:
99
+ - - ! '>='
100
+ - !ruby/object:Gem::Version
101
+ version: '0'
102
+ none: false
103
+ type: :development
104
+ version_requirements: !ruby/object:Gem::Requirement
105
+ requirements:
106
+ - - ! '>='
107
+ - !ruby/object:Gem::Version
108
+ version: '0'
109
+ none: false
110
+ - !ruby/object:Gem::Dependency
111
+ name: pry
112
+ prerelease: false
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - ! '>='
116
+ - !ruby/object:Gem::Version
117
+ version: '0'
118
+ none: false
119
+ type: :development
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - ! '>='
123
+ - !ruby/object:Gem::Version
124
+ version: '0'
125
+ none: false
126
+ - !ruby/object:Gem::Dependency
127
+ name: simplecov
128
+ prerelease: false
129
+ requirement: !ruby/object:Gem::Requirement
130
+ requirements:
131
+ - - ! '>='
132
+ - !ruby/object:Gem::Version
133
+ version: '0'
134
+ none: false
135
+ type: :development
136
+ version_requirements: !ruby/object:Gem::Requirement
137
+ requirements:
138
+ - - ! '>='
139
+ - !ruby/object:Gem::Version
140
+ version: '0'
141
+ none: false
142
+ - !ruby/object:Gem::Dependency
143
+ name: rcov
144
+ prerelease: false
145
+ requirement: !ruby/object:Gem::Requirement
146
+ requirements:
147
+ - - ! '>='
148
+ - !ruby/object:Gem::Version
149
+ version: '0'
150
+ none: false
151
+ type: :development
152
+ version_requirements: !ruby/object:Gem::Requirement
153
+ requirements:
154
+ - - ! '>='
155
+ - !ruby/object:Gem::Version
156
+ version: '0'
157
+ none: false
158
+ - !ruby/object:Gem::Dependency
159
+ name: minitest
160
+ prerelease: false
161
+ requirement: !ruby/object:Gem::Requirement
162
+ requirements:
163
+ - - ! '>='
164
+ - !ruby/object:Gem::Version
165
+ version: '0'
166
+ none: false
167
+ type: :development
168
+ version_requirements: !ruby/object:Gem::Requirement
169
+ requirements:
170
+ - - ! '>='
171
+ - !ruby/object:Gem::Version
172
+ version: '0'
173
+ none: false
174
+ - !ruby/object:Gem::Dependency
175
+ name: test-unit
176
+ prerelease: false
177
+ requirement: !ruby/object:Gem::Requirement
178
+ requirements:
179
+ - - ! '>='
180
+ - !ruby/object:Gem::Version
181
+ version: '0'
182
+ none: false
183
+ type: :development
184
+ version_requirements: !ruby/object:Gem::Requirement
185
+ requirements:
186
+ - - ! '>='
187
+ - !ruby/object:Gem::Version
188
+ version: '0'
189
+ none: false
190
+ - !ruby/object:Gem::Dependency
191
+ name: webmock
192
+ prerelease: false
193
+ requirement: !ruby/object:Gem::Requirement
194
+ requirements:
195
+ - - ! '>='
196
+ - !ruby/object:Gem::Version
197
+ version: '0'
198
+ none: false
199
+ type: :development
200
+ version_requirements: !ruby/object:Gem::Requirement
201
+ requirements:
202
+ - - ! '>='
203
+ - !ruby/object:Gem::Version
204
+ version: '0'
205
+ none: false
206
+ - !ruby/object:Gem::Dependency
207
+ name: mocha
208
+ prerelease: false
209
+ requirement: !ruby/object:Gem::Requirement
210
+ requirements:
211
+ - - ! '>='
212
+ - !ruby/object:Gem::Version
213
+ version: '0'
214
+ none: false
215
+ type: :development
216
+ version_requirements: !ruby/object:Gem::Requirement
217
+ requirements:
218
+ - - ! '>='
219
+ - !ruby/object:Gem::Version
220
+ version: '0'
221
+ none: false
222
+ - !ruby/object:Gem::Dependency
223
+ name: turn
224
+ prerelease: false
225
+ requirement: !ruby/object:Gem::Requirement
226
+ requirements:
227
+ - - ! '>='
228
+ - !ruby/object:Gem::Version
229
+ version: '0'
230
+ none: false
231
+ type: :development
232
+ version_requirements: !ruby/object:Gem::Requirement
233
+ requirements:
234
+ - - ! '>='
235
+ - !ruby/object:Gem::Version
236
+ version: '0'
237
+ none: false
238
+ - !ruby/object:Gem::Dependency
239
+ name: test_guard
240
+ prerelease: false
241
+ requirement: !ruby/object:Gem::Requirement
242
+ requirements:
243
+ - - ! '>='
244
+ - !ruby/object:Gem::Version
245
+ version: '0'
246
+ none: false
247
+ type: :development
248
+ version_requirements: !ruby/object:Gem::Requirement
249
+ requirements:
250
+ - - ! '>='
251
+ - !ruby/object:Gem::Version
252
+ version: '0'
253
+ none: false
254
+ - !ruby/object:Gem::Dependency
255
+ name: rb-inotify
256
+ prerelease: false
257
+ requirement: !ruby/object:Gem::Requirement
258
+ requirements:
259
+ - - ! '>='
260
+ - !ruby/object:Gem::Version
261
+ version: '0'
262
+ none: false
263
+ type: :development
264
+ version_requirements: !ruby/object:Gem::Requirement
265
+ requirements:
266
+ - - ! '>='
267
+ - !ruby/object:Gem::Version
268
+ version: '0'
269
+ none: false
270
+ - !ruby/object:Gem::Dependency
271
+ name: rb-fsevent
272
+ prerelease: false
273
+ requirement: !ruby/object:Gem::Requirement
274
+ requirements:
275
+ - - ! '>='
276
+ - !ruby/object:Gem::Version
277
+ version: '0'
278
+ none: false
279
+ type: :development
280
+ version_requirements: !ruby/object:Gem::Requirement
281
+ requirements:
282
+ - - ! '>='
283
+ - !ruby/object:Gem::Version
284
+ version: '0'
285
+ none: false
286
+ - !ruby/object:Gem::Dependency
287
+ name: rb-fchange
288
+ prerelease: false
289
+ requirement: !ruby/object:Gem::Requirement
290
+ requirements:
291
+ - - ! '>='
292
+ - !ruby/object:Gem::Version
293
+ version: '0'
294
+ none: false
295
+ type: :development
296
+ version_requirements: !ruby/object:Gem::Requirement
297
+ requirements:
298
+ - - ! '>='
299
+ - !ruby/object:Gem::Version
300
+ version: '0'
301
+ none: false
302
+ - !ruby/object:Gem::Dependency
303
+ name: json
304
+ prerelease: false
305
+ requirement: !ruby/object:Gem::Requirement
306
+ requirements:
307
+ - - ! '>='
308
+ - !ruby/object:Gem::Version
309
+ version: '0'
310
+ none: false
311
+ type: :development
312
+ version_requirements: !ruby/object:Gem::Requirement
313
+ requirements:
314
+ - - ! '>='
315
+ - !ruby/object:Gem::Version
316
+ version: '0'
317
+ none: false
318
+ - !ruby/object:Gem::Dependency
319
+ name: oj
320
+ prerelease: false
321
+ requirement: !ruby/object:Gem::Requirement
322
+ requirements:
323
+ - - ! '>='
324
+ - !ruby/object:Gem::Version
325
+ version: '0'
326
+ none: false
327
+ type: :development
328
+ version_requirements: !ruby/object:Gem::Requirement
329
+ requirements:
330
+ - - ! '>='
331
+ - !ruby/object:Gem::Version
332
+ version: '0'
333
+ none: false
334
+ - !ruby/object:Gem::Dependency
335
+ name: httpclient
336
+ prerelease: false
337
+ requirement: !ruby/object:Gem::Requirement
338
+ requirements:
339
+ - - ! '>='
340
+ - !ruby/object:Gem::Version
341
+ version: '0'
342
+ none: false
343
+ type: :development
344
+ version_requirements: !ruby/object:Gem::Requirement
345
+ requirements:
346
+ - - ! '>='
347
+ - !ruby/object:Gem::Version
348
+ version: '0'
349
+ none: false
350
+ - !ruby/object:Gem::Dependency
351
+ name: curb
352
+ prerelease: false
353
+ requirement: !ruby/object:Gem::Requirement
354
+ requirements:
355
+ - - ! '>='
356
+ - !ruby/object:Gem::Version
357
+ version: '0'
358
+ none: false
359
+ type: :development
360
+ version_requirements: !ruby/object:Gem::Requirement
361
+ requirements:
362
+ - - ! '>='
363
+ - !ruby/object:Gem::Version
364
+ version: '0'
365
+ none: false
366
+ - !ruby/object:Gem::Dependency
367
+ name: jruby-openssl
368
+ prerelease: false
369
+ requirement: !ruby/object:Gem::Requirement
370
+ requirements:
371
+ - - ! '>='
372
+ - !ruby/object:Gem::Version
373
+ version: '0'
374
+ none: false
375
+ type: :development
376
+ version_requirements: !ruby/object:Gem::Requirement
377
+ requirements:
378
+ - - ! '>='
379
+ - !ruby/object:Gem::Version
380
+ version: '0'
381
+ none: false
382
+ description: Bixby Common files/libs
383
+ email: chetan@pixelcop.net
384
+ executables: []
385
+ extensions: []
386
+ extra_rdoc_files: []
387
+ files:
388
+ - .document
389
+ - Gemfile
390
+ - Gemfile.lock
391
+ - Rakefile
392
+ - VERSION
393
+ - bixby-common.gemspec
394
+ - lib/bixby-common.rb
395
+ - lib/bixby_common.rb
396
+ - lib/bixby_common/api/json_request.rb
397
+ - lib/bixby_common/api/json_response.rb
398
+ - lib/bixby_common/bixby.rb
399
+ - lib/bixby_common/command_response.rb
400
+ - lib/bixby_common/command_spec.rb
401
+ - lib/bixby_common/exception/bundle_not_found.rb
402
+ - lib/bixby_common/exception/command_exception.rb
403
+ - lib/bixby_common/exception/command_not_found.rb
404
+ - lib/bixby_common/exception/encryption_error.rb
405
+ - lib/bixby_common/util/crypto_util.rb
406
+ - lib/bixby_common/util/debug.rb
407
+ - lib/bixby_common/util/hashify.rb
408
+ - lib/bixby_common/util/http_client.rb
409
+ - lib/bixby_common/util/jsonify.rb
410
+ - lib/bixby_common/util/log.rb
411
+ - test/bixby_common_test.rb
412
+ - test/command_response_test.rb
413
+ - test/command_spec_test.rb
414
+ - test/helper.rb
415
+ - test/support/repo/vendor/test_bundle/bin/cat
416
+ - test/support/repo/vendor/test_bundle/bin/cat.json
417
+ - test/support/repo/vendor/test_bundle/bin/echo
418
+ - test/support/repo/vendor/test_bundle/digest
419
+ - test/support/repo/vendor/test_bundle/manifest.json
420
+ - test/util/http_client_test.rb
421
+ - test/util/jsonify_test.rb
422
+ - test/util/log_test.rb
423
+ homepage: http://github.com/chetan/bixby-common
424
+ licenses: []
425
+ post_install_message:
426
+ rdoc_options: []
427
+ require_paths:
428
+ - lib
429
+ required_ruby_version: !ruby/object:Gem::Requirement
430
+ requirements:
431
+ - - ! '>='
432
+ - !ruby/object:Gem::Version
433
+ hash: -31160847080355140
434
+ segments:
435
+ - 0
436
+ version: '0'
437
+ none: false
438
+ required_rubygems_version: !ruby/object:Gem::Requirement
439
+ requirements:
440
+ - - ! '>='
441
+ - !ruby/object:Gem::Version
442
+ version: '0'
443
+ none: false
444
+ requirements: []
445
+ rubyforge_project:
446
+ rubygems_version: 1.8.25
447
+ signing_key:
448
+ specification_version: 3
449
+ summary: Bixby Common
450
+ test_files: []