bluekai 0.0.4 → 0.0.5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +3 -3
- data/lib/bluekai/request.rb +19 -16
- data/lib/bluekai/version.rb +1 -1
- data/spec/lib/bluekai/request_spec.rb +15 -4
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 774cef3b18775e0f088571f7d474faf5646202ba
|
4
|
+
data.tar.gz: f9e04b63d36e4e3c9b7d9742fad2d12a2d1060f3
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6345648e62bcd0ecba25bca44b82a09167ff2ab5a90173251f153021189e7d80dd957220cab30fff2c36ed3b9a0a24f772e3385c3b6e76f009e89d7bc03b4734
|
7
|
+
data.tar.gz: 90670e389cb1e762c5734c65b1bd8ae69265d88266c5dd7655a656f452aa2fd4f7a12c117b8258cc0928dc5eb24c4d3f0595429d41af0b7692d6a23b7924b74e
|
data/README.md
CHANGED
@@ -1,8 +1,8 @@
|
|
1
1
|
# Bluekai
|
2
2
|
[![Gem Version](http://img.shields.io/gem/v/bluekai.svg)](http://rubygems.org/gems/bluekai)
|
3
|
-
[![Circle CI](https://circleci.com/gh/ad2games/bluekai.
|
4
|
-
[![Code Climate](https://codeclimate.com/
|
5
|
-
[![Test Coverage](https://codeclimate.com/
|
3
|
+
[![Circle CI](https://circleci.com/gh/ad2games/bluekai.svg?style=svg)](https://circleci.com/gh/ad2games/bluekai)
|
4
|
+
[![Code Climate](https://codeclimate.com/github/ad2games/bluekai/badges/gpa.svg)](https://codeclimate.com/github/ad2games/bluekai)
|
5
|
+
[![Test Coverage](https://codeclimate.com/github/ad2games/bluekai/badges/coverage.svg)](https://codeclimate.com/github/ad2games/bluekai/coverage)
|
6
6
|
|
7
7
|
|
8
8
|
## Installation
|
data/lib/bluekai/request.rb
CHANGED
@@ -20,6 +20,13 @@ module Bluekai
|
|
20
20
|
JSON.parse(response.body, symbolize_names: true)
|
21
21
|
end
|
22
22
|
|
23
|
+
# HMAC-SHA256(Secret key, HTTP_METHOD + URI_PATH + QUERY_ARG_VALUES + POST_DATA)
|
24
|
+
def signature
|
25
|
+
digest = OpenSSL::Digest.new('sha256')
|
26
|
+
hmac = OpenSSL::HMAC.digest(digest, api_private_key, string_to_sign)
|
27
|
+
CGI.escape(Base64.strict_encode64(hmac))
|
28
|
+
end
|
29
|
+
|
23
30
|
private
|
24
31
|
|
25
32
|
attr_reader :method, :path, :query, :body, :domain
|
@@ -42,13 +49,8 @@ module Bluekai
|
|
42
49
|
end
|
43
50
|
|
44
51
|
def url
|
45
|
-
"#{domain}#{path}?#{
|
46
|
-
"bkuid=#{api_user_key}&bksig=#{signature}"
|
47
|
-
end
|
48
|
-
|
49
|
-
def query_values
|
50
|
-
return nil unless query
|
51
|
-
query.values.join
|
52
|
+
"#{domain}#{path}?#{query_string}"\
|
53
|
+
"&bkuid=#{api_user_key}&bksig=#{signature}"
|
52
54
|
end
|
53
55
|
|
54
56
|
def body_sorted
|
@@ -63,20 +65,21 @@ module Bluekai
|
|
63
65
|
}
|
64
66
|
end
|
65
67
|
|
66
|
-
def
|
68
|
+
def query_values
|
67
69
|
return nil unless query
|
68
|
-
|
70
|
+
query_string.split('&').map { |p| p.split('=', 2)[1] }.join
|
69
71
|
end
|
70
72
|
|
71
|
-
def
|
72
|
-
|
73
|
+
def query_string(params = nil, prefix = '')
|
74
|
+
# converts a (nested) hash of query parameters into a query string.
|
75
|
+
(params || query || {})
|
76
|
+
.map { |k, v| v.is_a?(Hash) ? query_string(v, "#{k}=") : "#{prefix}#{k}=#{v}" }
|
77
|
+
.join('&')
|
73
78
|
end
|
74
79
|
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
hmac = OpenSSL::HMAC.digest(digest, api_private_key, string_to_sign)
|
79
|
-
CGI.escape(Base64.strict_encode64(hmac))
|
80
|
+
def string_to_sign
|
81
|
+
# see the example here: https://kb.bluekai.com/display/PD/Programming+Example
|
82
|
+
method + path + query_values.to_s + body_sorted.to_s
|
80
83
|
end
|
81
84
|
end
|
82
85
|
end
|
data/lib/bluekai/version.rb
CHANGED
@@ -1,14 +1,25 @@
|
|
1
1
|
RSpec.describe Bluekai::Request do
|
2
|
-
describe '#
|
2
|
+
describe '#signature' do
|
3
3
|
it 'computes a correct signature' do
|
4
|
-
|
4
|
+
subject = described_class.new(
|
5
5
|
'GET',
|
6
6
|
'/Services/WS/classificationCategories/',
|
7
7
|
{ ho: 'blabli' },
|
8
8
|
{ key1: 'value1', key2: 'value2' },
|
9
9
|
'https://services.bluekai.com')
|
10
|
-
|
11
|
-
expect(
|
10
|
+
subject.api_private_key = '1234'
|
11
|
+
expect(subject.signature).to eq('t%2BE36Yup7ORbC3WRux5xY7ohUxqFo5AGsKrGjJYDCKs%3D')
|
12
|
+
end
|
13
|
+
|
14
|
+
it 'accounts for nested GET url params' do
|
15
|
+
subject = described_class.new(
|
16
|
+
'GET',
|
17
|
+
'/getdata/1234/v1.2',
|
18
|
+
{ puserid: '42', phint: { event: 'click', offer_id: 1234 } },
|
19
|
+
{},
|
20
|
+
'https://services.bluekai.com')
|
21
|
+
subject.api_private_key = '1234'
|
22
|
+
expect(subject.signature).to eq('KOl1c80m2SQ6%2Fv5K0OLAUKejcrw6zXEsQ9crbcV6n3Y%3D')
|
12
23
|
end
|
13
24
|
end
|
14
25
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: bluekai
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- ad2games GmbH
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-
|
11
|
+
date: 2015-06-04 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: httparty
|
@@ -177,7 +177,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
177
177
|
version: '0'
|
178
178
|
requirements: []
|
179
179
|
rubyforge_project:
|
180
|
-
rubygems_version: 2.4.
|
180
|
+
rubygems_version: 2.4.5
|
181
181
|
signing_key:
|
182
182
|
specification_version: 4
|
183
183
|
summary: Simple client for the BlueKai API
|