common-ruby-difio 2.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/.gitignore ADDED
@@ -0,0 +1,6 @@
1
+ *.gem
2
+ .bundle
3
+ Gemfile.lock
4
+ pkg/*
5
+
6
+ *~
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source "http://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in common-ruby-difio.gemspec
4
+ gemspec
data/LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2012, Svetlozar Argirov <zarrro [AT] gmail.com>
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining a copy
4
+ of this software and associated documentation files (the "Software"), to deal
5
+ in the Software without restriction, including without limitation the rights
6
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7
+ copies of the Software, and to permit persons to whom the Software is
8
+ furnished to do so, subject to the following conditions:
9
+
10
+ The above copyright notice and this permission notice shall be included in
11
+ all copies or substantial portions of the Software.
12
+
13
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
19
+ THE SOFTWARE.
20
+
data/README.md ADDED
@@ -0,0 +1,4 @@
1
+ This is a generic Ruby module used by Difio.
2
+
3
+ If you want to install into your Ruby application see
4
+ the difio-\<vendor\>-ruby packages for usage.
data/Rakefile ADDED
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
@@ -0,0 +1,24 @@
1
+ # -*- encoding: utf-8 -*-
2
+ $:.push File.expand_path("../lib", __FILE__)
3
+ require "common-ruby-difio/version"
4
+
5
+ Gem::Specification.new do |s|
6
+ s.name = "common-ruby-difio"
7
+ s.version = Difio::DifioBase::VERSION
8
+ s.authors = ["Svetlozar Argirov"]
9
+ s.email = ["zarrro@gmail.com"]
10
+ s.homepage = "http://github.com/difio/common-ruby-difio"
11
+ s.summary = %q{Common module for Difio ruby clients}
12
+ s.description = %q{Common module for Difio ruby clients. Not intended for direct use. Use a difio-\<vendor\>-ruby gem instead. }
13
+
14
+ s.rubyforge_project = "common-ruby-difio"
15
+
16
+ s.files = `git ls-files`.split("\n")
17
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
18
+ s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
19
+ s.require_paths = ["lib"]
20
+
21
+ # specify any dependencies here; for example:
22
+ # s.add_development_dependency "rspec"
23
+ s.add_runtime_dependency "json"
24
+ end
@@ -0,0 +1,87 @@
1
+ require "common-ruby-difio/version"
2
+ require "bundler"
3
+ require 'net/http'
4
+ require 'net/https'
5
+ require 'json'
6
+
7
+ module Difio
8
+ class DifioBase
9
+ @@difio_url = "https://difio-otb.rhcloud.com/application/register/"
10
+ @@post_data = {
11
+ 'user_id' => nil,
12
+ 'app_name' => nil,
13
+ 'app_uuid' => nil,
14
+ 'app_type' => 'Ruby',
15
+ 'app_url' => nil,
16
+ 'app_vendor' => nil,
17
+ 'pkg_type' => 1,
18
+ 'installed' => [],
19
+ }
20
+
21
+ def self.configure(options)
22
+ if options['url']
23
+ @@difio_url = options['url']
24
+ end
25
+ @@post_data.each do |k,v|
26
+ @@post_data[k] = options[k] if options[k]
27
+ end
28
+ end
29
+
30
+ def get_module_list()
31
+ Bundler.load.lock
32
+ gems = []
33
+ Bundler.load.specs.each do |g|
34
+ gems << {'n' => g.name, 'v' => "#{g.version}#{g.git_version}" }
35
+ end
36
+ return gems
37
+ end
38
+
39
+ def get_deps_as_json(gems=nil)
40
+ data = @@post_data.clone()
41
+ data['installed'] = gems || get_module_list()
42
+ return JSON.dump(data)
43
+ end
44
+
45
+ def post_to_difio()
46
+ gems = get_module_list()
47
+ json = get_deps_as_json(gems)
48
+ this_module = vendor_module = nil
49
+ gems.each do |m|
50
+ if m['n'] == "common-ruby-difio"
51
+ this_module = m['n'] + '/' + m['v']
52
+ end
53
+ if m['n'] =~ /difio-(.*?)-ruby/
54
+ vendor_module = m['n'] + '/' + m['v']
55
+ end
56
+ end
57
+ headers = {
58
+ 'User-Agent' => vendor_module + ' ' + this_module
59
+ }
60
+ uri = URI(@@difio_url)
61
+ req = Net::HTTP::Post.new(uri.path,headers)
62
+ req.set_form_data({ 'json_data' => json})
63
+ http = Net::HTTP.new(uri.host, uri.port)
64
+ http.use_ssl = true
65
+ #http.set_debug_output $stderr
66
+ res = http.start do |h|
67
+ h.request(req)
68
+ end
69
+
70
+ res
71
+ end
72
+
73
+ def cli()
74
+ if ARGV.include? '--printJSON'
75
+ puts get_deps_as_json()
76
+ exit
77
+ end
78
+ result = post_to_difio()
79
+ case result
80
+ when Net::HTTPSuccess
81
+ puts "difio: #{result.body}"
82
+ else
83
+ puts "difio: #{result.code} #{result.message}"
84
+ end
85
+ end
86
+ end
87
+ end
@@ -0,0 +1,5 @@
1
+ module Difio
2
+ class DifioBase
3
+ VERSION = "2.0.0"
4
+ end
5
+ end
metadata ADDED
@@ -0,0 +1,70 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: common-ruby-difio
3
+ version: !ruby/object:Gem::Version
4
+ version: 2.0.0
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Svetlozar Argirov
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-07-10 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: json
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: '0'
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ! '>='
28
+ - !ruby/object:Gem::Version
29
+ version: '0'
30
+ description: ! 'Common module for Difio ruby clients. Not intended for direct use.
31
+ Use a difio-\<vendor\>-ruby gem instead. '
32
+ email:
33
+ - zarrro@gmail.com
34
+ executables: []
35
+ extensions: []
36
+ extra_rdoc_files: []
37
+ files:
38
+ - .gitignore
39
+ - Gemfile
40
+ - LICENSE
41
+ - README.md
42
+ - Rakefile
43
+ - common-ruby-difio.gemspec
44
+ - lib/common-ruby-difio.rb
45
+ - lib/common-ruby-difio/version.rb
46
+ homepage: http://github.com/difio/common-ruby-difio
47
+ licenses: []
48
+ post_install_message:
49
+ rdoc_options: []
50
+ require_paths:
51
+ - lib
52
+ required_ruby_version: !ruby/object:Gem::Requirement
53
+ none: false
54
+ requirements:
55
+ - - ! '>='
56
+ - !ruby/object:Gem::Version
57
+ version: '0'
58
+ required_rubygems_version: !ruby/object:Gem::Requirement
59
+ none: false
60
+ requirements:
61
+ - - ! '>='
62
+ - !ruby/object:Gem::Version
63
+ version: '0'
64
+ requirements: []
65
+ rubyforge_project: common-ruby-difio
66
+ rubygems_version: 1.8.24
67
+ signing_key:
68
+ specification_version: 3
69
+ summary: Common module for Difio ruby clients
70
+ test_files: []