groupdocs 0.3.8 → 0.3.9

Sign up to get free protection for your applications and to get access to all the features.
@@ -43,7 +43,7 @@ module GroupDocs
43
43
  # @option access [String] :private_key
44
44
  # @return [Array<GroupDocs::Document::View>]
45
45
  #
46
- def self.views!(options = { page_index: 0 }, access = {})
46
+ def self.views!(options = {}, access = {})
47
47
  api = Api::Request.new do |request|
48
48
  request[:access] = access
49
49
  request[:method] = :GET
@@ -345,13 +345,10 @@ module GroupDocs
345
345
  # @return [GroupDocs::Job]
346
346
  #
347
347
  # @raise [ArgumentError] if datasource is not GroupDocs::DataSource object
348
- # @raise [ArgumentError] if options does not contain :new_type and/or :email_results
349
348
  #
350
- def datasource!(datasource, options, access = {})
349
+ def datasource!(datasource, options = {}, access = {})
351
350
  datasource.is_a?(GroupDocs::DataSource) or raise ArgumentError,
352
351
  "Datasource should be GroupDocs::DataSource object, received: #{datasource.inspect}"
353
- (options[:new_type].nil? || options[:email_results].nil?) and raise ArgumentError,
354
- "Both :new_type and :email_results should be passed, received: #{options.inspect}"
355
352
 
356
353
  api = Api::Request.new do |request|
357
354
  request[:access] = access
@@ -5,7 +5,7 @@ module GroupDocs
5
5
 
6
6
  include Api::Helpers::AccessMode
7
7
 
8
- TYPES = %w(Text Area Point)
8
+ TYPES = %w(Text Area Point TextStrikeout Polyline)
9
9
 
10
10
  # @attr [GroupDocs::Document] document
11
11
  attr_accessor :document
@@ -67,7 +67,7 @@ module GroupDocs
67
67
  #
68
68
  def type=(type)
69
69
  if type.is_a?(Symbol)
70
- type = type.to_s.capitalize
70
+ type = accessor_to_variable(type).to_s.delete(?@)
71
71
  TYPES.include?(type) or raise ArgumentError, "Unknown type: #{type.inspect}"
72
72
  end
73
73
 
@@ -80,7 +80,7 @@ module GroupDocs
80
80
  # @return [Symbol]
81
81
  #
82
82
  def type
83
- @type.downcase.to_sym
83
+ variable_to_accessor(@type)
84
84
  end
85
85
 
86
86
  #
@@ -15,7 +15,7 @@ module GroupDocs
15
15
  #
16
16
  # @param [String] filepath Path to file to be uploaded
17
17
  # @param [String] upload_path Full path to directory to upload file to starting with "/".
18
- # You can also add filename and then uploaded file will use it.
18
+ # You can also add filename and then uploaded file will use it.
19
19
  # @param [Hash] access Access credentials
20
20
  # @option access [String] :client_id
21
21
  # @option access [String] :private_key
@@ -62,7 +62,7 @@ module GroupDocs
62
62
 
63
63
  # @attr [Integer] id
64
64
  attr_accessor :id
65
- # @attr [Integer] guid
65
+ # @attr [String] guid
66
66
  attr_accessor :guid
67
67
  # @attr [Integer] size
68
68
  attr_accessor :size
@@ -80,11 +80,11 @@ module GroupDocs
80
80
  attr_accessor :name
81
81
  # @attr [Integer] version
82
82
  attr_accessor :version
83
- # @attr [Integer] type
83
+ # @attr [Symbol] type
84
84
  attr_accessor :type
85
- # @attr [Integer] file_type
85
+ # @attr [Symbol] file_type
86
86
  attr_accessor :file_type
87
- # @attr [Integer] access
87
+ # @attr [Symbol] access
88
88
  attr_accessor :access
89
89
  # @attr [String] path
90
90
  attr_accessor :path
@@ -116,6 +116,15 @@ module GroupDocs
116
116
  @type.downcase.to_sym
117
117
  end
118
118
 
119
+ #
120
+ # Returns file type in human-readable format.
121
+ #
122
+ # @return [Symbol]
123
+ #
124
+ def file_type
125
+ @file_type.downcase.to_sym
126
+ end
127
+
119
128
  #
120
129
  # Converts timestamp which is return by API server to Time object.
121
130
  #
@@ -143,6 +152,26 @@ module GroupDocs
143
152
  Time.at(@modified_on / 1000)
