netsuite_rails 0.1.0 → 0.2.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/.gitignore +3 -0
 - data/.travis.yml +3 -0
 - data/Gemfile +17 -7
 - data/README.md +9 -4
 - data/lib/netsuite_rails/configuration.rb +3 -1
 - data/lib/netsuite_rails/list_sync/poll_manager.rb +30 -0
 - data/lib/netsuite_rails/list_sync.rb +2 -2
 - data/lib/netsuite_rails/netsuite_rails.rb +13 -3
 - data/lib/netsuite_rails/poll_timestamp.rb +5 -0
 - data/lib/netsuite_rails/{poll_manager.rb → poll_trigger.rb} +18 -3
 - data/lib/netsuite_rails/record_sync/poll_manager.rb +186 -0
 - data/lib/netsuite_rails/record_sync/pull_manager.rb +10 -137
 - data/lib/netsuite_rails/record_sync/push_manager.rb +59 -21
 - data/lib/netsuite_rails/record_sync.rb +142 -140
 - data/lib/netsuite_rails/spec/spec_helper.rb +34 -6
 - data/lib/netsuite_rails/sync_trigger.rb +80 -75
 - data/lib/netsuite_rails/tasks/netsuite.rb +26 -30
 - data/lib/netsuite_rails/url_helper.rb +12 -3
 - data/netsuite_rails.gemspec +3 -3
 - data/spec/models/poll_manager_spec.rb +45 -0
 - data/spec/models/poll_trigger_spec.rb +26 -0
 - data/spec/models/record_sync/push_manager_spec.rb +0 -0
 - data/spec/models/spec_helper_spec.rb +29 -0
 - data/spec/models/sync_trigger_spec.rb +62 -0
 - data/spec/models/url_helper_spec.rb +23 -0
 - data/spec/spec_helper.rb +17 -1
 - data/spec/support/config/database.yml +11 -0
 - data/spec/support/dynamic_models/class_builder.rb +48 -0
 - data/spec/support/dynamic_models/model_builder.rb +83 -0
 - data/spec/support/example_models.rb +31 -0
 - data/spec/support/netsuite_rails.rb +1 -0
 - data/spec/support/test_application.rb +55 -0
 - metadata +36 -10
 - data/lib/netsuite_rails/list_sync/pull_manager.rb +0 -33
 
| 
         @@ -0,0 +1,31 @@ 
     | 
|
| 
      
 1 
     | 
    
         
            +
            module ExampleModels
         
     | 
| 
      
 2 
     | 
    
         
            +
             
     | 
| 
      
 3 
     | 
    
         
            +
              def self.included(example_group)
         
     | 
| 
      
 4 
     | 
    
         
            +
                example_group.class_eval do
         
     | 
| 
      
 5 
     | 
    
         
            +
                  before do
         
     | 
| 
      
 6 
     | 
    
         
            +
             
     | 
| 
      
 7 
     | 
    
         
            +
                    define_model :standard_record, phone: :string, netsuite_id: :integer do
         
     | 
| 
      
 8 
     | 
    
         
            +
                      include NetSuiteRails::RecordSync
         
     | 
| 
      
 9 
     | 
    
         
            +
             
     | 
| 
      
 10 
     | 
    
         
            +
                      netsuite_record_class NetSuite::Records::Customer
         
     | 
| 
      
 11 
     | 
    
         
            +
                      netsuite_sync :read_write
         
     | 
| 
      
 12 
     | 
    
         
            +
                      netsuite_field_map({
         
     | 
| 
      
 13 
     | 
    
         
            +
                        :phone => :phone
         
     | 
| 
      
 14 
     | 
    
         
            +
                      })
         
     | 
| 
      
 15 
     | 
    
         
            +
                    end
         
     | 
| 
      
 16 
     | 
    
         
            +
             
     | 
| 
      
 17 
     | 
    
         
            +
                    define_model :standard_list, netsuite_id: :integer, value: :string do
         
     | 
| 
      
 18 
     | 
    
         
            +
                      include NetSuiteRails::ListSync
         
     | 
| 
      
 19 
     | 
    
         
            +
                      netsuite_list_id 86
         
     | 
| 
      
 20 
     | 
    
         
            +
                    end
         
     | 
| 
      
 21 
     | 
    
         
            +
             
     | 
