groupdocs 0.2.11 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (33) hide show
  1. data/.travis.yml +0 -1
  2. data/lib/groupdocs/api/entity.rb +12 -0
  3. data/lib/groupdocs/api/helpers/access_mode_helper.rb +8 -13
  4. data/lib/groupdocs/api/helpers/actions_helper.rb +0 -27
  5. data/lib/groupdocs/api/helpers/status_helper.rb +8 -29
  6. data/lib/groupdocs/document.rb +20 -2
  7. data/lib/groupdocs/document/annotation.rb +11 -24
  8. data/lib/groupdocs/job.rb +13 -2
  9. data/lib/groupdocs/questionnaire.rb +0 -2
  10. data/lib/groupdocs/questionnaire/execution.rb +6 -28
  11. data/lib/groupdocs/questionnaire/question.rb +8 -6
  12. data/lib/groupdocs/storage/file.rb +6 -14
  13. data/lib/groupdocs/version.rb +1 -1
  14. data/spec/groupdocs/api/entity_spec.rb +10 -0
  15. data/spec/groupdocs/api/helpers/access_mode_helper_spec.rb +6 -33
  16. data/spec/groupdocs/api/helpers/actions_helper_spec.rb +0 -28
  17. data/spec/groupdocs/api/helpers/status_helper_spec.rb +7 -70
  18. data/spec/groupdocs/document/annotation_spec.rb +10 -20
  19. data/spec/groupdocs/document_spec.rb +5 -5
  20. data/spec/groupdocs/job_spec.rb +2 -3
  21. data/spec/groupdocs/questionnaire/execution_spec.rb +8 -39
  22. data/spec/groupdocs/questionnaire/question_spec.rb +10 -15
  23. data/spec/groupdocs/storage/file_spec.rb +4 -18
  24. data/spec/support/json/annotation_list.json +2 -2
  25. data/spec/support/json/document_access_info_get.json +1 -1
  26. data/spec/support/json/document_formats.json +1 -1
  27. data/spec/support/json/file_upload.json +1 -1
  28. data/spec/support/json/job_documents.json +3 -3
  29. data/spec/support/json/jobs_get.json +4 -4
  30. data/spec/support/json/questionnaire_executions.json +2 -2
  31. data/spec/support/shared_examples/api/helpers/access_mode_helper.rb +2 -2
  32. data/spec/support/shared_examples/api/helpers/status_helper.rb +3 -3
  33. metadata +20 -20
data/.travis.yml CHANGED
@@ -2,4 +2,3 @@ language: ruby
2
2
  rvm:
3
3
  - 1.9.2
4
4
  - 1.9.3
5
- - ruby-head
@@ -109,6 +109,18 @@ module GroupDocs
109
109
  word.to_sym
110
110
  end
111
111
 
112
+ #
113
+ # Converts accessor symbol to instance variable symbol.
114
+ # @api private
115
+ #
116
+ def accessor_to_variable(accessor)
117
+ word = accessor.to_s
118
+ word.capitalize!
119
+ word.gsub!(/_([a-z])/) { |match| match.upcase }
120
+ word.gsub!(/_/, '')
121
+ "@#{word}".to_sym
122
+ end
123
+
112
124
  end # Entity
113
125
  end # Api
114
126
  end # GroupDocs
@@ -3,27 +3,22 @@ module GroupDocs
3
3
  module Helpers
4
4
  module AccessMode
5
5
 
6
- MODES = {
7
- private: 0,
8
- restricted: 1,
9
- public: 2
10
- }
11
-
12
6
  private
13
7
 
14
8
  #
15
9
  # Converts access mode from/to human-readable format.
16
10
  #
17
- # @param [Integer, Symbol] mode
18
- # @return [Symbol, Integer]
11
+ # @param [String, Symbol] mode
12
+ # @return [Symbol, String]
13
+ # @raise [ArgumentError] if argument is not symbol/string
19
14
  # @api private
20
15
  #
21
16
  def parse_access_mode(mode)
22
- if mode.is_a?(Integer)
23
- MODES.invert[mode]
24
- else
25
- MODES[mode]
26
- end or raise ArgumentError, "Unknown access mode: #{mode.inspect}."
17
+ case mode
18
+ when Symbol then mode.to_s.capitalize
19
+ when String then mode.downcase.to_sym
20
+ else raise ArgumentError, "Expected string/symbol, received: #{mode.class}"
21
+ end
27
22
  end
28
23
 
29
24
  end # AccessMode
@@ -42,33 +42,6 @@ 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
-
72
45
  end # Actions
73
46
  end # Helpers
74
47
  end # Api
@@ -3,43 +3,22 @@ module GroupDocs
3
3
  module Helpers
4
4
  module Status
5
5
 
6
- STATUSES = {
7
- draft: -1,
8
- pending: 0,
9
- scheduled: 1,
10
- in_progress: 2,
11
- completed: 3,
12
- postponed: 4,
13
- archived: 5,
14
- }
15
-
16
- # @attr [Symbol] status
17
- attr_accessor :status
18
-
19
- #
20
- # Sets status of the entity.
21
- #
22
- # @return [Symbol]
23
- #
24
- def status
25
- parse_status(@status)
26
- end
27
-
28
6
  private
29
7
 
