nsicloudooo 0.2.6 → 0.2.7

Sign up to get free protection for your applications and to get access to all the features.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.2.6
1
+ 0.2.7
@@ -27,14 +27,20 @@ module NSICloudooo
27
27
  # @example A simple granulation
28
28
  # require 'base64'
29
29
  # doc = Base64.encode64(File.new('document.odt', 'r').read)
30
- # nsicloudooo.granulate(:file => doc, :filename => 'document.odt')
30
+ # response = nsicloudooo.granulate(:file => doc, :filename => 'document.odt')
31
+ # nsicloudooo.done(response["doc_key"])
32
+ # nsicloudooo.grains_keys_for(response["doc_key"])
31
33
  # @example Granulating from a SAM uid
32
34
  # doc = Base64.encode64(File.new('document.odt', 'r').read)
33
35
  # response = sam.store({:doc => doc})
34
36
  # doc_key = response["doc_key"]
35
- # nsicloudooo.granulate(:sam_uid => doc_key, :filename => 'document.odt')
37
+ # response = nsicloudooo.granulate(:sam_uid => doc_key, :filename => 'document.odt')
38
+ # nsicloudooo.done(response["doc_key"])
39
+ # nsicloudooo.grains_keys_for(response["doc_key"])
36
40
  # @example Downloading and granulating from web
37
- # nsicloudooo.granulate(:doc_link => 'http://google.com/document.odt')
41
+ # response = nsicloudooo.granulate(:doc_link => 'http://google.com/document.odt')
42
+ # nsicloudooo.done(response["doc_key"])
43
+ # nsicloudooo.grains_keys_for(response["doc_key"])
38
44
  # @example Sending a callback url
39
45
  # doc = Base64.encode64(File.new('document.odt', 'r').read)
40
46
  # nsicloudooo.granulate(:file => doc, :filename => 'document.odt', :callback => 'http://google.com')
@@ -46,16 +52,24 @@ module NSICloudooo
46
52
  #
47
53
  # @return [Hash] response
48
54
  # * "doc_key" [String] the key to access the granulated document if the sam node it was stored
55
+ #
56
+ # @raise NSICloudooo::Errors::Client::MissingParametersError when an invalid or incomplete set of parameters is provided
57
+ # @raise NSICloudooo::Errors::Client::SAMConnectionError when cannot connect to the SAM node
58
+ # @raise NSICloudooo::Errors::Client::AuthenticationError when invalids user and/or password are provided
59
+ # @raise NSICloudooo::Errors::Client::KeyNotFoundError when an invalid sam_uid is provided
60
+ #
49
61
  def granulate(options = {})
50
62
  @request_data = Hash.new
51
63
  if options[:doc_link]
52
64
  insert_download_data options
53
- elsif options[:sam_uid]
65
+ elsif options[:sam_uid] && options[:filename]
54
66
  file_data = {:sam_uid => options[:sam_uid], :filename => options[:filename]}
55
67
  @request_data.merge! file_data
56
- else
68
+ elsif options[:file] && options[:filename]
57
69
  file_data = {:doc => options[:file], :filename => options[:filename]}
58
70
  @request_data.merge! file_data
71
+ else
72
+ raise NSICloudooo::Errors::Client::MissingParametersError
59
73
  end
60
74
  insert_callback_data options
61
75
  request = prepare_request :POST, @request_data.to_json
@@ -64,7 +78,6 @@ module NSICloudooo
64
78
 
65
79
  # Verify if a document is already granulated
66
80
  #
67
- # @raise NSICloudooo::Errors::Client:KeyNotFoundError when an invalid document key is provided
68
81
  #
69
82
  # @param [String] key of the desired document
70
83
  # @return [Hash] response
@@ -72,6 +85,11 @@ module NSICloudooo
72
85
  #
73
86
  # @example
74
87
  # nsicloudooo.done("some key")
88
+ #
89
+ # @raise NSICloudooo::Errors::Client::SAMConnectionError when cannot connect to the SAM node
90
+ # @raise NSICloudooo::Errors::Client::AuthenticationError when invalids user and/or password are provided
91
+ # @raise NSICloudooo::Errors::Client::KeyNotFoundError when an invalid key is provided
92
+ #
75
93
  def done(key)