| 
      
 22 
     | 
    
         
            +
                  end
         
     | 
| 
      
 23 
     | 
    
         
            +
             
     | 
| 
      
 24 
     | 
    
         
            +
                  after do
         
     | 
| 
      
 25 
     | 
    
         
            +
                    NetSuiteRails::PollTrigger.instance_variable_set('@record_models', [])
         
     | 
| 
      
 26 
     | 
    
         
            +
                    NetSuiteRails::PollTrigger.instance_variable_set('@list_models', [])
         
     | 
| 
      
 27 
     | 
    
         
            +
                  end
         
     | 
| 
      
 28 
     | 
    
         
            +
             
     | 
| 
      
 29 
     | 
    
         
            +
                end
         
     | 
| 
      
 30 
     | 
    
         
            +
              end
         
     | 
| 
      
 31 
     | 
    
         
            +
            end
         
     | 
| 
         @@ -0,0 +1 @@ 
     | 
|
| 
      
 1 
     | 
    
         
            +
            NetSuiteRails::Configuration.netsuite_sync_mode(:sync)
         
     | 
| 
         @@ -0,0 +1,55 @@ 
     | 
|
| 
      
 1 
     | 
    
         
            +
            # https://github.com/thoughtbot/clearance/blob/master/spec/spec_helper.rb
         
     | 
| 
      
 2 
     | 
    
         
            +
             
     | 
| 
      
 3 
     | 
    
         
            +
            require 'rails/all'
         
     | 
| 
      
 4 
     | 
    
         
            +
             
     | 
| 
      
 5 
     | 
    
         
            +
            module TestApplication
         
     | 
| 
      
 6 
     | 
    
         
            +
              APP_ROOT = File.expand_path('..', __FILE__).freeze
         
     | 
| 
      
 7 
     | 
    
         
            +
             
     | 
| 
      
 8 
     | 
    
         
            +
              def self.rails4?
         
     | 
| 
      
 9 
     | 
    
         
            +
                Rails::VERSION::MAJOR >= 4
         
     | 
| 
      
 10 
     | 
    
         
            +
              end
         
     | 
| 
      
 11 
     | 
    
         
            +
             
     | 
| 
      
 12 
     | 
    
         
            +
              I18n.enforce_available_locales = true
         
     | 
| 
      
 13 
     | 
    
         
            +
             
     | 
| 
      
 14 
     | 
    
         
            +
              class Application < Rails::Application
         
     | 
| 
      
 15 
     | 
    
         
            +
                config.action_controller.allow_forgery_protection = false
         
     | 
| 
      
 16 
     | 
    
         
            +
                config.action_controller.perform_caching = false
         
     | 
| 
      
 17 
     | 
    
         
            +
                config.action_dispatch.show_exceptions = false
         
     | 
| 
      
 18 
     | 
    
         
            +
                config.action_mailer.default_url_options = { host: 'localhost' }
         
     | 
| 
      
 19 
     | 
    
         
            +
                config.action_mailer.delivery_method = :test
         
     | 
| 
      
 20 
     | 
    
         
            +
                config.active_support.deprecation = :stderr
         
     | 
| 
      
 21 
     | 
    
         
            +
                config.assets.enabled = true
         
     | 
| 
      
 22 
     | 
    
         
            +
                config.cache_classes = true
         
     | 
| 
      
 23 
     | 
    
         
            +
                config.consider_all_requests_local = true
         
     | 
| 
      
 24 
     | 
    
         
            +
                config.eager_load = false
         
     | 
| 
      
 25 
     | 
    
         
            +
                config.encoding = 'utf-8'
         
     | 
| 
      
 26 
     | 
    
         
            +
                config.paths['app/controllers'] << "#{APP_ROOT}/app/controllers"
         
     | 
| 
      
 27 
     | 
    
         
            +
                config.paths['app/views'] << "#{APP_ROOT}/app/views"
         
     | 
| 
      
 28 
     | 
    
         
            +
                config.paths['config/database'] = "#{APP_ROOT}/config/database.yml"
         
     | 
| 
      
 29 
     | 
    
         
            +
                config.paths['log'] = 'tmp/log/development.log'
         
     | 
