attache-api 1.0.0 → 2.0.1

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: ad7f4dc9aa75177f763af313edbd2e729b12fd28
4
- data.tar.gz: 8af7b0c32da05e86e13ed5964af69b6833615782
3
+ metadata.gz: fa024a85df979d4be9c55f08f9d1c8aef72ea2c7
4
+ data.tar.gz: 4bb7aadcb7d7b85894f37b610ab0e69a7abe7715
5
5
  SHA512:
6
- metadata.gz: ce5a320b2c0c8652691f8f54c3ab8ed5b910a89a162c07056add5d79ab73ae06b7084ff2d6c6770d30506020d5dbc92898eb45701c195c5d654c6231d7034f41
7
- data.tar.gz: 9d63f22d41a181eea617f85dbb843049404c98fb3fe7e64b0a690061a7d154313129994df0fa4eefa47327184a253e198987f0b9b91f683dedd414980bd1e830
6
+ metadata.gz: 11b1c84cc48a7eb82ee3c554e6402e890667e79af1ca06a03468b55a315fc42cb18ff3f24ef20b64cf9492932e6f9b78dd3a10a65fbfbcfeebdf183c8ea06e7b
7
+ data.tar.gz: c65f02cdf1a4d613846a9e21cee0ed21086ea78534cd86482f077cde1a467797928171ed4dc9078984a581bb4ecc4d7d0040ef0ba1895c492a3040bff7fc44aa
@@ -13,6 +13,13 @@ module Attache
13
13
  Utils.array(attr_value).inject([]) do |sum, obj|
14
14
  sum + Utils.array(obj && obj.tap {|attrs|
15
15
  attrs['url'] = V1.attache_url_for(attrs['path'], geometry)
16
+ attrs.delete 'signature'
17
+ attrs.delete 'multiple' # legacy extraneous attribute that affects signature
18
+
19
+ # add signature
20
+ Attache::API::V1.attache_signature_for(attrs) do |generated_signature|
21
+ attrs['signature'] = generated_signature
22
+ end
16
23
  })
17
24
  end
18
25
  end
@@ -22,6 +29,15 @@ module Attache
22
29
  hash = value.respond_to?(:read) && V1.attache_upload(value) || value
23
30
  hash = JSON.parse(hash.to_s) rescue Hash(error: $!) unless hash.kind_of?(Hash)
24
31
  okay = hash.respond_to?(:[]) && (hash['path'] || hash[:path])
32
+
33
+ # check signature
34
+ Attache::API::V1.attache_signature_for(hash) do |generated_signature|
35
+ if generated_signature == hash['signature']
36
+ hash.delete 'signature'
37
+ else
38
+ okay = nil
39
+ end
40
+ end
25
41
  okay ? sum + [hash] : sum
26
42
  }
27
43
  Utils.array(new_value)
@@ -83,6 +83,16 @@ module Attache
83
83
  raise
84
84
  end
85
85
 
86
+ def attache_signature_for(hash)
87
+ if ATTACHE_SECRET_KEY.to_s.strip != ""
88
+ hash_without_signature = hash.reject {|k,v| k == 'signature' || k == 'multiple'}
89
+ content = hash_without_signature.sort.collect {|k,v| "#{k}=#{v}" }.join('&')
90
+ generated_signature = OpenSSL::HMAC.hexdigest(OpenSSL::Digest.new('sha1'), ATTACHE_SECRET_KEY, content)
91
+ yield generated_signature if block_given?
92
+ generated_signature
93
+ end
94
+ end
95
+
86
96
  self.extend(self)
87
97
  end
88
98
  end
@@ -1,5 +1,5 @@
1
1
  module Attache
2
2
  module API
3
- VERSION = "1.0.0"
3
+ VERSION = "2.0.1"
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: attache-api
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0
4
+ version: 2.0.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - choonkeat
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-12-16 00:00:00.000000000 Z
11
+ date: 2016-06-26 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: httpclient
@@ -130,7 +130,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
130
130
  version: '0'
131
131
  requirements: []
132
132
  rubyforge_project:
133
- rubygems_version: 2.4.8
133
+ rubygems_version: 2.5.1
134
134
  signing_key:
135
135
  specification_version: 4
136
136
  summary: API for client lib to integrate with attache server