wp-hmac 0.2.1 → 0.2.2

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: 7890c63aaa7a52e55fae583b772d0fdd4ed2f09e
4
- data.tar.gz: 9de22c8167a45b4a20f45edc6daeb69e1a1fb53e
3
+ metadata.gz: 0b1fee8fa88eb3443cba2874b60dff707e07604e
4
+ data.tar.gz: 8d90cec9afaa7e183bab2bff42c645373368d8fa
5
5
  SHA512:
6
- metadata.gz: 4d2230ec01a97d7b2e18595ff3d6f4e16564c907c4f720c8a81d5042b629351366e649514cc38f4bfe27d5638dc12d7a85f5c055537cd98e666e7942443efff0
7
- data.tar.gz: 50f840e23e5aa29b9a3e71d45e9ef0728cdc2b5f56b83454a6b7a2d312e9d4db3d0d1cd924e077162534f6ca165995f9a333e4c1290ee4ca76b15da385e43eeb
6
+ metadata.gz: b0cde112d23e27ac62ed9269b3047506002c2fd8c4e16fc1ee75005282ca15de773f5271087ed6610336b66fb534fe125869ababfc9ec1e844fb57768d7cd498
7
+ data.tar.gz: 6d149a01edfa78c6ab700ab8e2c60eca946acb712702d5e49256749660c27aec353a3de7b39a912e4a4c78c3d5b19f58e876d459cac09d4fc101af167fcb0b32
@@ -21,21 +21,28 @@ module WP
21
21
  @client
22
22
  end
23
23
 
24
- def method_missing(method_missing, *args, &block)
25
- @client.send(method_missing, *args, &block)
26
- end
27
-
28
24
  def key_cabinet
29
25
  @key_cabinet ||= HMAC::KeyCabinet.find_by_auth_id(HMAC.auth_id)
30
26
  end
31
27
 
28
+ # Supports:
29
+ # client = WP::HMAC::Client.new('https://www.example.com')
30
+ # client.get('api/staff')
31
+ %i(delete get head options post put patch).each do |method|
32
+ define_method(method) do |*args|
33
+ response = @client.send(method, *args)
34
+ raise UnsuccessfulResponse unless /2\d\d/.match("#{response.status}")
35
+ response
36
+ end
37
+ end
38
+
39
+ # Supports:
40
+ # WP::HMAC::Client.get('https://www.example.com/api/staff')
32
41
  class << self
33
- %i(delete get head options post put).each do |method|
42
+ %i(delete get head options post put patch).each do |method|
34
43
  define_method(method) do |*args|
35
44
  client = Client.new
36
45
  client.send(method, *args)
37
-
38
- raise UnsuccessfulResponse unless /2\d\d/.match("#{client.status}")
39
46
  end
40
47
  end
41
48
  end
@@ -1,5 +1,5 @@
1
1
  module Wp
2
2
  module Hmac
3
- VERSION = "0.2.1"
3
+ VERSION = "0.2.2"
4
4
  end
5
5
  end
data/spec/hmac_spec.rb CHANGED
@@ -11,6 +11,10 @@ class DummyController < ActionController::Base
11
11
  def show
12
12
  render inline: 'Hello, world!'
13
13
  end
14
+
15
+ def create
16
+ head :bad_request
17
+ end
14
18
  end
15
19
 
16
20
  RSpec.describe WP::HMAC, type: :request do
@@ -31,7 +35,7 @@ RSpec.describe WP::HMAC, type: :request do
31
35
 
32
36
  before do
33
37
  Rails.application.routes.draw do
34
- resources :dummy, only: %i(show)
38
+ resources :dummy
35
39
  end
36
40
  end
37
41
 
@@ -78,6 +82,25 @@ RSpec.describe WP::HMAC, type: :request do
78
82
  rack_response = hmac_client.get 'http://esso.example.org/dummy/1'
79
83
  expect(rack_response.body).to include('Hello, world!')
80
84
  end
85
+
86
+ it 'succeeds when the request is correctly signed (alt syntax)' do
87
+ pending 'Need to work out how to test this'
88
+ rack_response = WP::HMAC::Client.get('http://esso.example.org/dummy/1')
89
+ expect(rack_response.body).to include('Hello, world!')
90
+ end
91
+
92
+ it 'raises UnsuccessfulResponse when server reponds 400' do
93
+ expect {
94
+ hmac_client.post('http://esso.example.org/dummy')
95
+ }.to raise_error(WP::HMAC::Client::UnsuccessfulResponse)
96
+ end
97
+
98
+ it 'raises UnsuccessfulResponse when server reponds 400 (alt syntax)' do
99
+ pending 'Need to work out how to test this'
100
+ expect {
101
+ WP::HMAC::Client.post('http://esso.example.org/dummy')
102
+ }.to raise_error(WP::HMAC::Client::UnsuccessfulResponse)
103
+ end
81
104
  end
82
105
 
83
106
  context 'with a key configured via a block' do
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: wp-hmac
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.1
4
+ version: 0.2.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Andrew Nagi
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-03-10 00:00:00.000000000 Z
11
+ date: 2015-03-13 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: ey_api_hmac