| 
      
 30 
     | 
    
         
            +
                config.secret_token = 'SECRET_TOKEN_IS_MIN_30_CHARS_LONG'
         
     | 
| 
      
 31 
     | 
    
         
            +
                config.active_support.test_order = :random
         
     | 
| 
      
 32 
     | 
    
         
            +
             
     | 
| 
      
 33 
     | 
    
         
            +
                if TestApplication.rails4?
         
     | 
| 
      
 34 
     | 
    
         
            +
                  config.paths.add 'config/routes.rb', with: "#{APP_ROOT}/config/routes.rb"
         
     | 
| 
      
 35 
     | 
    
         
            +
                  config.secret_key_base = 'SECRET_KEY_BASE'
         
     | 
| 
      
 36 
     | 
    
         
            +
                else
         
     | 
| 
      
 37 
     | 
    
         
            +
                  config.paths.add 'config/routes', with: "#{APP_ROOT}/config/routes.rb"
         
     | 
| 
      
 38 
     | 
    
         
            +
                end
         
     | 
| 
      
 39 
     | 
    
         
            +
             
     | 
| 
      
 40 
     | 
    
         
            +
                def require_environment!
         
     | 
| 
      
 41 
     | 
    
         
            +
                  initialize!
         
     | 
| 
      
 42 
     | 
    
         
            +
                end
         
     | 
| 
      
 43 
     | 
    
         
            +
             
     | 
| 
      
 44 
     | 
    
         
            +
                def initialize!(&block)
         
     | 
| 
      
 45 
     | 
    
         
            +
                  FileUtils.mkdir_p(Rails.root.join('db').to_s)
         
     | 
| 
      
 46 
     | 
    
         
            +
             
     | 
| 
      
 47 
     | 
    
         
            +
                  super unless @initialized
         
     | 
| 
      
 48 
     | 
    
         
            +
             
     | 
| 
      
 49 
     | 
    
         
            +
                  unless ActiveRecord::Base.connection.table_exists?('netsuite_poll_timestamps')
         
     | 
| 
      
 50 
     | 
    
         
            +
                    require "generators/netsuite_rails/templates/create_netsuite_poll_timestamps.rb"
         
     | 
| 
      
 51 
     | 
    
         
            +
                    CreateNetsuitePollTimestamps.new.migrate(:up)
         
     | 
| 
      
 52 
     | 
    
         
            +
                  end
         
     | 
| 
      
 53 
     | 
    
         
            +
                end
         
     | 
| 
      
 54 
     | 
    
         
            +
              end
         
     | 
| 
      
 55 
     | 
    
         
            +
            end
         
     | 
    
        metadata
    CHANGED
    
    | 
         @@ -1,7 +1,7 @@ 
     | 
|
| 
       1 
1 
     | 
    
         
             
            --- !ruby/object:Gem::Specification
         
     | 
| 
       2 
2 
     | 
    
         
             
            name: netsuite_rails
         
     | 
| 
       3 
3 
     | 
    
         
             
            version: !ruby/object:Gem::Version
         
     | 
| 
       4 
     | 
    
         
            -
              version: 0. 
     | 
| 
      
 4 
     | 
    
         
            +
              version: 0.2.0
         
     | 
| 
       5 
5 
     | 
    
         
             
              prerelease: 
         
     | 
| 
       6 
6 
     | 
    
         
             
            platform: ruby
         
     | 
| 
       7 
7 
     | 
    
         
             
            authors:
         
     | 
| 
         @@ -9,7 +9,7 @@ authors: 
     | 
|
| 
       9 
9 
     | 
    
         
             
            autorequire: 
         
     | 
| 
       10 
10 
     | 
    
         
             
            bindir: bin
         
     | 
| 
       11 
11 
     | 
    
         
             
            cert_chain: []
         
     | 
| 
       12 
     | 
    
         
            -
            date: 2014-12- 
     | 
| 
      
 12 
     | 
    
         
            +
            date: 2014-12-30 00:00:00.000000000 Z
         
     | 
| 
       13 
13 
     | 
    
         
             
            dependencies:
         
     | 
| 
       14 
14 
     | 
    
         
             
            - !ruby/object:Gem::Dependency
         
     | 
| 
       15 
15 
     | 
    
         
             
              name: netsuite
         
     | 
| 
         @@ -18,7 +18,7 @@ dependencies: 
     | 
