fms-admin-api 0.2 → 0.3
Sign up to get free protection for your applications and to get access to all the features.
- data/Gemfile.lock +7 -3
- data/fms-admin-api.gemspec +1 -0
- data/gems/fms-admin-api-0.2.gem +0 -0
- data/lib/fms/client.rb +25 -4
- data/lib/fms/cmdline.rb +1 -1
- data/lib/fms/version.rb +1 -1
- data/tests/client_tests.rb +16 -0
- data/tests/cmdline_tests.rb +5 -0
- data/tests/tests_helper.rb +1 -0
- metadata +14 -2
data/Gemfile.lock
CHANGED
@@ -1,21 +1,24 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
fms-admin-api (0.
|
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.
|
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
|
-
|
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
|
data/fms-admin-api.gemspec
CHANGED
Binary file
|
data/lib/fms/client.rb
CHANGED
@@ -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
|
-
|
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
|
-
|
41
|
-
|
42
|
-
|
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)
|
data/lib/fms/cmdline.rb
CHANGED
data/lib/fms/version.rb
CHANGED
data/tests/client_tests.rb
CHANGED
@@ -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
|
data/tests/cmdline_tests.rb
CHANGED
@@ -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)
|
data/tests/tests_helper.rb
CHANGED
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.
|
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-
|
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
|