fms-admin-api 0.2 → 0.3

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,21 +1,24 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- fms-admin-api (0.1)
4
+ fms-admin-api (0.3)
5
5
  activesupport
6
6
  colorize
7
7
 
8
8
  GEM
9
9
  remote: http://rubygems.org/
10
10
  specs:
11
- activesupport (3.2.3)
11
+ activesupport (3.2.7)
12
12
  i18n (~> 0.6)
13
13
  multi_json (~> 1.0)
14
14
  addressable (2.2.6)
15
15
  colorize (0.5.8)
16
16
  crack (0.3.1)
17
17
  i18n (0.6.0)
18
- multi_json (1.3.5)
18
+ metaclass (0.0.1)
19
+ mocha (0.12.3)
20
+ metaclass (~> 0.0.1)
21
+ multi_json (1.3.6)
19
22
  rake (0.9.2.2)
20
23
  webmock (1.7.8)
21
24
  addressable (~> 2.2, > 2.2.5)
@@ -26,5 +29,6 @@ PLATFORMS
26
29
 
27
30
  DEPENDENCIES
28
31
  fms-admin-api!
32
+ mocha
29
33
  rake
30
34
  webmock
@@ -23,4 +23,5 @@ Gem::Specification.new do |s|
23
23
  s.add_runtime_dependency "colorize"
24
24
  s.add_development_dependency "webmock"
25
25
  s.add_development_dependency "rake"
26
+ s.add_development_dependency "mocha"
26
27
  end
@@ -16,6 +16,7 @@ module FMS
16
16
  @host = defaults[:host]
17
17
  @port = defaults[:port]
18
18
  @base_params = {:auser => defaults[:auser], :apswd => defaults[:apswd]}
19
+ @timeout = options[:timeout]
19
20
  end
20
21
 
21
22
  def method_missing(meth, *args)
@@ -31,15 +32,17 @@ module FMS
31
32
  private
32
33
 
33
34
  def do_get(action, params = {})
34
- resp = Net::HTTP.get_response(build_url(action, params))
35
+ url = build_url action, params
36
+ http_client = HTTPClient.new @host, @port
37
+ resp = http_client.get url, @timeout
35
38
  raise NoMethodError, "#{action.inspect} is not a valid API method" unless resp.code == "200"
36
39
  resp.body
37
40
  end
38
41
 
39
42
  def build_url(method, extra_params = {})
40
- url = URI("http://#{@host}:#{@port}/admin/#{method}")
41
- url.query = URI.encode_www_form(@base_params.merge(extra_params))
42
- url
43
+ params = URI.encode_www_form(@base_params.merge(extra_params))
44
+ uri = URI.parse "http://#{@host}:#{@port}/admin/#{method}?#{params}"
45
+ uri.request_uri
43
46
  end
44
47
 
45
48
  def camelize_params(params)
@@ -52,6 +55,24 @@ module FMS
52
55
 
53
56
  end
54
57
 
58
+ class HTTPClient
59
+
60
+ def initialize(host, port)
61
+ @host = host
62
+ @port = port
63
+ end
64
+
65
+ def get(url, timeout)
66
+ http = Net::HTTP.new @host, @port
67
+ unless timeout.nil?
68
+ http.read_timeout = timeout
69
+ http.open_timeout = timeout
70
+ end
71
+ http.request Net::HTTP::Get.new(url)
72
+ end
73
+
74
+ end
75
+
55
76
  class Response
56
77
 
57
78
  def initialize(content)
@@ -94,7 +94,7 @@ module FMS
94
94
  end
95
95
 
96
96
  def init_param?(param)
97
- [:host, :port, :auser, :apswd].include? param
97
+ [:host, :port, :auser, :apswd, :timeout].include? param
98
98
  end
99
99
 
100
100
  end
@@ -1,3 +1,3 @@
1
1
  module FMS
2
- VERSION = "0.2"
2
+ VERSION = "0.3"
3
3
  end
@@ -55,6 +55,22 @@ class ClientTests < BaseTestCase
55
55
  assert str_resp.include?('<name>cam1</name>')
56
56
  end
57
57
 
58
+ def test_should_use_timeout_param
59
+ c = FMS::Client.new(:host => 'fms.example.com', :timeout => 3)
60
+ c.get_apps
61
+ assert_requested(:get, "http://fms.example.com:1111/admin/getApps?apswd=fms&auser=fms")
62
+ end
63
+
64
+ def test_should_respect_timeout_param
65
+ httpclient_mock = mock()
66
+ response_stub = stub(:code => "200", :body => "")
67
+ FMS::HTTPClient.expects(:new).with('fms.example.com', 1111).returns(httpclient_mock)
68
+ httpclient_mock.expects(:get).with('/admin/getApps?auser=fms&apswd=fms', 123).returns(response_stub)
69
+
70
+ c = FMS::Client.new(:host => 'fms.example.com', :timeout => 123)
71
+ c.get_apps
72
+ end
73
+
58
74
  end
59
75
 
60
76
  # Stub responses
@@ -72,6 +72,11 @@ class CommandLineTests < BaseTestCase
72
72
  assert_command_stdout_contains GET_LIVE_STREAMS.strip
73
73
  end
74
74
 
75
+ def test_should_have_timeout_option
76
+ run_command ['get_apps', '--host=fms.example.com', '--timeout=3']
77
+ assert_requested(:get, "http://fms.example.com:1111/admin/getApps?apswd=fms&auser=fms")
78
+ end
79
+
75
80
 
76
81
  def run_command(argv)
77
82
  FMS::CmdLine.parse(argv)
@@ -1,5 +1,6 @@
1
1
  require 'minitest/autorun'
2
2
  require 'webmock'
3
+ require 'mocha'
3
4
 
4
5
  require 'fms'
5
6
 
metadata CHANGED
@@ -2,7 +2,7 @@
2
2
  name: fms-admin-api
3
3
  version: !ruby/object:Gem::Version
4
4
  prerelease:
5
- version: "0.2"
5
+ version: "0.3"
6
6
  platform: ruby
7
7
  authors:
8
8
  - Igor Sobreira
@@ -10,7 +10,7 @@ autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
12
 
13
- date: 2012-05-17 00:00:00 Z
13
+ date: 2012-08-07 00:00:00 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: activesupport
@@ -56,6 +56,17 @@ dependencies:
56
56
  version: "0"
57
57
  type: :development
58
58
  version_requirements: *id004
59
+ - !ruby/object:Gem::Dependency
60
+ name: mocha
61
+ prerelease: false
62
+ requirement: &id005 !ruby/object:Gem::Requirement
63
+ none: false
64
+ requirements:
65
+ - - ">="
66
+ - !ruby/object:Gem::Version
67
+ version: "0"
68
+ type: :development
69
+ version_requirements: *id005
59
70
  description: Ruby client and command line interface to Flash Media Server Administration API
60
71
  email:
61
72
  - igor@igorsobreira.com
@@ -75,6 +86,7 @@ files:
75
86
  - bin/fmsapi
76
87
  - fms-admin-api.gemspec
77
88
  - gems/fms-admin-api-0.1.gem
89
+ - gems/fms-admin-api-0.2.gem
78
90
  - lib/fms.rb
79
91
  - lib/fms/client.rb
80
92
  - lib/fms/cmdline.rb