cassieq-client 1.0.1 → 1.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/cassieq/client.rb +7 -10
- data/lib/cassieq/client/messages.rb +7 -5
- data/lib/cassieq/client/queues.rb +4 -3
- data/lib/cassieq/utils.rb +5 -5
- 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: 8645c19e02a5a4d95fe60999b86245d408219c63
|
4
|
+
data.tar.gz: aec3a9c249a1537577c6c2c54a13b110f1c21cde
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8be3e823cdc241b94981965a288977f2a3010b78c278d3e6189c099c4bf2822fe0e26e7c9be0ba94d4b600f69ad3edaade017d777592d6221abfc9ad40f8ace7
|
7
|
+
data.tar.gz: 3eea39f38ef503b34a164bc2d4d20af97504ef00a111a06f06e949568a419a03bff98c99cf7c16b3f55a94a98a2ba8903e50786dc8af7e8cf583aab4d00f15c2
|
data/lib/cassieq/client.rb
CHANGED
@@ -12,7 +12,6 @@ module Cassieq
|
|
12
12
|
include Cassieq::Client::Queues
|
13
13
|
include Cassieq::Client::Messages
|
14
14
|
include Cassieq::Client::Statistics
|
15
|
-
include Cassieq::Utils
|
16
15
|
|
17
16
|
attr_accessor :host, :account, :port, :key, :provided_params
|
18
17
|
|
@@ -38,22 +37,20 @@ module Cassieq
|
|
38
37
|
end
|
39
38
|
end
|
40
39
|
|
41
|
-
def
|
42
|
-
"/api/v1/accounts/#{account}"
|
43
|
-
|
40
|
+
def request(method, path, body = nil, params = nil)
|
41
|
+
path_prefix = "/api/v1/accounts/#{account}"
|
42
|
+
request_path = "#{path_prefix}/#{path}"
|
44
43
|
|
45
|
-
def request(method, path, body = nil, params = {})
|
46
44
|
handle_response do
|
47
|
-
request_path = "#{path_prefix}/#{path}"
|
48
45
|
connection.run_request(method, request_path, body, nil) do |req|
|
49
|
-
req.params.merge!(params)
|
50
|
-
req.headers.merge!(
|
46
|
+
req.params.merge!(params) unless params.nil?
|
47
|
+
req.headers.merge!(auth_headers(method, request_path)) unless key.nil?
|
51
48
|
req.headers.merge!("Content-Type" => "application/json") unless body.nil?
|
52
49
|
end
|
53
50
|
end
|
54
51
|
end
|
55
52
|
|
56
|
-
def
|
53
|
+
def auth_headers(method, path)
|
57
54
|
Cassieq::Authentication.generate_auth_headers(key, account, method, path)
|
58
55
|
end
|
59
56
|
|
@@ -61,7 +58,7 @@ module Cassieq
|
|
61
58
|
response = request_block.call
|
62
59
|
Cassieq::Error.from_status_and_body(response)
|
63
60
|
unless response.body.empty?
|
64
|
-
underscore_and_symobolize_keys(response.body)
|
61
|
+
Cassieq::Utils.underscore_and_symobolize_keys(response.body)
|
65
62
|
else
|
66
63
|
true
|
67
64
|
end
|
@@ -3,16 +3,18 @@ require "json"
|
|
3
3
|
module Cassieq
|
4
4
|
class Client
|
5
5
|
module Messages
|
6
|
-
def publish_message(queue_name, message)
|
7
|
-
|
6
|
+
def publish_message(queue_name, message, initial_invis_seconds = nil)
|
7
|
+
query = { initialInvisibilitySeconds: initial_invis_seconds } unless initial_invis_seconds.nil?
|
8
|
+
request(:post, "queues/#{queue_name}/messages", message, query)
|
8
9
|
end
|
9
10
|
|
10
|
-
def next_message(queue_name)
|
11
|
-
|
11
|
+
def next_message(queue_name, initial_invis_seconds = nil)
|
12
|
+
query = { initialInvisibilitySeconds: initial_invis_seconds } unless initial_invis_seconds.nil?
|
13
|
+
request(:get, "queues/#{queue_name}/messages/next", nil, query)
|
12
14
|
end
|
13
15
|
|
14
16
|
def edit_message(queue_name, pop_receipt, options)
|
15
|
-
body = camelize_and_stringify_keys(options).to_json
|
17
|
+
body = Cassieq::Utils.camelize_and_stringify_keys(options).to_json
|
16
18
|
params = { popReceipt: pop_receipt }
|
17
19
|
request(:put, "queues/#{queue_name}/messages", body, params)
|
18
20
|
end
|
@@ -7,9 +7,10 @@ module Cassieq
|
|
7
7
|
request(:get, "queues")
|
8
8
|
end
|
9
9
|
|
10
|
-
def create_queue(options)
|
11
|
-
body = camelize_and_stringify_keys(options).to_json
|
12
|
-
|
10
|
+
def create_queue(options, error_if_exists = nil)
|
11
|
+
body = Cassieq::Utils.camelize_and_stringify_keys(options).to_json
|
12
|
+
query = { errorIfExists: error_if_exists } unless error_if_exists.nil?
|
13
|
+
request(:post, "queues", body, query)
|
13
14
|
end
|
14
15
|
|
15
16
|
def queue(queue_name)
|
data/lib/cassieq/utils.rb
CHANGED
@@ -3,17 +3,17 @@ require "active_support/inflector"
|
|
3
3
|
|
4
4
|
module Cassieq
|
5
5
|
module Utils
|
6
|
-
|
7
|
-
|
8
|
-
def underscore_and_symobolize_keys(data)
|
6
|
+
def self.underscore_and_symobolize_keys(data)
|
9
7
|
transform_keys_in_structure(data) { |key| key.underscore.to_sym }
|
10
8
|
end
|
11
9
|
|
12
|
-
def camelize_and_stringify_keys(data)
|
10
|
+
def self.camelize_and_stringify_keys(data)
|
13
11
|
transform_keys_in_structure(data) { |key| key.to_s.camelize(:lower) }
|
14
12
|
end
|
15
13
|
|
16
|
-
|
14
|
+
private
|
15
|
+
|
16
|
+
def self.transform_keys_in_structure(data)
|
17
17
|
case data
|
18
18
|
when Hash
|
19
19
|
data.transform_keys { |key| yield(key) }
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: cassieq-client
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0
|
4
|
+
version: 1.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Tom Conroy
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-04-
|
11
|
+
date: 2016-04-25 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|