spore 0.0.3 → 0.0.5

Sign up to get free protection for your applications and to get access to all the features.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.0.3
1
+ 0.0.5
@@ -22,7 +22,7 @@ class Spore
22
22
  attr_accessor :base_url, :format, :version
23
23
  attr_accessor :methods
24
24
  attr_accessor :middlewares
25
- attr_reader :specs
25
+ attr_reader :specs, :config
26
26
 
27
27
  class RequiredParameterExptected < Exception
28
28
  end
@@ -63,14 +63,16 @@ class Spore
63
63
  #
64
64
  def initialize(spec,options = {})
65
65
  # Don't load gems that are not needed
66
- # Only when it requires json, then json is loaded
66
+ # Only When it requires json, then json is loaded
67
67
  parser = self.class.load_parser(spec, options)
68
+ @config = options[:client_config] || {:ssl_verify_mode => OpenSSL::SSL::VERIFY_PEER | OpenSSL::SSL::VERIFY_FAIL_IF_NO_PEER_CERT }
69
+
68
70
  specs = parser.load_file(spec)
69
71
 
70
72
  inititliaze_api_attrs(specs)
71
73
  construct_client_class(self.methods)
72
74
  self.middlewares = []
73
- end
75
+ end
74
76
 
75
77
  ##
76
78
  # :call-seq:
@@ -253,10 +255,16 @@ class Spore
253
255
 
254
256
  # our HttpClient object
255
257
  client = HTTPClient.new
258
+ client.ssl_config.verify_mode = @config[:ssl_verify_mode]
256
259
 
257
260
  # normalize our headers for HttpClient
258
261
  h = headers.map{|header| header.values_at(:name,:value)}
259
-
262
+
263
+ # force content type to form urlencoded
264
+ if ! h.index{|a| a[0] == 'Content-Type' } && method_name != 'get'
265
+ h.push(['Content-Type', 'application/x-www-form-urlencoded'])
266
+ end
267
+
260
268
  # the response object we expect to have
261
269
  resp = client.send(method_name,path, params, h) if method_name =~ %r{get|post|put|delete}
262
270
 
@@ -0,0 +1,20 @@
1
+ ---
2
+ base_url: https://svn.rails-royce.org/
3
+ version: 0.2
4
+ format:
5
+ - json
6
+ - xml
7
+ - yml
8
+ methods:
9
+ ###################################################################
10
+ # repos functions
11
+ ###################################################################
12
+ get_repos:
13
+ path: /repos/:id.:format
14
+ method: GET
15
+ required_params:
16
+ - account_id
17
+ - id
18
+ optional_params:
19
+ - label
20
+ - account_id
@@ -23,7 +23,7 @@ class TestEnableIf < Test::Unit::TestCase
23
23
 
24
24
  # user_search is not altered
25
25
  r = spore.user_search(:format => 'json', :search => 'sukria')
26
- assert_equal 'sukria', r.body['users'][0]['name']
26
+ assert_equal 'Alexis Sukrieh', r.body['users'][0]['name']
27
27
 
28
28
  spore.enable_if(Spore::Middleware::FooBar, {}) do |env|
29
29
  env['spore.request_path'].match(/\/user\/search/)
@@ -43,7 +43,7 @@ class TestGitHub < Test::Unit::TestCase
43
43
  assert_kind_of HTTP::Message, r
44
44
  assert_equal r.status, 200
45
45
  assert_kind_of Hash, r.body
46
- assert_equal 'sukria', r.body['users'][0]['name']
46
+ assert_equal 'Alexis Sukrieh', r.body['users'][0]['name']
47
47
  end
48
48
  end
49
49
 
@@ -0,0 +1,16 @@
1
+ require "helper"
2
+ require 'spore/spec_parser/yaml'
3
+
4
+ class TestTestSelfSignedCertificate < Test::Unit::TestCase
5
+ def test_no_verify_ssl_cert
6
+ yaml = File.expand_path( '../royce.yml', __FILE__)
7
+ assert_raise OpenSSL::SSL::SSLError do
8
+ spore = Spore.new(yaml)
9
+ spore.get_repos(:id => 1, :account_id => 1, :format => :json)
10
+ end
11
+ assert_nothing_raised do
12
+ spore = Spore.new(yaml, :client_config => {:ssl_verify_mode => OpenSSL::SSL::VERIFY_NONE })
13
+ spore.get_repos(:id => 1, :account_id => 1, :format => :json)
14
+ end
15
+ end
16
+ end
metadata CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
5
5
  segments:
6
6
  - 0
7
7
  - 0
8
- - 3
9
- version: 0.0.3
8
+ - 5
9
+ version: 0.0.5
10
10
  platform: ruby
11
11
  authors:
12
12
  - Alexis Sukrieh <sukria@sukria.net> [sukria]
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2010-12-22 00:00:00 +01:00
18
+ date: 2011-01-20 00:00:00 +01:00
19
19
  default_executable:
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency
@@ -73,12 +73,14 @@ files:
73
73
  - test/github1.yml
74
74
  - test/github2.yml
75
75
  - test/helper.rb
76
+ - test/royce.yml
76
77
  - test/test_collapsing.rb
77
78
  - test/test_constructor.rb
78
79
  - test/test_enable_if.rb
79
80
  - test/test_github.rb
80
81
  - test/test_middleware_runtime.rb
81
82
  - test/test_parser.rb
83
+ - test/test_self_signed_certificate.rb
82
84
  - test/xml_parser.rb
83
85
  has_rdoc: true
84
86
  homepage: http://github.com/sukria/Ruby-Spore
@@ -120,4 +122,5 @@ test_files:
120
122
  - test/test_github.rb
121
123
  - test/test_middleware_runtime.rb
122
124
  - test/test_parser.rb
125
+ - test/test_self_signed_certificate.rb
123
126
  - test/xml_parser.rb