Commit 8749cbb

mo khan <mo@mokhan.ca>
2014-11-11 22:22:05
complete example for public facing API.
1 parent 48af77c
Changed files (3)
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
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
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