class KintoneNotifier::Bot

Public Class Methods

config=(h) click to toggle source
# File lib/kintone_notifier/bot.rb, line 13
def self.config=(h)
  @@config = h
end
new(options={}) click to toggle source
# File lib/kintone_notifier/bot.rb, line 4
def initialize(options={})
  raise ArgumentError, "invalid argument. class configuration haven't been given." if @@config.blank?
  @options = default_options.reverse_merge(default_options)
  @api =  Kintone::Api.new(@options["url"],@options["user"],@options["password"])
end

Public Instance Methods

tweet(values={}) click to toggle source
# File lib/kintone_notifier/bot.rb, line 9
def tweet(values={})
  @api.record.create(@options["app_id"],convert_hash(values.reverse_merge(default_values)))
end

Private Instance Methods

app_name() click to toggle source
# File lib/kintone_notifier/bot.rb, line 40
def app_name
  if Rails.respond_to?(:application)
    Rails.application.class.name.split("::").shift
  else
    Rails.root.to_s.split("/")[-2]
  end
end
convert_hash(h) click to toggle source
# File lib/kintone_notifier/bot.rb, line 18
def convert_hash(h)
  val = {}.tap do |_val|
    h.each do |k,v|
      _val.merge!(k => {"value" => v})
    end
  end
end
default_options() click to toggle source
# File lib/kintone_notifier/bot.rb, line 26
def default_options
  @@config.stringify_keys
end
default_values() click to toggle source
# File lib/kintone_notifier/bot.rb, line 30
def default_values
  {
    "app_name"        => app_name,
    "server"          =>  Socket.gethostname ,
    "rails_root"      =>  Rails.root,
    "svn_version"     =>   %x[ svnversion ],
    "pid"             =>  $$
  }
end