aliyun-mqs 0.0.3 → 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +2 -0
- data/.travis.yml +8 -0
- data/Gemfile +2 -1
- data/README.md +160 -66
- data/Rakefile +6 -1
- data/aliyun-mqs.gemspec +7 -3
- data/bin/mqs +4 -0
- data/lib/aliyun/mqs.rb +39 -15
- data/lib/aliyun/mqs/cli.rb +54 -0
- data/lib/aliyun/mqs/message.rb +56 -0
- data/lib/aliyun/mqs/queue.rb +50 -60
- data/lib/aliyun/mqs/request.rb +88 -0
- data/lib/aliyun/mqs/version.rb +1 -1
- data/spec/lib/aliyun/mqs/message_spec.rb +63 -0
- data/spec/lib/aliyun/mqs/queue_spec.rb +179 -0
- data/spec/lib/aliyun/mqs/request_spec.rb +83 -0
- data/spec/spec_helper.rb +17 -0
- metadata +81 -11
- data/lib/aliyun/mqs/configuration.rb +0 -8
- data/lib/aliyun/mqs/http.rb +0 -58
- data/lib/aliyun/mqs/response.rb +0 -46
@@ -0,0 +1,83 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Aliyun::Mqs::Request do
|
4
|
+
|
5
|
+
describe "Reqest methods" do
|
6
|
+
specify "get" do
|
7
|
+
expect(RestClient).to receive(:get) do |*args|
|
8
|
+
path, headers = *args
|
9
|
+
expect(path).to eq("http://owner-id.mqs-region.aliyuncs.com/path")
|
10
|
+
expect(headers).to be_a(Hash)
|
11
|
+
end
|
12
|
+
|
13
|
+
Aliyun::Mqs::Request.get("/path")
|
14
|
+
end
|
15
|
+
|
16
|
+
specify "get with params" do
|
17
|
+
expect(RestClient).to receive(:get) do |*args|
|
18
|
+
path, headers = *args
|
19
|
+
expect(path).to eq("http://owner-id.mqs-region.aliyuncs.com/path?a=1")
|
20
|
+
expect(headers).to be_a(Hash)
|
21
|
+
end
|
22
|
+
|
23
|
+
Aliyun::Mqs::Request.get("/path", params:{a:1})
|
24
|
+
end
|
25
|
+
|
26
|
+
specify "get with mqs_headers" do
|
27
|
+
expect(RestClient).to receive(:get) do |*args|
|
28
|
+
path, headers = *args
|
29
|
+
expect(path).to eq("http://owner-id.mqs-region.aliyuncs.com/path")
|
30
|
+
expect(headers.slice("x-mqs-1")).to eq("x-mqs-1"=>"1")
|
31
|
+
end
|
32
|
+
|
33
|
+
Aliyun::Mqs::Request.get("/path", mqs_headers:{"x-mqs-1"=>"1"})
|
34
|
+
end
|
35
|
+
|
36
|
+
specify "delete" do
|
37
|
+
expect(RestClient).to receive(:delete) do |*args|
|
38
|
+
path, headers = *args
|
39
|
+
expect(path).to eq("http://owner-id.mqs-region.aliyuncs.com/path")
|
40
|
+
expect(headers).to be_a(Hash)
|
41
|
+
end
|
42
|
+
|
43
|
+
Aliyun::Mqs::Request.delete("/path")
|
44
|
+
end
|
45
|
+
|
46
|
+
specify "post with content" do
|
47
|
+
expect(RestClient).to receive(:post) do |*args|
|
48
|
+
path, body, headers = *args
|
49
|
+
expect(path).to eq("http://owner-id.mqs-region.aliyuncs.com/path")
|
50
|
+
expect(body).not_to be_empty
|
51
|
+
expect(headers).to be_a(Hash)
|
52
|
+
end
|
53
|
+
|
54
|
+
Aliyun::Mqs::Request.post("/path"){|request| request.content "content"}
|
55
|
+
end
|
56
|
+
|
57
|
+
specify "put with content" do
|
58
|
+
expect(RestClient).to receive(:put) do |*args|
|
59
|
+
path, body, headers = *args
|
60
|
+
expect(path).to eq("http://owner-id.mqs-region.aliyuncs.com/path")
|
61
|
+
expect(body).not_to be_empty
|
62
|
+
expect(headers).to be_a(Hash)
|
63
|
+
end
|
64
|
+
|
65
|
+
Aliyun::Mqs::Request.put("/path"){|request| request.content "content"}
|
66
|
+
end
|
67
|
+
end
|
68
|
+
|
69
|
+
specify "has default x-mqs-version header" do
|
70
|
+
expect(subject.mqs_headers).to eq("x-mqs-version" => "2014-07-08")
|
71
|
+
end
|
72
|
+
|
73
|
+
specify "has default content namespace when content is set" do
|
74
|
+
subject.content("content", attr1: 1, attr2: 2)
|
75
|
+
xml = Hash.from_xml(subject.body)
|
76
|
+
|
77
|
+
expect(subject.content_type).to eq("text/xml;charset=utf-8")
|
78
|
+
expect(xml["content"]["xmlns"]).to eq("http://mqs.aliyuncs.com/doc/v1/")
|
79
|
+
expect(subject.content_length).not_to be_nil
|
80
|
+
expect(subject.content_md5).not_to be_nil
|
81
|
+
end
|
82
|
+
|
83
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,17 @@
|
|
1
|
+
require 'rspec'
|
2
|
+
require "codeclimate-test-reporter"
|
3
|
+
CodeClimate::TestReporter.start
|
4
|
+
require 'aliyun/mqs'
|
5
|
+
|
6
|
+
Dir[File.join(File.dirname(__FILE__), "../spec/support/**/*.rb")].sort.each {|f| require f}
|
7
|
+
RSpec.configure do |config|
|
8
|
+
config.color = true
|
9
|
+
config.mock_with :rspec
|
10
|
+
end
|
11
|
+
|
12
|
+
Aliyun::Mqs.configure do |config|
|
13
|
+
config.access_id = 'access-id'
|
14
|
+
config.key = "key"
|
15
|
+
config.region = 'region'
|
16
|
+
config.owner_id = 'owner-id'
|
17
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,15 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: aliyun-mqs
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.1.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- mgampkay
|
8
|
+
- skinnyworm
|
8
9
|
autorequire:
|
9
10
|
bindir: bin
|
10
11
|
cert_chain: []
|
11
|
-
date: 2014-
|
12
|
+
date: 2014-12-14 00:00:00.000000000 Z
|
12
13
|
dependencies:
|
13
14
|
- !ruby/object:Gem::Dependency
|
14
15
|
name: nokogiri
|
@@ -38,20 +39,48 @@ dependencies:
|
|
38
39
|
- - ">="
|
39
40
|
- !ruby/object:Gem::Version
|
40
41
|
version: '4.1'
|
42
|
+
- !ruby/object:Gem::Dependency
|
43
|
+
name: rest-client
|
44
|
+
requirement: !ruby/object:Gem::Requirement
|
45
|
+
requirements:
|
46
|
+
- - ">="
|
47
|
+
- !ruby/object:Gem::Version
|
48
|
+
version: '0'
|
49
|
+
type: :runtime
|
50
|
+
prerelease: false
|
51
|
+
version_requirements: !ruby/object:Gem::Requirement
|
52
|
+
requirements:
|
53
|
+
- - ">="
|
54
|
+
- !ruby/object:Gem::Version
|
55
|
+
version: '0'
|
56
|
+
- !ruby/object:Gem::Dependency
|
57
|
+
name: thor
|
58
|
+
requirement: !ruby/object:Gem::Requirement
|
59
|
+
requirements:
|
60
|
+
- - ">="
|
61
|
+
- !ruby/object:Gem::Version
|
62
|
+
version: '0'
|
63
|
+
type: :runtime
|
64
|
+
prerelease: false
|
65
|
+
version_requirements: !ruby/object:Gem::Requirement
|
66
|
+
requirements:
|
67
|
+
- - ">="
|
68
|
+
- !ruby/object:Gem::Version
|
69
|
+
version: '0'
|
41
70
|
- !ruby/object:Gem::Dependency
|
42
71
|
name: bundler
|
43
72
|
requirement: !ruby/object:Gem::Requirement
|
44
73
|
requirements:
|
45
|
-
- - "
|
74
|
+
- - ">="
|
46
75
|
- !ruby/object:Gem::Version
|
47
|
-
version: '
|
76
|
+
version: '0'
|
48
77
|
type: :development
|
49
78
|
prerelease: false
|
50
79
|
version_requirements: !ruby/object:Gem::Requirement
|
51
80
|
requirements:
|
52
|
-
- - "
|
81
|
+
- - ">="
|
53
82
|
- !ruby/object:Gem::Version
|
54
|
-
version: '
|
83
|
+
version: '0'
|
55
84
|
- !ruby/object:Gem::Dependency
|
56
85
|
name: rake
|
57
86
|
requirement: !ruby/object:Gem::Requirement
|
@@ -66,25 +95,61 @@ dependencies:
|
|
66
95
|
- - "~>"
|
67
96
|
- !ruby/object:Gem::Version
|
68
97
|
version: '10.0'
|
98
|
+
- !ruby/object:Gem::Dependency
|
99
|
+
name: rspec
|
100
|
+
requirement: !ruby/object:Gem::Requirement
|
101
|
+
requirements:
|
102
|
+
- - ">="
|
103
|
+
- !ruby/object:Gem::Version
|
104
|
+
version: '0'
|
105
|
+
type: :development
|
106
|
+
prerelease: false
|
107
|
+
version_requirements: !ruby/object:Gem::Requirement
|
108
|
+
requirements:
|
109
|
+
- - ">="
|
110
|
+
- !ruby/object:Gem::Version
|
111
|
+
version: '0'
|
112
|
+
- !ruby/object:Gem::Dependency
|
113
|
+
name: pry
|
114
|
+
requirement: !ruby/object:Gem::Requirement
|
115
|
+
requirements:
|
116
|
+
- - ">="
|
117
|
+
- !ruby/object:Gem::Version
|
118
|
+
version: '0'
|
119
|
+
type: :development
|
120
|
+
prerelease: false
|
121
|
+
version_requirements: !ruby/object:Gem::Requirement
|
122
|
+
requirements:
|
123
|
+
- - ">="
|
124
|
+
- !ruby/object:Gem::Version
|
125
|
+
version: '0'
|
69
126
|
description: Non-official SDK for Aliyun MQS
|
70
127
|
email:
|
71
128
|
- mgampkay@gmail.com
|
72
|
-
|
129
|
+
- askinnyworm@gmail.com
|
130
|
+
executables:
|
131
|
+
- mqs
|
73
132
|
extensions: []
|
74
133
|
extra_rdoc_files: []
|
75
134
|
files:
|
76
135
|
- ".gitignore"
|
136
|
+
- ".travis.yml"
|
77
137
|
- Gemfile
|
78
138
|
- LICENSE.txt
|
79
139
|
- README.md
|
80
140
|
- Rakefile
|
81
141
|
- aliyun-mqs.gemspec
|
142
|
+
- bin/mqs
|
82
143
|
- lib/aliyun/mqs.rb
|
83
|
-
- lib/aliyun/mqs/
|
84
|
-
- lib/aliyun/mqs/
|
144
|
+
- lib/aliyun/mqs/cli.rb
|
145
|
+
- lib/aliyun/mqs/message.rb
|
85
146
|
- lib/aliyun/mqs/queue.rb
|
86
|
-
- lib/aliyun/mqs/
|
147
|
+
- lib/aliyun/mqs/request.rb
|
87
148
|
- lib/aliyun/mqs/version.rb
|
149
|
+
- spec/lib/aliyun/mqs/message_spec.rb
|
150
|
+
- spec/lib/aliyun/mqs/queue_spec.rb
|
151
|
+
- spec/lib/aliyun/mqs/request_spec.rb
|
152
|
+
- spec/spec_helper.rb
|
88
153
|
homepage: https://github.com/mgampkay/aliyun-mqs
|
89
154
|
licenses:
|
90
155
|
- MIT
|
@@ -109,4 +174,9 @@ rubygems_version: 2.2.2
|
|
109
174
|
signing_key:
|
110
175
|
specification_version: 4
|
111
176
|
summary: Ruby SDK for Aliyun MQS (non-official)
|
112
|
-
test_files:
|
177
|
+
test_files:
|
178
|
+
- spec/lib/aliyun/mqs/message_spec.rb
|
179
|
+
- spec/lib/aliyun/mqs/queue_spec.rb
|
180
|
+
- spec/lib/aliyun/mqs/request_spec.rb
|
181
|
+
- spec/spec_helper.rb
|
182
|
+
has_rdoc:
|
data/lib/aliyun/mqs/http.rb
DELETED
@@ -1,58 +0,0 @@
|
|
1
|
-
require 'base64'
|
2
|
-
require 'date'
|
3
|
-
require 'digest'
|
4
|
-
require 'net/http'
|
5
|
-
require 'uri'
|
6
|
-
|
7
|
-
module Aliyun
|
8
|
-
module Mqs
|
9
|
-
module Http
|
10
|
-
Version = '2014-07-08'
|
11
|
-
ContentType = 'text/xml;utf-8'
|
12
|
-
|
13
|
-
def send_request(verb, request_uri, body = '')
|
14
|
-
uri = URI.parse(request_uri)
|
15
|
-
content_md5 = Base64::encode64(Digest::MD5.hexdigest body).chop
|
16
|
-
gmt_date = DateTime.now.httpdate
|
17
|
-
mqs_headers = {'x-mqs-version' => Version}
|
18
|
-
headers = {'Host' => uri.host,
|
19
|
-
'Date' => gmt_date,
|
20
|
-
'Content-Type' => ContentType,
|
21
|
-
'Content-MD5' => content_md5
|
22
|
-
}
|
23
|
-
headers.merge! mqs_headers
|
24
|
-
resource = uri.path + (uri.query != nil ? '?' + uri.query : '')
|
25
|
-
headers['Authorization'] = sign_header(verb, content_md5, gmt_date, mqs_headers, resource)
|
26
|
-
|
27
|
-
http = Net::HTTP.new(uri.host, uri.port)
|
28
|
-
|
29
|
-
case verb.downcase
|
30
|
-
when 'get'
|
31
|
-
request = Net::HTTP::Get.new(uri.request_uri)
|
32
|
-
when 'post'
|
33
|
-
request = Net::HTTP::Post.new(uri.request_uri)
|
34
|
-
request.body = body
|
35
|
-
when 'delete'
|
36
|
-
request = Net::HTTP::Delete.new(uri.request_uri)
|
37
|
-
when 'put'
|
38
|
-
request = Net::HTTP::Put.new(uri.request_uri)
|
39
|
-
request.body = body
|
40
|
-
end
|
41
|
-
request.initialize_http_header(headers)
|
42
|
-
response = http.request(request)
|
43
|
-
Response.new(self, response)
|
44
|
-
end
|
45
|
-
|
46
|
-
def sign_header(verb, content_md5, gmt_date, mqs_headers = {}, resources = '/')
|
47
|
-
header = ''
|
48
|
-
mqs_headers.sort.each do |k,v|
|
49
|
-
header << k.downcase + ':'+ v + "\n"
|
50
|
-
end
|
51
|
-
sign = sprintf "%s\n%s\n%s\n%s\n%s%s", verb, content_md5, ContentType, gmt_date, header, resources
|
52
|
-
sign = Base64::encode64(Digest::HMAC.digest(sign, Mqs.configuration.access_key_secret, Digest::SHA1)).chop
|
53
|
-
"MQS #{Mqs.configuration.access_key_id}:#{sign}"
|
54
|
-
end
|
55
|
-
|
56
|
-
end
|
57
|
-
end
|
58
|
-
end
|
data/lib/aliyun/mqs/response.rb
DELETED
@@ -1,46 +0,0 @@
|
|
1
|
-
require 'nokogiri'
|
2
|
-
require 'active_support/core_ext/string/inflections'
|
3
|
-
|
4
|
-
module Aliyun
|
5
|
-
module Mqs
|
6
|
-
|
7
|
-
class Response
|
8
|
-
|
9
|
-
def initialize(queue, response)
|
10
|
-
@queue = queue
|
11
|
-
@success = (response.code =~ /^20./) == 0
|
12
|
-
if response.body
|
13
|
-
begin
|
14
|
-
xml_to_attribute(response.body)
|
15
|
-
end
|
16
|
-
end
|
17
|
-
end
|
18
|
-
|
19
|
-
def success?
|
20
|
-
@success
|
21
|
-
end
|
22
|
-
|
23
|
-
def delete
|
24
|
-
@queue.delete self
|
25
|
-
end
|
26
|
-
|
27
|
-
private
|
28
|
-
|
29
|
-
def xml_to_attribute(xml)
|
30
|
-
Nokogiri::XML(xml).root.children.each do |child|
|
31
|
-
if child.element?
|
32
|
-
name = child.name.underscore
|
33
|
-
value = child.content.to_s
|
34
|
-
value = Time.at(value.to_f / 1000) if name.end_with?('_time')
|
35
|
-
define_singleton_method name do
|
36
|
-
instance_variable_get ('@' + name)
|
37
|
-
end
|
38
|
-
self.instance_variable_set('@' + name, value)
|
39
|
-
end
|
40
|
-
end
|
41
|
-
end
|
42
|
-
|
43
|
-
end
|
44
|
-
|
45
|
-
end
|
46
|
-
end
|