30
8
  #
31
9
  # Converts status from/to human-readable format.
32
10
  #
33
- # @param [Integer, Symbol] status
34
- # @return [Symbol, Integer]
11
+ # @param [String, Symbol] status
12
+ # @return [Symbol, String]
13
+ # @raise [ArgumentError] if argument is not symbol/string
35
14
  # @api private
36
15
  #
37
16
  def parse_status(status)
38
- if status.is_a?(Integer)
39
- STATUSES.invert[status]
40
- else
41
- STATUSES[status]
42
- end or raise ArgumentError, "Unknown status: #{status.inspect}."
17
+ case status
18
+ when Symbol then accessor_to_variable(status).to_s.delete(?@)
19
+ when String then variable_to_accessor(status)
20
+ else raise ArgumentError, "Expected string/symbol, received: #{status.class}"
21
+ end
43
22
  end
44
23
 
45
24
  end # Status
@@ -8,6 +8,13 @@ module GroupDocs
8
8
  require 'groupdocs/document/rectangle'
9
9
  require 'groupdocs/document/view'
10
10
 
11
+ ACCESS_MODES = {
12
+ private: 0,
13
+ restricted: 1,
14
+ inherited: 2,
15
+ public: 3,
16
+ }
17
+
11
18
  extend Extensions::Lookup
12
19
  include Api::Helpers::AccessMode
13
20
  include Api::Helpers::Status
@@ -58,6 +65,8 @@ module GroupDocs
58
65
  attr_accessor :outputs
59
66
  # @attr [Array<Symbol>] output_formats
60
67
  attr_accessor :output_formats
68
+ # @attr [Symbol] status
69
+ attr_accessor :status
61
70
 
62
71
  #
63
72
  # Coverts passed array of attributes hash to array of GroupDocs::Storage::File.
@@ -81,6 +90,15 @@ module GroupDocs
81
90
  @output_formats.split(?,).map(&:to_sym)
82
91
  end
83
92
 
93
+ #
94
+ # Converts status to human-readable format.
95
+ #
96
+ # @return [Symbol]
97
+ #
98
+ def status
99
+ parse_status(@status)
100
+ end
101
+
84
102
  #
85
103
  # Converts timestamp which is return by API server to Time object.
86
104
  #
@@ -140,7 +158,7 @@ module GroupDocs
140
158
  request[:method] = :PUT
141
159
  request[:path] = "/doc/{{client_id}}/files/#{file.id}/accessinfo"
142
160
  end
143
- api.add_params(mode: parse_access_mode(mode))
161
+ api.add_params(mode: ACCESS_MODES[mode])
144
162
  json = api.execute!
145
163
 
146
164
  parse_access_mode(json[:access])
@@ -163,7 +181,7 @@ module GroupDocs
163
181
  request[:path] = "/doc/{{client_id}}/files/#{file.id}/formats"
164
182
  end.execute!
165
183
 
166
- json[:types].split(';').map do |format|
184
+ json[:types].map do |format|
167
185
  format.downcase.to_sym
168
186
  end
169
187
  end
@@ -3,16 +3,9 @@ module GroupDocs
3
3
 
4
4
  require 'groupdocs/document/annotation/reply'
5
5
 
6
- TYPES = {
7
- text: 0,
8
- area: 1,
9
- point: 2,
10
- }
6
+ include Api::Helpers::AccessMode
11
7
 
12
- ACCESS = {
13
- private: 0,
14
- public: 1,
15
- }
8
+ TYPES = %w(Text Area Point)
16
9
 
17
10
  # @attr [GroupDocs::Document] document
18
11
  attr_accessor :document
@@ -74,8 +67,8 @@ module GroupDocs
74
67
  #
75
68
  def type=(type)
76
69
  if type.is_a?(Symbol)
77
- TYPES.keys.include?(type) or raise ArgumentError, "Unknown type: #{type.inspect}"
78
- type = TYPES[type]
70
+ type = type.to_s.capitalize
71
+ TYPES.include?(type) or raise ArgumentError, "Unknown type: #{type.inspect}"
79
72
  end
80
73
 
81
74
  @type = type
@@ -87,31 +80,25 @@ module GroupDocs
87
80
  # @return [Symbol]
88
81
  #
89
82
  def type
90
- TYPES.invert[@type]
83
+ @type.downcase.to_sym
91
84
  end
92
85
 
93
86
  #
94
- # Updates access mode with machine-readable format.
87
+ # Converts access mode to machine-readable format.
95
88
  #
96
- # @param [Symbol] access
97
- # @raise [ArgumentError] if access mode is unknown
89
+ # @param [Symbol] mode
98
90
  #
99
- def access=(access)
100
- if access.is_a?(Symbol)
101
- ACCESS.keys.include?(access) or raise ArgumentError, "Unknown access mode: #{access.inspect}"
102
- access = ACCESS[access]
103
- end
104
-
105
- @access = access
91
+ def access=(mode)
92
+ @access = (mode.is_a?(Symbol) ? parse_access_mode(mode) : mode)
106
93
  end
107
94
 
108
95
  #
109
- # Returns access mode in human-readable format.
96
+ # Converts access mode to human-readable format.
110
97
  #
111
98
  # @return [Symbol]
112
99
  #
113
100
  def access
