goldfish 0.0.1

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.
File without changes
@@ -0,0 +1,3 @@
1
+ === 0.0.1 2012-03-08
2
+
3
+ * get/post poi data
@@ -0,0 +1,13 @@
1
+ History.txt
2
+ Manifest.txt
3
+ README.rdoc
4
+ Rakefile
5
+ lib/goldfish.rb
6
+ lib/goldfish/poi.rb
7
+ script/console
8
+ script/destroy
9
+ script/generate
10
+ test/test_goldfish-poi.rb
11
+ test/test_helper.rb
12
+ samples/get.rb
13
+ samples/post.rb
@@ -0,0 +1,51 @@
1
+ = goldfish rubygem
2
+
3
+ * http://github.com/shokai/goldfish-rubygem
4
+
5
+ == DESCRIPTION:
6
+
7
+ rubygem for client of GoldFish (https://github.com/shokai/goldfish) and POI (https://github.com/shokai/goldfish-poi).
8
+
9
+ == SYNOPSIS:
10
+
11
+ wait response with comet.
12
+
13
+ require 'goldfish'
14
+
15
+ poi = GoldFish::Poi.new
16
+ res = poi.get(tag_name)
17
+
18
+
19
+ post data.
20
+
21
+ poi.post(tag_name, 'hello!')
22
+
23
+
24
+ == INSTALL:
25
+
26
+ * gem install goldfish
27
+
28
+ == LICENSE:
29
+
30
+ (The MIT License)
31
+
32
+ Copyright (c) 2012 Sho Hashimoto
33
+
34
+ Permission is hereby granted, free of charge, to any person obtaining
35
+ a copy of this software and associated documentation files (the
36
+ 'Software'), to deal in the Software without restriction, including
37
+ without limitation the rights to use, copy, modify, merge, publish,
38
+ distribute, sublicense, and/or sell copies of the Software, and to
39
+ permit persons to whom the Software is furnished to do so, subject to
40
+ the following conditions:
41
+
42
+ The above copyright notice and this permission notice shall be
43
+ included in all copies or substantial portions of the Software.
44
+
45
+ THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
46
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
47
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
48
+ IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
49
+ CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
50
+ TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
51
+ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,25 @@
1
+ require 'rubygems'
2
+ gem 'hoe', '>= 2.1.0'
3
+ require 'hoe'
4
+ require 'fileutils'
5
+ require './lib/goldfish'
6
+
7
+ Hoe.plugin :newgem
8
+ # Hoe.plugin :website
9
+ # Hoe.plugin :cucumberfeatures
10
+
11
+ # Generate all the Rake tasks
12
+ # Run 'rake -T' to see list of generated tasks (from gem root directory)
13
+ $hoe = Hoe.spec 'goldfish' do
14
+ self.developer 'Sho Hashimoto', 'hashimoto@shokai.org'
15
+ self.rubyforge_name = self.name # TODO this is default value
16
+ # self.extra_deps = [['activesupport','>= 2.0.2']]
17
+
18
+ end
19
+
20
+ require 'newgem/tasks'
21
+ Dir['tasks/**/*.rake'].each { |t| load t }
22
+
23
+ # TODO - want other tests/tasks run by default? Add them to the list
24
+ # remove_task :default
25
+ # task :default => [:spec, :features]
@@ -0,0 +1,10 @@
1
+ $:.unshift(File.dirname(__FILE__)) unless
2
+ $:.include?(File.dirname(__FILE__)) || $:.include?(File.expand_path(File.dirname(__FILE__)))
3
+
4
+ require 'goldfish/poi'
5
+
6
+ module GoldFish
7
+ class Poi
8
+ VERSION = '0.0.1'
9
+ end
10
+ end
@@ -0,0 +1,47 @@
1
+ require 'net/http'
2
+ require 'uri'
3
+
4
+ module GoldFish
5
+ class Poi
6
+
7
+ class Error < StandardError
8
+ end
9
+
10
+ attr_reader :api
11
+
12
+ def initialize(api='http://ubif.org:8932')
13
+ api = api.to_s unless api.class != String
14
+ api.gsub!(/\/$/,'')
15
+ raise Error.new "#{api} is Invalid URI" unless api =~ /^https?:\/\/.+/
16
+ @api = api
17
+ end
18
+
19
+ def get(tag, &block)
20
+ uri = URI.parse "#{@api}/#{tag}"
21
+ loop do
22
+ begin
23
+ res = Net::HTTP.start(uri.host, uri.port).get(uri.path)
24
+ rescue StandardError, Timeout::Error
25
+ sleep 1
26
+ next
27
+ end
28
+ if res.code.to_i == 200
29
+ yield res if block_given?
30
+ return res.body
31
+ end
32
+ sleep 1
33
+ end
34
+ end
35
+
36
+ def post(tag, data)
37
+ uri = URI.parse "#{@api}/to_#{tag}"
38
+ begin
39
+ res = Net::HTTP.start(uri.host, uri.port).post(uri.path, data)
40
+ rescue StandardError, Timeout::Error => e
41
+ raise Error.new e.to_s
42
+ end
43
+ res
44
+ end
45
+
46
+ end
47
+ end
@@ -0,0 +1,12 @@
1
+ #!/usr/bin/env ruby
2
+ $:.unshift File.dirname(__FILE__)+'/../lib'
3
+ require 'rubygems'
4
+
5
+ require 'goldfish'
6
+
7
+
8
+ poi = GoldFish::Poi.new
9
+ poi.get('test'){|res|
10
+ puts res.body
11
+ }
12
+
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env ruby
2
+ $:.unshift File.dirname(__FILE__)+'/../lib'
3
+ require 'rubygems'
4
+
5
+ require 'goldfish'
6
+
7
+ poi = GoldFish::Poi.new
8
+ puts poi.post('test', Time.now.to_s)
@@ -0,0 +1,10 @@
1
+ #!/usr/bin/env ruby
2
+ # File: script/console
3
+ irb = RUBY_PLATFORM =~ /(:?mswin|mingw)/ ? 'irb.bat' : 'irb'
4
+
5
+ libs = " -r irb/completion"
6
+ # Perhaps use a console_lib to store any extra methods I may want available in the cosole
7
+ # libs << " -r #{File.dirname(__FILE__) + '/../lib/console_lib/console_logger.rb'}"
8
+ libs << " -r #{File.dirname(__FILE__) + '/../lib/goldfish-poi.rb'}"
9
+ puts "Loading goldfish-poi gem"
10
+ exec "#{irb} #{libs} --simple-prompt"
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+ APP_ROOT = File.expand_path(File.join(File.dirname(__FILE__), '..'))
3
+
4
+ begin
5
+ require 'rubigen'
6
+ rescue LoadError
7
+ require 'rubygems'
8
+ require 'rubigen'
9
+ end
10
+ require 'rubigen/scripts/destroy'
11
+
12
+ ARGV.shift if ['--help', '-h'].include?(ARGV[0])
13
+ RubiGen::Base.use_component_sources! [:rubygems, :newgem, :newgem_theme, :test_unit]
14
+ RubiGen::Scripts::Destroy.new.run(ARGV)
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+ APP_ROOT = File.expand_path(File.join(File.dirname(__FILE__), '..'))
3
+
4
+ begin
5
+ require 'rubigen'
6
+ rescue LoadError
7
+ require 'rubygems'
8
+ require 'rubigen'
9
+ end
10
+ require 'rubigen/scripts/generate'
11
+
12
+ ARGV.shift if ['--help', '-h'].include?(ARGV[0])
13
+ RubiGen::Base.use_component_sources! [:rubygems, :newgem, :newgem_theme, :test_unit]
14
+ RubiGen::Scripts::Generate.new.run(ARGV)
@@ -0,0 +1,26 @@
1
+ require File.dirname(__FILE__) + '/test_helper.rb'
2
+
3
+ class TestGoldfishPoi < Test::Unit::TestCase
4
+
5
+ def setup
6
+ @tag = "test_#{Time.now.to_i}_#{Time.now.usec}"
7
+ @data = "data_#{Time.now.to_i}_#{Time.now.usec}"
8
+ @poi = GoldFish::Poi.new('http://ubif.org:8932')
9
+ end
10
+
11
+ def test_post_get
12
+ @poi.post(@tag, @data)
13
+ @res = @poi.get(@tag)
14
+ assert true if @res == @data
15
+ end
16
+
17
+ def test_commet
18
+ Thread.new do
19
+ @res = @poi.get(@tag)
20
+ end
21
+ sleep 3
22
+ @poi.post(@tag, @data)
23
+ assert true if @res == @data
24
+ end
25
+
26
+ end
@@ -0,0 +1,3 @@
1
+ require 'stringio'
2
+ require 'test/unit'
3
+ require File.dirname(__FILE__) + '/../lib/goldfish'
metadata ADDED
@@ -0,0 +1,128 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: goldfish
3
+ version: !ruby/object:Gem::Version
4
+ hash: 29
5
+ prerelease:
6
+ segments:
7
+ - 0
8
+ - 0
9
+ - 1
10
+ version: 0.0.1
11
+ platform: ruby
12
+ authors:
13
+ - Sho Hashimoto
14
+ autorequire:
15
+ bindir: bin
16
+ cert_chain: []
17
+
18
+ date: 2012-03-08 00:00:00 Z
19
+ dependencies:
20
+ - !ruby/object:Gem::Dependency
21
+ name: rdoc
22
+ prerelease: false
23
+ requirement: &id001 !ruby/object:Gem::Requirement
24
+ none: false
25
+ requirements:
26
+ - - ~>
27
+ - !ruby/object:Gem::Version
28
+ hash: 19
29
+ segments:
30
+ - 3
31
+ - 10
32
+ version: "3.10"
33
+ type: :development
34
+ version_requirements: *id001
35
+ - !ruby/object:Gem::Dependency
36
+ name: newgem
37
+ prerelease: false
38
+ requirement: &id002 !ruby/object:Gem::Requirement
39
+ none: false
40
+ requirements:
41
+ - - ">="
42
+ - !ruby/object:Gem::Version
43
+ hash: 5
44
+ segments:
45
+ - 1
46
+ - 5
47
+ - 3
48
+ version: 1.5.3
49
+ type: :development
50
+ version_requirements: *id002
51
+ - !ruby/object:Gem::Dependency
52
+ name: hoe
53
+ prerelease: false
54
+ requirement: &id003 !ruby/object:Gem::Requirement
55
+ none: false
56
+ requirements:
57
+ - - ~>
58
+ - !ruby/object:Gem::Version
59
+ hash: 29
60
+ segments:
61
+ - 2
62
+ - 15
63
+ version: "2.15"
64
+ type: :development
65
+ version_requirements: *id003
66
+ description: rubygem for client of GoldFish (https://github.com/shokai/goldfish) and POI (https://github.com/shokai/goldfish-poi).
67
+ email:
68
+ - hashimoto@shokai.org
69
+ executables: []
70
+
71
+ extensions: []
72
+
73
+ extra_rdoc_files:
74
+ - History.txt
75
+ - Manifest.txt
76
+ - README.rdoc
77
+ files:
78
+ - History.txt
79
+ - Manifest.txt
80
+ - README.rdoc
81
+ - Rakefile
82
+ - lib/goldfish.rb
83
+ - lib/goldfish/poi.rb
84
+ - script/console
85
+ - script/destroy
86
+ - script/generate
87
+ - test/test_goldfish-poi.rb
88
+ - test/test_helper.rb
89
+ - samples/get.rb
90
+ - samples/post.rb
91
+ - .gemtest
92
+ homepage: http://github.com/shokai/goldfish-rubygem
93
+ licenses: []
94
+
95
+ post_install_message:
96
+ rdoc_options:
97
+ - --main
98
+ - README.rdoc
99
+ require_paths:
100
+ - lib
101
+ required_ruby_version: !ruby/object:Gem::Requirement
102
+ none: false
103
+ requirements:
104
+ - - ">="
105
+ - !ruby/object:Gem::Version
106
+ hash: 3
107
+ segments:
108
+ - 0
109
+ version: "0"
110
+ required_rubygems_version: !ruby/object:Gem::Requirement
111
+ none: false
112
+ requirements:
113
+ - - ">="
114
+ - !ruby/object:Gem::Version
115
+ hash: 3
116
+ segments:
117
+ - 0
118
+ version: "0"
119
+ requirements: []
120
+
121
+ rubyforge_project: goldfish
122
+ rubygems_version: 1.8.17
123
+ signing_key:
124
+ specification_version: 3
125
+ summary: rubygem for client of GoldFish (https://github.com/shokai/goldfish) and POI (https://github.com/shokai/goldfish-poi).
126
+ test_files:
127
+ - test/test_goldfish-poi.rb
128
+ - test/test_helper.rb