Skip to content

Commit

Permalink
Remove HTTParty because the JSON gem is evil
Browse files Browse the repository at this point in the history
  • Loading branch information
sethvargo committed Nov 6, 2013
1 parent 2b0c1b5 commit b3fd3c8
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 4 deletions.
1 change: 0 additions & 1 deletion fauxhai.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ Gem::Specification.new do |spec|
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
spec.require_paths = ['lib']

spec.add_runtime_dependency 'httparty'
spec.add_runtime_dependency 'net-ssh'
spec.add_runtime_dependency 'ohai'

Expand Down
17 changes: 14 additions & 3 deletions lib/fauxhai/mocker.rb
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
require 'httparty'
require 'json'
require 'net/http'
require 'pathname'

module Fauxhai
class Mocker
# The base URL for the GitHub project (raw)
RAW_BASE = 'https://raw.github.com/customink/fauxhai/master'

# @return [Hash] The raw ohai data for the given Mock
attr_reader :data

Expand Down Expand Up @@ -54,8 +57,7 @@ def fauxhai_data
elsif
# Try loading from github (in case someone submitted a PR with a new file, but we haven't
# yet updated the gem version). Cache the response locally so it's faster next time.
url = "https://raw.github.com/customink/fauxhai/master/lib/fauxhai/platforms/#{platform}/#{version}.json"
response = HTTParty.get(url)
response = get("#{RAW_BASE}/lib/fauxhai/platforms/#{platform}/#{version}.json")

if response.code.to_i == 200
path = Pathname.new(filepath)
Expand Down Expand Up @@ -85,5 +87,14 @@ def version
def chefspec_version
platform == 'chefspec' ? '0.6.1' : nil
end

def get(url)
url = URI.parse(url)
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true

request = Net::HTTP::Get.new(url.path)
http.start { |http| http.request(request) }
end
end
end

0 comments on commit b3fd3c8

Please sign in to comment.