114
- ACCESS.invert[@access]
101
+ parse_access_mode(@access)
115
102
  end
116
103
 
117
104
  #
data/lib/groupdocs/job.rb CHANGED
@@ -34,7 +34,7 @@ module GroupDocs
34
34
  #
35
35
  # @param [Hash] options
36
36
  # @option options [Integer] :actions Array of actions to be performed. Required
37
- # @option options [Boolean] :emails_results
37
+ # @option options [Boolean] :email_results
38
38
  # @option options [Array] :out_formats
39
39
  # @option options [Boolean] :url_only
40
40
  # @param [Hash] access Access credentials
@@ -70,6 +70,8 @@ module GroupDocs
70
70
  attr_accessor :documents
71
71
  # @attr [Time] requested_time
72
72
  attr_accessor :requested_time
73
+ # @attr [Symbol] status
74
+ attr_accessor :status
73
75
 
74
76
  #
75
77
  # Coverts passed array of attributes hash to array of GroupDocs::Document.
@@ -85,6 +87,15 @@ module GroupDocs
85
87
  end
86
88
  end
87
89
 
90
+ #
91
+ # Converts status to human-readable format.
92
+ #
93
+ # @return [Symbol]
94
+ #
95
+ def status
96
+ parse_status(@status)
97
+ end
98
+
88
99
  #
89
100
  # Converts timestamp which is return by API server to Time object.
90
101
  #
@@ -100,7 +111,7 @@ module GroupDocs
100
111
  # @return [Array<Symbol>]
101
112
  #
102
113
  def actions
103
- self.class.convert_byte_to_actions(@actions)
114
+ @actions.split(', ').map { |action| variable_to_accessor(action) }
104
115
  end
105
116
 
106
117
  #
@@ -5,8 +5,6 @@ module GroupDocs
5
5
  require 'groupdocs/questionnaire/page'
6
6
  require 'groupdocs/questionnaire/question'
7
7
 
8
- include Api::Helpers::AccessMode
9
-
10
8
  #
11
9
  # Returns an array of all questionnaires.
12
10
  #
@@ -1,14 +1,7 @@
1
1
  module GroupDocs
2
2
  class Questionnaire::Execution < GroupDocs::Api::Entity
3
3
 
4
- STATUSES = {
5
- draft: 0,
6
- submitted: 1,
7
- executed: 2,
8
- approved: 3,
9
- rejected: 4,
10
- closed: 5,
11
- }
4
+ include Api::Helpers::Status
12
5
 
13
6
  #
14
7
  # Returns an array of all executions.
@@ -56,29 +49,12 @@ module GroupDocs
56
49
  alias_method :document_id=, :documentId=
57
50
 
58
51
  #
59
- # Updates status with machine-readable format.
60
- #
61
- # If you want to update status on server, use #set_status! method.
62
- #
63
- # @param [Symbol, Integer] status
64
- # @raise [ArgumentError] if status is unknown
65
- #
66
- def status=(status)
67
- if status.is_a?(Symbol)
68
- STATUSES.keys.include?(status) or raise ArgumentError, "Unknown status: #{status.inspect}"
69
- status = STATUSES[status]
70
- end
71
-
72
- @status = status
73
- end
74
-
75
- #
76
- # Returns execution status in human-readable format.
52
+ # Converts status to human-readable format.
77
53
  #
78
54
  # @return [Symbol]
79
55
  #
80
56
  def status
81
- STATUSES.invert[@status]
57
+ parse_status(@status)
82
58
  end
83
59
 
84
60
  #
@@ -90,11 +66,13 @@ module GroupDocs
90
66
  # @option access [String] :private_key
91
67
  #
92
68
  def set_status!(status, access = {})
69
+ status = parse_status(status)
70
+
93
71
  Api::Request.new do |request|
94
72
  request[:access] = access
95
73
  request[:method] = :PUT
96
74
  request[:path] = "/merge/{{client_id}}/questionnaires/executions/#{id}/status"
97
- request[:request_body] = STATUSES[status]
75
+ request[:request_body] = status
98
76
  end.execute!
99
77
 
100
78
  self.status = status
@@ -3,10 +3,7 @@ module GroupDocs
3
3
 
4
4
  require 'groupdocs/questionnaire/question/answer'
5
5
 
6
- TYPES = {
7
- simple: 0,
8
- multiple_choice: 1,
9
- }
6
+ TYPES = %w(GenericText MultipleChoice)
10
7
 
11
8
  # @attr [String] field
12
9
  attr_accessor :field
@@ -60,9 +57,14 @@ module GroupDocs
60
57
  # Updates type with machine-readable format.
61
58
  #
62
59
  # @param [Symbol] type
60
+ # @raise [ArgumentError] if type is unknown
63
61
  #
64
62
  def type=(type)
65
- type = TYPES[type] if type.is_a?(Symbol)
63
+ if type.is_a?(Symbol)
64
+ type = accessor_to_variable(type).to_s.delete(?@)
65
+ TYPES.include?(type) or raise ArgumentError, "Unknown type: #{type.inspect}"
66
+ end
67
+
66
68
  @type = type
67
69
  end
68
70
 
@@ -72,7 +74,7 @@ module GroupDocs
72
74
  # @return [Symbol]
