Class: Monupco::MonupcoBase
- Inherits:
-
Object
- Object
- Monupco::MonupcoBase
- Defined in:
- lib/common-ruby-monupco.rb,
lib/common-ruby-monupco/version.rb
Constant Summary collapse
- VERSION =
"0.0.5"- @@monupco_url =
"https://monupco-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
- #cli ⇒ Object
- #get_deps_as_json(gems = nil) ⇒ Object
- #get_module_list ⇒ Object
- #post_to_monupco ⇒ Object
Class Method Details
.configure(options) ⇒ Object
21 22 23 24 25 26 27 28 |
# File 'lib/common-ruby-monupco.rb', line 21 def self.configure() if ['url'] @@monupco_url = ['url'] end @@post_data.each do |k,v| @@post_data[k] = [k] if [k] end end |
Instance Method Details
#cli ⇒ Object
73 74 75 76 77 78 79 80 81 82 83 84 85 |
# File 'lib/common-ruby-monupco.rb', line 73 def cli() if ARGV.include? '--printJSON' puts get_deps_as_json() exit end result = post_to_monupco() case result when Net::HTTPSuccess puts "Monupco: #{result.body}" else puts "Monupco: #{result.code} #{result.}" end end |
#get_deps_as_json(gems = nil) ⇒ Object
39 40 41 42 43 |
# File 'lib/common-ruby-monupco.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_list ⇒ Object
30 31 32 33 34 35 36 37 |
# File 'lib/common-ruby-monupco.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_monupco ⇒ Object
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-monupco.rb', line 45 def post_to_monupco() gems = get_module_list() json = get_deps_as_json(gems) this_module = vendor_module = nil gems.each do |m| if m['n'] == "common-ruby-monupco" this_module = m['n'] + '/' + m['v'] end if m['n'] =~ /monupco-(.*?)-ruby/ vendor_module = m['n'] + '/' + m['v'] end end headers = { 'User-Agent' => vendor_module + ' ' + this_module } uri = URI(@@monupco_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 |