144
153
  end
145
154
 
155
+ #
156
+ # Uploads file to server.
157
+ #
158
+ # Note that it doesn't update self and instead returns new instance.
159
+ #
160
+ # @example
161
+ # file = GroupDocs::Storage::File.new(name: 'document_one.doc', path: File.dirname(__FILE__))
162
+ # file = file.upload!
163
+ #
164
+ # @param [String] upload_path Full path to directory to upload file to starting with "/".
165
+ # You can also add filename and then uploaded file will use it.
166
+ # @param [Hash] access Access credentials
167
+ # @option access [String] :client_id
168
+ # @option access [String] :private_key
169
+ # @return [GroupDocs::Storage::File]
170
+ #
171
+ def upload!(upload_path = '/', access = {})
172
+ self.class.upload!("#{path}/#{name}", upload_path, access)
173
+ end
174
+
146
175
  #
147
176
  # Downloads file to given path.
148
177
  #
@@ -89,7 +89,7 @@ module GroupDocs
89
89
  attr_accessor :version
90
90
  # @attr [Integer] type
91
91
  attr_accessor :type
92
- # @attr [Integer] access
92
+ # @attr [Symbol] access
93
93
  attr_accessor :access
94
94
 
95
95
  #
@@ -215,9 +215,16 @@ module GroupDocs
215
215
  #
216
216
  # Creates folder on server.
217
217
  #
218
+ # Note that it doesn't update self and instead returns new instance.
219
+ #
220
+ # @example
221
+ # folder = GroupDocs::Storage::Folder.new(name: 'Folder')
222
+ # folder = folder.create!
223
+ #
218
224
  # @param [Hash] access Access credentials
219
225
  # @option access [String] :client_id
220
226
  # @option access [String] :private_key
227
+ # @return [GroupDocs::Storage::Folder] Created folder
221
228
  #
222
229
  def create!(access = {})
223
230
  self.class.create!("/#{name}", access)
@@ -1,3 +1,3 @@
1
1
  module GroupDocs
2
- VERSION = '0.3.8'
2
+ VERSION = '0.3.9'
3
3
  end # GroupDocs
@@ -17,7 +17,7 @@ describe GroupDocs::DataSource do
17
17
 
18
18
  it 'accepts options hash' do
19
19
  lambda do
20
- described_class.get!(1, fields: %w(field1 field2))
20
+ described_class.get!(1, field: %w(field1 field2))
21
21
  end.should_not raise_error(ArgumentError)
22
22
  end
23
23
 
@@ -78,8 +78,8 @@ describe GroupDocs::Document::Annotation do
78
78
 
79
79
  describe '#type=' do
80
80
  it 'saves type in machine readable format if symbol is passed' do
81
- subject.type = :area
82
- subject.instance_variable_get(:@type).should == 'Area'
81
+ subject.type = :text_strikeout
82
+ subject.instance_variable_get(:@type).should == 'TextStrikeout'
83
83
  end
84
84
 
85
85
  it 'does nothing if parameter is not symbol' do
@@ -94,8 +94,8 @@ describe GroupDocs::Document::Annotation do
94
94
 
95
95
  describe '#type' do
96
96
  it 'returns type in human-readable format' do
97
- subject.type = 'Area'
98
- subject.type.should == :area
97
+ subject.type = 'TextStrikeout'
98
+ subject.type.should == :text_strikeout
99
99
  end
100
100
  end
101
101
 
@@ -22,11 +22,6 @@ describe GroupDocs::Document do
22
22
  end.should_not raise_error(ArgumentError)
23
23
  end
24
24
 
25
- it 'adds page index option by default' do
26
- GroupDocs::Api::Request.any_instance.should_receive(:add_params).with({ page_index: 0 })
27
- described_class.views!
28
- end
29
-
30
25
  it 'returns an array of GroupDocs::Document::View objects' do
31
26
  views = described_class.views!
32
27
  views.should be_an(Array)
@@ -414,24 +409,22 @@ describe GroupDocs::Document do
414
409
 
415
410
  it 'accepts access credentials hash' do
416
411
  lambda do
417
- subject.datasource!(datasource, { new_type: 1, email_results: false }, client_id: 'client_id', private_key: 'private_key')
412
+ subject.datasource!(datasource, {}, client_id: 'client_id', private_key: 'private_key')
418
413
  end.should_not raise_error(ArgumentError)
419
414
  end
