swivel 0.0.102 → 0.0.103

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.
Files changed (4) hide show
  1. data/bin/swivel +47 -12
  2. data/lib/swivel.rb +4 -5
  3. metadata +1 -3
  4. data/lib/benchmarking.rb +0 -4
data/bin/swivel CHANGED
@@ -12,7 +12,7 @@ config.load
12
12
  config.save
13
13
 
14
14
  ARGV.options do |opts|
15
- opts.banner = 'Usage: swivel < list, show, upload, append > [options]'
15
+ opts.banner = 'Usage: swivel < list, show, upload, append, replace > [options]'
16
16
 
17
17
  opts.separator ''
18
18
 
@@ -31,6 +31,34 @@ ARGV.options do |opts|
31
31
  options[:filename] = v
32
32
  end
33
33
 
34
+ opts.on '-n', '--column-names=column_names', String,
35
+ "Column names." do |v|
36
+ options[:column_names] = v
37
+ end
38
+
39
+ opts.on '-t', '--column-types=column_types', String,
40
+ "Column types specification. Choose from {number, currency, date, percent, text}." do |v|
41
+ options[:column_types] =
42
+ v.split(',').collect do |type|
43
+ case type
44
+ when /^n/i
45
+ 'NumberDataColumnType'
46
+ when /^w/i
47
+ 'WholeNumberDataColumnType'
48
+ when /^c/i
49
+ 'CurrencyDataColumnType'
50
+ when /^t/i
51
+ 'DateTimeDataColumnType'
52
+ when /^d/i
53
+ 'DateDataColumnType'
54
+ when /^p/i
55
+ 'PercentageDataColumnType'
56
+ else
57
+ 'TextDataColumnType'
58
+ end
59
+ end.join ','
60
+ end
61
+
34
62
  opts.on_tail '-r', '--raw=path', String,
35
63
  "Perform a raw call and print the XML response." do |v|
36
64
  puts Swivel::Connection.new(options).call(v, options)
@@ -74,25 +102,22 @@ class SwivelHelper
74
102
 
75
103
  def upload name, options = Hash.new
76
104
  filename = options[:filename]
77
- data_set = @swivel.upload! :original_asset_name => filename,
78
- :original_asset_path => filename,
79
- :auto_estimate => true,
80
- :data => read(filename),
81
- :name => name,
82
- :citation => $0,
83
- :display_tags => 'swivel'
105
+ opts = {:original_asset_name => filename, :original_asset_path => filename,
106
+ :name => name, :citation => $0, :display_tags => 'swivel'}
107
+ opts.merge! column_types(options)
108
+ data_set = @swivel.upload! opts.merge(:data => read(filename))
84
109
  puts "uploaded #{data_set.id}"
85
110
  end
86
111
 
87
112
  def append id, options = Hash.new
88
- filename = options[:filename]
89
- data_set = @swivel.append :id => id, :data => read(filename)
113
+ opts = {:id => id}.merge column_types(options)
114
+ data_set = @swivel.append! opts.merge(:data => read(options[:filename]))
90
115
  puts "appended #{data_set.id}"
91
116
  end
92
117
 
93
118
  def replace id, options = Hash.new
94
- filename = options[:filename]
95
- data_set = @swivel.replace :id => id, :data => read(filename)
119
+ opts = {:id => id}.merge column_types(options)
120
+ data_set = @swivel.replace! opts.merge(:data => read(options[:filename]))
96
121
  puts "replaced #{data_set.id}"
97
122
  end
98
123
 
@@ -106,6 +131,16 @@ class SwivelHelper
106
131
  readlines.join
107
132
  end
108
133
  end
134
+
135
+ def column_types options
136
+ if options[:column_types].blank?
137
+ {:auto_estimate => true}
138
+ else
139
+ {:column_types => options[:column_types],
140
+ :column_names => options[:column_names],
141
+ :column_separator => options[:column_separator] || ','}
142
+ end
143
+ end
109
144
  end
110
145
 
111
146
  helper = SwivelHelper.new options
data/lib/swivel.rb CHANGED
@@ -724,7 +724,7 @@ module Swivel
724
724
  silence_warnings do
725
725
  DEFAULT_UPLOAD_OPTIONS = {
726
726
  :citation => 'swivel.rb',
727
- :citation_url => 'www.swivel.com/developer',
727
+ :citation_url => 'http://www.swivel.com/developer',
728
728
  :image_url => 'http://www.swivel.com/images/logo.png',
729
729
  :image_source_url => 'http://www.swivel.com',
730
730
  :display_tags => 'swivel api swivel.rb'
@@ -780,12 +780,8 @@ module Swivel
780
780
  uri, method =
781
781
  case opts[:mode]
782
782
  when 'append', 'replace'
783
- opts[:auto_estimate] = true
784
783
  ["/data_sets/#{opts[:id]}", :put]
785
784
  else
786
- force_auto_estimate =
787
- !opts.has_key?(:auto_estimate) && !opts.has_key?(:column_types)
788
- opts[:auto_estimate] = true if force_auto_estimate
789
785
  opts.reverse_merge! DEFAULT_UPLOAD_OPTIONS
790
786
  ['/data_sets', :post]
791
787
  end
@@ -802,6 +798,9 @@ module Swivel
802
798
  end
803
799
  LAZY
804
800
  end
801
+ # TODO: deprecate the non-bang versions of these methods
802
+ alias_method :append!, :append
803
+ alias_method :replace!, :replace
805
804
 
806
805
  # Lets you create a transient graph in Swivel.
807
806
  #
metadata CHANGED
@@ -3,7 +3,7 @@ rubygems_version: 0.9.4
3
3
  specification_version: 1
4
4
  name: swivel
5
5
  version: !ruby/object:Gem::Version
6
- version: 0.0.102
6
+ version: 0.0.103
7
7
  date: 2007-10-18 00:00:00 -07:00
8
8
  summary: Ruby interface to the Swivel API.
9
9
  require_paths:
@@ -32,9 +32,7 @@ files:
32
32
  - COPYING
33
33
  - README
34
34
  - Rakefile
35
- - lib/benchmarking.rb
36
35
  - lib/swivel.rb
37
- - lib/test
38
36
  - bin/swivel
39
37
  - CHANGELOG
40
38
  test_files: []
data/lib/benchmarking.rb DELETED
@@ -1,4 +0,0 @@
1
- module Swivel
2
- module Benchmarking
3
- end
4
- end