gisty 0.0.16 → 0.0.17

Sign up to get free protection for your applications and to get access to all the features.
Files changed (5) hide show
  1. data/README.rdoc +5 -2
  2. data/bin/gisty +5 -1
  3. data/lib/gisty.rb +8 -2
  4. data/test/gisty_test.rb +36 -26
  5. metadata +4 -4
data/README.rdoc CHANGED
@@ -16,7 +16,7 @@ yet another command line client for gist
16
16
  set environment variable GISTY_DIR.
17
17
  example .zshrc
18
18
 
19
- export GISTY_DIR="$HOME/dev/gists"
19
+ export GISTY_DIR="$HOME/dev/gists"
20
20
 
21
21
  set global git config. see "Global Git Config" at https://github.com/account
22
22
 
@@ -29,7 +29,10 @@ http://github.com/swdyh/gisty/raw/master/_gisty
29
29
 
30
30
  == Features/Problems
31
31
 
32
- use API token with HTTP. at your own risk.
32
+ if "certificate verify failed" is occurred, set environment variable GISTY_SSL_CA.
33
+ example .zshrc
34
+
35
+ export GISTY_SSL_CA="/your_ca_file_path/cert.pem"
33
36
 
34
37
  == Synopsis
35
38
 
data/bin/gisty CHANGED
@@ -95,7 +95,11 @@ end
95
95
 
96
96
  if ENV['GISTY_DIR']
97
97
  begin
98
- @g = Gisty.new ENV['GISTY_DIR']
98
+ if ENV['GISTY_SSL_CA']
99
+ @g = Gisty.new ENV['GISTY_DIR'], nil, nil, :ssl_ca => ENV['GISTY_SSL_CA']
100
+ else
101
+ @g = Gisty.new ENV['GISTY_DIR']
102
+ end
99
103
  rescue Gisty::UnsetAuthInfoException => e
100
104
  puts 'Error: set your api token.'
101
105
  puts 'see Global Git Config at https://github.com/account'
data/lib/gisty.rb CHANGED
@@ -7,7 +7,7 @@ require 'nokogiri'
7
7
  require 'net/https'
8
8
 
9
9
  class Gisty
10
- VERSION = '0.0.16'
10
+ VERSION = '0.0.17'
11
11
  GIST_URL = 'https://gist.github.com/'
12
12
  GISTY_URL = 'http://github.com/swdyh/gisty/tree/master'
13
13
 
@@ -35,12 +35,15 @@ class Gisty
35
35
  }
36
36
  end
37
37
 
38
- def initialize path, login = nil, token = nil
38
+ def initialize path, login = nil, token = nil, opt = {}
39
39
  @auth = (login && token) ? { 'login' => login, 'token' => token } : auth
40
40
  raise UnsetAuthInfoException if @auth['login'].nil? || @auth['token'].nil?
41
41
  @auth_query = "login=#{@auth['login']}&token=#{@auth['token']}"
42
42
  @dir = Pathname.pwd.realpath.join path
43
43
  FileUtils.mkdir_p @dir unless @dir.exist?
44
+ if opt[:ssl_ca]
45
+ @ssl_ca = opt[:ssl_ca]
46
+ end
44
47
  end
45
48
 
46
49
  def next_link str
@@ -157,6 +160,9 @@ class Gisty
157
160
  https.use_ssl = true
158
161
  https.verify_mode = OpenSSL::SSL::VERIFY_PEER
159
162
  https.verify_depth = 5
163
+ if @ssl_ca
164
+ https.ca_file = @ssl_ca
165
+ end
160
166
  res = https.start {|http| http.request(req) }
161
167
  case res
162
168
  when Net::HTTPSuccess, Net::HTTPRedirection
data/test/gisty_test.rb CHANGED
@@ -43,11 +43,11 @@ class GistyTest < Test::Unit::TestCase
43
43
  end
44
44
  end
45
45
 
46
- def stub_post_form! dummy = 'http://gist.github.com/111111'
47
- stub(Net::HTTP).post_form do |uri, opt|
48
- { 'Location' => dummy }
49
- end
50
- end
46
+ # def stub_post_form! dummy = 'http://gist.github.com/111111'
47
+ # stub(Net::HTTP).post_form do |uri, opt|
48
+ # { 'Location' => dummy }
49
+ # end
50
+ # end
51
51
 
52
52
  def test_extract_ids
53
53
  path = File.join 'test', 'fixtures', 'swdyh_page_4'
@@ -150,26 +150,36 @@ class GistyTest < Test::Unit::TestCase
150
150
  assert_equal "// bar.user.js\n", params['file_contents[gistfile2]']
151
151
  end
152
152
 
153
- def test_create
154
- stub_post_form!
155
- path = File.join('test', 'fixtures', 'foo.user.js')
156
- @gisty.create path
157
- end
158
-
159
- def test_create_multi
160
- path1 = File.join('test', 'fixtures', 'foo.user.js')
161
- path2 = File.join('test', 'fixtures', 'bar.user.js')
162
- @gisty.create [path1, path2]
163
- end
164
-
165
- def test_post_failure
166
- stub(Net::HTTP).post_form do |uri, opt|
167
- Net::HTTPClientError.new 'foo', 'bar', 'baz'
168
- end
169
- path = File.join('test', 'fixtures', 'foo.user.js')
170
- assert_raise Gisty::PostFailureException do
171
- @gisty.create path
172
- end
173
- end
153
+ def test_ssl_ca_option
154
+ ca = '/ssl_ca_path/cert.pem'
155
+ @gisty = Gisty.new @gisty_dir, 'foo', 'bar'
156
+ assert_nil @gisty.instance_eval { @ssl_ca }
157
+
158
+ ca = '/ssl_ca_path/cert.pem'
159
+ @gisty = Gisty.new @gisty_dir, 'foo', 'bar', :ssl_ca => ca
160
+ assert_equal ca, @gisty.instance_eval { @ssl_ca }
161
+ end
162
+
163
+ # def test_create
164
+ # stub_post_form!
165
+ # path = File.join('test', 'fixtures', 'foo.user.js')
166
+ # @gisty.create path
167
+ # end
168
+
169
+ # def test_create_multi
170
+ # path1 = File.join('test', 'fixtures', 'foo.user.js')
171
+ # path2 = File.join('test', 'fixtures', 'bar.user.js')
172
+ # @gisty.create [path1, path2]
173
+ # end
174
+
175
+ # def test_post_failure
176
+ # stub(Net::HTTP).post_form do |uri, opt|
177
+ # Net::HTTPClientError.new 'foo', 'bar', 'baz'
178
+ # end
179
+ # path = File.join('test', 'fixtures', 'foo.user.js')
180
+ # assert_raise Gisty::PostFailureException do
181
+ # @gisty.create path
182
+ # end
183
+ # end
174
184
  end
175
185
 
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: gisty
3
3
  version: !ruby/object:Gem::Version
4
- hash: 63
4
+ hash: 61
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
8
  - 0
9
- - 16
10
- version: 0.0.16
9
+ - 17
10
+ version: 0.0.17
11
11
  platform: ruby
12
12
  authors:
13
13
  - swdyh
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2010-11-05 00:00:00 +09:00
18
+ date: 2010-12-13 00:00:00 +09:00
19
19
  default_executable: gisty
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency