This repository was archived by the owner on Mar 5, 2026. It is now read-only.
File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1515require "buff/datastructure"
1616require "buff/info"
1717require "buff/client"
18+ require "buff/setup"
1819
1920module Buff
2021end
Original file line number Diff line number Diff 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 } "
Original file line number Diff line number Diff line change 11module Buff
2- InvalidIdLength = Class . new ( ArgumentError )
3- InvalidIdContent = Class . new ( ArgumentError )
4- MissingStatus = Class . new ( ArgumentError )
5- APIError = Class . new ( StandardError )
6- UnauthorizeRequest = Class . new ( StandardError )
2+ module Error
3+ 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 )
9+ end
710end
Original file line number Diff line number Diff line change 1+ module Buff
2+ RC_VERSION = "0.0.1"
3+ class Setup
4+
5+ def initialize ( args = "~/.bufferapprc" )
6+ @path = Pathname . new ( args )
7+ if exists?
8+ @content = YAML . load_file ( File . expand_path path )
9+ else
10+ raise Buff ::Error ::ConfigFileMissing
11+ end
12+ end
13+
14+ def path
15+ @path . to_s
16+ end
17+
18+ def exists?
19+ File . exists? ( File . expand_path path )
20+ end
21+
22+ end
23+ end
Original file line number Diff line number Diff 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
Original file line number Diff line number Diff line change 1+ require "spec_helper"
2+
3+ describe Buff ::Setup do
4+
5+ let ( :bad_config_setup ) { Buff ::Setup . new "~/notpresentexample" }
6+ let ( :setup ) { Buff ::Setup . new }
7+
8+ context "pathname" do
9+ it "sets the default path" do
10+ expect ( setup . path ) . to eq ( "~/.bufferapprc" )
11+ end
12+ it "fails with error when specified file not found" do
13+ lambda { bad_config_setup . path } . should
14+ raise_error ( Buff ::Error ::ConfigFileMissing )
15+ end
16+ end
17+ context "verifies whether rc file exists" do
18+ it "documents when rc file not present" do
19+ expect ( bad_config_setup . exists? ) . to eq ( false )
20+ end
21+ it "documents when rc file is present" do
22+ expect ( setup . exists? ) . to eq ( true )
23+ end
24+ end
25+ context "determines if rc file is the most current version" do
26+ it "checks current RC_VERSION" do
27+ expect ( Buff ::RC_VERSION ) . to_not eq ( nil )
28+ end
29+
30+ it "reports error when file is out of date" do
31+ end
32+ it "returns true when current"
33+ end
34+ context "when rc file is current"
35+ it "exits without altering state"
36+ context "when rc file is not present"
37+ it "verifies that rc file doesn't exist"
38+ it "creates an rc file and prompts for authorization"
39+
40+ context "when rc file is out of date"
41+ end
Original file line number Diff line number Diff line change 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
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
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
Original file line number Diff line number Diff line change 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
You can’t perform that action at this time.
0 commit comments