summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authormo khan <mo@mokhan.ca>2014-11-11 15:22:05 -0700
committermo khan <mo@mokhan.ca>2014-11-11 15:22:05 -0700
commit8749cbb3d78f402f2d8fcc08325773c9d7ce7549 (patch)
treedcc716f609dc4acf7b9d336d2b05c36c0a180b25
parent48af77cb5a6c12c37a232e154dd01cec9b80fdaf (diff)
complete example for public facing API.
-rw-r--r--lib/urkel.rb9
-rw-r--r--lib/urkel/configuration.rb7
-rw-r--r--spec/urkel_spec.rb5
3 files changed, 17 insertions, 4 deletions
diff --git a/lib/urkel.rb b/lib/urkel.rb
index b08d857..23db6ba 100644
--- a/lib/urkel.rb
+++ b/lib/urkel.rb
@@ -4,4 +4,13 @@ require 'urkel/configuration'
require 'urkel/connection'
module Urkel
+ def self.configure
+ configuration = Configuration.new
+ yield configuration
+ @connection = Connection.new(configuration)
+ end
+
+ def self.oops(error)
+ @connection.publish(error)
+ end
end
diff --git a/lib/urkel/configuration.rb b/lib/urkel/configuration.rb
index a595b55..5daa4f0 100644
--- a/lib/urkel/configuration.rb
+++ b/lib/urkel/configuration.rb
@@ -1,9 +1,9 @@
module Urkel
class Configuration
- attr_reader :uri, :api_key
+ attr_accessor :api_host, :api_key
- def initialize(api_host, api_key)
- @uri = URI.parse(api_host)
+ def initialize(api_host = '', api_key = '')
+ @api_host = api_host
@api_key = api_key
end
@@ -15,6 +15,7 @@ module Urkel
private
def http_connection
+ uri = URI.parse(api_host)
http = Net::HTTP.new(uri.host, uri.port)
http.use_ssl = (uri.scheme == "https")
http
diff --git a/spec/urkel_spec.rb b/spec/urkel_spec.rb
index 5b3bc6d..8e63d01 100644
--- a/spec/urkel_spec.rb
+++ b/spec/urkel_spec.rb
@@ -6,12 +6,15 @@ describe Urkel do
end
describe ".oops" do
+ let(:error) { StandardError.new("Ooops... did i do that?") }
+
it 'publishes a new error' do
+ stub_request(:post, "http://localhost:3000/api/v1/failures").to_return(status: 200)
Urkel.configure do |configuration|
configuration.api_host = 'http://localhost:3000'
configuration.api_key = '02513a35-b875-40a1-a1fc-f2d2582bdcc5'
end
- Urkel.oops(error)
+ expect(Urkel.oops(error)).to be_truthy
end
end
end