|
| 
       18 
18 
     | 
    
         
             
                requirements:
         
     | 
| 
       19 
19 
     | 
    
         
             
                - - ~>
         
     | 
| 
       20 
20 
     | 
    
         
             
                  - !ruby/object:Gem::Version
         
     | 
| 
       21 
     | 
    
         
            -
                    version:  
     | 
| 
      
 21 
     | 
    
         
            +
                    version: 0.3.2
         
     | 
| 
       22 
22 
     | 
    
         
             
              type: :runtime
         
     | 
| 
       23 
23 
     | 
    
         
             
              prerelease: false
         
     | 
| 
       24 
24 
     | 
    
         
             
              version_requirements: !ruby/object:Gem::Requirement
         
     | 
| 
         @@ -26,7 +26,7 @@ dependencies: 
     | 
|
| 
       26 
26 
     | 
    
         
             
                requirements:
         
     | 
| 
       27 
27 
     | 
    
         
             
                - - ~>
         
     | 
| 
       28 
28 
     | 
    
         
             
                  - !ruby/object:Gem::Version
         
     | 
| 
       29 
     | 
    
         
            -
                    version:  
     | 
| 
      
 29 
     | 
    
         
            +
                    version: 0.3.2
         
     | 
| 
       30 
30 
     | 
    
         
             
            - !ruby/object:Gem::Dependency
         
     | 
| 
       31 
31 
     | 
    
         
             
              name: rails
         
     | 
| 
       32 
32 
     | 
    
         
             
              requirement: !ruby/object:Gem::Requirement
         
     | 
| 
         @@ -80,17 +80,17 @@ dependencies: 
     | 
|
| 
       80 
80 
     | 
    
         
             
              requirement: !ruby/object:Gem::Requirement
         
     | 
| 
       81 
81 
     | 
    
         
             
                none: false
         
     | 
| 
       82 
82 
     | 
    
         
             
                requirements:
         
     | 
| 
       83 
     | 
    
         
            -
                - -  
     | 
| 
      
 83 
     | 
    
         
            +
                - - ~>
         
     | 
| 
       84 
84 
     | 
    
         
             
                  - !ruby/object:Gem::Version
         
     | 
| 
       85 
     | 
    
         
            -
                    version: ' 
     | 
| 
      
 85 
     | 
    
         
            +
                    version: '3.1'
         
     | 
| 
       86 
86 
     | 
    
         
             
              type: :development
         
     | 
| 
       87 
87 
     | 
    
         
             
              prerelease: false
         
     | 
| 
       88 
88 
     | 
    
         
             
              version_requirements: !ruby/object:Gem::Requirement
         
     | 
| 
       89 
89 
     | 
    
         
             
                none: false
         
     | 
| 
       90 
90 
     | 
    
         
             
                requirements:
         
     | 
| 
       91 
     | 
    
         
            -
                - -  
     | 
| 
      
 91 
     | 
    
         
            +
                - - ~>
         
     | 
| 
       92 
92 
     | 
    
         
             
                  - !ruby/object:Gem::Version
         
     | 
| 
       93 
     | 
    
         
            -
                    version: ' 
     | 
| 
      
 93 
     | 
    
         
            +
                    version: '3.1'
         
     | 
| 
       94 
94 
     | 
    
         
             
            description: 
         
     | 
| 
       95 
95 
     | 
    
         
             
            email:
         
     | 
| 
       96 
96 
     | 
    
         
             
            - mike@cliffsidemedia.com
         
     | 
| 
         @@ -99,6 +99,7 @@ extensions: [] 
     | 
|
| 
       99 
99 
     | 
    
         
             
            extra_rdoc_files: []
         
     | 
| 
       100 
100 
     | 
    
         
             
            files:
         
     | 
| 
       101 
101 
     | 
    
         
             
            - .gitignore
         
     | 
| 
      
 102 
     | 
    
         
            +
            - .travis.yml
         
     | 
| 
       102 
103 
     | 
    
         
             
            - Gemfile
         
     | 
| 
       103 
104 
     | 
    
         
             
            - LICENSE.txt
         
     | 
| 
       104 
105 
     | 
    
         
             
            - README.md
         
     | 
| 
         @@ -108,11 +109,12 @@ files: 
     | 
