button 1.1.1 → 1.2.0

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,15 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: 554dc2147f47d860cca675f697009f591eaf9e05
4
- data.tar.gz: eb9318d22215c7063b8d058c06a0bef8d8e656d4
2
+ !binary "U0hBMQ==":
3
+ metadata.gz: !binary |-
4
+ Mjg5ZThjM2ExMjhiYmFiNjU1MTZhMzViYTIzY2NlYTNiNzc4NGM1ZQ==
5
+ data.tar.gz: !binary |-
6
+ ODBkYTM3Nzc4ZjdiODU2MDEwZWJiN2FkZTg3NTRkOTJhZTU3NGMxOQ==
5
7
  SHA512:
6
- metadata.gz: e497e33ff19b28f46b9ccc24bd63bf87f6a1a331c42509285311c5a3853a0c5e18454de84ff75d5540af884fd021441fc8810dba9104405972e70f46dfa076c1
7
- data.tar.gz: 2f9abd98c76efff13054341b34a362edc7ae9bd758b402d4308f7884751d02fe088bf7ac7bccfe6d087d2e76ec665a682eecea6f97d91d67f874139712dc24b5
8
+ metadata.gz: !binary |-
9
+ MWI4ODgzNjg0YTBkMjE5NTFiZDQ0YmI2M2MzZjJjYTg5MmE5ZGU0YWM2MjZj
10
+ ZjVjMjMxZGI4YTM4MmExNTM0ZDljOTg4NDRjMjIzZGIzYzlkMzJjMWE5N2U0
11
+ YmRiMzZiMTQ2MDZmNGQwMDI1Y2M3OTAxNTYwNWRiNTA1M2Y3ODU=
12
+ data.tar.gz: !binary |-
13
+ YmY1MGY3NjE4OTliYTU3Y2FjMTUwNjMwODkzMjYzZDNhNjg5YWI2MmU2OWUz
14
+ N2IzMjE1Yzg2OTVkZjM4YmU0NjMxNmMwYWMwNzI4YTE0YTAyZWEzNDk1MmU0
15
+ MzMxYWNhYjgxNjk1NGZiMTEyNDgwZjNkODliNTE0NTZiNDhiNDM=
data/CHANGELOG.md CHANGED
@@ -1,3 +1,6 @@
1
+ 1.2.0 January 4, 2017
2
+ - Add `Button::Utils::webhook_authentic?` function
3
+
1
4
  1.1.1 December 1, 2016
2
5
  - Fix User-Agent bug
3
6
 
data/README.md CHANGED
@@ -140,9 +140,28 @@ puts response
140
140
  # => Button::Response()
141
141
  ```
142
142
 
143
+ ## Utils
144
+
145
+ Utils houses generic helpers useful in a Button Integration.
146
+
147
+ ### #webhook_authentic?
148
+
149
+ Used to verify that requests sent to a webhook endpoint are from Button and that their payload can be trusted. Returns `true` if a webhook request body matches the sent signature and `false` otherwise. See [Webhook Security](https://www.usebutton.com/developers/webhooks/#security) for more details.
150
+
151
+ ```ruby
152
+ require 'button'
153
+
154
+ Button::Utils::webhook_authentic?(
155
+ ENV['WEBHOOK_SECRET'],
156
+ request_body,
157
+ request_headers.fetch('X-Button-Signature')
158
+ )
159
+ ```
160
+
143
161
  ## Contributing
144
162
 
145
163
  * Building the gem: `gem build button.gemspec`
146
164
  * Installing locally: `gem install ./button-X.Y.Z.gem`
147
165
  * Installing development dependencies: `bundle install`
166
+ * Running linter: `rake lint`
148
167
  * Running tests: `bundle exec rake`
data/lib/button/client.rb CHANGED
@@ -2,7 +2,7 @@ require 'button/resources/orders'
2
2
  require 'button/errors'
3
3
 
4
4
  NO_API_KEY_MESSAGE = 'Must provide a Button API key. Find yours at '\
5
- 'https://app.usebutton.com/settings/organization'
5
+ 'https://app.usebutton.com/settings/organization'.freeze
6
6
 
7
7
  module Button
8
8
  # Client is the top-level interface for the Button API. It exposes one
@@ -29,7 +29,7 @@ module Button
29
29
  def merge_defaults(config)
30
30
  secure = config.fetch(:secure, true)
31
31
 
32
- return {
32
+ {
33
33
  secure: secure,
34
34
  timeout: config.fetch(:timeout, nil),
35
35
  hostname: config.fetch(:hostname, 'api.usebutton.com'),
@@ -32,9 +32,8 @@ module Button
32
32
  @http = Net::HTTP.new(config[:hostname], config[:port])
33
33
  @http.use_ssl = config[:secure]
34
34
 
35
- if not config[:timeout].nil?
36
- @http.read_timeout = config[:timeout]
37
- end
35
+ return if config[:timeout].nil?
36
+ @http.read_timeout = config[:timeout]
38
37
  end
39
38
 
40
39
  def timeout
@@ -0,0 +1,23 @@
1
+ require 'openssl'
2
+
3
+ module Button
4
+ # Generally handy functions for various aspects of a Button integration
5
+ #
6
+ module Utils
7
+ # Used to verify that requests sent to a webhook endpoint are from Button
8
+ # and that their payload can be trusted. Returns true if a webhook request
9
+ # body matches the sent signature and false otherwise.
10
+ #
11
+ def webhook_authentic?(webhook_secret, request_body, sent_signature)
12
+ computed_signature = OpenSSL::HMAC.hexdigest(
13
+ OpenSSL::Digest.new('sha256'),
14
+ webhook_secret,
15
+ request_body
16
+ )
17
+
18
+ sent_signature == computed_signature
19
+ end
20
+
21
+ module_function :webhook_authentic?
22
+ end
23
+ end
@@ -1,3 +1,3 @@
1
1
  module Button
2
- VERSION = '1.1.1'.freeze
2
+ VERSION = '1.2.0'.freeze
3
3
  end
data/lib/button.rb CHANGED
@@ -1,2 +1,3 @@
1
1
  require 'button/client'
2
2
  require 'button/version'
3
+ require 'button/utils'
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: button
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.1
4
+ version: 1.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Button
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-12-01 00:00:00.000000000 Z
11
+ date: 2017-01-04 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: Button is a contextual acquisition channel and closed-loop attribution
14
14
  and affiliation system for mobile commerce.
@@ -27,6 +27,7 @@ files:
27
27
  - lib/button/resources/orders.rb
28
28
  - lib/button/resources/resource.rb
29
29
  - lib/button/response.rb
30
+ - lib/button/utils.rb
30
31
  - lib/button/version.rb
31
32
  homepage: https://usebutton.com
32
33
  licenses:
@@ -38,17 +39,17 @@ require_paths:
38
39
  - lib
39
40
  required_ruby_version: !ruby/object:Gem::Requirement
40
41
  requirements:
41
- - - ">="
42
+ - - ! '>='
42
43
  - !ruby/object:Gem::Version
43
44
  version: 1.9.3
44
45
  required_rubygems_version: !ruby/object:Gem::Requirement
45
46
  requirements:
46
- - - ">="
47
+ - - ! '>='
47
48
  - !ruby/object:Gem::Version
48
49
  version: '0'
49
50
  requirements: []
50
51
  rubyforge_project:
51
- rubygems_version: 2.5.1
52
+ rubygems_version: 2.4.8
52
53
  signing_key:
53
54
  specification_version: 4
54
55
  summary: ruby client for the Button Order API