collins_client 0.2.10 → 0.2.11
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/VERSION +1 -1
- data/collins_client.gemspec +6 -5
- data/lib/collins/api.rb +2 -0
- data/lib/collins/api/asset_state.rb +22 -4
- data/lib/collins/api/asset_type.rb +98 -0
- data/lib/collins/asset_type.rb +37 -0
- metadata +40 -41
- data/.rbenv-version +0 -1
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 16ab54b81d038f140c59584b761713f4d771c21b
|
4
|
+
data.tar.gz: 0c377aa52c3a063a6e08535372e9acfb14bddc4c
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 2716ad0b825440c3a212850f9951cb5e67eef0950db86ab251cbbb2ad3c61610e050d6dcdd24a9b9e257ec3c12e2cddf44ce8e98738b1a7ca4150228b05f1c30
|
7
|
+
data.tar.gz: 085a10106bd8c24202858a3bdbc0e0ab492313b56d87d54c07956301d8be3676054545a75f18a610dee4e33283ddb243c667956d8b051eae80f64b28fa9dafba
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.2.
|
1
|
+
0.2.11
|
data/collins_client.gemspec
CHANGED
@@ -5,18 +5,17 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = "collins_client"
|
8
|
-
s.version =
|
8
|
+
s.version = File.read 'VERSION'
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
|
-
s.authors = ["Blake Matheny"]
|
12
|
-
s.date = "
|
11
|
+
s.authors = ["Blake Matheny", "Gabe Conradi"]
|
12
|
+
s.date = "2014-08-08"
|
13
13
|
s.description = "Provides ruby support for interacting with the Collins API"
|
14
|
-
s.email = "bmatheny@tumblr.com"
|
14
|
+
s.email = ["bmatheny@tumblr.com","gabe@tumblr.com"]
|
15
15
|
s.extra_rdoc_files = [
|
16
16
|
"README.md"
|
17
17
|
]
|
18
18
|
s.files = [
|
19
|
-
".rbenv-version",
|
20
19
|
"Gemfile",
|
21
20
|
"Gemfile.lock",
|
22
21
|
"README.md",
|
@@ -28,6 +27,7 @@ Gem::Specification.new do |s|
|
|
28
27
|
"lib/collins/api/admin.rb",
|
29
28
|
"lib/collins/api/asset.rb",
|
30
29
|
"lib/collins/api/asset_state.rb",
|
30
|
+
"lib/collins/api/asset_type.rb",
|
31
31
|
"lib/collins/api/attributes.rb",
|
32
32
|
"lib/collins/api/ip_address.rb",
|
33
33
|
"lib/collins/api/logging.rb",
|
@@ -41,6 +41,7 @@ Gem::Specification.new do |s|
|
|
41
41
|
"lib/collins/asset.rb",
|
42
42
|
"lib/collins/asset_client.rb",
|
43
43
|
"lib/collins/asset_find.rb",
|
44
|
+
"lib/collins/asset_type.rb",
|
44
45
|
"lib/collins/asset_update.rb",
|
45
46
|
"lib/collins/client.rb",
|
46
47
|
"lib/collins/errors.rb",
|
data/lib/collins/api.rb
CHANGED
@@ -1,6 +1,7 @@
|
|
1
1
|
require 'collins/api/admin'
|
2
2
|
require 'collins/api/asset'
|
3
3
|
require 'collins/api/asset_state'
|
4
|
+
require 'collins/api/asset_type'
|
4
5
|
require 'collins/api/attributes'
|
5
6
|
require 'collins/api/ip_address'
|
6
7
|
require 'collins/api/logging'
|
@@ -104,6 +105,7 @@ module Collins
|
|
104
105
|
include Collins::Api::Admin
|
105
106
|
include Collins::Api::Asset
|
106
107
|
include Collins::Api::AssetState
|
108
|
+
include Collins::Api::AssetType
|
107
109
|
include Collins::Api::Attributes
|
108
110
|
include Collins::Api::IpAddress
|
109
111
|
include Collins::Api::Logging
|
@@ -12,16 +12,25 @@ module Collins; module Api
|
|
12
12
|
:description => description,
|
13
13
|
:status => status
|
14
14
|
}
|
15
|
+
|
15
16
|
if not ::Collins::Api::AssetState.state_test then
|
16
17
|
parameters = select_non_empty_parameters parameters
|
17
18
|
end
|
19
|
+
|
18
20
|
logger.debug("Creating state with name #{name}")
|
19
21
|
http_put("/api/state/#{name}", parameters) do |r|
|
20
22
|
parse_response r, :expects => 201, :as => :status, :raise => strict?, :default => false
|
21
23
|
end
|
22
24
|
end
|
23
|
-
|
24
|
-
|
25
|
+
|
26
|
+
def state_delete! state
|
27
|
+
name = validate_state_name case state.class
|
28
|
+
when ::Collins::AssetState
|
29
|
+
state.name
|
30
|
+
else
|
31
|
+
state
|
32
|
+
end
|
33
|
+
|
25
34
|
logger.debug("Deleting state with name #{name}")
|
26
35
|
http_delete("/api/state/#{name}") do |r|
|
27
36
|
parse_response r, :expects => 202, :as => :data, :raise => strict?, :default => 0 do |js|
|
@@ -29,8 +38,15 @@ module Collins; module Api
|
|
29
38
|
end
|
30
39
|
end
|
31
40
|
end
|
32
|
-
|
33
|
-
|
41
|
+
|
42
|
+
def state_update! state, options = {}
|
43
|
+
name = validate_state_name case state.class
|
44
|
+
when ::Collins::AssetState
|
45
|
+
state.name
|
46
|
+
else
|
47
|
+
state
|
48
|
+
end
|
49
|
+
|
34
50
|
parameters = {
|
35
51
|
:label => options[:label],
|
36
52
|
:description => options[:description],
|
@@ -45,6 +61,7 @@ module Collins; module Api
|
|
45
61
|
parse_response r, :expects => 200, :as => :status, :raise => strict?, :default => false
|
46
62
|
end
|
47
63
|
end
|
64
|
+
|
48
65
|
def state_get name
|
49
66
|
name = validate_state_name name
|
50
67
|
logger.debug("Fetching state with name #{name}")
|
@@ -55,6 +72,7 @@ module Collins; module Api
|
|
55
72
|
end
|
56
73
|
end
|
57
74
|
end
|
75
|
+
|
58
76
|
def state_get_all
|
59
77
|
http_get("/api/states") do |r|
|
60
78
|
parse_response r, :expects => 200, :as => :data, :default => [], :raise => false do |js|
|
@@ -0,0 +1,98 @@
|
|
1
|
+
require 'collins/asset_type'
|
2
|
+
module Collins; module Api
|
3
|
+
|
4
|
+
module AssetType
|
5
|
+
def asset_type_test; @asset_type_test end
|
6
|
+
def asset_type_test= v; @asset_type_test = v end
|
7
|
+
module_function :asset_type_test, :asset_type_test=
|
8
|
+
|
9
|
+
def asset_type_create! name, label
|
10
|
+
name = validate_name name
|
11
|
+
parameters = { :label => label }
|
12
|
+
|
13
|
+
if not ::Collins::Api::AssetType.asset_type_test then
|
14
|
+
parameters = select_non_empty_parameters parameters
|
15
|
+
end
|
16
|
+
|
17
|
+
logger.debug("Creating asset type with name #{name}")
|
18
|
+
http_put("/api/assettype/#{name}", parameters) do |r|
|
19
|
+
parse_response r, :expects => 201, :as => :status, :raise => strict?, :default => false
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
def asset_type_delete! atype
|
24
|
+
name = validate_name case atype.class
|
25
|
+
when ::Collins::AssetType
|
26
|
+
atype.name
|
27
|
+
else
|
28
|
+
atype
|
29
|
+
end
|
30
|
+
|
31
|
+
logger.debug("Deleting asset type with name #{name}")
|
32
|
+
http_delete("/api/assettype/#{name}") do |r|
|
33
|
+
parse_response r, :expects => 202, :as => :data, :raise => strict?, :default => 0 do |js|
|
34
|
+
js["DELETED"].to_s.to_i
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
def asset_type_update! atype, options = {}
|
40
|
+
name = validate_name case atype.class
|
41
|
+
when ::Collins::AssetType
|
42
|
+
atype.name
|
43
|
+
else
|
44
|
+
atype
|
45
|
+
end
|
46
|
+
|
47
|
+
parameters = {
|
48
|
+
:name => options[:name],
|
49
|
+
:label => options[:label]
|
50
|
+
}
|
51
|
+
if not ::Collins::Api::AssetType.asset_type_test then
|
52
|
+
parameters = select_non_empty_parameters parameters
|
53
|
+
end
|
54
|
+
logger.debug("Updating asset type with name #{name} params #{parameters}")
|
55
|
+
http_post("/api/assettype/#{name}", parameters) do |r|
|
56
|
+
parse_response r, :expects => 200, :as => :status, :raise => strict?, :default => false
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
60
|
+
def asset_type_get name
|
61
|
+
name = validate_name name
|
62
|
+
logger.debug("Fetching asset type with name #{name}")
|
63
|
+
http_get("/api/assettype/#{name}") do |r|
|
64
|
+
empty = ::Collins::AssetType.new({})
|
65
|
+
parse_response r, :expects => 200, :as => :data, :default => empty, :raise => false do |js|
|
66
|
+
::Collins::AssetType.from_json(js)
|
67
|
+
end
|
68
|
+
end
|
69
|
+
end
|
70
|
+
|
71
|
+
def asset_type_get_all
|
72
|
+
http_get("/api/assettypes") do |r|
|
73
|
+
parse_response r, :expects => 200, :as => :data, :default => [], :raise => false do |js|
|
74
|
+
js.map do |atype|
|
75
|
+
::Collins::AssetType.from_json(atype)
|
76
|
+
end
|
77
|
+
end
|
78
|
+
end
|
79
|
+
end
|
80
|
+
|
81
|
+
private
|
82
|
+
def validate_name name
|
83
|
+
if ::Collins::Api::AssetType.asset_type_test then
|
84
|
+
return name
|
85
|
+
end
|
86
|
+
name_opt = ::Collins::Option(name).map {|x| x.to_s.strip}.filter_not {|x| x.empty?}.filter {|x|
|
87
|
+
x.size > 1 && x.size <= 32
|
88
|
+
}
|
89
|
+
if name_opt.empty? then
|
90
|
+
raise ::Collins::ExpectationFailedError.new("name must be between 2 and 32 characters")
|
91
|
+
else
|
92
|
+
name_opt.get
|
93
|
+
end
|
94
|
+
end
|
95
|
+
|
96
|
+
end # end module AssetType
|
97
|
+
|
98
|
+
end; end
|
@@ -0,0 +1,37 @@
|
|
1
|
+
require 'ostruct'
|
2
|
+
|
3
|
+
module Collins
|
4
|
+
class AssetType
|
5
|
+
include Collins::Util
|
6
|
+
|
7
|
+
attr_accessor :id, :label, :name
|
8
|
+
|
9
|
+
def self.from_json json
|
10
|
+
Collins::AssetType.new json
|
11
|
+
end
|
12
|
+
|
13
|
+
def initialize opts = {}
|
14
|
+
hash = symbolize_hash(opts).inject({}) do |result, (k,v)|
|
15
|
+
key = k.to_s.downcase.to_sym
|
16
|
+
result[key] = v
|
17
|
+
result
|
18
|
+
end
|
19
|
+
@id = hash[:id].to_s.to_i
|
20
|
+
@label = hash[:label].to_s
|
21
|
+
@name = hash[:name].to_s
|
22
|
+
end
|
23
|
+
|
24
|
+
def empty?
|
25
|
+
@id == 0
|
26
|
+
end
|
27
|
+
|
28
|
+
def to_s
|
29
|
+
if empty? then
|
30
|
+
"AssetType(None)"
|
31
|
+
else
|
32
|
+
"AssetType(id = #{id}, name = '#{name}', label = '#{label}')"
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
end
|
37
|
+
end
|
metadata
CHANGED
@@ -1,40 +1,38 @@
|
|
1
|
-
--- !ruby/object:Gem::Specification
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
2
|
name: collins_client
|
3
|
-
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
5
|
-
prerelease:
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.2.11
|
6
5
|
platform: ruby
|
7
|
-
authors:
|
6
|
+
authors:
|
8
7
|
- Blake Matheny
|
8
|
+
- Gabe Conradi
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
|
13
|
-
|
14
|
-
|
12
|
+
|
13
|
+
date: 2014-08-08 00:00:00 Z
|
14
|
+
dependencies:
|
15
|
+
- !ruby/object:Gem::Dependency
|
15
16
|
name: httparty
|
16
|
-
requirement: !ruby/object:Gem::Requirement
|
17
|
-
none: false
|
18
|
-
requirements:
|
19
|
-
- - ~>
|
20
|
-
- !ruby/object:Gem::Version
|
21
|
-
version: 0.8.3
|
22
|
-
type: :runtime
|
23
17
|
prerelease: false
|
24
|
-
|
25
|
-
|
26
|
-
requirements:
|
18
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
19
|
+
requirements:
|
27
20
|
- - ~>
|
28
|
-
- !ruby/object:Gem::Version
|
21
|
+
- !ruby/object:Gem::Version
|
29
22
|
version: 0.8.3
|
23
|
+
type: :runtime
|
24
|
+
version_requirements: *id001
|
30
25
|
description: Provides ruby support for interacting with the Collins API
|
31
|
-
email:
|
26
|
+
email:
|
27
|
+
- bmatheny@tumblr.com
|
28
|
+
- gabe@tumblr.com
|
32
29
|
executables: []
|
30
|
+
|
33
31
|
extensions: []
|
34
|
-
|
32
|
+
|
33
|
+
extra_rdoc_files:
|
35
34
|
- README.md
|
36
|
-
files:
|
37
|
-
- .rbenv-version
|
35
|
+
files:
|
38
36
|
- Gemfile
|
39
37
|
- Gemfile.lock
|
40
38
|
- README.md
|
@@ -46,6 +44,7 @@ files:
|
|
46
44
|
- lib/collins/api/admin.rb
|
47
45
|
- lib/collins/api/asset.rb
|
48
46
|
- lib/collins/api/asset_state.rb
|
47
|
+
- lib/collins/api/asset_type.rb
|
49
48
|
- lib/collins/api/attributes.rb
|
50
49
|
- lib/collins/api/ip_address.rb
|
51
50
|
- lib/collins/api/logging.rb
|
@@ -59,6 +58,7 @@ files:
|
|
59
58
|
- lib/collins/asset.rb
|
60
59
|
- lib/collins/asset_client.rb
|
61
60
|
- lib/collins/asset_find.rb
|
61
|
+
- lib/collins/asset_type.rb
|
62
62
|
- lib/collins/asset_update.rb
|
63
63
|
- lib/collins/client.rb
|
64
64
|
- lib/collins/errors.rb
|
@@ -73,31 +73,30 @@ files:
|
|
73
73
|
- lib/collins/util.rb
|
74
74
|
- lib/collins_client.rb
|
75
75
|
homepage: https://github.com/tumblr/collins/tree/master/support/ruby/collins-client
|
76
|
-
licenses:
|
76
|
+
licenses:
|
77
77
|
- APL 2.0
|
78
|
+
metadata: {}
|
79
|
+
|
78
80
|
post_install_message:
|
79
81
|
rdoc_options: []
|
80
|
-
|
82
|
+
|
83
|
+
require_paths:
|
81
84
|
- lib
|
82
|
-
required_ruby_version: !ruby/object:Gem::Requirement
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
- !ruby/object:Gem::Version
|
87
|
-
version:
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
required_rubygems_version: !ruby/object:Gem::Requirement
|
92
|
-
none: false
|
93
|
-
requirements:
|
94
|
-
- - ! '>='
|
95
|
-
- !ruby/object:Gem::Version
|
96
|
-
version: '0'
|
85
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- &id002
|
88
|
+
- ">="
|
89
|
+
- !ruby/object:Gem::Version
|
90
|
+
version: "0"
|
91
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
92
|
+
requirements:
|
93
|
+
- *id002
|
97
94
|
requirements: []
|
95
|
+
|
98
96
|
rubyforge_project:
|
99
|
-
rubygems_version:
|
97
|
+
rubygems_version: 2.4.1
|
100
98
|
signing_key:
|
101
99
|
specification_version: 3
|
102
100
|
summary: Client library for Collins API
|
103
101
|
test_files: []
|
102
|
+
|
data/.rbenv-version
DELETED
@@ -1 +0,0 @@
|
|
1
|
-
1.9.2-p290
|