Class: Difio::DifioBase

Inherits:
Object
  • Object
show all
Defined in:
lib/common-ruby-difio.rb,
lib/common-ruby-difio/version.rb

Constant Summary collapse

VERSION =
"2.0.0"
@@difio_url =
"https://difio-otb.rhcloud.com/application/register/"
@@post_data =
{
  'user_id' => nil,
  'app_name' => nil,
  'app_uuid' => nil,
  'app_type' => 'Ruby',
  'app_url'  => nil,
  'app_vendor' => nil,
  'pkg_type' => 1,
  'installed' => [],
}

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.configure(options) ⇒ Object



21
22
23
24
25
26
27
28
# File 'lib/common-ruby-difio.rb', line 21

def self.configure(options)
	if options['url']
		@@difio_url = options['url']
	end
	@@post_data.each do |k,v|
		@@post_data[k] = options[k] if options[k]
	end
end

Instance Method Details

#cliObject



73
74
75
76
77
78
79
80
81
82
83
84
85
# File 'lib/common-ruby-difio.rb', line 73

def cli()
	if ARGV.include? '--printJSON'
		puts get_deps_as_json()
		exit
	end
	result = post_to_difio()
	case result
	when Net::HTTPSuccess
		puts "difio: #{result.body}"
	else
		puts "difio: #{result.code} #{result.message}"
	end
end

#get_deps_as_json(gems = nil) ⇒ Object



39
40
41
42
43
# File 'lib/common-ruby-difio.rb', line 39

def get_deps_as_json(gems=nil)
	data  = @@post_data.clone()
	data['installed'] = gems || get_module_list()
	return JSON.dump(data)
end

#get_module_listObject



30
31
32
33
34
35
36
37
# File 'lib/common-ruby-difio.rb', line 30

def get_module_list()
	Bundler.load.lock
	gems = []
	Bundler.load.specs.each do |g|
		gems << {'n' => g.name, 'v' => "#{g.version}#{g.git_version}" }
	end
	return gems
end

#post_to_difioObject



45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
# File 'lib/common-ruby-difio.rb', line 45

def post_to_difio()
	gems = get_module_list()
	json = get_deps_as_json(gems)
	this_module = vendor_module = nil
	gems.each do |m|
		if m['n'] == "common-ruby-difio"
			this_module = m['n'] + '/' + m['v']
		end
		if m['n'] =~ /difio-(.*?)-ruby/
			vendor_module = m['n'] + '/' + m['v']
		end
	end
	headers = {
		'User-Agent' =>  vendor_module + ' ' + this_module
	}			
	uri = URI(@@difio_url)
	req = Net::HTTP::Post.new(uri.path,headers)
	req.set_form_data({ 'json_data' => json})
	http = Net::HTTP.new(uri.host, uri.port)
	http.use_ssl = true
	#http.set_debug_output $stderr
	res = http.start do |h|
		h.request(req)
	end

	res
end