Skip to content

Commit 693b41c

Browse files
committed
Migrated error classes into Buff::Error namespace
1 parent 7af8848 commit 693b41c

5 files changed

Lines changed: 14 additions & 16 deletions

File tree

lib/buff/core.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ def interpret_response(response)
5757

5858
def handle_response_code(response)
5959
error = Hashie::Mash.new(response.body)
60-
raise Buff::APIError unless error.code
60+
raise Buff::Error::APIError unless error.code
6161
"Buffer API Error Code: #{error.code}\n" +
6262
"HTTP Code: #{response.code}." +
6363
"Description: #{error.error}"

lib/buff/error.rb

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,10 @@
11
module Buff
2-
#TODO: refactor errors into Error Module and fix references
3-
InvalidIdLength = Class.new(ArgumentError)
4-
InvalidIdContent = Class.new(ArgumentError)
5-
MissingStatus = Class.new(ArgumentError)
6-
APIError = Class.new(StandardError)
7-
UnauthorizeRequest = Class.new(StandardError)
8-
92
module Error
103
ConfigFileMissing = Class.new(StandardError)
4+
InvalidIdLength = Class.new(ArgumentError)
5+
InvalidIdContent = Class.new(ArgumentError)
6+
MissingStatus = Class.new(ArgumentError)
7+
APIError = Class.new(StandardError)
8+
UnauthorizedRequest = Class.new(StandardError)
119
end
1210
end

lib/buff/update.rb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ def update_by_id(id, options = {})
99

1010
def updates_by_profile_id(id, options = {})
1111
status = options.fetch(:status) do
12-
raise Buff::MissingStatus, "Include :pending or :sent in args"
12+
raise Buff::Error::MissingStatus, "Include :pending or :sent in args"
1313
end
1414
options.delete(:status)
1515
response = get("/profiles/#{id}/updates/#{status.to_s}.json", options)
@@ -67,8 +67,8 @@ def destroy_update(update_id)
6767
end
6868

6969
def check_id(id)
70-
raise Buff::InvalidIdLength unless id.length == 24
71-
raise Buff::InvalidIdContent unless id[/^[a-f0-9]+$/i]
70+
raise Buff::Error::InvalidIdLength unless id.length == 24
71+
raise Buff::Error::InvalidIdContent unless id[/^[a-f0-9]+$/i]
7272
end
7373
end
7474
end

spec/lib/buff/update_spec.rb

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@
3737

3838
it "fails without a :status arg" do
3939
lambda { client.updates_by_profile_id(profile_id)}.
40-
should raise_error(Buff::MissingStatus)
40+
should raise_error(Buff::Error::MissingStatus)
4141
end
4242

4343
it "connects to the correct endpoint" do
@@ -70,7 +70,7 @@
7070

7171
it "requires an id" do
7272
lambda { client.interactions_by_update_id(page: 2) }.
73-
should raise_error(Buff::InvalidIdLength)
73+
should raise_error(Buff::Error::InvalidIdLength)
7474
end
7575

7676
it "allows optional params" do
@@ -122,15 +122,15 @@
122122
to_return(:status => 200, :body => "", :headers => {})
123123
id = "4eb8565e0acb04bb82000004X"
124124
lambda { client.update_by_id(id) }.
125-
should raise_error(Buff::InvalidIdLength)
125+
should raise_error(Buff::Error::InvalidIdLength)
126126
end
127127

128128
it "fails if id is not numbers and a-f" do
129129
stub_request(:get, "https://api.bufferapp.com/1/updates/4eb8565e0acb04bb8200000X.json?access_token=some_token").
130130
to_return(:status => 200, :body => "", :headers => {})
131131
id = "4eb8565e0acb04bb8200000X"
132132
lambda { client.update_by_id(id) }.
133-
should raise_error(Buff::InvalidIdContent)
133+
should raise_error(Buff::Error::InvalidIdContent)
134134
end
135135
end
136136

spec/lib/core_spec.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@
5252
url = "#{base_path}/updates/#{id}.json?access_token=some_token"
5353
stub_with_to_return(:get, url, "update_by_id_non_auth.txt")
5454
lambda { client.update_by_id(id) }.
55-
should raise_error(Buff::APIError)
55+
should raise_error(Buff::Error::APIError)
5656
end
5757
end
5858
end

0 commit comments

Comments
 (0)