73
75
  #
74
76
  def type
75
- TYPES.invert[@type]
77
+ variable_to_accessor(@type)
76
78
  end
77
79
 
78
80
  end # Questionnaire::Question
@@ -5,15 +5,7 @@ module GroupDocs
5
5
  extend Extensions::Lookup
6
6
  include Api::Helpers::AccessMode
7
7
 
8
- DOCUMENT_TYPES = {
9
- undefined: -1,
10
- cells: 0,
11
- words: 1,
12
- slides: 2,
13
- pdf: 3,
14
- html: 4,
15
- image: 5,
16
- }
8
+ DOCUMENT_TYPES = %w(Undefined Cells Words Slides Pdf Html Image)
17
9
 
18
10
  #
19
11
  # Uploads file to API server.
@@ -103,25 +95,25 @@ module GroupDocs
103
95
  #
104
96
  # Updates type with machine-readable format.
105
97
  #
106
- # @param [Symbol, Integer] type
98
+ # @param [Symbol] type
107
99
  # @raise [ArgumentError] if type is unknown
108
100
  #
109
101
  def type=(type)
110
102
  if type.is_a?(Symbol)
111
- DOCUMENT_TYPES.keys.include?(type) or raise ArgumentError, "Unknown type: #{type.inspect}"
112
- type = DOCUMENT_TYPES[type]
103
+ type = type.to_s.capitalize
104
+ DOCUMENT_TYPES.include?(type) or raise ArgumentError, "Unknown type: #{type.inspect}"
113
105
  end
114
106
 
115
107
  @type = type
116
108
  end
117
109
 
118
110
  #
119
- # Returns document type in human-readable format.
111
+ # Returns type in human-readable format.
120
112
  #
121
113
  # @return [Symbol]
122
114
  #
123
115
  def type
124
- DOCUMENT_TYPES.invert[@type]
116
+ @type.downcase.to_sym
125
117
  end
126
118
 
127
119
  #
@@ -1,3 +1,3 @@
1
1
  module GroupDocs
2
- VERSION = '0.2.11'
2
+ VERSION = '0.3.0'
3
3
  end # GroupDocs
@@ -55,4 +55,14 @@ describe GroupDocs::Api::Entity do
55
55
  subject.send(:variable_to_accessor, :@TestOneAndTWO).should == :test_one_and_two
56
56
  end
57
57
  end
58
+
59
+ describe '#accessor_to_variable' do
60
+ it 'converts accessor method symbol to instance variable symbol' do
61
+ subject.send(:accessor_to_variable, :test).should == :@Test
62
+ end
63
+
64
+ it 'converts underscored words to camelized ' do
65
+ subject.send(:accessor_to_variable, :test_one_and_two).should == :@TestOneAndTwo
66
+ end
67
+ end
58
68
  end
@@ -6,44 +6,17 @@ describe GroupDocs::Api::Helpers::AccessMode do
6
6
  GroupDocs::Storage::Folder.new
7
7
  end
8
8
 
9
- describe 'MODES' do
10
- it 'contains hash of access modes' do
11
- described_class::MODES.should == {
12
- private: 0,
13
- restricted: 1,
14
- public: 2,
15
- }
16
- end
17
- end
18
-
19
9
  describe '#parse_access_mode' do
20
- it 'raise error if mode is unknown' do
21
- -> { subject.send(:parse_access_mode, 3) }.should raise_error(ArgumentError)
22
- -> { subject.send(:parse_access_mode, :unknown) }.should raise_error(ArgumentError)
23
- end
24
-
25
- it 'returns :private if passed mode is 0' do
26
- subject.send(:parse_access_mode, 0).should == :private
27
- end
28
-
29
- it 'returns :restricted if passed mode is 1' do
30
- subject.send(:parse_access_mode, 1).should == :restricted
31
- end
32
-
33
- it 'returns :public if passed mode is 2' do
34
- subject.send(:parse_access_mode, 2).should == :public
35
- end
36
-
37
- it 'returns 0 if passed mode is :private' do
38
- subject.send(:parse_access_mode, :private).should == 0
10
+ it 'returns downcased symbol if string is passed' do
11
+ subject.send(:parse_access_mode, 'Public').should == :public
39
12
  end
40
13
 
41
- it 'returns 1 if passed mode is :restricted' do
42
- subject.send(:parse_access_mode, :restricted).should == 1
14
+ it 'returns capitalized string if symbol is passed' do
15
+ subject.send(:parse_access_mode, :public).should == 'Public'
43
16
  end
44
17
 
45
- it 'returns 2 if passed mode is :public' do
46
- subject.send(:parse_access_mode, :public).should == 2
18
+ it 'raises error if argument is not string or symbol' do
19
+ -> { subject.send(:parse_access_mode, 1) }.should raise_error(ArgumentError)
47
20
  end
48
21
  end
49
22
  end
@@ -10,23 +10,6 @@ describe GroupDocs::Api::Helpers::Actions do
10
10
  %w(convert combine compress_zip compress_rar trace convert_body bind_data print import_annotations)
11
11
  end
12
12
 