76
94
  request = prepare_request :GET, {:key => key}.to_json
77
95
  execute_request(request)
@@ -79,7 +97,6 @@ module NSICloudooo
79
97
 
80
98
  # Return the keys of the grains of a document
81
99
  #
82
- # @raise NSICloudooo::Errors::Client:KeyNotFoundError when an invalid document key is provided
83
100
  #
84
101
  # @param [String] key of the desired document
85
102
  # @return [Hash] response
@@ -88,6 +105,11 @@ module NSICloudooo
88
105
  #
89
106
  # @example
90
107
  # nsicloudooo.grains_keys_for("some key")
108
+ #
109
+ # @raise NSICloudooo::Errors::Client::SAMConnectionError when cannot connect to the SAM node
110
+ # @raise NSICloudooo::Errors::Client::AuthenticationError when invalids user and/or password are provided
111
+ # @raise NSICloudooo::Errors::Client::KeyNotFoundError when an invalid key is provided
112
+ #
91
113
  def grains_keys_for(document_key)
92
114
  request = prepare_request :GET, {:doc_key => document_key}.to_json
93
115
  execute_request(request)
@@ -118,6 +140,11 @@ module NSICloudooo
118
140
  http.request(request)
119
141
  end
120
142
  raise NSICloudooo::Errors::Client::KeyNotFoundError if response.code == "404"
143
+ raise NSICloudooo::Errors::Client::MalformedRequestError if response.code == "400"
144
+ raise NSICloudooo::Errors::Client::AuthenticationError if response.code == "401"
145
+ if response.code == "500" and response.body.include?("SAM")
146
+ raise NSICloudooo::Errors::Client::SAMConnectionError
147
+ end
121
148
  JSON.parse(response.body)
122
149
  end
123
150
  end
@@ -3,6 +3,18 @@ module NSICloudooo
3
3
  module Client
4
4
  class KeyNotFoundError < RuntimeError
5
5
  end
6
+
7
+ class MissingParametersError < RuntimeError
8
+ end
9
+
10
+ class MalformedRequestError < RuntimeError
11
+ end
12
+
13
+ class AuthenticationError < RuntimeError
14
+ end
15
+
16
+ class SAMConnectionError < RuntimeError
17
+ end
6
18
  end
7
19
  end
8
20
  end
data/nsicloudooo.gemspec CHANGED
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = "nsicloudooo"
8
- s.version = "0.2.6"
8
+ s.version = "0.2.7"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Douglas Camata"]
12
- s.date = "2012-04-02"
12
+ s.date = "2012-04-03"
13
13
  s.description = "A simple gem to access a nsi.cloudooo node"
14
14
  s.email = "d.camata@gmail.com"
15
15
  s.extra_rdoc_files = [
@@ -20,6 +20,12 @@ describe NSICloudooo do
20
20
  response.should_not be_nil
21
21
  response["doc_key"].should == "key for document test.odt"
22
22
  end
23
+
24
+ it "should throw error if any required parameter is missing" do
25
+ expect { @nsicloudooo.granulate(:file => 'document') }.to raise_error(NSICloudooo::Errors::Client::MissingParametersError)
26
+ expect { @nsicloudooo.granulate(:sam_uid => 'document') }.to raise_error(NSICloudooo::Errors::Client::MissingParametersError)
27
+ expect { @nsicloudooo.granulate(:filename => 'document') }.to raise_error(NSICloudooo::Errors::Client::MissingParametersError)
28
+ end
23
29
  end
24
30
 
25
31
  context "granulation with conversion" do
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: nsicloudooo
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.6
4
+ version: 0.2.7
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: 2012-04-02 00:00:00.000000000 Z
12
+ date: 2012-04-03 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: sinatra
@@ -144,7 +144,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
144
144
  version: '0'
145
145
  segments:
146
146
  - 0
147
- hash: 2544257564898028649
147
+ hash: 1165319240348010888
148
148
  required_rubygems_version: !ruby/object:Gem::Requirement
149
149
  none: false
150
150
  requirements: