easypost 2.5.0 → 2.6.0

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: fb5b2a2aec96dd52db2877a8d37d8fb45864c6b5
4
- data.tar.gz: 64c58f1e552166b38e9ce5a847c8b309ba597f87
3
+ metadata.gz: 1b360f6133e438fbd6da1c82a6d3fd896fc6e5c0
4
+ data.tar.gz: 0a428545bec4b22c37612d1880b7b9ece706136d
5
5
  SHA512:
6
- metadata.gz: c47dca1f33b6a3815e81e2de2e4086317ecf22991e5d4f9768b66458cc42824e1daad419a1ea2fb70d558c0234a2fadcccebfb632f1317d406abbc9edbeedf30
7
- data.tar.gz: 429562b83a019209a6c246361a9ec47dc1c8bcf299ec2c7f5533de15f238f3f7af03be96149fddc5fd611e9571b01411c91a03e46de3674f0563a2ec61e3cc39
6
+ metadata.gz: 154082e65747ede8cb1fbb9d06c99ae0ad4d336c7b52fecd8a3c51ab35bfab6dbde9d7a3e04e603e7eb4689b2e7f4419b51be37667ffdd8db6ddbcf695f2528d
7
+ data.tar.gz: 8d62d3abafc9f1df1a67199b8653a2ca772ef371c60b3a45f615b663b4d4fbee7c8080743fdc0da3c9a00e9272fa18e513fb69f1da3d58bc6ad031af8a79bd4f
data/CHANGELOG CHANGED
@@ -1,3 +1,7 @@
1
+ === 2.6.0 2017-01-17
2
+
3
+ * Add basic CRUD methods for Webhooks
4
+
1
5
  === 2.5.0 2016-12-19
2
6
 
3
7
  * Add prefixes to report in utils
data/VERSION CHANGED
@@ -1 +1 @@
1
- 2.5.0
1
+ 2.6.0
data/lib/easypost.rb CHANGED
@@ -32,6 +32,7 @@ require 'easypost/print_job'
32
32
  require 'easypost/carrier_account'
33
33
  require 'easypost/user'
34
34
  require 'easypost/report'
35
+ require 'easypost/webhook'
35
36
 
36
37
  require 'easypost/error'
37
38
 
data/lib/easypost/util.rb CHANGED
@@ -42,7 +42,8 @@ module EasyPost
42
42
  'Report' => Report,
43
43
  'ShipmentReport' => Report,
44
44
  'PaymentLogReport' => Report,
45
- 'TrackerReport' => Report
45
+ 'TrackerReport' => Report,
46
+ 'Webhook' => Webhook
46
47
  }
47
48
 
48
49
  prefixes = {
@@ -70,7 +71,8 @@ module EasyPost
70
71
  'user' => User,
71
72
  'shprep' => Report,
72
73
  'plrep' => Report,
73
- 'trkrep' => Report
74
+ 'trkrep' => Report,
75
+ 'hook' => Webhook
74
76
  }
75
77
 
76
78
  case response
@@ -0,0 +1,28 @@
1
+ module EasyPost
2
+ class Webhook < Resource
3
+ def update(params={})
4
+ unless self.id
5
+ raise Error.new("Could not determine which URL to request: #{self.class} instance has invalid ID: #{self.id.inspect}")
6
+ end
7
+ instance_url = "#{self.class.url}/#{CGI.escape(id)}"
8
+
9
+ response, api_key = EasyPost.request(:put, instance_url, @api_key, params)
10
+ self.refresh_from(response, api_key, true)
11
+
12
+ return self
13
+ end
14
+
15
+ def delete
16
+ # Note: This method is redefined here since the "url" method conflicts with the objects field
17
+ unless self.id
18
+ raise Error.new("Could not determine which URL to request: #{self.class} instance has invalid ID: #{self.id.inspect}")
19
+ end
20
+ instance_url = "#{self.class.url}/#{CGI.escape(id)}"
21
+
22
+ response, api_key = EasyPost.request(:delete, instance_url, @api_key)
23
+ refresh_from(response, api_key)
24
+
25
+ return self
26
+ end
27
+ end
28
+ end
@@ -0,0 +1,75 @@
1
+ require 'spec_helper'
2
+
3
+ describe EasyPost::Webhook do
4
+ let(:url) { "http://example.com" }
5
+ let(:webhook) { EasyPost::Webhook.create({url: url}) }
6
+
7
+ context 'with automated cleanup' do
8
+ after do
9
+ webhook.delete()
10
+ end
11
+
12
+ describe '#create' do
13
+ it 'creates' do
14
+ expect(webhook.id).not_to be_nil
15
+ expect(webhook.url).to eq(url)
16
+ expect(webhook.mode).to eq("test")
17
+ expect(webhook.disabled_at).to be_nil
18
+ expect(webhook.class).to eq(EasyPost::Webhook)
19
+ end
20
+ end
21
+
22
+ describe '#retrieve' do
23
+ it 'retrieves' do
24
+ hook = EasyPost::Webhook.retrieve(webhook.id)
25
+
26
+ expect(hook.id).to eq(webhook.id)
27
+ expect(hook.url).to eq(url)
28
+ expect(hook.mode).to eq("test")
29
+ expect(hook.disabled_at).to be_nil
30
+ expect(hook.class).to eq(EasyPost::Webhook)
31
+ end
32
+ end
33
+
34
+ describe '#index' do
35
+ it 'indexes with the recently created webhook as the last one' do
36
+ webhook
37
+ webhooks = EasyPost::Webhook.all({})
38
+
39
+ hook = webhooks["webhooks"].last
40
+
41
+ expect(hook.id).to eq(webhook.id)
42
+ expect(hook.url).to eq(url)
43
+ expect(hook.mode).to eq("test")
44
+ expect(hook.disabled_at).to be_nil
45
+ expect(hook.class).to eq(EasyPost::Webhook)
46
+ end
47
+ end
48
+
49
+ describe '#retrieve' do
50
+ it 'retrieves' do
51
+ hook = webhook.update({})
52
+
53
+ expect(hook.id).to eq(webhook.id)
54
+ expect(hook.url).to eq(url)
55
+ expect(hook.mode).to eq("test")
56
+ expect(hook.disabled_at).to be_nil
57
+ expect(hook.class).to eq(EasyPost::Webhook)
58
+ end
59
+ end
60
+ end
61
+
62
+ describe '#delete' do
63
+ it 'deletes the tracker' do
64
+ webhook.delete()
65
+
66
+ begin
67
+ EasyPost::Webhook.retrieve(webhook.id)
68
+ rescue EasyPost::Error => e
69
+ expect(e.http_status).to eq(404)
70
+ expect(e.code).to eq("NOT_FOUND")
71
+ expect(e.message).to eq("The requested resource could not be found.")
72
+ end
73
+ end
74
+ end
75
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: easypost
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.5.0
4
+ version: 2.6.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Sawyer Bateman
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-12-19 00:00:00.000000000 Z
11
+ date: 2017-01-17 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rest-client
@@ -126,6 +126,7 @@ files:
126
126
  - lib/easypost/user.rb
127
127
  - lib/easypost/util.rb
128
128
  - lib/easypost/version.rb
129
+ - lib/easypost/webhook.rb
129
130
  - spec/address_spec.rb
130
131
  - spec/batch_spec.rb
131
132
  - spec/carrier_account_spec.rb
@@ -140,6 +141,7 @@ files:
140
141
  - spec/support/constant.rb
141
142
  - spec/tracker_spec.rb
142
143
  - spec/user_spec.rb
144
+ - spec/webhook_spec.rb
143
145
  homepage: https://www.easypost.com/docs
144
146
  licenses: []
145
147
  metadata: {}
@@ -178,3 +180,4 @@ test_files:
178
180
  - spec/support/constant.rb
179
181
  - spec/tracker_spec.rb
180
182
  - spec/user_spec.rb
183
+ - spec/webhook_spec.rb