|
| 
       108 
109 
     | 
    
         
             
            - lib/netsuite_rails.rb
         
     | 
| 
       109 
110 
     | 
    
         
             
            - lib/netsuite_rails/configuration.rb
         
     | 
| 
       110 
111 
     | 
    
         
             
            - lib/netsuite_rails/list_sync.rb
         
     | 
| 
       111 
     | 
    
         
            -
            - lib/netsuite_rails/list_sync/ 
     | 
| 
      
 112 
     | 
    
         
            +
            - lib/netsuite_rails/list_sync/poll_manager.rb
         
     | 
| 
       112 
113 
     | 
    
         
             
            - lib/netsuite_rails/netsuite_rails.rb
         
     | 
| 
       113 
     | 
    
         
            -
            - lib/netsuite_rails/poll_manager.rb
         
     | 
| 
       114 
114 
     | 
    
         
             
            - lib/netsuite_rails/poll_timestamp.rb
         
     | 
| 
      
 115 
     | 
    
         
            +
            - lib/netsuite_rails/poll_trigger.rb
         
     | 
| 
       115 
116 
     | 
    
         
             
            - lib/netsuite_rails/record_sync.rb
         
     | 
| 
      
 117 
     | 
    
         
            +
            - lib/netsuite_rails/record_sync/poll_manager.rb
         
     | 
| 
       116 
118 
     | 
    
         
             
            - lib/netsuite_rails/record_sync/pull_manager.rb
         
     | 
| 
       117 
119 
     | 
    
         
             
            - lib/netsuite_rails/record_sync/push_manager.rb
         
     | 
| 
       118 
120 
     | 
    
         
             
            - lib/netsuite_rails/spec/spec_helper.rb
         
     | 
| 
         @@ -122,7 +124,19 @@ files: 
     | 
|
| 
       122 
124 
     | 
    
         
             
            - lib/netsuite_rails/transformations.rb
         
     | 
| 
       123 
125 
     | 
    
         
             
            - lib/netsuite_rails/url_helper.rb
         
     | 
| 
       124 
126 
     | 
    
         
             
            - netsuite_rails.gemspec
         
     | 
| 
      
 127 
     | 
    
         
            +
            - spec/models/poll_manager_spec.rb
         
     | 
| 
      
 128 
     | 
    
         
            +
            - spec/models/poll_trigger_spec.rb
         
     | 
| 
      
 129 
     | 
    
         
            +
            - spec/models/record_sync/push_manager_spec.rb
         
     | 
| 
      
 130 
     | 
    
         
            +
            - spec/models/spec_helper_spec.rb
         
     | 
| 
      
 131 
     | 
    
         
            +
            - spec/models/sync_trigger_spec.rb
         
     | 
| 
      
 132 
     | 
    
         
            +
            - spec/models/url_helper_spec.rb
         
     | 
| 
       125 
133 
     | 
    
         
             
            - spec/spec_helper.rb
         
     | 
| 
      
 134 
     | 
    
         
            +
            - spec/support/config/database.yml
         
     | 
| 
      
 135 
     | 
    
         
            +
            - spec/support/dynamic_models/class_builder.rb
         
     | 
| 
      
 136 
     | 
    
         
            +
            - spec/support/dynamic_models/model_builder.rb
         
     | 
| 
      
 137 
     | 
    
         
            +
            - spec/support/example_models.rb
         
     | 
| 
      
 138 
     | 
    
         
            +
            - spec/support/netsuite_rails.rb
         
     | 
| 
      
 139 
     | 
    
         
            +
            - spec/support/test_application.rb
         
     | 
| 
       126 
140 
     | 
    
         
             
            homepage: http://github.com/netsweet/netsuite_rails
         
     | 
| 
       127 
141 
     | 
    
         
             
            licenses:
         
     | 
| 
       128 
142 
     | 
    
         
             
            - MIT
         
     | 
| 
         @@ -149,4 +163,16 @@ signing_key: 
     | 
|
| 
       149 
163 
     | 
    
         
             
            specification_version: 3
         
     | 
| 
       150 
164 
     | 
    
         
             
            summary: Write Rails applications that integrate with NetSuite
         
     | 
| 
       151 
165 
     | 
    
         
             
            test_files:
         
     | 
