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 +13 -5
- data/CHANGELOG.md +3 -0
- data/README.md +19 -0
- data/lib/button/client.rb +2 -2
- data/lib/button/resources/resource.rb +2 -3
- data/lib/button/utils.rb +23 -0
- data/lib/button/version.rb +1 -1
- data/lib/button.rb +1 -0
- metadata +6 -5
checksums.yaml
CHANGED
@@ -1,7 +1,15 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
|
2
|
+
!binary "U0hBMQ==":
|
3
|
+
metadata.gz: !binary |-
|
4
|
+
Mjg5ZThjM2ExMjhiYmFiNjU1MTZhMzViYTIzY2NlYTNiNzc4NGM1ZQ==
|
5
|
+
data.tar.gz: !binary |-
|
6
|
+
ODBkYTM3Nzc4ZjdiODU2MDEwZWJiN2FkZTg3NTRkOTJhZTU3NGMxOQ==
|
5
7
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
|
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
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
|
-
|
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
|
36
|
-
|
37
|
-
end
|
35
|
+
return if config[:timeout].nil?
|
36
|
+
@http.read_timeout = config[:timeout]
|
38
37
|
end
|
39
38
|
|
40
39
|
def timeout
|
data/lib/button/utils.rb
ADDED
@@ -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
|
data/lib/button/version.rb
CHANGED
data/lib/button.rb
CHANGED
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.
|
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:
|
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.
|
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
|