tangzero-basemashup 0.8.5

Sign up to get free protection for your applications and to get access to all the features.
data/README.textile ADDED
@@ -0,0 +1,24 @@
1
+ h2. LICENSE:
2
+
3
+ (The MIT License)
4
+
5
+ Copyright (c) 2009 TangZero
6
+
7
+ Permission is hereby granted, free of charge, to any person obtaining
8
+ a copy of this software and associated documentation files (the
9
+ 'Software'), to deal in the Software without restriction, including
10
+ without limitation the rights to use, copy, modify, merge, publish,
11
+ distribute, sublicense, and/or sell copies of the Software, and to
12
+ permit persons to whom the Software is furnished to do so, subject to
13
+ the following conditions:
14
+
15
+ The above copyright notice and this permission notice shall be
16
+ included in all copies or substantial portions of the Software.
17
+
18
+ THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
19
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
20
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
21
+ IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
22
+ CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
23
+ TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
24
+ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/Rakefile ADDED
@@ -0,0 +1,49 @@
1
+ require 'rubygems'
2
+ require 'rubygems/specification'
3
+ require 'rake'
4
+ require 'rake/gempackagetask'
5
+ require 'spec/rake/spectask'
6
+
7
+ GEM = "basemashup"
8
+ GEM_VERSION = "0.8.5"
9
+ SUMMARY = "Base Classes and Utils for Mashups Librarys"
10
+ AUTHOR = "TangZero"
11
+ EMAIL = "t4ngz3r0@gmail.com"
12
+ HOMEPAGE = "http://github.com/tangzero/basemashup"
13
+
14
+
15
+ spec = Gem::Specification.new do |s|
16
+ s.name = GEM
17
+ s.version = GEM_VERSION
18
+ s.platform = Gem::Platform::RUBY
19
+ s.summary = SUMMARY
20
+ s.require_paths = ['lib']
21
+ s.files = FileList['lib/**/*.rb', '[A-Z]*'].to_a
22
+
23
+ s.author = AUTHOR
24
+ s.email = EMAIL
25
+ s.homepage = HOMEPAGE
26
+
27
+ s.rubyforge_project = GEM # GitHub bug, gem isn't being build when this miss
28
+ end
29
+
30
+ Spec::Rake::SpecTask.new do |t|
31
+ t.spec_files = FileList['spec/**/*_spec.rb']
32
+ t.spec_opts = %w(-fs --color)
33
+ end
34
+
35
+ Rake::GemPackageTask.new(spec) do |pkg|
36
+ pkg.gem_spec = spec
37
+ end
38
+
39
+ desc "Install the gem locally"
40
+ task :install => [:package] do
41
+ sh %{sudo gem install pkg/#{GEM}-#{GEM_VERSION}}
42
+ end
43
+
44
+ desc "Create a gemspec file"
45
+ task :make_spec do
46
+ File.open("#{GEM}.gemspec", "w") do |file|
47
+ file.puts spec.to_ruby
48
+ end
49
+ end
data/lib/basemashup.rb ADDED
@@ -0,0 +1,8 @@
1
+ require "uri"
2
+ require "open-uri"
3
+
4
+ Dir["#{File.dirname(__FILE__)}/basemashup/*.rb"].sort.each { |lib| require lib }
5
+
6
+ module BaseMashup
7
+
8
+ end
@@ -0,0 +1,30 @@
1
+ module BaseMashup
2
+
3
+ class Request
4
+
5
+ def self.get(url, params = {}, options = {})
6
+ options = {:proxy => proxy?}.merge(options)
7
+ uri = get_uri(url, params)
8
+ return uri.open(options).collect.join
9
+ end
10
+
11
+ private
12
+ def self.proxy?
13
+ ENV.include?("http_proxy") || ENV.include?("HTTP_PROXY")
14
+ end
15
+
16
+ def self.to_query(params = {})
17
+ query = []
18
+ params.each { |k, v| query << "#{k}=#{v}" }
19
+ URI.encode(query.join("&"))
20
+ end
21
+
22
+ def self.get_uri(url, params)
23
+ uri = URI.parse(URI.encode(url))
24
+ uri.query = to_query(params) if params.size > 0
25
+ return uri
26
+ end
27
+
28
+ end
29
+
30
+ end
@@ -0,0 +1,33 @@
1
+ module BaseMashup
2
+
3
+ class Result
4
+
5
+ def initialize(data)
6
+ if data.kind_of?(Hash)
7
+ data.each do |key, value|
8
+ set_att(key, make_result(value))
9
+ end
10
+ end
11
+ end
12
+
13
+ private
14
+ def make_result(value)
15
+ if value.kind_of?(String) or value.kind_of?(Numeric) \
16
+ or value.kind_of?(TrueClass) or value.kind_of?(FalseClass) \
17
+ or value.kind_of?(Symbol)
18
+ value
19
+ elsif value.kind_of?(Hash)
20
+ Result.new(value)
21
+ elsif value.kind_of?(Array)
22
+ value.collect {|v| make_result(v)}
23
+ end
24
+ end
25
+
26
+ def set_att(key, value)
27
+ instance_variable_set("@#{key}", value)
28
+ instance_eval("def #{key}; @#{key}; end")
29
+ end
30
+
31
+ end
32
+
33
+ end
metadata ADDED
@@ -0,0 +1,57 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: tangzero-basemashup
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.8.5
5
+ platform: ruby
6
+ authors:
7
+ - TangZero
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+
12
+ date: 2009-05-07 00:00:00 -07:00
13
+ default_executable:
14
+ dependencies: []
15
+
16
+ description:
17
+ email: t4ngz3r0@gmail.com
18
+ executables: []
19
+
20
+ extensions: []
21
+
22
+ extra_rdoc_files: []
23
+
24
+ files:
25
+ - lib/basemashup.rb
26
+ - lib/basemashup/result.rb
27
+ - lib/basemashup/request.rb
28
+ - README.textile
29
+ - Rakefile
30
+ has_rdoc: false
31
+ homepage: http://github.com/tangzero/basemashup
32
+ post_install_message:
33
+ rdoc_options: []
34
+
35
+ require_paths:
36
+ - lib
37
+ required_ruby_version: !ruby/object:Gem::Requirement
38
+ requirements:
39
+ - - ">="
40
+ - !ruby/object:Gem::Version
41
+ version: "0"
42
+ version:
43
+ required_rubygems_version: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: "0"
48
+ version:
49
+ requirements: []
50
+
51
+ rubyforge_project: basemashup
52
+ rubygems_version: 1.2.0
53
+ signing_key:
54
+ specification_version: 3
55
+ summary: Base Classes and Utils for Mashups Librarys
56
+ test_files: []
57
+