groupdocs 0.3.0 → 0.3.5

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,16 +1,39 @@
1
1
  module GroupDocs
2
2
  class User < GroupDocs::Api::Entity
3
3
 
4
+ #
5
+ # Returns current user profile.
6
+ #
7
+ # @example Get fill
8
+ # user = GroupDocs::User.get!
9
+ # user.first_name
10
+ # #=> "John"
11
+ #
12
+ # @param [Hash] access Access credentials
13
+ # @option access [String] :client_id
14
+ # @option access [String] :private_key
15
+ # @return [GroupDocs::User]
16
+ #
17
+ def self.get!(access = {})
18
+ json = Api::Request.new do |request|
19
+ request[:access] = access
20
+ request[:method] = :GET
21
+ request[:path] = '/mgmt/{{client_id}}/profile'
22
+ end.execute!
23
+
24
+ new(json[:user])
25
+ end
26
+
4
27
  # @attr [Integer] id
5
28
  attr_accessor :id
6
29
  # @attr [String] guid
7
30
  attr_accessor :guid
8
31
  # @attr [String] nickname
9
32
  attr_accessor :nickname
10
- # @attr [String] first_name
11
- attr_accessor :first_name
12
- # @attr [String] last_name
13
- attr_accessor :last_name
33
+ # @attr [String] firstname
34
+ attr_accessor :firstname
35
+ # @attr [String] lastname
36
+ attr_accessor :lastname
14
37
  # @attr [String] primary_email
15
38
  attr_accessor :primary_email
16
39
  # @attr [String] private_key
@@ -32,6 +55,12 @@ module GroupDocs
32
55
  # @attr [Time] signed_up_on
33
56
  attr_accessor :signed_up_on
34
57
 
58
+ # Human-readable accessors
59
+ alias_method :first_name, :firstname
60
+ alias_method :first_name=, :firstname=
61
+ alias_method :last_name, :lastname
62
+ alias_method :last_name=, :lastname=
63
+
35
64
  #
36
65
  # Converts timestamp which is return by API server to Time object.
37
66
  #
@@ -46,5 +75,27 @@ module GroupDocs
46
75
  alias_method :pswd_salt=, :password_salt=
47
76
  alias_method :signedupOn=, :signed_up_on=
48
77
 
78
+ #
79
+ # Updates user profile.
80
+ #
81
+ # @example
82
+ # user = GroupDocs::User.get!
83
+ # user.first_name = 'John'
84
+ # user.last_name = 'Smith'
85
+ # user.update!
86
+ #
87
+ # @param [Hash] access Access credentials
88
+ # @option access [String] :client_id
89
+ # @option access [String] :private_key
90
+ #
91
+ def update!(access = {})
92
+ Api::Request.new do |request|
93
+ request[:access] = access
94
+ request[:method] = :PUT
95
+ request[:path] = '/mgmt/{{client_id}}/profile'
96
+ request[:request_body] = to_hash
97
+ end.execute!
98
+ end
99
+
49
100
  end # User
50
101
  end # GroupDocs
@@ -1,3 +1,3 @@
1
1
  module GroupDocs
2
- VERSION = '0.3.0'
2
+ VERSION = '0.3.5'
3
3
  end # GroupDocs
@@ -4,16 +4,32 @@ describe GroupDocs::User do
4
4
 
5
5
  it_behaves_like GroupDocs::Api::Entity
6
6
 
7
+ describe '.get!' do
8
+ before(:each) do
9
+ mock_api_server(load_json('user_profile_get'))
10
+ end
11
+
12
+ it 'accepts access credentials hash' do
13
+ lambda do
14
+ described_class.get!(client_id: 'client_id', private_key: 'private_key')
15
+ end.should_not raise_error(ArgumentError)
16
+ end
17
+
18
+ it 'returns GroupDocs::User object' do
19
+ described_class.get!.should be_a(GroupDocs::User)
20
+ end
21
+ end
22
+
7
23
  it { should respond_to(:id) }
8
24
  it { should respond_to(:id=) }
9
25
  it { should respond_to(:guid) }
10
26
  it { should respond_to(:guid=) }
11
27
  it { should respond_to(:nickname) }
12
28
  it { should respond_to(:nickname=) }
13
- it { should respond_to(:first_name) }
14
- it { should respond_to(:first_name=) }
15
- it { should respond_to(:last_name) }
16
- it { should respond_to(:last_name=) }
29
+ it { should respond_to(:firstname) }
30
+ it { should respond_to(:firstname=) }
31
+ it { should respond_to(:lastname) }
32
+ it { should respond_to(:lastname=) }
17
33
  it { should respond_to(:primary_email) }
18
34
  it { should respond_to(:primary_email=) }
19
35
  it { should respond_to(:private_key) }
@@ -44,10 +60,38 @@ describe GroupDocs::User do
44
60
  subject.method(:signedupOn=).should == subject.method(:signed_up_on=)
45
61
  end
46
62
 
63
+ it 'has human-readable accessors' do
64
+ subject.should respond_to(:first_name)
65
+ subject.should respond_to(:first_name=)
66
+ subject.should respond_to(:last_name)
67
+ subject.should respond_to(:last_name=)
68
+ subject.method(:first_name).should == subject.method(:firstname)
69
+ subject.method(:first_name=).should == subject.method(:firstname=)
70
+ subject.method(:last_name).should == subject.method(:lastname)
71
+ subject.method(:last_name=).should == subject.method(:lastname=)
72
+ end
73
+
47
74
  describe '#signed_up_on' do