13
- describe 'ACTIONS' do
14
- it 'contains hash of actions' do
15
- described_class::ACTIONS.should == {
16
- none: 0,
17
- convert: 1,
18
- combine: 2,
19
- compress_zip: 4,
20
- compress_rar: 8,
21
- trace: 16,
22
- convert_body: 32,
23
- bind_data: 64,
24
- print: 128,
25
- import_annotations: 256,
26
- }
27
- end
28
- end
29
-
30
13
  describe '.convert_actions_to_byte' do
31
14
  it 'raises error if actions is not an array' do
32
15
  -> { subject.convert_actions_to_byte(:convert) }.should raise_error(ArgumentError)
@@ -51,15 +34,4 @@ describe GroupDocs::Api::Helpers::Actions do
51
34
  flag.should == 511
52
35
  end
53
36
  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
65
37
  end
@@ -3,83 +3,20 @@ require 'spec_helper'
3
3
  describe GroupDocs::Api::Helpers::Status do
4
4
 
5
5
  subject do
6
- Object.extend(described_class)
7
- end
8
-
9
- describe 'STATUSES' do
10
- it 'contains hash of entity statuses' do
11
- described_class::STATUSES.should == {
12
- draft: -1,
13
- pending: 0,
14
- scheduled: 1,
15
- in_progress: 2,
16
- completed: 3,
17
- postponed: 4,
18
- archived: 5,
19
- }
20
- end
6
+ GroupDocs::Job.new
21
7
  end
22
8
 
23
9
  describe '#parse_status' do
24
- it 'raise error if status is unknown' do
25
- -> { subject.send(:parse_status, 8) }.should raise_error(ArgumentError)
26
- -> { subject.send(:parse_status, :unknown) }.should raise_error(ArgumentError)
27
- end
28
-
29
- it 'returns :draft if passed status is -1' do
30
- subject.send(:parse_status, -1).should == :draft
31
- end
32
-
33
- it 'returns :pending if passed status is 0' do
34
- subject.send(:parse_status, 0).should == :pending
35
- end
36
-
37
- it 'returns :scheduled if passed status is 1' do
38
- subject.send(:parse_status, 1).should == :scheduled
39
- end
40
-
41
- it 'returns :in_progress if passed status is 2' do
42
- subject.send(:parse_status, 2).should == :in_progress
43
- end
44
-
45
- it 'returns :completed if passed status is 3' do
46
- subject.send(:parse_status, 3).should == :completed
47
- end
48
-
49
- it 'returns :postponed if passed status is 4' do
50
- subject.send(:parse_status, 4).should == :postponed
51
- end
52
-
53
- it 'returns :archived if passed status is 5' do
54
- subject.send(:parse_status, 5).should == :archived
55
- end
56
-
57
- it 'returns -1 if passed status is :draft' do
58
- subject.send(:parse_status, :draft).should == -1
59
- end
60
-
61
- it 'returns 0 if passed status is :pending' do
62
- subject.send(:parse_status, :pending).should == 0
63
- end
64
-
65
- it 'returns 1 if passed status is :scheduled' do
66
- subject.send(:parse_status, :scheduled).should == 1
67
- end
68
-
69
- it 'returns 2 if passed status is :in_progress' do
70
- subject.send(:parse_status, :in_progress).should == 2
71
- end
72
-
73
- it 'returns 3 if passed status is :completed' do
74
- subject.send(:parse_status, :completed).should == 3
10
+ it 'returns underscored symbol if string is passed' do
11
+ subject.send(:parse_status, 'InProgress').should == :in_progress
75
12
  end
76
13
 
77
- it 'returns 4 if passed status is :postponed' do
78
- subject.send(:parse_status, :postponed).should == 4
14
+ it 'returns capitalized string if symbol is passed' do
15
+ subject.send(:parse_status, :in_progress).should == 'InProgress'
79
16
  end
80
17
 
81
- it 'returns 5 if passed status is :archived' do
82
- subject.send(:parse_status, :archived).should == 5
18
+ it 'raises error if argument is not string or symbol' do
19
+ -> { subject.send(:parse_status, 1) }.should raise_error(ArgumentError)
83
20
  end
84
21
  end
85
22
  end
@@ -3,6 +3,7 @@ require 'spec_helper'
3
3
  describe GroupDocs::Document::Annotation do
4
4
 
5
5
  it_behaves_like GroupDocs::Api::Entity
6
+ include_examples GroupDocs::Api::Helpers::AccessMode
6
7
 
7
8
  subject do
8
9
  file = GroupDocs::Storage::File.new
@@ -78,12 +79,12 @@ describe GroupDocs::Document::Annotation do
78
79
  describe '#type=' do
79
80
  it 'saves type in machine readable format if symbol is passed' do
80
81
  subject.type = :area
81
- subject.instance_variable_get(:@type).should == 1
82
+ subject.instance_variable_get(:@type).should == 'Area'
82
83
  end
83
84
 
84
85
  it 'does nothing if parameter is not symbol' do
85
- subject.type = 1
86
- subject.instance_variable_get(:@type).should == 1
86
+ subject.type = 'Area'
87
+ subject.instance_variable_get(:@type).should == 'Area'
87
88
  end
88
89
 
89
90
  it 'raises error if type is unknown' do
@@ -93,31 +94,20 @@ describe GroupDocs::Document::Annotation do
93
94
 
94
95
  describe '#type' do
95
96
  it 'returns type in human-readable format' do
