groupdocs 0.2.3 → 0.2.4

Sign up to get free protection for your applications and to get access to all the features.
@@ -25,7 +25,7 @@ module GroupDocs
25
25
  # @raise [ArgumentError] if action is unknown
26
26
  # @api private
27
27
  #
28
- def convert_actions(actions)
28
+ def convert_actions_to_byte(actions)
29
29
  actions.is_a?(Array) or raise ArgumentError, "Actions should be an array, received: #{actions.inspect}"
30
30
  actions = actions.map(&:to_sym)
31
31
 
@@ -42,6 +42,33 @@ module GroupDocs
42
42
  flag
43
43
  end
44
44
 
45
+ #
46
+ # Converts actions byte flag to array.
47
+ #
48
+ # @param [Integer] byte
49
+ # @return [Array<Symbol>]
50
+ # @raise [ArgumentError] if actions is not an array
51
+ # @api private
52
+ #
53
+ def convert_byte_to_actions(byte)
54
+ byte.is_a?(Integer) or raise ArgumentError, "Byte flag should be an integer, received: #{byte.inspect}"
55
+
56
+ actions = []
57
+ ACTIONS.reverse_each do |action, flag|
58
+ decreased_byte = byte - flag
59
+ if decreased_byte >= 0
60
+ actions << action
61
+ byte = decreased_byte
62
+ end
63
+ end
64
+
65
+ unless actions == [:none]
66
+ actions.delete(:none)
67
+ end
68
+
69
+ actions
70
+ end
71
+
45
72
  end # Actions
46
73
  end # Helpers
47
74
  end # Api
@@ -51,7 +51,7 @@ module GroupDocs
51
51
  # @return [Time]
52
52
  #
53
53
  def created_on
54
- Time.at(@created_on)
54
+ Time.at(@created_on / 1000)
55
55
  end
56
56
 
57
57
  #
@@ -60,7 +60,7 @@ module GroupDocs
60
60
  # @return [Time]
61
61
  #
62
62
  def modified_on
63
- Time.at(@modified_on)
63
+ Time.at(@modified_on / 1000)
64
64
  end
65
65
 
66
66
  #
@@ -63,7 +63,7 @@ module GroupDocs
63
63
  # @return [Time]
64
64
  #
65
65
  def process_date
66
- Time.at(@process_date)
66
+ Time.at(@process_date / 1000)
67
67
  end
68
68
 
69
69
  # Compatibility with response JSON
@@ -14,7 +14,7 @@ module GroupDocs
14
14
  # @return [Time]
15
15
  #
16
16
  def viewed_on
17
- Time.at(@viewed_on)
17
+ Time.at(@viewed_on / 1000)
18
18
  end
19
19
 
20
20
  #
data/lib/groupdocs/job.rb CHANGED
@@ -44,7 +44,7 @@ module GroupDocs
44
44
  #
45
45
  def self.create!(options, access = {})
46
46
  options[:actions] or raise ArgumentError, 'options[:actions] is required.'
47
- options[:actions] = convert_actions(options[:actions])
47
+ options[:actions] = convert_actions_to_byte(options[:actions])
48
48
  options[:out_formats] = options[:out_formats].join(?;) if options[:out_formats]
49
49
 
50
50
  api = Api::Request.new do |request|
@@ -60,8 +60,19 @@ module GroupDocs
60
60
 
61
61
  # @attr [Integer] id
62
62
  attr_accessor :id
63
+ # @attr [Array<Symbol>] actions
64
+ attr_accessor :actions
65
+ # @attr [Array<Symbol>] out_formats
66
+ # TODO how should it behave?
67
+ attr_accessor :out_formats
68
+ # @attr [Boolean] email_results
69
+ attr_accessor :email_results
70
+ # @attr [Boolean] url_only
71
+ attr_accessor :url_only
63
72
  # @attr [Array<GroupDocs::Document] documents
64
73
  attr_accessor :documents
74
+ # @attr [Time] requested_time
75
+ attr_accessor :requested_time
65
76
 
66
77
  #
67
78
  # Coverts passed array of attributes hash to array of GroupDocs::Document.
@@ -69,12 +80,32 @@ module GroupDocs
69
80
  # @param [Array<Hash>] documents Array of document attributes hashes
70
81
  #
71
82
  def documents=(documents)
72
- @documents = documents.map do |document|
73
- document.merge!(file: GroupDocs::Storage::File.new(document))
74
- Document.new(document)
83
+ if documents
84
+ @documents = documents.map do |document|
85
+ document.merge!(file: GroupDocs::Storage::File.new(document))
86
+ Document.new(document)
87
+ end
75
88
  end
76
89
  end
77
90
 
