kimotter 0.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/.document ADDED
@@ -0,0 +1,5 @@
1
+ README.rdoc
2
+ lib/**/*.rb
3
+ bin/*
4
+ features/**/*.feature
5
+ LICENSE
data/.gitignore ADDED
@@ -0,0 +1,5 @@
1
+ *.sw?
2
+ .DS_Store
3
+ coverage
4
+ rdoc
5
+ pkg
data/LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2009 kimoto
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.rdoc ADDED
@@ -0,0 +1,18 @@
1
+ = kimotter
2
+
3
+ Description goes here.
4
+
5
+ == Note on Patches/Pull Requests
6
+
7
+ * Fork the project.
8
+ * Make your feature addition or bug fix.
9
+ * Add tests for it. This is important so I don't break it in a
10
+ future version unintentionally.
11
+ * Commit, do not mess with rakefile, version, or history.
12
+ (if you want to have your own version, that is fine but
13
+ bump version in a commit by itself I can ignore when I pull)
14
+ * Send me a pull request. Bonus points for topic branches.
15
+
16
+ == Copyright
17
+
18
+ Copyright (c) 2012 kimoto. See LICENSE for details.
data/Rakefile ADDED
@@ -0,0 +1,56 @@
1
+ require 'rubygems'
2
+ require 'rake'
3
+
4
+ begin
5
+ require 'jeweler'
6
+ Jeweler::Tasks.new do |gem|
7
+ gem.name = "kimotter"
8
+ gem.summary = %Q{kimotter}
9
+ gem.description = %Q{kiomtter}
10
+ gem.email = "peerler@gmail.com"
11
+ gem.homepage = "http://github.com/kimoto/kimotter"
12
+ gem.authors = ["kimoto"]
13
+ gem.add_development_dependency "thoughtbot-shoulda"
14
+ # gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
15
+ end
16
+ rescue LoadError
17
+ puts "Jeweler (or a dependency) not available. Install it with: sudo gem install jeweler"
18
+ end
19
+
20
+ require 'rake/testtask'
21
+ Rake::TestTask.new(:test) do |test|
22
+ test.libs << 'lib' << 'test'
23
+ test.pattern = 'test/**/*_test.rb'
24
+ test.verbose = true
25
+ end
26
+
27
+ begin
28
+ require 'rcov/rcovtask'
29
+ Rcov::RcovTask.new do |test|
30
+ test.libs << 'test'
31
+ test.pattern = 'test/**/*_test.rb'
32
+ test.verbose = true
33
+ end
34
+ rescue LoadError
35
+ task :rcov do
36
+ abort "RCov is not available. In order to run rcov, you must: sudo gem install spicycode-rcov"
37
+ end
38
+ end
39
+
40
+ task :test => :check_dependencies
41
+
42
+ task :default => :test
43
+
44
+ require 'rake/rdoctask'
45
+ Rake::RDocTask.new do |rdoc|
46
+ if File.exist?('VERSION')
47
+ version = File.read('VERSION')
48
+ else
49
+ version = ""
50
+ end
51
+
52
+ rdoc.rdoc_dir = 'rdoc'
53
+ rdoc.title = "kimotter #{version}"
54
+ rdoc.rdoc_files.include('README*')
55
+ rdoc.rdoc_files.include('lib/**/*.rb')
56
+ end
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.0.0
data/bin/kimotter ADDED
@@ -0,0 +1,50 @@
1
+ #!/usr/bin/env ruby
2
+ # encoding: utf-8
3
+ $LOAD_PATH << File.expand_path(File.join(File.dirname(__FILE__), "../lib"))
4
+ require 'kimotter'
5
+ require 'logger'
6
+
7
+ if $0 == __FILE__
8
+ require 'optparse'
9
+ options = {}
10
+ OptionParser.new{ |opts|
11
+ opts.banner = "Usage: #{$0} [options] tweet_message"
12
+ opts.on("-d", "--debug", "Debug Mode"){ |v|
13
+ options[:debug_mode] = true
14
+ }
15
+ opts.on("-f", "--force", "Force execute, ignore api limit"){ |v|
16
+ options[:force_execute] = true
17
+ }
18
+ }.parse!
19
+
20
+ message = ARGV.shift
21
+ raise "argument error" unless message
22
+
23
+ logger = options[:debug_mode] ? Logger.new(STDERR) : Logger.new(nil)
24
+ kimotter = Kimotter.new(:logger => logger)
25
+
26
+ kimotter.fetch_api_limit
27
+ if !options[:force_execute] and kimotter.api_limit?
28
+ puts "u cant use this api now(api limit)"
29
+ puts "try again later or retry with --force option (ignore API limit)"
30
+ exit(1)
31
+ end
32
+
33
+ print kimotter.confirm_msg + "[y/N] "
34
+ if user_input_line = $stdin.gets
35
+ if user_input_line =~ /^(yes|y)$/i
36
+ puts "hi kimoto. try to tweet your message"
37
+ puts message
38
+ kimotter.tweet(message)
39
+ puts "done"
40
+ exit(0)
41
+ else
42
+ puts "u guys so fucking retard"
43
+ exit(3)
44
+ end
45
+ else
46
+ puts "omg?"
47
+ exit(2)
48
+ end
49
+ end
50
+
data/lib/kimotter.rb ADDED
@@ -0,0 +1,89 @@
1
+ # encoding: utf-8
2
+ require 'mechanize'
3
+ require 'nokogiri'
4
+ require 'logger'
5
+
6
+ class Kimotter
7
+ class APILimit
8
+ attr_accessor :limit
9
+ attr_accessor :used
10
+
11
+ def initialize
12
+ @current = @max = nil
13
+ end
14
+ end
15
+
16
+ attr_reader :confirm_msg
17
+
18
+ def self.tweet(message, options={})
19
+ raise ArgumentError unless message
20
+
21
+ kimotter = self.new(options)
22
+ kimotter.fetch_api_limit
23
+ kimotter.tweet(message)
24
+ end
25
+
26
+ def initialize(options={})
27
+ default_options = {
28
+ :api => 'http://api.ma.la/twitter/',
29
+ :logger => Logger.new(nil), # nop logger
30
+ :user_agent => 'kimotter'
31
+ }
32
+ options = default_options.merge(options)
33
+
34
+ @logger = options[:logger]
35
+ @api = options[:api]
36
+
37
+ @agent = Mechanize.new{ |agent|
38
+ agent.user_agent = options[:user_agent]
39
+ }
40
+
41
+ @api_limit = APILimit.new
42
+ @confirm_msg = nil
43
+
44
+ @logger.info "setup finished"
45
+ end
46
+
47
+ def fetch_api_limit
48
+ @logger.info "try to fetch api limit: URL is #{@api.inspect}"
49
+ @agent.get(@api)
50
+ @logger.info "successful fetched api limit"
51
+
52
+ load_from_mala_html(@agent.page.body)
53
+ end
54
+
55
+ def load_from_mala_html(content_body)
56
+ @logger.info "try to parse api limit information"
57
+ doc = Nokogiri(content_body)
58
+ body_text = doc.search("html > body").text
59
+
60
+ if body_text =~ /API\s*Limit:\s*(\d+)\s*\/\s*(\d+)/
61
+ @api_limit.used = Regexp.last_match(1).to_i
62
+ @api_limit.limit = Regexp.last_match(2).to_i
63
+
64
+ @logger.info "successful parsed api limit"
65
+ else
66
+ raise "not found api limit: #{body_text.inspect}"
67
+ end
68
+
69
+ begin
70
+ @confirm_msg = doc.search("body > form > input[@type='checkbox']").first.next.text.chomp
71
+ rescue => ex
72
+ raise "not found confirm_msg: #{ex.inspect}"
73
+ end
74
+ end
75
+
76
+ def tweet(message)
77
+ @logger.info "try to tweet: #{message.inspect}"
78
+ @agent.page.form_with(:action => '/twitter/'){ |form|
79
+ form.field_with(:name => 'status').value = message
80
+ form.checkbox_with(:name => 'is_kimoto').check
81
+ form.click_button
82
+ }
83
+ @logger.info "successful tweeted"
84
+ end
85
+
86
+ def api_limit?
87
+ (@api_limit.used >= @api_limit.limit)
88
+ end
89
+ end
@@ -0,0 +1,7 @@
1
+ require 'test_helper'
2
+
3
+ class KimotterTest < Test::Unit::TestCase
4
+ should "dont test" do
5
+ true
6
+ end
7
+ end
@@ -0,0 +1,10 @@
1
+ require 'rubygems'
2
+ require 'test/unit'
3
+ require 'shoulda'
4
+
5
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
6
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
7
+ require 'kimotter'
8
+
9
+ class Test::Unit::TestCase
10
+ end
metadata ADDED
@@ -0,0 +1,87 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: kimotter
3
+ version: !ruby/object:Gem::Version
4
+ prerelease: false
5
+ segments:
6
+ - 0
7
+ - 0
8
+ - 0
9
+ version: 0.0.0
10
+ platform: ruby
11
+ authors:
12
+ - kimoto
13
+ autorequire:
14
+ bindir: bin
15
+ cert_chain: []
16
+
17
+ date: 2012-01-20 00:00:00 +09:00
18
+ default_executable: kimotter
19
+ dependencies:
20
+ - !ruby/object:Gem::Dependency
21
+ name: thoughtbot-shoulda
22
+ prerelease: false
23
+ requirement: &id001 !ruby/object:Gem::Requirement
24
+ none: false
25
+ requirements:
26
+ - - ">="
27
+ - !ruby/object:Gem::Version
28
+ segments:
29
+ - 0
30
+ version: "0"
31
+ type: :development
32
+ version_requirements: *id001
33
+ description: kiomtter
34
+ email: peerler@gmail.com
35
+ executables:
36
+ - kimotter
37
+ extensions: []
38
+
39
+ extra_rdoc_files:
40
+ - LICENSE
41
+ - README.rdoc
42
+ files:
43
+ - .document
44
+ - .gitignore
45
+ - LICENSE
46
+ - README.rdoc
47
+ - Rakefile
48
+ - VERSION
49
+ - lib/kimotter.rb
50
+ - test/kimotter_test.rb
51
+ - test/test_helper.rb
52
+ - bin/kimotter
53
+ has_rdoc: true
54
+ homepage: http://github.com/kimoto/kimotter
55
+ licenses: []
56
+
57
+ post_install_message:
58
+ rdoc_options:
59
+ - --charset=UTF-8
60
+ require_paths:
61
+ - lib
62
+ required_ruby_version: !ruby/object:Gem::Requirement
63
+ none: false
64
+ requirements:
65
+ - - ">="
66
+ - !ruby/object:Gem::Version
67
+ segments:
68
+ - 0
69
+ version: "0"
70
+ required_rubygems_version: !ruby/object:Gem::Requirement
71
+ none: false
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ segments:
76
+ - 0
77
+ version: "0"
78
+ requirements: []
79
+
80
+ rubyforge_project:
81
+ rubygems_version: 1.3.7
82
+ signing_key:
83
+ specification_version: 3
84
+ summary: kimotter
85
+ test_files:
86
+ - test/test_helper.rb
87
+ - test/kimotter_test.rb