420
415
 
421
- it 'raises error if datasource is not GroupDocs::Datasource object' do
422
- -> { subject.datasource!('Datasource') }.should raise_error(ArgumentError)
423
- end
424
-
425
- it 'raises error if :new_type option is not passed' do
426
- -> { subject.datasource!(datasource, email_results: false) }.should raise_error(ArgumentError)
416
+ it 'accepts options hash' do
417
+ lambda do
418
+ subject.datasource!(datasource, new_type: :pdf)
419
+ end.should_not raise_error(ArgumentError)
427
420
  end
428
421
 
429
- it 'raises error if :email_results option is not passed' do
430
- -> { subject.datasource!(datasource, new_type: :doc) }.should raise_error(ArgumentError)
422
+ it 'raises error if datasource is not GroupDocs::Datasource object' do
423
+ -> { subject.datasource!('Datasource') }.should raise_error(ArgumentError)
431
424
  end
432
425
 
433
426
  it 'returns GroupDocs::Job object' do
434
- job = subject.datasource!(datasource, new_type: :doc, email_results: false)
427
+ job = subject.datasource!(datasource)
435
428
  job.should be_a(GroupDocs::Job)
436
429
  end
437
430
  end
@@ -455,7 +448,7 @@ describe GroupDocs::Document do
455
448
  end
456
449
  end
457
450
 
458
- it 'returns empty array if annotations are null in reponse' do
451
+ it 'returns empty array if annotations are null in response' do
459
452
  mock_api_server('{"status": "Ok", "result": {"annotations": null }}')
460
453
  subject.annotations!.should be_empty
461
454
  end
@@ -87,6 +87,13 @@ describe GroupDocs::Storage::File do
87
87
  end
88
88
  end
89
89
 
90
+ describe '#file_type' do
91
+ it 'returns file type in human-readable format' do
92
+ subject.file_type = 'Doc'
93
+ subject.file_type.should == :doc
94
+ end
95
+ end
96
+
90
97
  describe '#created_on' do
91
98
  it 'converts timestamp to Time object' do
92
99
  subject.created_on = 1330450135000
@@ -101,6 +108,31 @@ describe GroupDocs::Storage::File do
101
108
  end
102
109
  end
103
110
 
111
+ describe '#upload!' do
112
+ before(:each) do
113
+ mock_api_server(load_json('file_upload'))
114
+ end
115
+
116
+ it 'accepts access credentials hash' do
117
+ lambda do
118
+ subject.upload!('/', client_id: 'client_id', private_key: 'private_key')
119
+ end.should_not raise_error(ArgumentError)
120
+ end
121
+
122
+ it 'calls upload! class method and pass parameters to it' do
123
+ subject = described_class.new(name: File.basename(__FILE__), path: File.dirname(__FILE__))
124
+ described_class.should_receive(:upload!).with(__FILE__, '/Folder', {})
125
+ subject.upload!('/Folder')
126
+ end
127
+
128
+ it 'returns new GroupDocs::Storage::File object' do
129
+ subject = described_class.new(name: File.basename(__FILE__), path: File.dirname(__FILE__))
130
+ new_file = subject.upload!
131
+ new_file.should be_a(GroupDocs::Storage::File)
132
+ new_file.should_not == subject
133
+ end
134
+ end
135
+
104
136
  describe '#download!' do
105
137
  before(:each) do
106
138
  mock_api_server(File.read('spec/support/files/resume.pdf'))
@@ -229,6 +229,13 @@ describe GroupDocs::Storage::Folder do
229
229
  described_class.should_receive(:create!).with('/Test1', {})
230
230
  subject.create!
231
231
  end
232
+
233
+ it 'returns new GroupDocs::Storage::Folder object' do
234
+ subject = described_class.new(name: 'Test1')
235
+ new_folder = subject.create!
236
+ new_folder.should be_a(GroupDocs::Storage::Folder)
237
+ new_folder.should_not == subject
238
+ end
232
239
  end
233
240
 
234
241
  describe '#delete!' do
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: groupdocs
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.8
4
+ version: 0.3.9
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,11 +9,11 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-06-27 00:00:00.000000000 Z
12
+ date: 2012-07-18 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rest-client
16
- requirement: &18874340 !ruby/object:Gem::Requirement
16
+ requirement: &4299240 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ~>
@@ -21,10 +21,10 @@ dependencies:
21
21
  version: '1.6'
22
22
  type: :runtime