91
+ #
92
+ # Converts timestamp which is return by API server to Time object.
93
+ #
94
+ # @return [Time]
95
+ #
96
+ def requested_time
97
+ Time.at(@requested_time / 1000)
98
+ end
99
+
100
+ #
101
+ # Returns job actions in human-readable format.
102
+ #
103
+ # @return [Array<Symbol>]
104
+ #
105
+ def actions
106
+ self.class.convert_byte_to_actions(@actions)
107
+ end
108
+
78
109
  #
79
110
  # Returns an array of documents associated to job.
80
111
  #
@@ -130,7 +130,7 @@ module GroupDocs
130
130
  # @return [Time]
131
131
  #
132
132
  def created_on
133
- Time.at(@created_on)
133
+ Time.at(@created_on / 1000)
134
134
  end
135
135
 
136
136
  #
@@ -148,7 +148,7 @@ module GroupDocs
148
148
  # @return [Time]
149
149
  #
150
150
  def modified_on
151
- Time.at(@modified_on)
151
+ Time.at(@modified_on / 1000)
152
152
  end
153
153
 
154
154
  #
@@ -98,7 +98,7 @@ module GroupDocs
98
98
  # @return [Time]
99
99
  #
100
100
  def created_on
101
- Time.at(@created_on)
101
+ Time.at(@created_on / 1000)
102
102
  end
103
103
 
104
104
  #
@@ -107,7 +107,7 @@ module GroupDocs
107
107
  # @return [Time]
108
108
  #
109
109
  def modified_on
110
- Time.at(@modified_on)
110
+ Time.at(@modified_on / 1000)
111
111
  end
112
112
 
113
113
  #
@@ -38,7 +38,7 @@ module GroupDocs
38
38
  # @return [Time]
39
39
  #
40
40
  def signed_up_on
41
- Time.at(@signed_up_on)
41
+ Time.at(@signed_up_on / 1000)
42
42
  end
43
43
 
44
44
  # Compatibility with response JSON
@@ -1,3 +1,3 @@
1
1
  module GroupDocs
2
- VERSION = '0.2.3'
2
+ VERSION = '0.2.4'
3
3
  end # GroupDocs
@@ -6,6 +6,10 @@ describe GroupDocs::Api::Helpers::Actions do
6
6
  Object.extend(described_class)
7
7
  end
8
8
 
9
+ let(:actions) do
10
+ %w(convert combine compress_zip compress_rar trace convert_body bind_data print import_annotations)
11
+ end
12
+
9
13
  describe 'ACTIONS' do
10
14
  it 'contains hash of actions' do