96
- subject.type = 1
97
+ subject.type = 'Area'
97
98
  subject.type.should == :area
98
99
  end
99
100
  end
100
101
 
101
102
  describe '#access=' do
102
- it 'saves access mode in machine readable format if symbol is passed' do
103
+ it 'converts symbol to string if passed' do
103
104
  subject.access = :public
104
- subject.instance_variable_get(:@access).should == 1
105
+ subject.instance_variable_get(:@access).should == 'Public'
105
106
  end
106
107
 
107
- it 'does nothing if parameter is not symbol' do
108
- subject.access = 1
109
- subject.instance_variable_get(:@access).should == 1
110
- end
111
-
112
- it 'raises error if access mode is unknown' do
113
- -> { subject.access = :unknown }.should raise_error(ArgumentError)
114
- end
115
- end
116
-
117
- describe '#access' do
118
- it 'returns access in human-readable format' do
119
- subject.access = 1
120
- subject.access.should == :public
108
+ it 'does nothing if not a symbol is passed' do
109
+ subject.access = 'Blah'
110
+ subject.instance_variable_get(:@access).should == 'Blah'
121
111
  end
122
112
  end
123
113
 
@@ -127,14 +127,14 @@ describe GroupDocs::Document do
127
127
  end
128
128
 
129
129
  it 'returns access mode in human readable presentation' do
130
- subject.should_receive(:parse_access_mode).with(0).and_return(:private)
130
+ subject.should_receive(:parse_access_mode).with('Private').and_return(:private)
131
131
  subject.access_mode!.should == :private
132
132
  end
133
133
  end
134
134
 
135
135
  describe '#access_mode_set!' do
136
136
  before(:each) do
137
- mock_api_server('{"status": "Ok", "result": {"access": 0 }}')
137
+ mock_api_server('{"status": "Ok", "result": {"access": "Private" }}')
138
138
  end
139
139
 
140
140
  it 'accepts access credentials hash' do
@@ -143,9 +143,9 @@ describe GroupDocs::Document do
143
143
  end.should_not raise_error(ArgumentError)
144
144
  end
145
145
 
146
- it 'sets corresponding access mode and determines set' do
147
- subject.should_receive(:parse_access_mode).with(:private).and_return(0)
148
- subject.should_receive(:parse_access_mode).with(0).and_return(:private)
146
+ it 'sets corresponding access mode' do
147
+ described_class::ACCESS_MODES.should_receive(:[]).with(:private).and_return(0)
148
+ subject.should_receive(:parse_access_mode).with('Private').and_return(:private)
149
149
  subject.access_mode_set!(:private)
150
150
  end
151
151
 
@@ -112,9 +112,8 @@ describe GroupDocs::Job do
112
112
 
113
113
  describe '#actions' do
114
114
  it 'converts actions to human-readable format' do
115
- subject.actions = 129
116
- described_class.should_receive(:convert_byte_to_actions).with(129)
117
- subject.actions
115
+ subject.actions = 'Convert, Combine, CompressZip'
116
+ subject.actions.should == [:convert, :combine, :compress_zip]
118
117
  end
119
118
  end
120
119
 
@@ -3,19 +3,7 @@ require 'spec_helper'
3
3
  describe GroupDocs::Questionnaire::Execution do
4
4
 
5
5
  it_behaves_like GroupDocs::Api::Entity
6
-
7
- describe 'STATUSES' do
8
- it 'contains hash of execution statuses' do
9
- described_class::STATUSES.should == {
10
- draft: 0,
11
- submitted: 1,
12
- executed: 2,
13
- approved: 3,
14
- rejected: 4,
15
- closed: 5,
16
- }
17
- end
18
- end
6
+ include_examples GroupDocs::Api::Helpers::Status
19
7
 
20
8
  describe '.all!' do
21
9
  it 'accepts access credentials hash' do
@@ -76,29 +64,6 @@ describe GroupDocs::Questionnaire::Execution do
76
64
  subject.method(:document_id=).should == subject.method(:documentId=)
77
65
  end
78
66
 
79
- describe '#status=' do
80
- it 'saves status in machine readable format if symbol is passed' do
81
- subject.status = :executed
82
- subject.instance_variable_get(:@status).should == 2
83
- end
84
-
85
- it 'does nothing if parameter is not symbol' do
86
- subject.status = 2
87
- subject.instance_variable_get(:@status).should == 2
88
- end
89
-
90
- it 'raises error if status is unknown' do
91
- -> { subject.status = :unknown }.should raise_error(ArgumentError)
92
- end
93
- end
94
-
95
- describe '#status' do
96
- it 'returns status in human-readable format' do
97
- subject.status = 2
98
- subject.status.should == :executed
99
- end
100
- end
101
-
102
67
  describe '#set_status!' do
103
68
  before(:each) do
104
69
  mock_api_server(load_json('questionnaire_execution_status_set'))
@@ -110,10 +75,14 @@ describe GroupDocs::Questionnaire::Execution do
110
75
  end.should_not raise_error(ArgumentError)
111
76
  end
112
77
 
78
+ it 'parses status' do
79
+ subject.should_receive(:parse_status).with(:submitted).and_return('Submitted')
80
+ subject.set_status!(:submitted)
81
+ end
82
+
113
83
  it 'updates status of execution object' do