| 
      
 166 
     | 
    
         
            +
            - spec/models/poll_manager_spec.rb
         
     | 
| 
      
 167 
     | 
    
         
            +
            - spec/models/poll_trigger_spec.rb
         
     | 
| 
      
 168 
     | 
    
         
            +
            - spec/models/record_sync/push_manager_spec.rb
         
     | 
| 
      
 169 
     | 
    
         
            +
            - spec/models/spec_helper_spec.rb
         
     | 
| 
      
 170 
     | 
    
         
            +
            - spec/models/sync_trigger_spec.rb
         
     | 
| 
      
 171 
     | 
    
         
            +
            - spec/models/url_helper_spec.rb
         
     | 
| 
       152 
172 
     | 
    
         
             
            - spec/spec_helper.rb
         
     | 
| 
      
 173 
     | 
    
         
            +
            - spec/support/config/database.yml
         
     | 
| 
      
 174 
     | 
    
         
            +
            - spec/support/dynamic_models/class_builder.rb
         
     | 
| 
      
 175 
     | 
    
         
            +
            - spec/support/dynamic_models/model_builder.rb
         
     | 
| 
      
 176 
     | 
    
         
            +
            - spec/support/example_models.rb
         
     | 
| 
      
 177 
     | 
    
         
            +
            - spec/support/netsuite_rails.rb
         
     | 
| 
      
 178 
     | 
    
         
            +
            - spec/support/test_application.rb
         
     | 
| 
         @@ -1,33 +0,0 @@ 
     | 
|
| 
       1 
     | 
    
         
            -
            module NetSuiteRails
         
     | 
| 
       2 
     | 
    
         
            -
              module ListSync
         
     | 
| 
       3 
     | 
    
         
            -
             
     | 
| 
       4 
     | 
    
         
            -
                class PullManager
         
     | 
| 
       5 
     | 
    
         
            -
                  class << self
         
     | 
| 
       6 
     | 
    
         
            -
             
     | 
| 
       7 
     | 
    
         
            -
                    def poll(klass, opts = {})
         
     | 
| 
       8 
     | 
    
         
            -
                      custom_list = NetSuite::Records::CustomList.get(klass.netsuite_list_id)
         
     | 
| 
       9 
     | 
    
         
            -
             
     | 
| 
       10 
     | 
    
         
            -
                      process_results(custom_list.custom_value_list.custom_value)
         
     | 
| 
       11 
     | 
    
         
            -
                    end
         
     | 
| 
       12 
     | 
    
         
            -
             
     | 
| 
       13 
     | 
    
         
            -
                    def process_results(klass, opts, list)
         
     | 
| 
       14 
     | 
    
         
            -
                      list.each do |custom_value|
         
     | 
| 
       15 
     | 
    
         
            -
                        local_record = klass.where(netsuite_id: custom_value.attributes[:value_id]).first_or_initialize
         
     | 
| 
       16 
     | 
    
         
            -
             
     | 
| 
       17 
     | 
    
         
            -
                        if local_record.respond_to?(:value=)
         
     | 
| 
       18 
     | 
    
         
            -
                          local_record.value = custom_value.attributes[:value]
         
     | 
| 
       19 
     | 
    
         
            -
                        end
         
     | 
| 
       20 
     | 
    
         
            -
             
     | 
| 
       21 
     | 
    
         
            -
                        if local_record.respond_to?(:inactive=)
         
     | 
| 
       22 
     | 
    
         
            -
                          local_record.inactive = custom_value.attributes[:is_inactive]
         
     | 
| 
       23 
     | 
    
         
            -
                        end
         
     | 
| 
       24 
     | 
    
         
            -
             
     | 
| 
       25 
     | 
    
         
            -
                        local_record.save!
         
     | 
| 
       26 
     | 
    
         
            -
                      end
         
     | 
| 
       27 
     | 
    
         
            -
                    end
         
     | 
| 
       28 
     | 
    
         
            -
             
     | 
| 
       29 
     | 
    
         
            -
                  end
         
     | 
| 
       30 
     | 
    
         
            -
                end
         
     | 
| 
       31 
     | 
    
         
            -
             
     | 
| 
       32 
     | 
    
         
            -
              end
         
     | 
| 
       33 
     | 
    
         
            -
            end
         
     |