lib/fluent/plugin/in_sforce.rb in fluent-plugin-sforce-0.0.2 vs lib/fluent/plugin/in_sforce.rb in fluent-plugin-sforce-0.0.3
- old
+ new
@@ -1,38 +1,38 @@
-# -*- coding: utf-8 -*-
+# frozen_string_literal: true
+
require 'nokogiri'
require 'restforce'
require 'date'
require 'net/http'
-gem 'faye', '0.8.9'
require 'faye'
module Fluent
class SforceInput < Input
unless method_defined?(:log)
define_method("log") { $log }
end
-
+
Plugin.register_input('sforce', self)
config_param :query, :string, :default => "SELECT id, Body, CreatedById FROM FeedItem"
config_param :tag, :string, :default => "sforce"
config_param :polling_interval, :integer, :default => 60
config_param :topic, :string, :default => nil
config_param :username, :string
config_param :password, :string
-
+
def configure(conf)
super
end
def start
super
login_info = login()
client = Restforce.new :oauth_token => login_info["sessionId"],
:instance_url => login_info["instanceUrl"]
-
+
th_low = DateTime.now().strftime("%Y-%m-%dT%H:%M:%S.000%Z")
# query
if @topic == nil then
sleep(@polling_interval)
th_high = DateTime.now().strftime("%Y-%m-%dT%H:%M:%S.000%Z")
@@ -43,11 +43,11 @@
if @query =~ /^(.+)\s(where|WHERE)\s(.+)$/ then
soql = "#{$1} WHERE #{where} AND #{$3}"
elsif @query =~ /^(.+)$/ then
soql = "#{$1} WHERE #{where}"
end
-
+
begin
log.info "query: #{soql}"
records = client.query(soql)
records.each do |record|
Fluent::Engine.emit(@tag, Fluent::Engine.now, record)
@@ -61,11 +61,11 @@
login_info = login()
client = Restforce.new :oauth_token => login_info["sessionId"],
:instance_url => login_info["instanceUrl"]
end
end
- # streaming api
+ # streaming api
else
EM.run do
log.info "suscribe: #{@topic}"
# Subscribe to the PushTopic.
client.subscribe @topic do |message|
@@ -76,10 +76,11 @@
end
def shutdown
end
- private
+ private
+
def login
uri = URI('https://login.salesforce.com/services/Soap/u/30.0')
request = Net::HTTP::Post.new(uri.request_uri, initheader = {'Content-Type' =>'text/xml', 'SOAPAction' => '""'})
request.body = <<"BODY"
<?xml version="1.0" encoding="utf-8"?>