114
- lambda do
115
- subject.set_status!(:submitted)
116
- end.should change(subject, :status).to(:submitted)
84
+ subject.set_status!(:submitted)
85
+ subject.status.should == :submitted
117
86
  end
118
87
  end
119
88
 
@@ -4,15 +4,6 @@ describe GroupDocs::Questionnaire::Question do
4
4
 
5
5
  it_behaves_like GroupDocs::Api::Entity
6
6
 
7
- describe 'TYPES' do
8
- it 'contains hash of field types' do
9
- described_class::TYPES.should == {
10
- simple: 0,
11
- multiple_choice: 1,
12
- }
13
- end
14
- end
15
-
16
7
  it { should respond_to(:field) }
17
8
  it { should respond_to(:field=) }
18
9
  it { should respond_to(:text) }
@@ -72,20 +63,24 @@ describe GroupDocs::Questionnaire::Question do
72
63
 
73
64
  describe '#type=' do
74
65
  it 'saves type in machine readable format if symbol is passed' do
75
- subject.type = :multiple_choice
76
- subject.instance_variable_get(:@type).should == 1
66
+ subject.type = :generic_text
67
+ subject.instance_variable_get(:@type).should == 'GenericText'
77
68
  end
78
69
 
79
70
  it 'does nothing if parameter is not symbol' do
80
- subject.type = 1
81
- subject.instance_variable_get(:@type).should == 1
71
+ subject.type = 'GenericText'
72
+ subject.instance_variable_get(:@type).should == 'GenericText'
73
+ end
74
+
75
+ it 'raises error if type is unknown' do
76
+ -> { subject.type = :unknown }.should raise_error(ArgumentError)
82
77
  end
83
78
  end
84
79
 
85
80
  describe '#type' do
86
81
  it 'returns type in human-readable format' do
87
- subject.type = 1
88
- subject.type.should == :multiple_choice
82
+ subject.type = 'GenericText'
83
+ subject.type.should == :generic_text
89
84
  end
90
85
  end
91
86
  end
@@ -6,20 +6,6 @@ describe GroupDocs::Storage::File do
6
6
  include_examples GroupDocs::Extensions::Lookup
7
7
  include_examples GroupDocs::Api::Helpers::AccessMode
8
8
 
9
- describe 'DOCUMENT_TYPES' do
10
- it 'contains hash of document types' do
11
- described_class::DOCUMENT_TYPES.should == {
12
- undefined: -1,
13
- cells: 0,
14
- words: 1,
15
- slides: 2,
16
- pdf: 3,
17
- html: 4,
18
- image: 5,
19
- }
20
- end
21
- end
22
-
23
9
  describe '.upload!' do
24
10
  before(:each) do
25
11
  mock_api_server(load_json('file_upload'))
@@ -81,12 +67,12 @@ describe GroupDocs::Storage::File do
81
67
  describe '#type=' do
82
68
  it 'saves type in machine readable format if symbol is passed' do
83
69
  subject.type = :words
84
- subject.instance_variable_get(:@type).should == 1
70
+ subject.instance_variable_get(:@type).should == 'Words'
85
71
  end
86
72
 
87
73
  it 'does nothing if parameter is not symbol' do
88
- subject.type = 2
89
- subject.instance_variable_get(:@type).should == 2
74
+ subject.type = 'Words'
75
+ subject.instance_variable_get(:@type).should == 'Words'
90
76
  end
91
77
 
92
78
  it 'raises error if type is unknown' do
@@ -96,7 +82,7 @@ describe GroupDocs::Storage::File do
96
82
 
97
83
  describe '#type' do
98
84
  it 'returns type in human-readable format' do
99
- subject.type = 1
85
+ subject.type = 'Words'
100
86
  subject.type.should == :words
101
87
  end
102
88
  end
@@ -20,8 +20,8 @@
20
20
  "X": null,
21
21
  "Y": null
22
22
  },
23
- "type": 0,
24
- "access":null,
23
+ "type": "Text",
24
+ "access": "Public",
25
25
  "createdOn": 1334028956687,
26
26
  "replies": []
