gaebot 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.
data/.gitignore ADDED
@@ -0,0 +1,17 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
data/Gemfile ADDED
@@ -0,0 +1,9 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in gaebot.gemspec
4
+ gemspec
5
+
6
+ gem 'mysql'
7
+ gem 'activesupport', :require => 'active_support/all'
8
+ gem 'activerecord'
9
+ gem 'sqlite3'
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2014 Taketo Yoshida
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,29 @@
1
+ # Gaebot
2
+
3
+ TODO: Write a gem description
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ gem 'gaebot'
10
+
11
+ And then execute:
12
+
13
+ $ bundle
14
+
15
+ Or install it yourself as:
16
+
17
+ $ gem install gaebot
18
+
19
+ ## Usage
20
+
21
+ TODO: Write usage instructions here
22
+
23
+ ## Contributing
24
+
25
+ 1. Fork it ( http://github.com/<my-github-username>/gaebot/fork )
26
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
27
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
28
+ 4. Push to the branch (`git push origin my-new-feature`)
29
+ 5. Create new Pull Request
data/Rakefile ADDED
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
data/config.yml ADDED
@@ -0,0 +1,3 @@
1
+ ---
2
+ :cursor: 0
3
+ :count: 20
data/create_table.rb ADDED
@@ -0,0 +1,21 @@
1
+ # -*- encoding: utf-8 -*-
2
+
3
+ require 'active_record'
4
+
5
+ ActiveRecord::Base.establish_connection(
6
+ :adapter => 'mysql',
7
+ :host => "your host",
8
+ :username => "your username",
9
+ :password => "your password",
10
+ :database => "your database"
11
+ )
12
+
13
+ ActiveRecord::Migration.create_table(:auto_tasks, :primary_key => "id") do |t|
14
+ t.column :date, :date
15
+ end
16
+
17
+ ActiveRecord::Migration.create_table(:users, :primary_key => "id") do |t|
18
+ t.column :access_token_key, :string
19
+ t.column :access_token_secret, :string
20
+ t.column :is_post, :string
21
+ end
data/gaebot.gemspec ADDED
@@ -0,0 +1,25 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'gaebot/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "gaebot"
8
+ spec.version = Gaebot::VERSION
9
+ spec.authors = ["Taketo Yoshida"]
10
+ spec.email = ["tamanyan.sss@gmail.com"]
11
+ spec.summary = %q{None}
12
+ spec.description = %q{None}
13
+ spec.homepage = ""
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files -z`.split("\x0")
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_development_dependency "bundler", "~> 1.5"
22
+ spec.add_development_dependency "rake"
23
+
24
+ spec.add_development_dependency "rspec"
25
+ end
@@ -0,0 +1,3 @@
1
+ module Gaebot
2
+ VERSION = "0.0.1"
3
+ end
data/lib/gaebot.rb ADDED
@@ -0,0 +1,98 @@
1
+ require "gaebot/version"
2
+ require 'yaml'
3
+ require 'active_record'
4
+
5
+ module Gaebot
6
+ class Task
7
+ def initialize(*args, &block)
8
+ @host = "localhost"
9
+ @database = "twimaker_game"
10
+ @user_model = nil
11
+ @tweets = []
12
+ instance_eval(&block)
13
+ ActiveRecord::Base.establish_connection(
14
+ :adapter => 'mysql',
15
+ :host => @host,
16
+ :username => @username,
17
+ :password => @password,
18
+ :database => @database
19
+ )
20
+ @config = Config.load()
21
+ end
22
+
23
+ def each_user
24
+ users = Gaebot::User.where("id > :id", {:id => @config[:cursor]}).order(:id).limit(@config[:count])
25
+ last_id = 0
26
+ users.each do |user|
27
+ unless AutoTask.done?(user.id)
28
+ yield user
29
+ task = AutoTask.new(:id => user.id)
30
+ task.do
31
+ last_id = user.id
32
+ end
33
+ end
34
+ unless users.empty?
35
+ @config[:cursor] = last_id
36
+ else
37
+ @config[:cursor] = 0
38
+ end
39
+ Config.save(@config)
40
+ end
41
+
42
+ def add_tweet(hash = {})
43
+ @tweets.push(
44
+ :msg => hash[:msg],
45
+ :token_key => hash[:token_key],
46
+ :token_secret => hash[:token_secret],
47
+ )
48
+ end
49
+
50
+ def output()
51
+ JSON.generate(@tweets)
52
+ end
53
+ end
54
+
55
+ class User < ActiveRecord::Base
56
+ end
57
+
58
+ class AutoTask < ActiveRecord::Base
59
+ def self.done?(id)
60
+ task = AutoTask.where(:id => id, :date => Time.now.strftime("%Y-%m-%d")).first
61
+ task != nil
62
+ end
63
+
64
+ def do()
65
+ if self.id != nil
66
+ self.date = Time.now.strftime("%Y-%m-%d")
67
+ begin
68
+ self.save!
69
+ rescue Exception => e
70
+ AutoTask.update(self.id, :date => self.date)
71
+ #task = AutoTask.where(:id => id).first
72
+ #task.date = self.date
73
+ #task.save!
74
+ end
75
+ end
76
+ end
77
+ end
78
+
79
+ class Config
80
+ def self.load()
81
+ if File.exist?("config.yml")
82
+ YAML.load_file("config.yml")
83
+ else
84
+ {:cursor => 0, :count => 100}
85
+ end
86
+ end
87
+
88
+ def self.save(config)
89
+ open("config.yml","w") do |f|
90
+ YAML.dump(config, f)
91
+ end
92
+ end
93
+ end
94
+
95
+ def self.new(*args, &block)
96
+ Task.new(args, &block)
97
+ end
98
+ end
@@ -0,0 +1,26 @@
1
+ # -*- encoding: utf-8 -*-
2
+
3
+ require 'spec_helper'
4
+ require 'gaebot'
5
+
6
+ describe Gaebot do
7
+ it "test" do
8
+ client = Gaebot.new do |test|
9
+ @host = "localhost"
10
+ @database = "twimaker_game"
11
+ @username = "root"
12
+ @password = "ty245769"
13
+ end
14
+
15
+ client.each_user do |user|
16
+ if user.is_post == 1
17
+ client.add_tweet(
18
+ :msg => "test",
19
+ :token_key => user.access_token_key,
20
+ :token_secret => user.access_token_secret
21
+ )
22
+ end
23
+ end
24
+ p client.output
25
+ end
26
+ end
@@ -0,0 +1,16 @@
1
+ # -*- encoding: utf-8 -*-
2
+
3
+ require 'bundler/setup'
4
+ Bundler.setup
5
+
6
+ require 'gaebot' # and any other gems you need
7
+
8
+ RSpec.configure do |config|
9
+ # some (optional) config here
10
+ end
11
+
12
+ RSpec::Matchers.define :my_matcher do |expected|
13
+ match do |actual|
14
+ true
15
+ end
16
+ end
metadata ADDED
@@ -0,0 +1,108 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: gaebot
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Taketo Yoshida
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2014-04-11 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: bundler
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ~>
20
+ - !ruby/object:Gem::Version
21
+ version: '1.5'
22
+ type: :development
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ~>
28
+ - !ruby/object:Gem::Version
29
+ version: '1.5'
30
+ - !ruby/object:Gem::Dependency
31
+ name: rake
32
+ requirement: !ruby/object:Gem::Requirement
33
+ none: false
34
+ requirements:
35
+ - - ! '>='
36
+ - !ruby/object:Gem::Version
37
+ version: '0'
38
+ type: :development
39
+ prerelease: false
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ! '>='
44
+ - !ruby/object:Gem::Version
45
+ version: '0'
46
+ - !ruby/object:Gem::Dependency
47
+ name: rspec
48
+ requirement: !ruby/object:Gem::Requirement
49
+ none: false
50
+ requirements:
51
+ - - ! '>='
52
+ - !ruby/object:Gem::Version
53
+ version: '0'
54
+ type: :development
55
+ prerelease: false
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ! '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ description: None
63
+ email:
64
+ - tamanyan.sss@gmail.com
65
+ executables: []
66
+ extensions: []
67
+ extra_rdoc_files: []
68
+ files:
69
+ - .gitignore
70
+ - Gemfile
71
+ - LICENSE.txt
72
+ - README.md
73
+ - Rakefile
74
+ - config.yml
75
+ - create_table.rb
76
+ - gaebot.gemspec
77
+ - lib/gaebot.rb
78
+ - lib/gaebot/version.rb
79
+ - spec/gaebot_spec.rb
80
+ - spec/spec_helper.rb
81
+ homepage: ''
82
+ licenses:
83
+ - MIT
84
+ post_install_message:
85
+ rdoc_options: []
86
+ require_paths:
87
+ - lib
88
+ required_ruby_version: !ruby/object:Gem::Requirement
89
+ none: false
90
+ requirements:
91
+ - - ! '>='
92
+ - !ruby/object:Gem::Version
93
+ version: '0'
94
+ required_rubygems_version: !ruby/object:Gem::Requirement
95
+ none: false
96
+ requirements:
97
+ - - ! '>='
98
+ - !ruby/object:Gem::Version
99
+ version: '0'
100
+ requirements: []
101
+ rubyforge_project:
102
+ rubygems_version: 1.8.23
103
+ signing_key:
104
+ specification_version: 3
105
+ summary: None
106
+ test_files:
107
+ - spec/gaebot_spec.rb
108
+ - spec/spec_helper.rb