collins_client 0.2.11 → 0.2.15
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile +1 -1
- data/Gemfile.lock +1 -1
- data/VERSION +1 -1
- data/collins_client.gemspec +3 -3
- data/lib/collins/api/asset.rb +34 -0
- data/lib/collins/api/logging.rb +18 -3
- metadata +6 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 42f443869d38df5e776cc352fbd070a6c987b182
|
4
|
+
data.tar.gz: 2706390265c708a02a1d7f911fc8d370000fa842
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1c4a51bc5f16121738a5d89d69d8a5f77cc9a23563eb0159b87f82bf3d03ecd668a26417abde9ecc611979cc35b7faf9797bcb9a2e868fde95743e145bee1204
|
7
|
+
data.tar.gz: a236080e09f67961e04d842e73af11a8d20495ef5d2eb9707439cd42f0dd9f62e5937e1d48e4988e98f2506890599c7493d1ccdb99475ec1c16697e43ed7e48e
|
data/Gemfile
CHANGED
data/Gemfile.lock
CHANGED
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.2.
|
1
|
+
0.2.15
|
data/collins_client.gemspec
CHANGED
@@ -8,10 +8,10 @@ Gem::Specification.new do |s|
|
|
8
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", "Gabe Conradi"]
|
12
|
-
s.date = "
|
11
|
+
s.authors = ["Blake Matheny", "Gabe Conradi", "Will Richard"]
|
12
|
+
s.date = "2015-03-17"
|
13
13
|
s.description = "Provides ruby support for interacting with the Collins API"
|
14
|
-
s.email = ["
|
14
|
+
s.email = ["accounts@tumblr.com","gabe@tumblr.com","will@tumblr.com"]
|
15
15
|
s.extra_rdoc_files = [
|
16
16
|
"README.md"
|
17
17
|
]
|
data/lib/collins/api/asset.rb
CHANGED
@@ -123,6 +123,40 @@ module Collins; module Api
|
|
123
123
|
end
|
124
124
|
end
|
125
125
|
|
126
|
+
# Count number of assets matching the specified criteria
|
127
|
+
#
|
128
|
+
# @param [Hash] options Query options (same as in the "find" method)
|
129
|
+
# @return integer The number of assets matching the query
|
130
|
+
# @raise [UnexpectedResponseError] If the HTTP response code is not a 200
|
131
|
+
def count options = {}
|
132
|
+
# create a copy so that we do not modify the original options array
|
133
|
+
options = options.dup
|
134
|
+
|
135
|
+
if options.include? :size or options.include? :page
|
136
|
+
raise ExpectationFailedError.new "Do not specify 'size' or 'page' options when counting assets"
|
137
|
+
else
|
138
|
+
options[:size] = 1
|
139
|
+
options[:page] = 0
|
140
|
+
end
|
141
|
+
|
142
|
+
query = asset_hash_to_find_query options
|
143
|
+
params = query.to_a.map do |param|
|
144
|
+
key, val = param
|
145
|
+
if val.is_a?(Array)
|
146
|
+
val.map{|v| "#{key}=#{asset_escape_attribute(v)}"}.join("&")
|
147
|
+
else
|
148
|
+
"#{key}=#{asset_escape_attribute(val)}"
|
149
|
+
end
|
150
|
+
end.reject{|s| s.empty?}
|
151
|
+
|
152
|
+
logger.debug("Counting assets using params #{params.inspect}")
|
153
|
+
http_get("/api/assets", params) do |response|
|
154
|
+
parse_response response, :expects => 200, :as => :data do |json|
|
155
|
+
json["Pagination"]["TotalResults"].to_i
|
156
|
+
end
|
157
|
+
end
|
158
|
+
end
|
159
|
+
|
126
160
|
private
|
127
161
|
def asset_escape_attribute value
|
128
162
|
URI.escape(value.to_s, Regexp.new("[^#{URI::PATTERN::UNRESERVED}]"))
|
data/lib/collins/api/logging.rb
CHANGED
@@ -58,7 +58,7 @@ module Collins; module Api
|
|
58
58
|
# @param [String,Collins::Asset] asset_or_tag
|
59
59
|
# @param [String] message
|
60
60
|
# @param [Severity] level severity level to use
|
61
|
-
# @return [
|
61
|
+
# @return [OpenStruct] The log struct created
|
62
62
|
# @raise [Collins::ExpectationFailed] the specified level was invalid
|
63
63
|
# @raise [Collins::RequestError,Collins::UnexpectedResponseError] if the asset or message invalid
|
64
64
|
def log! asset_or_tag, message, level = nil
|
@@ -70,7 +70,9 @@ module Collins; module Api
|
|
70
70
|
parameters = select_non_empty_parameters parameters
|
71
71
|
logger.debug("Logging to #{asset.tag} with parameters #{parameters.inspect}")
|
72
72
|
http_put("/api/asset/#{asset.tag}/log", parameters, asset.location) do |response|
|
73
|
-
parse_response response, :as => :
|
73
|
+
parse_response response, :as => :paginated, :expects => 201 do |json|
|
74
|
+
OpenStruct.new(symbolize_hash(json))
|
75
|
+
end
|
74
76
|
end
|
75
77
|
end
|
76
78
|
|
@@ -84,7 +86,7 @@ module Collins; module Api
|
|
84
86
|
# @option options [Fixnum] :size (25) Number of results to retrieve
|
85
87
|
# @option options [String] :sort (DESC) Sort ordering for results
|
86
88
|
# @option options [String] :filter Semicolon separated list of severity levels to include or exclude
|
87
|
-
# @option options [String] :all_tag If specified,
|
89
|
+
# @option options [String] :all_tag If specified, and asset tag is set to :all_tag, proxy to the all_logs method
|
88
90
|
# @note To exclude a level via a filter it must be prepended with a `!`
|
89
91
|
# @return [Array<OpenStruct>] Array of log objects
|
90
92
|
# @raise [Collins::UnexpectedResponseError] on a non-200 response
|
@@ -136,6 +138,19 @@ module Collins; module Api
|
|
136
138
|
end
|
137
139
|
end
|
138
140
|
|
141
|
+
# Get a log, given its id
|
142
|
+
# @param [Int] id The log id to retrieve
|
143
|
+
# @return [OpenStruct] The log openstruct
|
144
|
+
# @raise [Collins::UnexpectedResponseError] on a non-200 response
|
145
|
+
def get_log id
|
146
|
+
logger.debug("Fetching log #{id}")
|
147
|
+
http_get("/api/log/#{id}") do |response|
|
148
|
+
parse_response response, :as => :paginated, :default => nil, :raise => strict?, :expects => 200 do |json|
|
149
|
+
OpenStruct.new(symbolize_hash(json))
|
150
|
+
end
|
151
|
+
end
|
152
|
+
end
|
153
|
+
|
139
154
|
private
|
140
155
|
def log_level_from_string level
|
141
156
|
return nil if (level.nil? || level.empty?)
|
metadata
CHANGED
@@ -1,16 +1,17 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: collins_client
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.15
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Blake Matheny
|
8
8
|
- Gabe Conradi
|
9
|
+
- Will Richard
|
9
10
|
autorequire:
|
10
11
|
bindir: bin
|
11
12
|
cert_chain: []
|
12
13
|
|
13
|
-
date:
|
14
|
+
date: 2015-03-17 00:00:00 Z
|
14
15
|
dependencies:
|
15
16
|
- !ruby/object:Gem::Dependency
|
16
17
|
name: httparty
|
@@ -24,8 +25,9 @@ dependencies:
|
|
24
25
|
version_requirements: *id001
|
25
26
|
description: Provides ruby support for interacting with the Collins API
|
26
27
|
email:
|
27
|
-
-
|
28
|
+
- accounts@tumblr.com
|
28
29
|
- gabe@tumblr.com
|
30
|
+
- will@tumblr.com
|
29
31
|
executables: []
|
30
32
|
|
31
33
|
extensions: []
|
@@ -94,7 +96,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
94
96
|
requirements: []
|
95
97
|
|
96
98
|
rubyforge_project:
|
97
|
-
rubygems_version: 2.
|
99
|
+
rubygems_version: 2.3.0
|
98
100
|
signing_key:
|
99
101
|
specification_version: 3
|
100
102
|
summary: Client library for Collins API
|