11
15
  described_class::ACTIONS.should == {
@@ -23,13 +27,13 @@ describe GroupDocs::Api::Helpers::Actions do
23
27
  end
24
28
  end
25
29
 
26
- describe '.convert_actions' do
30
+ describe '.convert_actions_to_byte' do
27
31
  it 'raises error if actions is not an array' do
28
- -> { subject.convert_actions(:convert) }.should raise_error(ArgumentError)
32
+ -> { subject.convert_actions_to_byte(:convert) }.should raise_error(ArgumentError)
29
33
  end
30
34
 
31
35
  it 'raises error if action is unknown' do
32
- -> { subject.convert_actions(%w(unknown)) }.should raise_error(ArgumentError)
36
+ -> { subject.convert_actions_to_byte(%w(unknown)) }.should raise_error(ArgumentError)
33
37
  end
34
38
 
35
39
  it 'converts each action to Symbol' do
@@ -38,14 +42,24 @@ describe GroupDocs::Api::Helpers::Actions do
38
42
  symbol = action.to_sym
39
43
  action.should_receive(:to_sym).and_return(symbol)
40
44
  end
41
- subject.convert_actions(actions)
45
+ subject.convert_actions_to_byte(actions)
42
46
  end
43
47
 
44
48
  it 'returns correct byte flag' do
45
- actions = %w(none convert combine compress_zip compress_rar trace convert_body bind_data print import_annotations)
46
- flag = subject.convert_actions(actions)
49
+ flag = subject.convert_actions_to_byte(actions)
47
50
  flag.should be_an(Integer)
48
51
  flag.should == 511
49
52
  end
50
53
  end
54
+
55
+ describe '#convert_byte_to_actions' do
56
+ it 'raises error if byte is not an integer' do
57
+ -> { subject.convert_byte_to_actions('byte') }.should raise_error(ArgumentError)
58
+ end
59
+
60
+
61
+ it 'returns correct array of actions' do
62
+ subject.convert_byte_to_actions(511).should =~ actions.map(&:to_sym)
63
+ end
64
+ end
51
65
  end
@@ -53,15 +53,15 @@ describe GroupDocs::DataSource do
53
53
 
54
54
  describe '#created_on' do
55
55
  it 'returns converted to Time object Unix timestamp' do
56
- subject.created_on = 1332950825
57
- subject.created_on.should be_a(Time)
56
+ subject.created_on = 1332950825000
57
+ subject.created_on.should == Time.at(1332950825)
58
58
  end
59
59
  end
60
60
 
61
61
  describe '#modified_on' do
62
62
  it 'returns converted to Time object Unix timestamp' do
63
- subject.modified_on = 1332950825
64
- subject.modified_on.should be_a(Time)
63
+ subject.modified_on = 1332950825000
64
+ subject.modified_on.should == Time.at(1332950825)
65
65
  end
66
66
  end
67
67
 
@@ -104,11 +104,6 @@ describe GroupDocs::Document::Annotation::Reply do
104
104
 
105
105
  describe '#replied_on' do
106
106
  it 'returns converted to Time object Unix timestamp' do
107
- subject.replied_on = 1332950825
108
- subject.replied_on.should be_a(Time)
109
- end
110
-
111
- it 'divides timestamp by 1000 because it is in milliseconds' do
112
107
  subject.replied_on = 1332950825000
113
108
  subject.replied_on.should == Time.at(1332950825)
114
109
  end
@@ -92,11 +92,6 @@ describe GroupDocs::Document::Annotation do
92
92
 
93
93
  describe '#created_on' do
94
94
  it 'returns converted to Time object Unix timestamp' do
95
- subject.created_on = 1332950825
96
- subject.created_on.should be_a(Time)
97
- end
98
-
99
- it 'divides timestamp by 1000 because it is in milliseconds' do
100
95
  subject.created_on = 1332950825000
101
96
  subject.created_on.should == Time.at(1332950825)
102
97
  end
@@ -29,8 +29,8 @@ describe GroupDocs::Document::View do
29
29
 
30
30
  describe '#viewed_on' do
31
31
  it 'returns converted to Time object Unix timestamp' do
32
- subject.viewed_on = 1330450135
33
- subject.viewed_on.should be_a(Time)
32
+ subject.viewed_on = 1330450135000
33
+ subject.viewed_on.should == Time.at(1330450135)
34
34
  end
35
35
  end
36
36
  end
@@ -67,8 +67,8 @@ describe GroupDocs::Document do
67
67
 
68
68
  describe '#process_date' do
69
69
  it 'returns converted to Time object Unix timestamp' do
70
- subject.process_date = 1330450135
71
- subject.process_date.should be_a(Time)
70
+ subject.process_date = 1330450135000
71
+ subject.process_date.should == Time.at(1330450135)
72
72
  end
73
73
  end
74
74
 
@@ -49,7 +49,7 @@ describe GroupDocs::Job do
49
49
  end
50
50
 
51
51
  it 'convert actions to byte flag' do
52
- described_class.should_receive(:convert_actions).with(actions).and_return(5)
52
+ described_class.should_receive(:convert_actions_to_byte).with(actions).and_return(5)
53
53
  described_class.create!(actions: actions)
54
54
  end
55
55
 
@@ -64,10 +64,20 @@ describe GroupDocs::Job do
64
64
  end
65
65
  end
66
66
 
67
- it { should respond_to(:id) }
68
- it { should respond_to(:id=) }
69
- it { should respond_to(:documents) }
70
- it { should respond_to(:documents=) }
67
+ it { should respond_to(:id) }
68
+ it { should respond_to(:id=) }
69
+ it { should respond_to(:actions) }
70
+ it { should respond_to(:actions=) }
71
+ it { should respond_to(:out_formats) }
72
+ it { should respond_to(:out_formats=) }
73
+ it { should respond_to(:email_results) }
74
+ it { should respond_to(:email_results=) }
75
+ it { should respond_to(:url_only) }
76
+ it { should respond_to(:url_only=) }
77
+ it { should respond_to(:documents) }
78
+ it { should respond_to(:documents=) }
79
+ it { should respond_to(:requested_time) }
80
+ it { should respond_to(:requested_time=) }
71
81
 
72
82
  describe '#documents=' do
73
83
  let(:response) do
@@ -83,6 +93,27 @@ describe GroupDocs::Job do
83
93
  document.should be_a(GroupDocs::Document)
84
94
  end
85
95
  end
96
+
97
+ it 'does nothing if nil is passed' do
98
+ lambda do
99
+ subject.documents = nil
100
+ end.should_not change(subject, :documents)
101
+ end
102
+ end
103
+
104
+ describe '#requested_time' do
105
+ it 'converts timestamp to Time object' do
106
+ subject.requested_time = 1330450135000
107
+ subject.requested_time.should == Time.at(1330450135)
108
+ end
109
+ end
110
+
111
+ describe '#actions' do
112
+ it 'converts actions to human-readable format' do
113
+ subject.actions = 129
114
+ described_class.should_receive(:convert_byte_to_actions).with(129)
115
+ subject.actions
116
+ end
86
117
  end
87
118
 
88
119
  describe '#documents!' do
@@ -103,15 +103,15 @@ describe GroupDocs::Storage::File do
103
103
 
104
104
  describe '#created_on' do
105
105
  it 'converts timestamp to Time object' do
106
- subject.created_on = 1330450135
107
- subject.created_on.should be_a(Time)
106
+ subject.created_on = 1330450135000
107
+ subject.created_on.should == Time.at(1330450135)
108
108
  end
109
109
  end
110
110
 
111
111
  describe '#modified_on' do
112
112
  it 'returns converted to Time object Unix timestamp' do
113
- subject.modified_on = 1330450135
114
- subject.modified_on.should be_a(Time)
113
+ subject.modified_on = 1330450135000
114
+ subject.modified_on.should == Time.at(1330450135)
115
115
  end
116
116
  end
117
117
 
@@ -79,15 +79,15 @@ describe GroupDocs::Storage::Folder do
79
79
 
80
80
  describe '#created_on' do
81
81
  it 'returns converted to Time object Unix timestamp' do
82
- subject.created_on = 1330450135
83
- subject.created_on.should be_a(Time)
82
+ subject.created_on = 1330450135000
83
+ subject.created_on.should == Time.at(1330450135)
84
84
  end
85
85
  end
86
86
 
87
87
  describe '#modified_on' do
88
88
  it 'returns converted to Time object Unix timestamp' do
89
- subject.modified_on = 1330450135
90
- subject.modified_on.should be_a(Time)
89
+ subject.modified_on = 1330450135000
90
+ subject.modified_on.should == Time.at(1330450135)
91
91
  end
92
92
  end
93
93
 
@@ -46,8 +46,8 @@ describe GroupDocs::User do
46
46
 
47
47
  describe '#signed_up_on' do
48
48
  it 'returns converted to Time object Unix timestamp' do
49
- subject.signed_up_on = 1330450135
50
- subject.signed_up_on.should be_a(Time)
49
+ subject.signed_up_on = 1330450135000
50
+ subject.signed_up_on.should == Time.at(1330450135)
51
51
  end
52
52
  end
53
53
  end
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.2.3
4
+ version: 0.2.4
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-05-19 00:00:00.000000000 Z
12
+ date: 2012-05-27 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rest-client
16
- requirement: &6748580 !ruby/object:Gem::Requirement
16
+ requirement: &10687000 !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: *6748580
24
+ version_requirements: *10687000
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: json
27
- requirement: &6763480 !ruby/object:Gem::Requirement
27
+ requirement: &10702060 !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: *6763480
35
+ version_requirements: *10702060
36
36
  - !ruby/object:Gem::Dependency
37
37
  name: ruby-hmac
38
- requirement: &6761660 !ruby/object:Gem::Requirement
38
+ requirement: &10700260 !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: *6761660
46
+ version_requirements: *10700260
47
47
  - !ruby/object:Gem::Dependency
48
48
  name: rspec
49
- requirement: &6759960 !ruby/object:Gem::Requirement
49
+ requirement: &10698500 !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: *6759960
57
+ version_requirements: *10698500
58
58
  - !ruby/object:Gem::Dependency
59
59
  name: rake
60
- requirement: &6759060 !ruby/object:Gem::Requirement
60
+ requirement: &10697660 !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: *6759060
68
+ version_requirements: *10697660
69
69
  - !ruby/object:Gem::Dependency
70
70
  name: simplecov
71
- requirement: &6758080 !ruby/object:Gem::Requirement
71
+ requirement: &10696640 !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: *6758080
79
+ version_requirements: *10696640
80
80
  - !ruby/object:Gem::Dependency
81
81
  name: yard
82
- requirement: &6756520 !ruby/object:Gem::Requirement
82
+ requirement: &10694880 !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: *6756520
90
+ version_requirements: *10694880
91
91
  - !ruby/object:Gem::Dependency
92
92
  name: webmock
93
- requirement: &6769060 !ruby/object:Gem::Requirement
93
+ requirement: &10707460 !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: *6769060
101
+ version_requirements: *10707460
102
102
  description: Ruby SDK for GroupDocs REST API
103
103
  email: p0deje@gmail.com
104
104
  executables: []
@@ -253,7 +253,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
253
253
  version: '0'
254
254
  segments:
255
255
  - 0
256
- hash: 2726974365030193800
256
+ hash: -2096464079406588274
257
257
  required_rubygems_version: !ruby/object:Gem::Requirement
258
258
  none: false
259
259
  requirements:
@@ -262,7 +262,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
262
262
  version: '0'
263
263
  segments:
264
264
  - 0
265
- hash: 2726974365030193800
265
+ hash: -2096464079406588274
266
266
  requirements: []
267
267
  rubyforge_project:
268
268
  rubygems_version: 1.8.10