23
23
  prerelease: false
24
- version_requirements: *18874340
24
+ version_requirements: *4299240
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: json
27
- requirement: &18888780 !ruby/object:Gem::Requirement
27
+ requirement: &4314240 !ruby/object:Gem::Requirement
28
28
  none: false
29
29
  requirements:
30
30
  - - ~>
@@ -32,10 +32,10 @@ dependencies:
32
32
  version: '1.7'
33
33
  type: :runtime
34
34
  prerelease: false
35
- version_requirements: *18888780
35
+ version_requirements: *4314240
36
36
  - !ruby/object:Gem::Dependency
37
37
  name: ruby-hmac
38
- requirement: &18887640 !ruby/object:Gem::Requirement
38
+ requirement: &4312700 !ruby/object:Gem::Requirement
39
39
  none: false
40
40
  requirements:
41
41
  - - ~>
@@ -43,10 +43,10 @@ dependencies:
43
43
  version: '0.4'
44
44
  type: :runtime
45
45
  prerelease: false
46
- version_requirements: *18887640
46
+ version_requirements: *4312700
47
47
  - !ruby/object:Gem::Dependency
48
48
  name: rspec
49
- requirement: &18886060 !ruby/object:Gem::Requirement
49
+ requirement: &4310660 !ruby/object:Gem::Requirement
50
50
  none: false
51
51
  requirements:
52
52
  - - ~>
@@ -54,10 +54,10 @@ dependencies:
54
54
  version: '2.9'
55
55
  type: :development
56
56
  prerelease: false
57
- version_requirements: *18886060
57
+ version_requirements: *4310660
58
58
  - !ruby/object:Gem::Dependency
59
59
  name: rake
60
- requirement: &18885040 !ruby/object:Gem::Requirement
60
+ requirement: &4309820 !ruby/object:Gem::Requirement
61
61
  none: false
62
62
  requirements:
63
63
  - - ~>
@@ -65,10 +65,10 @@ dependencies:
65
65
  version: '0.9'
66
66
  type: :development
67
67
  prerelease: false
68
- version_requirements: *18885040
68
+ version_requirements: *4309820
69
69
  - !ruby/object:Gem::Dependency
70
70
  name: simplecov
71
- requirement: &18884140 !ruby/object:Gem::Requirement
71
+ requirement: &4308540 !ruby/object:Gem::Requirement
72
72
  none: false
73
73
  requirements:
74
74
  - - ~>
@@ -76,10 +76,10 @@ dependencies:
76
76
  version: '0.6'
77
77
  type: :development
78
78
  prerelease: false
79
- version_requirements: *18884140
79
+ version_requirements: *4308540
80
80
  - !ruby/object:Gem::Dependency
81
81
  name: yard
82
- requirement: &18897000 !ruby/object:Gem::Requirement
82
+ requirement: &4320860 !ruby/object:Gem::Requirement
83
83
  none: false
84
84
  requirements:
85
85
  - - ~>
@@ -87,10 +87,10 @@ dependencies:
87
87
  version: '0.8'
88
88
  type: :development
89
89
  prerelease: false
90
- version_requirements: *18897000
90
+ version_requirements: *4320860
91
91
  - !ruby/object:Gem::Dependency
92
92
  name: webmock
93
- requirement: &18894420 !ruby/object:Gem::Requirement
93
+ requirement: &4319120 !ruby/object:Gem::Requirement
94
94
  none: false
95
95
  requirements:
96
96
  - - ~>
@@ -98,7 +98,7 @@ dependencies:
98
98
  version: '1.8'
99
99
  type: :development
100
100
  prerelease: false
101
- version_requirements: *18894420
101
+ version_requirements: *4319120
102
102
  description: Ruby SDK for GroupDocs REST API
103
103
  email: p0deje@gmail.com
104
104
  executables: []
@@ -256,7 +256,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
256
256
  version: '0'
257
257
  segments:
258
258
  - 0
259
- hash: 2096644299297283301
259
+ hash: -1332657655199071037
260
260
  required_rubygems_version: !ruby/object:Gem::Requirement
261
261
  none: false
262
262
  requirements:
@@ -265,7 +265,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
265
265
  version: '0'
266
266
  segments:
267
267
  - 0
268
- hash: 2096644299297283301
268
+ hash: -1332657655199071037
269
269
  requirements: []
270
270
  rubyforge_project:
271
271
  rubygems_version: 1.8.10