seiun 0.0.1 → 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: f5007ec6a09aa9bafcfb5ca763bf3f79dd84a2ba
4
- data.tar.gz: 770f1d6e68f386243d032fdd31e86ea789dc8dbb
3
+ metadata.gz: 91891c974d9bc379c22e7898c44eea9bcd842a83
4
+ data.tar.gz: 9adeee1ecea3a7d4be408742db193b8ad4308492
5
5
  SHA512:
6
- metadata.gz: a569196984d50e6345426fc477d099e2274e31334f5e206d079da235e097a15bdf5544a7258f1b08800f101888d68f6a4293ceae8071523cb6c8d93926eaf3c9
7
- data.tar.gz: b83f143bd8923414748e2959943da767da60b93c653fa6e45352b352f1deaca1457537e935347ac8e4a0a08c97bfae077566c97ce914d013d0bdbf94a29d26b7
6
+ metadata.gz: fae81b3efd78c7994b9ab669021572597ec4864da079af25e11470abf6dc729286a32caac1c46ccc84bd6849b922ed7816b37a33b6ac7d061001e6be5c9fd96f
7
+ data.tar.gz: 303c872863a668447e83fd07d98f1da1a0b9b89162132c9beb1e52433f06c54507460ce8aa5bd8f73ee70db58ad0e9fff71cddfd98b420391fdafd1f09f71232
data/README.md CHANGED
@@ -1,8 +1,90 @@
1
- # Seiun
1
+ ![Seiun](https://s3-ap-northeast-1.amazonaws.com/naoki-watanabe/GitHub/seiun_20160101.jpg)
2
2
 
3
- Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/seiun`. To experiment with that code, run `bin/console` for an interactive prompt.
3
+ ## What's this?
4
4
 
5
- TODO: Delete this and the text above, and describe your gem
5
+ * This is the Salesforce client for ruby environment.
6
+ * You can read/write Salesforce database via Salesforce Bulk API with this gem.
7
+ * "Winter '16" version correspondence.
8
+
9
+ ## Faster than popular gem
10
+
11
+ This gem "seiun" is **33 times** as fast as "salesforce_bulk_api" gem that is popular to use Salesforce Bulk API.
12
+
13
+ About system time, this gem more than 1,000 times as fast as "salesforce_bulk_api" gem.
14
+
15
+ ```
16
+ user system total real
17
+ seiun#0
18
+ seiun#0 33.020000 0.290000 33.310000 ( 33.310086)
19
+ salesforce_bulk_api#0
20
+ salesforce_bulk_api#0 1457.280000 316.500000 1773.780000 (1773.840572)
21
+
22
+ ```
23
+
24
+ The above measure time from receiving arguments to sending xml (10,000 records) on Amazon EC2 t2.medium instance.
25
+
26
+ ## Callbacks
27
+
28
+ You can use original callback class.
29
+
30
+ ```ruby
31
+ # example
32
+ class SomeModel < ActiveRecord::Base
33
+ include Seiun::Callback::Extends
34
+ seiun_before_request :before_request # call from gem
35
+ seiun_hashalize :hashalize # call from gem
36
+
37
+ def hashalize
38
+ # return hash object to write salesforce database
39
+ end
40
+ end
41
+
42
+ # You can pass ActiveRecord Object without converting
43
+ @seiun.insert("TableName", SomeModel.where(category: "something"), callback_class: SomeModel)
44
+
45
+ ```
46
+
47
+ ## Queues
48
+
49
+ You can use insert/update/upsert/delete queues.
50
+ You are not a cause for concern about the record size limit. Queue process each 10,000 records.
51
+
52
+ ```ruby
53
+ # example
54
+ queue = @seiun.insert_queue("TableName")
55
+ SomeMode.find_each{|model| queue << model if model.available? }
56
+ queue.close
57
+
58
+ ```
59
+
60
+ ## Mocks
61
+
62
+ With mocks, you can test your application without connecting Salesforce API.
63
+
64
+ ```ruby
65
+ class Mocks
66
+ include Seiun::Callback::Extends
67
+ seiun_mock_response_create_job :create_job
68
+
69
+ # This gem process as receive response below
70
+ def self.create_job
71
+ <<EOS
72
+ <?xml version="1.0" encoding="UTF-8"?><jobInfo xmlns="http://www.force.com/2009/06/asyncapi/dataload">
73
+ <id>75028000000oEcVAAU</id>
74
+ <operation>upsert</operation>
75
+ <object>Campaign</object>
76
+ <createdById>00528000001lckgAAA</createdById>
77
+ <createdDate>2015-12-30T14:51:51.000Z</createdDate>
78
+ <systemModstamp>2015-12-30T14:51:51.000Z</systemModstamp>
79
+ <state>Open</state>
80
+ </jobInfo>
81
+ EOS
82
+ end
83
+ end
84
+
85
+ @seiun.insert("TableName", records, callback_class: Mocks)
86
+
87
+ ```
6
88
 
7
89
  ## Installation
8
90
 
@@ -22,7 +104,21 @@ Or install it yourself as:
22
104
 
23
105
  ## Usage
24
106
 
25
- TODO: Write usage instructions here
107
+ This gem dependent on [databasedotcom](https://github.com/heroku/databasedotcom).
108
+
109
+ ```ruby
110
+ databasedotcom = Databasedotcom::Client.new(client_id: "customer_key", client_secret: "consumer_secret")
111
+ databasedotcom.authenticate(:username => "username", :password => "password_woth_security_token")
112
+ @seiun = Seiun::Client.new(databasedotcom: databasedotcom)
113
+
114
+ # example: insert
115
+ @seiun.insert("TableName", records)
116
+
117
+ # example: query
118
+ @seiun.query("TableName", "SELECT Id, Name FROM Account ORDER BY Id LIMIT 10000")
119
+ #=> [{ "Id" => "00528000001lckgAAA", "Name" => "Salesforce.com, Inc." }, { "Id" => "75028000000oEcVAAU", "Name" => "GitHub, Inc." }]
120
+
121
+ ```
26
122
 
27
123
  ## Development
28
124
 
@@ -32,10 +128,9 @@ To install this gem onto your local machine, run `bundle exec rake install`. To
32
128
 
33
129
  ## Contributing
34
130
 
35
- Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/seiun. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
131
+ Bug reports and pull requests are welcome on GitHub at https://github.com/naoki-watanabe/seiun. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
36
132
 
37
133
 
38
134
  ## License
39
135
 
40
136
  The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
41
-
data/lib/seiun/client.rb CHANGED
@@ -1,6 +1,6 @@
1
1
  module Seiun
2
2
  class Client
3
- SEC_TO_WAIT_ASYNC = 180
3
+ SEC_TO_WAIT_ASYNC = 60*10
4
4
  private_constant :SEC_TO_WAIT_ASYNC
5
5
 
6
6
  def initialize(databasedotcom: nil, batch_size: 10_000)
@@ -102,7 +102,9 @@ module Seiun
102
102
  yield
103
103
  rescue => ex
104
104
  count += 1
105
- raise ex, ex.response.body if count >= times
105
+ if count >= times
106
+ ex.is_a?(Net::HTTPResponse) ? raise(ex, ex.response.body) : raise(ex)
107
+ end
106
108
  sleep 1
107
109
  retry
108
110
  end
@@ -0,0 +1,7 @@
1
+ module Seiun
2
+ class Error < StandardError
3
+ end
4
+
5
+ class BatchFailError < Error
6
+ end
7
+ end
data/lib/seiun/job.rb CHANGED
@@ -87,14 +87,16 @@ module Seiun
87
87
  end
88
88
  batch.job_id = response.job_id || batch.job_id
89
89
  batch.sf_state = response.state || batch.sf_state
90
+ batch.sf_state_message = response.state_message || batch.sf_state_message
90
91
  batch.sf_created_at = response.created_date || batch.sf_created_at
91
92
  batch.sf_updated_at = response.system_modstamp || batch.sf_updated_at
93
+ raise Seiun::BatchFailError, response.state_message if response.state == "Failed"
92
94
  end
93
95
  end
94
96
 
95
97
  class Batch
96
98
  attr_reader :id
97
- attr_accessor :job_id, :sf_state, :sf_created_at, :sf_updated_at, :number_records_processed
99
+ attr_accessor :job_id, :sf_state, :sf_state_message, :sf_created_at, :sf_updated_at, :number_records_processed
98
100
 
99
101
  def initialize(id)
100
102
  @id = id
data/lib/seiun/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Seiun
2
- VERSION = "0.0.1"
2
+ VERSION = "0.0.2"
3
3
  end
@@ -22,7 +22,9 @@ module Seiun
22
22
 
23
23
  def to_s
24
24
  @callback.after_build_xml(rexml_doc) if @callback
25
- super
25
+ str = super
26
+ @rexml_doc = nil
27
+ str
26
28
  end
27
29
 
28
30
  def add_record(parent, record)
@@ -7,7 +7,7 @@ module Seiun
7
7
  end
8
8
  end
9
9
 
10
- [ :id, :job_id, :state, :created_date, :system_modstamp ].each do |name|
10
+ [ :id, :job_id, :state, :created_date, :system_modstamp, :state_message ].each do |name|
11
11
  define_method name do
12
12
  to_hash(true)[Seiun::Utils.camelize(name)]
13
13
  end
@@ -31,7 +31,7 @@ module Seiun
31
31
 
32
32
  def tag_end(name)
33
33
  if @stack.size == 1 && name == @find_tag
34
- @callback.call(@current)
34
+ @callback.call(Marshal.load(Marshal.dump(@current)))
35
35
  @current, @stack = nil, []
36
36
  elsif @current
37
37
  pop_tag = @stack.pop
data/lib/seiun.rb CHANGED
@@ -3,6 +3,7 @@ require 'rexml/parsers/baseparser'
3
3
  require 'rexml/parsers/streamparser'
4
4
  require 'rexml/streamlistener'
5
5
  require "seiun/version"
6
+ require "seiun/error"
6
7
  require "seiun/utils"
7
8
  require "seiun/xml_generators/base"
8
9
  require "seiun/xml_generators/batch_xml"
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: seiun
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Naoki Watanabe
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2015-12-31 00:00:00.000000000 Z
11
+ date: 2016-01-10 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: databasedotcom
@@ -91,6 +91,7 @@ files:
91
91
  - lib/seiun/callback/wrapper.rb
92
92
  - lib/seiun/client.rb
93
93
  - lib/seiun/connection.rb
94
+ - lib/seiun/error.rb
94
95
  - lib/seiun/job.rb
95
96
  - lib/seiun/queue.rb
96
97
  - lib/seiun/utils.rb