mms-api 0.1.1 → 0.1.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/mms/cli.rb +1 -2
- data/lib/mms/client.rb +12 -43
- data/lib/mms/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 50ef9789119c25dc3d0061bd092475344eb30d4a
|
4
|
+
data.tar.gz: f85fb48393f03e4485984a27c0d04ca814397214
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ba8ca38b105d5de0948607a673d4f6bb293982013f9b569dee5fc692c79c58d6831cc6b16557b6404c34ead8088aa830c21e096a8e426b18820706ef4d88e165
|
7
|
+
data.tar.gz: 1a8b3bb28a32f6c74a63d76a1cc4c413ed37cf56de64237f9e2207d3ed527cbd6b2ed51a374ef3c62489d5ced642f26be08b33617a3e7d106c7bf6fbc4a8ed32
|
data/lib/mms/cli.rb
CHANGED
@@ -68,12 +68,11 @@ module MMS
|
|
68
68
|
raise MMS::ConfigError.new("Config option `#{key}` from file `#{config_file}` is not allowed!")
|
69
69
|
end
|
70
70
|
end
|
71
|
-
|
72
71
|
end
|
73
72
|
|
74
73
|
# @return [MMS::Agent]
|
75
74
|
def agent
|
76
|
-
@client = MMS::Client.new(@config.username, @config.apikey)
|
75
|
+
@client = MMS::Client.new(@config.username, @config.apikey, @config.apiurl)
|
77
76
|
@agent = MMS::Agent.new(client)
|
78
77
|
end
|
79
78
|
|
data/lib/mms/client.rb
CHANGED
@@ -18,59 +18,26 @@ module MMS
|
|
18
18
|
# @param [String] path
|
19
19
|
# @return [Hash]
|
20
20
|
def get(path)
|
21
|
-
|
21
|
+
_request(Net::HTTP::Get, @url + path, @username, @apikey, nil)
|
22
22
|
end
|
23
23
|
|
24
24
|
# @param [String] path
|
25
25
|
# @param [Hash] data
|
26
26
|
# @return [Hash]
|
27
27
|
def post(path, data)
|
28
|
-
|
28
|
+
_request(Net::HTTP::Post, @url + path, @username, @apikey, data)
|
29
29
|
end
|
30
30
|
|
31
31
|
private
|
32
32
|
|
33
|
+
# @param [Net::HTTPRequest] http_method
|
33
34
|
# @param [String] path
|
34
35
|
# @param [String] username
|
35
36
|
# @param [String] password
|
36
|
-
def _get(path, username, password)
|
37
|
-
|
38
|
-
digest_auth = Net::HTTP::DigestAuth.new
|
39
|
-
digest_auth.next_nonce
|
40
|
-
|
41
|
-
uri = URI.parse path
|
42
|
-
uri.user= CGI.escape(username)
|
43
|
-
uri.password= CGI.escape(password)
|
44
|
-
|
45
|
-
http = Net::HTTP.new(uri.host, uri.port)
|
46
|
-
http.use_ssl = true
|
47
|
-
|
48
|
-
req = Net::HTTP::Get.new uri.request_uri
|
49
|
-
res = http.request req
|
50
|
-
|
51
|
-
auth = digest_auth.auth_header uri, res['WWW-Authenticate'], 'GET'
|
52
|
-
req = Net::HTTP::Get.new uri.request_uri
|
53
|
-
req.add_field 'Authorization', auth
|
54
|
-
|
55
|
-
response = http.request(req)
|
56
|
-
response_json = JSON.parse(response.body)
|
57
|
-
|
58
|
-
unless response.code == 200 or response_json['error'].nil?
|
59
|
-
msg = "http 'get' error for url `#{url}`"
|
60
|
-
msg = response_json['detail'] unless response_json['detail'].nil?
|
61
|
-
|
62
|
-
raise MMS::AuthError.new(msg, req, response) if response.code == '401'
|
63
|
-
raise MMS::ApiError.new(msg, req, response)
|
64
|
-
end
|
65
|
-
|
66
|
-
(response_json.nil? or response_json['results'].nil?) ? response_json : response_json['results']
|
67
|
-
end
|
68
|
-
|
69
|
-
# @param [String] path
|
70
37
|
# @param [Hash] data
|
71
|
-
# @
|
72
|
-
|
73
|
-
|
38
|
+
# @return [Hash]
|
39
|
+
def _request(http_method, path, username, password, data = nil)
|
40
|
+
|
74
41
|
digest_auth = Net::HTTP::DigestAuth.new
|
75
42
|
digest_auth.next_nonce
|
76
43
|
|
@@ -79,13 +46,15 @@ module MMS
|
|
79
46
|
uri.password= CGI.escape(password)
|
80
47
|
|
81
48
|
http = Net::HTTP.new uri.host, uri.port
|
82
|
-
http.use_ssl =
|
49
|
+
http.use_ssl = (uri.scheme == 'https')
|
83
50
|
|
84
|
-
req =
|
51
|
+
req = http_method.new(uri.request_uri, {'Content-Type' => 'application/json'})
|
85
52
|
res = http.request req
|
86
53
|
|
87
|
-
|
88
|
-
req =
|
54
|
+
raise 'Invalid method' unless http_method.kind_of? Class and http_method < Net::HTTPRequest
|
55
|
+
req = http_method.new(uri.request_uri, {'Content-Type' => 'application/json'})
|
56
|
+
method_name = http_method.name.split('::').last.upcase
|
57
|
+
auth = digest_auth.auth_header(uri, res['WWW-Authenticate'], method_name)
|
89
58
|
req.add_field 'Authorization', auth
|
90
59
|
req.body = data.to_json
|
91
60
|
|
data/lib/mms/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: mms-api
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Cargo Media
|
@@ -10,7 +10,7 @@ authors:
|
|
10
10
|
autorequire:
|
11
11
|
bindir: bin
|
12
12
|
cert_chain: []
|
13
|
-
date: 2015-
|
13
|
+
date: 2015-04-17 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: net-http-digest_auth
|