Skip to content

Commit

Permalink
Added configuration.
Browse files Browse the repository at this point in the history
  • Loading branch information
Tim Stephenson committed Mar 17, 2011
1 parent b192a87 commit 9894073
Show file tree
Hide file tree
Showing 8 changed files with 91 additions and 6 deletions.
5 changes: 4 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,7 @@ pkg

# For TextMate
*.tmproj
tmtags
tmtags

#api key info
keys.txt
6 changes: 3 additions & 3 deletions Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,12 @@ require 'jeweler'
Jeweler::Tasks.new do |gem|
# gem is a Gem::Specification... see http://docs.rubygems.org/read/chapter/20 for more options
gem.name = "r_hapi"
gem.homepage = "http://github.com/timstephenson/r_hapi"
gem.homepage = "http://github.com/timstephenson/rHAPI"
gem.license = "MIT"
gem.summary = %Q{TODO: one-line summary of your gem}
gem.summary = %Q{A ruby wrapper for the HubSpot API (HAPI).}
gem.description = %Q{TODO: longer description of your gem}
gem.email = "tim@raddonline.com"
gem.authors = ["Tim Stephenson"]
gem.authors = ["Tim Stephenson of RaddOnline"]
# Include your dependencies below. Runtime dependencies are required when using your gem,
# and development dependencies are only needed for development (ie running rake tasks, tests, etc)
# gem.add_runtime_dependency 'jabber4r', '> 0.1'
Expand Down
6 changes: 6 additions & 0 deletions lib/r_hapi.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
require File.expand_path('../r_hapi/lead', __FILE__)
require File.expand_path('../r_hapi/configuration', __FILE__)

module RHapi
extend Configuration
end
28 changes: 28 additions & 0 deletions lib/r_hapi/configuration.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
module RHapi
module Configuration
VALID_OPTIONS_KEYS = [:api_key, :end_point, :hub_spot_site]
DEFAULT_API_KEY = nil
DEFAULT_END_POINT = "https://hubapi.com"
DEFAULT_HUB_SPOT_SITE = nil

attr_accessor *VALID_OPTIONS_KEYS

def configure
yield self
end

# Create a hash of options and their values
def options
Hash[VALID_OPTIONS_KEYS.map {|key| [key, send(key)] }]
end

# Reset all configuration options to defaults
def reset
self.api_key = DEFAULT_API_KEY
self.end_point = DEFAULT_END_POINT
self.hub_spot_site = DEFAULT_HUB_SPOT_SITE
self
end

end
end
9 changes: 9 additions & 0 deletions lib/r_hapi/lead.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
module RHapi

class Lead
def truth
true
end
end

end
30 changes: 30 additions & 0 deletions spec/configuration_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
require File.expand_path(File.dirname(__FILE__) + '/spec_helper')

describe "Configuration" do
before do
RHapi.configure do |config|
config.api_key = "123"
config.end_point = "https://mysite.com"
config.hub_spot_site = "http://mysite.hubspot.com"
end
end

it "sets the api key" do
RHapi.options[:api_key].should == "123"
end

it "sets the endpoint" do
RHapi.options[:end_point].should == "https://mysite.com"
end

it "sets the hub_spot_site" do
RHapi.options[:hub_spot_site].should == "http://mysite.hubspot.com"
end

it "resets to the default values" do
RHapi.reset
RHapi.options[:api_key].should == nil
RHapi.options[:end_point].should == "https://hubapi.com"
RHapi.options[:hub_spot_site].should == nil
end
end
8 changes: 8 additions & 0 deletions spec/lead_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
require File.expand_path(File.dirname(__FILE__) + '/spec_helper')

describe "RHapi::Lead" do
it "passes" do
lead = RHapi::Lead.new
lead.truth.should == true
end
end
5 changes: 3 additions & 2 deletions spec/r_hapi_spec.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
require File.expand_path(File.dirname(__FILE__) + '/spec_helper')

describe "RHapi" do
it "fails" do
fail "hey buddy, you should probably rename this file and start specing for real"
it "passes" do
lead = RHapi::Lead.new
lead.truth.should == true
end
end

0 comments on commit 9894073

Please sign in to comment.