27
27
  }
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "result":
3
3
  {
4
- "access": 0,
4
+ "access": "Private",
5
5
  "sharers":
6
6
  [
7
7
  {
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "result":
3
3
  {
4
- "types": "Pdf;Tiff;Jpeg"
4
+ "types": ["Pdf", "Tiff", "Jpeg"]
5
5
  },
6
6
  "status": "Ok",
7
7
  "error_message": null
@@ -3,6 +3,6 @@
3
3
  "result":
4
4
  {
5
5
  "adj_name": "File.pdf",
6
- "type": 1
6
+ "type": "Words"
7
7
  }
8
8
  }
@@ -1,11 +1,11 @@
1
1
  {
2
2
  "result":
3
3
  {
4
- "job_status": 5,
4
+ "job_status": "Archived",
5
5
  "inputs":
6
6
  [
7
7
  {
8
- "status": 2,
8
+ "status": "InProgress",
9
9
  "output_formats": "pdf",
10
10
  "outputs":
11
11
  [
@@ -19,7 +19,7 @@
19
19
  "id": 123
20
20
  },
21
21
  {
22
- "status": 1,
22
+ "status": "Scheduled",
23
23
  "output_formats": "tiff",
24
24
  "outputs":
25
25
  [
@@ -5,13 +5,13 @@
5
5
  [
6
6
  {
7
7
  "id": 1,
8
- "status": 5,
8
+ "status": "Archived",
9
9
  "documents":
10
10
  {
11
11
  "inputs":
12
12
  [
13
13
  {
14
- "status": 2,
14
+ "status": "InProgress",
15
15
  "output_formats": "pdf",
16
16
  "outputs":
17
17
  [
@@ -29,13 +29,13 @@
29
29
  },
30
30
  {
31
31
  "id": 2,
32
- "status": 3,
32
+ "status": "Completed",
33
33
  "documents":
34
34
  {
35
35
  "inputs":
36
36
  [
37
37
  {
38
- "status": 1,
38
+ "status": "Scheduled",
39
39
  "output_formats": "tiff",
40
40
  "outputs":
41
41
  [
@@ -8,14 +8,14 @@
8
8
  "executiveId": 789,
9
9
  "approverId": 987,
10
10
  "datasourceId": 654,
11
- "status": 5
11
+ "status": "Closed"
12
12
  },
13
13
  {
14
14
  "questionnaireId": 111,
15
15
  "executiveId": 222,
16
16
  "approverId": null,
17
17
  "datasourceId": null,
18
- "status": 2
18
+ "status": "Executed"
19
19
  }
20
20
  ]
21
21
  },
@@ -4,8 +4,8 @@ shared_examples_for GroupDocs::Api::Helpers::AccessMode do
4
4
 
5
5
  describe '#access' do
6
6
  it 'returns converted to human-readable format access mode' do
7
- subject.should_receive(:parse_access_mode).with(1).and_return(:restricted)
8
- subject.access = 1
7
+ subject.should_receive(:parse_access_mode).with('Restricted').and_return(:restricted)
8
+ subject.access = 'Restricted'
9
9
  subject.access.should == :restricted
10
10
  end
11
11
  end
@@ -4,9 +4,9 @@ shared_examples_for GroupDocs::Api::Helpers::Status do
4
4
 
5
5
  describe '#status' do
6
6
  it 'returns converted to human-readable format status' do
7
- subject.should_receive(:parse_status).with(0).and_return(:pending)
8
- subject.status = 0
9
- subject.status.should == :pending
7
+ subject.should_receive(:parse_status).with('InProgress').and_return(:in_progress)
8
+ subject.status = 'InProgress'
9
+ subject.status.should == :in_progress
10
10
  end
11
11
  end
12
12
  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.11
4
+ version: 0.3.0
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-05 00:00:00.000000000 Z
12
+ date: 2012-06-18 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rest-client
16
- requirement: &14690440 !ruby/object:Gem::Requirement
16
+ requirement: &5249340 !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: *14690440
24
+ version_requirements: *5249340
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: json
27
- requirement: &14705180 !ruby/object:Gem::Requirement
27
+ requirement: &5264040 !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: *14705180
35
+ version_requirements: *5264040
36
36
  - !ruby/object:Gem::Dependency
37
37
  name: ruby-hmac
38
- requirement: &14703760 !ruby/object:Gem::Requirement
38
+ requirement: &5262620 !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: *14703760
46
+ version_requirements: *5262620
47
47
  - !ruby/object:Gem::Dependency
48
48
  name: rspec
49
- requirement: &14702040 !ruby/object:Gem::Requirement
49
+ requirement: &5260820 !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: *14702040
57
+ version_requirements: *5260820
58
58
  - !ruby/object:Gem::Dependency
59
59
  name: rake
60
- requirement: &14701000 !ruby/object:Gem::Requirement
60
+ requirement: &5259840 !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: *14701000
68
+ version_requirements: *5259840
69
69
  - !ruby/object:Gem::Dependency
70
70
  name: simplecov
71
- requirement: &14700140 !ruby/object:Gem::Requirement
71
+ requirement: &5258940 !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: *14700140
79
+ version_requirements: *5258940
80
80
  - !ruby/object:Gem::Dependency
81
81
  name: yard
82
- requirement: &14713080 !ruby/object:Gem::Requirement
82
+ requirement: &5257440 !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: *14713080
90
+ version_requirements: *5257440
91
91
  - !ruby/object:Gem::Dependency
92
92
  name: webmock
93
- requirement: &14710840 !ruby/object:Gem::Requirement
93
+ requirement: &5269720 !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: *14710840
101
+ version_requirements: *5269720
102
102
  description: Ruby SDK for GroupDocs REST API
103
103
  email: p0deje@gmail.com
104
104
  executables: []
@@ -255,7 +255,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
255
255
  version: '0'
256
256
  segments:
257
257
  - 0
258
- hash: -266361151929611546
258
+ hash: 546322050822999212
259
259
  required_rubygems_version: !ruby/object:Gem::Requirement
260
260
  none: false
261
261
  requirements:
@@ -264,7 +264,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
264
264
  version: '0'
265
265
  segments:
266
266
  - 0
267
- hash: -266361151929611546
267
+ hash: 546322050822999212
268
268
  requirements: []
269
269
  rubyforge_project:
270
270
  rubygems_version: 1.8.10