Permalink
Browse files

Merge pull request #2 from tstmedia/modify-baseuri

Allow Changing of the HasOffers API base URI
  • Loading branch information...
2 parents 7c2628e + 4cce012 commit f720fb72148f96c5a6afda8d92f8dec48de49375 Luke Ludwig committed Feb 10, 2012
Showing with 25 additions and 7 deletions.
  1. +3 −3 Gemfile.lock
  2. +12 −4 lib/hasoffers/base.rb
  3. +10 −0 test/base_test.rb
View
@@ -1,16 +1,16 @@
PATH
remote: .
specs:
- hasoffers (0.1.2)
+ hasoffers (0.1.3)
crack
yajl-ruby
GEM
remote: http://rubygems.org/
specs:
- crack (0.1.8)
+ crack (0.3.1)
rake (0.9.2)
- yajl-ruby (0.8.2)
+ yajl-ruby (1.1.0)
PLATFORMS
ruby
View
@@ -3,12 +3,20 @@ module HasOffers
class Base
- BaseUri = 'https://api.hasoffers.com/Api'
+ @@base_uri = 'https://api.hasoffers.com/Api'
@@api_mode = ((defined?(Rails) and Rails.env.production?) or ENV['HAS_OFFERS_LIVE'] == '1') ? :live : :test
@@default_params = nil
class << self
+ def base_uri=(uri)
+ @@base_uri = uri
+ end
+
+ def base_uri
+ @@base_uri
+ end
+
def initialize_credentials
config_file = ENV['HAS_OFFERS_CONFIG_FILE'] || "config/has_offers.yml"
if File.exists?(config_file)
@@ -77,12 +85,12 @@ def make_request(http_method, target, method, params)
data = build_request_params(target, method, params)
if live?
if http_method == :post
- uri = URI.parse BaseUri
+ uri = URI.parse base_uri
http = new_http uri
raw_request = Net::HTTP::Post.new(uri.request_uri)
raw_request.body = query_string data
else # assume get
- uri = URI.parse("#{BaseUri}?#{query_string(data)}")
+ uri = URI.parse("#{base_uri}?#{query_string(data)}")
http = new_http uri
raw_request = Net::HTTP::Get.new(uri.request_uri)
end
@@ -108,4 +116,4 @@ def build_data(data, return_object = false)
end
-end
+end
View
@@ -0,0 +1,10 @@
+require File.dirname(__FILE__) + '/test_helper'
+
+class AdvertiserTest < Test::Unit::TestCase
+ def test_set_base_uri
+ new_uri = "http://example.com"
+ HasOffers::Base.base_uri = new_uri
+ assert_equal new_uri, HasOffers::Base.base_uri
+ end
+end
+

0 comments on commit f720fb7

Please sign in to comment.