teapi 0.0.1 → 0.0.2
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/teapi.rb +11 -0
- data/lib/teapi/sender.rb +10 -7
- data/lib/teapi/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: aef895c695574ed1e75b94afbd9b36566672e610
|
4
|
+
data.tar.gz: 1fbb569bb6636b3dcdff77b01aa4fe029eb4a36b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a5d5b294981dcb6f22d19f42f7a0708d040f108ea5b4ac473a272e468c33e556e53c7799e2fb8d9b5f65a22d865f870288e5632523374f0a9eb63a6f16a777b2
|
7
|
+
data.tar.gz: 3f5d666191be1bfa30459f36aa232da24838554ae1762354359a8ceb0af96fcddcebe36019b9861ec25b4b558d63c1b4a8645667b36aed9e2528f40e74982f59
|
data/lib/teapi.rb
CHANGED
@@ -28,6 +28,7 @@ module Teapi #:nodoc
|
|
28
28
|
# @param resource [Symbol] name of resource
|
29
29
|
# @param body [Hash] to send to the service
|
30
30
|
def post(resource, body)
|
31
|
+
assert_configured()
|
31
32
|
sender.request(:post, resource, {body: body})
|
32
33
|
end
|
33
34
|
|
@@ -35,6 +36,7 @@ module Teapi #:nodoc
|
|
35
36
|
# @param resource [Symbol] name of resource
|
36
37
|
# @param body [Hash] to send to the service
|
37
38
|
def put(resource, body)
|
39
|
+
assert_configured()
|
38
40
|
sender.request(:put, resource, {body: body})
|
39
41
|
end
|
40
42
|
|
@@ -42,7 +44,16 @@ module Teapi #:nodoc
|
|
42
44
|
# @param resource [Symbol] name of resource
|
43
45
|
# @param body [Hash] to send to the service
|
44
46
|
def delete(resource, body)
|
47
|
+
assert_configured()
|
45
48
|
sender.request(:delete, resource, {body: body})
|
46
49
|
end
|
50
|
+
|
51
|
+
private
|
52
|
+
def assert_configured()
|
53
|
+
raise 'teapi invalid configuration' if @configuration.nil?
|
54
|
+
raise 'teapi invalid sync_key' if @configuration.sync_key.nil?
|
55
|
+
raise 'teapi invalid sync_secret' if @configuration.sync_secret.nil?
|
56
|
+
raise 'teapi invalid host' if @configuration.host.nil?
|
57
|
+
end
|
47
58
|
end
|
48
59
|
end
|
data/lib/teapi/sender.rb
CHANGED
@@ -1,6 +1,7 @@
|
|
1
1
|
require 'oj'
|
2
2
|
require 'uri'
|
3
3
|
require 'zlib'
|
4
|
+
require 'time'
|
4
5
|
require 'openssl'
|
5
6
|
require 'httparty'
|
6
7
|
require 'stringio'
|
@@ -14,10 +15,12 @@ module Teapi
|
|
14
15
|
@configuration = configuration
|
15
16
|
end
|
16
17
|
|
17
|
-
def request(method, resource, args = {},
|
18
|
-
url =
|
18
|
+
def request(method, resource, args = {}, date = nil)
|
19
|
+
url = BASE_URL + resource.to_s
|
20
|
+
d = date || Time.now.httpdate
|
19
21
|
args[:headers] = (args[:headers] || {}).merge({
|
20
|
-
'
|
22
|
+
'Date' => d,
|
23
|
+
'Authorization' => sign(url, d, args),
|
21
24
|
})
|
22
25
|
if args[:body] != nil && args[:body].length > 1024 then
|
23
26
|
args[:body] = gzip(args[:body])
|
@@ -25,14 +28,14 @@ module Teapi
|
|
25
28
|
end
|
26
29
|
scheme = @configuration.secure ? "https" : "http"
|
27
30
|
res = HTTParty.send(method, "#{scheme}://#{@configuration.host}#{url}", args)
|
28
|
-
if res.code == 401 && res.parsed_response.include?('
|
29
|
-
return request(method, resource, args, res.parsed_response['
|
31
|
+
if res.code == 401 && res.parsed_response.include?('date') && date.nil?
|
32
|
+
return request(method, resource, args, res.parsed_response['date'])
|
30
33
|
end
|
31
34
|
res
|
32
35
|
end
|
33
36
|
|
34
|
-
def sign(url, args)
|
35
|
-
data = url
|
37
|
+
def sign(url, date, args)
|
38
|
+
data = url + date
|
36
39
|
data += args[:body] if args.include?(:body)
|
37
40
|
signature = OpenSSL::HMAC.hexdigest(OpenSSL::Digest.new('sha256'), @configuration.sync_secret, data)
|
38
41
|
"HMAC-SHA256 Credential=#{@configuration.sync_key},Signature=#{signature}"
|
data/lib/teapi/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: teapi
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Karl Seguin
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-12-
|
11
|
+
date: 2014-12-17 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: httparty
|