nitroapi 0.0.8 → 0.0.9

Sign up to get free protection for your applications and to get access to all the features.
@@ -129,7 +129,11 @@ module NitroApi
129
129
  end
130
130
 
131
131
  def base_url
132
- "#{self.protocol}://#{self.host}/nitro/#{self.accepts}"
132
+ "#{self.protocol}://#{self.host}#{base_url_path}"
133
+ end
134
+
135
+ def base_url_path
136
+ "/nitro/#{self.accepts}"
133
137
  end
134
138
 
135
139
  private
@@ -152,14 +156,35 @@ module NitroApi
152
156
  end
153
157
 
154
158
  def really_make_call params, method
155
- if :get == method
156
- request = "#{base_url}?#{to_query(params)}"
157
- data = Net::HTTP.get(URI.parse(request))
158
- elsif :post == method
159
- data = Net::HTTP.post_form(URI.parse(base_url), params)
160
- data = data.body
159
+ data = nil
160
+ if :http == protocol or 'http' == protocol
161
+ if :get == method
162
+ request = "#{base_url}?#{to_query(params)}"
163
+ data = Net::HTTP.get(URI.parse(request))
164
+ elsif :post == method
165
+ data = Net::HTTP.post_form(URI.parse(base_url), params)
166
+ data = data.body
167
+ end
168
+ elsif :https == protocol or 'https' == protocol
169
+ http = Net::HTTP.new(host, 443)
170
+ http.use_ssl = true
171
+ http.verify_mode = OpenSSL::SSL::VERIFY_PEER
172
+
173
+ if :get == method
174
+ request = "#{base_url_path}?#{to_query(params)}"
175
+ data = http.request(Net::HTTP::Get.new(request))
176
+ data = data.body
177
+ elsif :post == method
178
+ request = Net::HTTP::Post.new(base_url_path)
179
+ request.set_form_data(params)
180
+ data = http.request request
181
+ data = data.body
182
+ end
183
+ else
184
+ raise NitroError.new(1), "Unknown protocl: #{protocol.to_s}"
161
185
  end
162
186
 
187
+
163
188
  json = JSON.parse(data)
164
189
  response = json["Nitro"]
165
190
  error = response["Error"]
@@ -1,3 +1,3 @@
1
1
  module NitroApi
2
- VERSION = "0.0.8"
2
+ VERSION = "0.0.9"
3
3
  end
@@ -60,6 +60,15 @@ describe NitroApi do
60
60
  end
61
61
  end
62
62
 
63
+ describe "#base_url_path" do
64
+ it "correclty users the configured accepts value" do
65
+ @nitro.base_url_path.should == '/nitro/json'
66
+
67
+ @nitro.accepts = 'xml'
68
+ @nitro.base_url_path.should == '/nitro/xml'
69
+ end
70
+ end
71
+
63
72
  context "when authenticated" do
64
73
  before do
65
74
  @nitro.session = @session
@@ -467,8 +476,35 @@ describe NitroApi do
467
476
  expect {@nitro.action_history 'action1'}.to raise_error(NitroApi::NitroError)
468
477
  end
469
478
  end
479
+ end
480
+ end
481
+
482
+ context "https connections" do
483
+ it "makes a single call successfully via https" do
484
+ @nitro.protocol = 'https'
485
+ mock_json = {"Nitro" => {"Login" => {"sessionKey" => @session}}}
486
+ url = @nitro.base_url + "?.*method=user.login.*"
487
+ stub_http_request(:get, Regexp.new(url)).
488
+ to_return(:body => mock_json.to_json)
470
489
 
490
+ @nitro.login
491
+ @nitro.session.should == @session
492
+ end
493
+
494
+ it "makes a batch call successfully via https" do
495
+ @nitro.protocol = 'https'
496
+ mock_json = {'Nitro' => {'Login' => {'sessionKey' => @session}, 'method' => 'user.login', 'res' => 'ok'}}
497
+ url = @nitro.base_url #+ "?.*method=batch.run.*"
498
+ stub_http_request(:get, Regexp.new(url)).
499
+ to_return(:body => mock_json.to_json)
500
+
501
+ @nitro.start_batch!
502
+ @nitro.login
503
+ @nitro.run_batch
504
+
505
+ @nitro.session.should == @session
471
506
  end
472
507
  end
508
+
473
509
  end
474
510
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: nitroapi
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.8
4
+ version: 0.0.9
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -10,7 +10,7 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2012-12-06 00:00:00.000000000 Z
13
+ date: 2012-12-09 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: activesupport