48
75
  it 'returns converted to Time object Unix timestamp' do
49
76
  subject.signed_up_on = 1330450135000
50
77
  subject.signed_up_on.should == Time.at(1330450135)
51
78
  end
52
79
  end
80
+
81
+ describe '#update!' do
82
+ before(:each) do
83
+ mock_api_server('{ "result": { "user_guid": "s8dfts8" }, "status": "Ok" }')
84
+ end
85
+
86
+ it 'accepts access credentials hash' do
87
+ lambda do
88
+ subject.update!(client_id: 'client_id', private_key: 'private_key')
89
+ end.should_not raise_error(ArgumentError)
90
+ end
91
+
92
+ it 'uses hashed version of self as request body' do
93
+ subject.should_receive(:to_hash)
94
+ subject.update!
95
+ end
96
+ end
53
97
  end
@@ -0,0 +1,24 @@
1
+ {
2
+ "result": {
3
+ "user": {
4
+ "nickname": "test@test.com",
5
+ "firstname": "First",
6
+ "lastname": "Last",
7
+ "pkey": "iwhfsfy8sdufh9hfsfsd9",
8
+ "pswd_salt": null,
9
+ "claimed_id": null,
10
+ "token": null,
11
+ "storage": null,
12
+ "photo": null,
13
+ "active": false,
14
+ "news_eanbled": false,
15
+ "signedupOn": 1335963525287,
16
+ "roles": null,
17
+ "id": 85,
18
+ "guid": "8sd7tfsdf",
19
+ "primary_email": "test@test.com"
20
+ }
21
+ },
22
+ "status": "Ok",
23
+ "error_message": null
24
+ }
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.0
4
+ version: 0.3.5
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-18 00:00:00.000000000 Z
12
+ date: 2012-06-21 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rest-client
16
- requirement: &5249340 !ruby/object:Gem::Requirement
16
+ requirement: &7184720 !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: *5249340
24
+ version_requirements: *7184720
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: json
27
- requirement: &5264040 !ruby/object:Gem::Requirement
27
+ requirement: &7199340 !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: *5264040
35
+ version_requirements: *7199340
36
36
  - !ruby/object:Gem::Dependency
37
37
  name: ruby-hmac
38
- requirement: &5262620 !ruby/object:Gem::Requirement
38
+ requirement: &7198000 !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: *5262620
46
+ version_requirements: *7198000
47
47
  - !ruby/object:Gem::Dependency
48
48
  name: rspec
49
- requirement: &5260820 !ruby/object:Gem::Requirement
49
+ requirement: &7196220 !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: *5260820
57
+ version_requirements: *7196220
58
58
  - !ruby/object:Gem::Dependency
59
59
  name: rake
60
- requirement: &5259840 !ruby/object:Gem::Requirement
60
+ requirement: &7195200 !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: *5259840
68
+ version_requirements: *7195200
69
69
  - !ruby/object:Gem::Dependency
70
70
  name: simplecov
71
- requirement: &5258940 !ruby/object:Gem::Requirement
71
+ requirement: &7194280 !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: *5258940
79
+ version_requirements: *7194280
80
80
  - !ruby/object:Gem::Dependency
81
81
  name: yard
82
- requirement: &5257440 !ruby/object:Gem::Requirement
82
+ requirement: &7192780 !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: *5257440
90
+ version_requirements: *7192780
91
91
  - !ruby/object:Gem::Dependency
92
92
  name: webmock
93
- requirement: &5269720 !ruby/object:Gem::Requirement
93
+ requirement: &7205080 !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: *5269720
101
+ version_requirements: *7205080
102
102
  description: Ruby SDK for GroupDocs REST API
103
103
  email: p0deje@gmail.com
104
104
  executables: []
@@ -237,6 +237,7 @@ files:
237
237
  - spec/support/json/questionnaire_update.json
238
238
  - spec/support/json/questionnaires_get.json
239
239
  - spec/support/json/storage_info.json
240
+ - spec/support/json/user_profile_get.json
240
241
  - spec/support/shared_examples/api/entity.rb
241
242
  - spec/support/shared_examples/api/helpers/access_mode_helper.rb
242
243
  - spec/support/shared_examples/api/helpers/status_helper.rb
@@ -255,7 +256,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
255
256
  version: '0'
256
257
  segments:
257
258
  - 0
258
- hash: 546322050822999212
259
+ hash: -885604598236996557
259
260
  required_rubygems_version: !ruby/object:Gem::Requirement
260
261
  none: false
261
262
  requirements:
@@ -264,7 +265,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
264
265
  version: '0'
265
266
  segments:
266
267
  - 0
267
- hash: 546322050822999212
268
+ hash: -885604598236996557
268
269
  requirements: []
269
270
  rubyforge_project:
270
271
  rubygems_version: 1.8.10
@@ -362,6 +363,7 @@ test_files:
362
363
  - spec/support/json/questionnaire_update.json
363
364
  - spec/support/json/questionnaires_get.json
364
365
  - spec/support/json/storage_info.json
366
+ - spec/support/json/user_profile_get.json
365
367
  - spec/support/shared_examples/api/entity.rb
366
368
  - spec/support/shared_examples/api/helpers/access_mode_helper.rb
367
369
  - spec/support/shared_examples/api/helpers/status_helper.rb