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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 51af5eb445beb71937839077803c711846d636b1
4
- data.tar.gz: 8358216076ae1562c321988381de79a700c24b36
3
+ metadata.gz: 774cef3b18775e0f088571f7d474faf5646202ba
4
+ data.tar.gz: f9e04b63d36e4e3c9b7d9742fad2d12a2d1060f3
5
5
  SHA512:
6
- metadata.gz: e6ab9bf86b7975e822786df0d50458f5f9051dc59477013ae9149cd9e1f219473ab5f9b15b29fa6dc8da54ecb50ddd6428b06fe5c254f3334e2977e811205e1c
7
- data.tar.gz: 68e0deae9ecc2f9f95e745ab3607667927cad730bfcf83b35c7a31671dd3ce2acb3987fbe6db1f14770a8d61ea3cad0d56c3745b199e02f021137c500358a112
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.png?style=shield&circle-token=323d6ce1376f1473cab4474d89f8fc7287446595)](https://circleci.com/gh/ad2games/bluekai)
4
- [![Code Climate](https://codeclimate.com/repos/5523e6d8695680516e00144d/badges/40648ea53c768dd15de5/gpa.svg)](https://codeclimate.com/repos/5523e6d8695680516e00144d/feed)
5
- [![Test Coverage](https://codeclimate.com/repos/5523e6d8695680516e00144d/badges/40648ea53c768dd15de5/coverage.svg)](https://codeclimate.com/repos/5523e6d8695680516e00144d/feed)
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
@@ -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}?#{query_url_formatted}"\
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 query_url_formatted
68
+ def query_values
67
69
  return nil unless query
68
- query.map { |k, v| "#{k}=#{v}" }.join('&') + '&'
70
+ query_string.split('&').map { |p| p.split('=', 2)[1] }.join
69
71
  end
70
72
 
71
- def string_to_sign
72
- method + path + query_values.to_s + body_sorted.to_s
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
- # HMAC-SHA256(Secret key, HTTP_METHOD + URI_PATH + QUERY_ARG_VALUES + POST_DATA)
76
- def signature
77
- digest = OpenSSL::Digest.new('sha256')
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
@@ -1,3 +1,3 @@
1
1
  module Bluekai
2
- VERSION = '0.0.4'
2
+ VERSION = '0.0.5'
3
3
  end
@@ -1,14 +1,25 @@
1
1
  RSpec.describe Bluekai::Request do
2
- describe '#sign' do
2
+ describe '#signature' do
3
3
  it 'computes a correct signature' do
4
- rq = described_class.new(
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
- rq.api_private_key = '1234'
11
- expect(rq.send(:signature)).to eq('t%2BE36Yup7ORbC3WRux5xY7ohUxqFo5AGsKrGjJYDCKs%3D')
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
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-05-13 00:00:00.000000000 Z
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.6
180
+ rubygems_version: 2.4.5
181
181
  signing_key:
182
182
  specification_version: 4
183
183
  summary: Simple client for the BlueKai API