ruby-box 1.1.2 → 1.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,15 +1,15 @@
1
1
  ---
2
2
  !binary "U0hBMQ==":
3
3
  metadata.gz: !binary |-
4
- M2IwZDUyYzhhNzE4Njc4YzdmNjUyZDg2NmFiNDc3MDc1NzIzYTJjYQ==
4
+ YzA2NGU1NGE3NjRiYmQzYWE0NmNmNDFmZWY1ZTA3NDJjMjljMjhkNw==
5
5
  data.tar.gz: !binary |-
6
- ZjQ5NDE2Yjk1N2NhMjdjY2FhZThmZTE1MDRkMDkyMzQ0NTU4MmMxNg==
6
+ Y2E3MzIzOWE3NjY3YjFlNGIzOTBkNzVkZTI4Y2UwMTAxNWVjNzc1MA==
7
7
  !binary "U0hBNTEy":
8
8
  metadata.gz: !binary |-
9
- YzJmZWEyODkwODQwYTY0ODMxZGE1NGZkZWMzZGE1OWYwYzFhYmQ0ZWU4NjBl
10
- NWU0ZGI2ZjY3ZjBmOTE2MTdkMWVlNTFlZTEzMGY3MWNlNzQ1MWZhMWQyZGVj
11
- NjkzOWM2OTg3ZmI0MTAyZWIwMDFhMmI1NWZiYzQ5YjJlYmY5ZjM=
9
+ NTFiYWM5MGEzNjRhZDMwNGJlNjhhOTkxMjhiZTM2ZDEwN2M4OTQ3ZTI3MTFk
10
+ NDc4ZDcwOTg1MWFmMTk4OTExOGZkNTE0YThhMWRkZDg5YzY1NjBkNTBjMmQ3
11
+ N2U3Yzg3ZGIxOGMxNDI2ZDI5MmI2NmNjNmQxN2E3OTE0Mzc2N2Q=
12
12
  data.tar.gz: !binary |-
13
- NDE1ZDBhMWNmNWI4M2FjZWQwOGU0OTgyM2E0Njg4OThmMjM4MzkyOTk1Yjdi
14
- OTExMmY1Y2NlNDJkY2Q2YjE0NmU3OGYzMTc4ZDZjYjljYWIxZTMyMThlOGM4
15
- NWVhYWYyMGRlOTdmNjUzODQ3YjU3NzUxNjI2ZDNmYTkxOGFjZjA=
13
+ ZDY2ZWQ0ZTBhZjMxOTMzZDVmMjQ2NmI5MTAwZTNlNzBhYTRhY2VkODliNTc2
14
+ NDJhODQwMjE1NTg2YjFlNzdiOTY2MzM3MzkwY2E1MDgxNWY4ODRiNzg5MWNk
15
+ ZDVmZGJiYzI1M2MyNGNmODAzY2Q3YTc1MTU2NzQ2MTI3M2JjMDA=
data/Gemfile CHANGED
@@ -2,6 +2,7 @@ source "http://rubygems.org"
2
2
 
3
3
  gem "multipart-post"
4
4
  gem "oauth2"
5
+ gem "json"
5
6
 
6
7
  group :development do
7
8
  gem "rspec"
@@ -12,6 +12,7 @@ GEM
12
12
  bundler (~> 1.0)
13
13
  git (>= 1.2.5)
14
14
  rake
15
+ json (1.7.7)
15
16
  jwt (0.1.5)
16
17
  multi_json (>= 1.0)
17
18
  multi_json (1.6.0)
@@ -42,6 +43,7 @@ PLATFORMS
42
43
  DEPENDENCIES
43
44
  bundler
44
45
  jeweler (~> 1.6.4)
46
+ json
45
47
  multipart-post
46
48
  oauth2
47
49
  rspec
data/VERSION CHANGED
@@ -1 +1 @@
1
- 1.1.2
1
+ 1.2.0
@@ -6,6 +6,7 @@ require 'ruby-box/file'
6
6
  require 'ruby-box/folder'
7
7
  require 'ruby-box/user'
8
8
  require 'ruby-box/comment'
9
+ require 'ruby-box/collaboration'
9
10
  require 'ruby-box/discussion'
10
11
  require 'ruby-box/exceptions'
11
12
  require 'ruby-box/event_response'
@@ -16,12 +16,14 @@ module RubyBox
16
16
  folder.reload_meta
17
17
  end
18
18
 
19
- def folder(path)
19
+ def folder(path='/')
20
+ path = path.sub(/(^\.$)|(^\.\/)/, '') if path # handle folders with leading '.'
21
+ return root_folder if ['', '/'].member?(path)
20
22
  folder_from_split_path( split_path(path) )
21
23
  end
22
24
 
23
25
  def file(path)
24
- path = split_path(path)
26
+ path = split_path( path.sub(/^\.\//, '') )
25
27
  file_name = path.pop
26
28
  folder = folder_from_split_path( path )
27
29
  folder.files(file_name).first if folder
@@ -96,6 +98,11 @@ module RubyBox
96
98
  EventResponse.new(@session, resp)
97
99
  end
98
100
 
101
+ def me
102
+ resp = @session.get( "#{RubyBox::API_URL}/users/me" )
103
+ User.new(@session, resp)
104
+ end
105
+
99
106
  private
100
107
 
101
108
  def folder_from_split_path(path)
@@ -108,7 +115,9 @@ module RubyBox
108
115
  end
109
116
 
110
117
  def fmt_events_args(stream_position, stream_type, limit)
111
- stream_position = stream_position.kind_of?(Numeric) ? stream_position : 0
118
+ unless stream_position.to_s == 'now'
119
+ stream_position = stream_position.kind_of?(Numeric) ? stream_position : 0
120
+ end
112
121
  stream_type = [:all, :changes, :sync].include?(stream_type) ? stream_type : :all
113
122
  limit = limit.kind_of?(Fixnum) ? limit : 100
114
123
  "stream_position=#{stream_position}&stream_type=#{stream_type}&limit=#{limit}"
@@ -0,0 +1,15 @@
1
+ module RubyBox
2
+ class Collaboration < Item
3
+
4
+ private
5
+
6
+ def resource_name
7
+ 'collaborations'
8
+ end
9
+
10
+ def update_fields
11
+ ['role', 'status']
12
+ end
13
+
14
+ end
15
+ end
@@ -16,6 +16,12 @@ module RubyBox
16
16
  end
17
17
  end
18
18
 
19
+ def collaborations(item_limit=100, offset=0)
20
+ items(item_limit, offset).select do |item|
21
+ item.kind_of? RubyBox::Collaboration
22
+ end
23
+ end
24
+
19
25
  def upload_file(filename, data)
20
26
  file = RubyBox::File.new(@session, {
21
27
  'name' => filename,
@@ -73,21 +73,12 @@ module RubyBox
73
73
  protected
74
74
 
75
75
  def self.factory(session, entry)
76
- case entry['type']
77
- when 'folder'
78
- return RubyBox::Folder.new(session, entry)
79
- when 'file'
80
- return RubyBox::File.new(session, entry)
81
- when 'comment'
82
- return RubyBox::Comment.new(session, entry)
83
- when 'user'
84
- return RubyBox::User.new(session, entry)
85
- when 'discussion'
86
- return RubyBox::Discussion.new(session, entry)
87
- when 'web_link'
88
- return RubyBox::WebLink.new(session, entry)
76
+ type = entry['type'].capitalize.to_sym
77
+ if RubyBox.constants.include? type
78
+ RubyBox.const_get(type).new(session, entry)
79
+ else
80
+ entry
89
81
  end
90
- entry
91
82
  end
92
83
 
93
84
  def has_mini_format?
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = "ruby-box"
8
- s.version = "1.1.2"
8
+ s.version = "1.2.0"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Attachments.me"]
12
- s.date = "2013-05-01"
12
+ s.date = "2013-05-03"
13
13
  s.description = "ruby gem for box.com 2.0 api"
14
14
  s.email = "ben@attachments.me"
15
15
  s.extra_rdoc_files = [
@@ -26,6 +26,7 @@ Gem::Specification.new do |s|
26
26
  "VERSION",
27
27
  "lib/ruby-box.rb",
28
28
  "lib/ruby-box/client.rb",
29
+ "lib/ruby-box/collaboration.rb",
29
30
  "lib/ruby-box/comment.rb",
30
31
  "lib/ruby-box/discussion.rb",
31
32
  "lib/ruby-box/event.rb",
@@ -42,11 +43,13 @@ Gem::Specification.new do |s|
42
43
  "spec/event_spec.rb",
43
44
  "spec/file_spec.rb",
44
45
  "spec/fixtures/events.json",
46
+ "spec/fixtures/me.json",
45
47
  "spec/fixtures/遠志教授.jpg",
46
48
  "spec/folder_spec.rb",
47
49
  "spec/helper/account.example",
48
50
  "spec/helper/account.rb",
49
51
  "spec/integration_spec.rb",
52
+ "spec/me_spec.rb",
50
53
  "spec/spec_helper.rb"
51
54
  ]
52
55
  s.homepage = "http://github.com/attachmentsme/ruby-box"
@@ -61,6 +64,7 @@ Gem::Specification.new do |s|
61
64
  if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
62
65
  s.add_runtime_dependency(%q<multipart-post>, [">= 0"])
63
66
  s.add_runtime_dependency(%q<oauth2>, [">= 0"])
67
+ s.add_runtime_dependency(%q<json>, [">= 0"])
64
68
  s.add_development_dependency(%q<rspec>, [">= 0"])
65
69
  s.add_development_dependency(%q<bundler>, [">= 0"])
66
70
  s.add_development_dependency(%q<jeweler>, ["~> 1.6.4"])
@@ -68,6 +72,7 @@ Gem::Specification.new do |s|
68
72
  else
69
73
  s.add_dependency(%q<multipart-post>, [">= 0"])
70
74
  s.add_dependency(%q<oauth2>, [">= 0"])
75
+ s.add_dependency(%q<json>, [">= 0"])
71
76
  s.add_dependency(%q<rspec>, [">= 0"])
72
77
  s.add_dependency(%q<bundler>, [">= 0"])
73
78
  s.add_dependency(%q<jeweler>, ["~> 1.6.4"])
@@ -76,6 +81,7 @@ Gem::Specification.new do |s|
76
81
  else
77
82
  s.add_dependency(%q<multipart-post>, [">= 0"])
78
83
  s.add_dependency(%q<oauth2>, [">= 0"])
84
+ s.add_dependency(%q<json>, [">= 0"])
79
85
  s.add_dependency(%q<rspec>, [">= 0"])
80
86
  s.add_dependency(%q<bundler>, [">= 0"])
81
87
  s.add_dependency(%q<jeweler>, ["~> 1.6.4"])
@@ -10,6 +10,17 @@ describe RubyBox::Client do
10
10
  @session = RubyBox::Session.new
11
11
  end
12
12
 
13
+ describe '#folder' do
14
+ it "should return root folder as default behavior for paths such as ./" do
15
+ RubyBox::Client.any_instance.should_receive(:root_folder).exactly(4).times
16
+ client = RubyBox::Client.new(@session)
17
+ client.folder()
18
+ client.folder('.')
19
+ client.folder('./')
20
+ client.folder('/')
21
+ end
22
+ end
23
+
13
24
  describe '#split_path' do
14
25
  it "returns the appropriate path" do
15
26
  client = RubyBox::Client.new(@session)
@@ -29,6 +29,11 @@ describe RubyBox::EventResponse do
29
29
  event.missing_key
30
30
  end
31
31
 
32
+ it '#fmt_events_args should return a properly formatted URL' do
33
+ @client.send(:fmt_events_args, 0, :all, 100).should eql("stream_position=0&stream_type=all&limit=100")
34
+ @client.send(:fmt_events_args, 'now', :changes, 55).should eql("stream_position=now&stream_type=changes&limit=55")
35
+ end
36
+
32
37
  describe '#event_response' do
33
38
  before do
34
39
  @response = @client.event_response
@@ -0,0 +1,17 @@
1
+ {
2
+ "type": "user",
3
+ "id": "10000000",
4
+ "name": "Test User",
5
+ "login": "test@example.com",
6
+ "created_at": "2013-05-01T11:26:07-05:00",
7
+ "modified_at": "2013-05-01T11:26:07-05:00",
8
+ "language": "en",
9
+ "space_amount": 2400000000,
10
+ "space_used": 2000000,
11
+ "max_upload_size": 200000000,
12
+ "status": "active",
13
+ "job_title": "Unit Tester",
14
+ "phone": "5555555555",
15
+ "address": "600 Unit Test Way",
16
+ "avatar_url": "https://www.box.com/api/avatar/large/10000000"
17
+ }
@@ -11,8 +11,8 @@ describe RubyBox::Folder do
11
11
  @full_folder = JSON.parse('{ "type": "folder", "id": "11446498", "sequence_id": "1", "etag": "1", "name": "Pictures", "created_at": "2012-12-12T10:53:43-08:00", "modified_at": "2012-12-12T11:15:04-08:00", "description": "Some pictures I took", "size": 629644, "path_collection": { "total_count": 1, "entries": [ { "type": "folder", "id": "0", "sequence_id": null, "etag": null, "name": "All Files" } ] }, "created_by": { "type": "user", "id": "17738362", "name": "sean rose", "login": "sean@box.com" }, "modified_by": { "type": "user", "id": "17738362", "name": "sean rose", "login": "sean@box.com" }, "owned_by": { "type": "user", "id": "17738362", "name": "sean rose", "login": "sean@box.com" }, "shared_link": { "url": "https://www.box.com/s/vspke7y05sb214wjokpk", "download_url": "https://www.box.com/shared/static/vspke7y05sb214wjokpk", "vanity_url": null, "is_password_enabled": false, "unshared_at": null, "download_count": 0, "preview_count": 0, "access": "open", "permissions": { "can_download": true, "can_preview": true } }, "folder_upload_email": { "access": "open", "email": "upload.Picture.k13sdz1@u.box.com" }, "parent": { "type": "folder", "id": "0", "sequence_id": null, "etag": null, "name": "All Files" }, "item_status": "active", "item_collection": { "total_count": 1, "entries": [ { "type": "file", "id": "5000948880", "sequence_id": "3", "etag": "3", "sha1": "134b65991ed521fcfe4724b7d814ab8ded5185dc", "name": "tigers.jpeg" } ], "offset": 0, "limit": 100 }}')
12
12
  @mini_folder = JSON.parse('{ "type":"folder", "id":"301415432", "sequence_id":"0", "name":"my first sub-folder"}')
13
13
  @items = [
14
- JSON.parse('{ "total_count": 4, "entries": [ { "type": "folder", "id": "409047867", "sequence_id": "1", "etag": "1", "name": "Here\'s your folder" }, { "type": "file", "id": "409042867", "sequence_id": "1", "etag": "1", "name": "A choice file" } ], "offset": "0", "limit": "2"}'),
15
- JSON.parse('{ "total_count": 4, "entries": [ { "type": "folder", "id": "409047868", "sequence_id": "1", "etag": "1", "name": "Here\'s another folder" }, { "type": "file", "id": "409042810", "sequence_id": "1", "etag": "1", "name": "A choice file" } ], "offset": "2", "limit": "2"}')
14
+ JSON.parse('{ "total_count": 4, "entries": [ { "type": "folder", "id": "409047867", "sequence_id": "1", "etag": "1", "name": "Here\'s your folder" }, { "type": "file", "id": "409042867", "sequence_id": "1", "etag": "1", "name": "A choice file" }, { "type": "collaboration", "id": "409042000", "status": "accepted" } ], "offset": "0", "limit": "3"}'),
15
+ JSON.parse('{ "total_count": 4, "entries": [ { "type": "folder", "id": "409047868", "sequence_id": "1", "etag": "1", "name": "Here\'s another folder" }, { "type": "file", "id": "409042810", "sequence_id": "1", "etag": "1", "name": "A choice file" }, { "type": "collaboration", "id": "409042001", "status": "accepted" } ], "offset": "2", "limit": "3"}')
16
16
  ]
17
17
  end
18
18
 
@@ -109,4 +109,14 @@ describe RubyBox::Folder do
109
109
  files.first.kind_of?(RubyBox::Folder).should == true
110
110
  end
111
111
  end
112
- end
112
+
113
+ describe '#collaborations' do
114
+ it "should only return items of type Collaboration" do
115
+ RubyBox::Session.any_instance.stub(:request) { @items.pop }
116
+ session = RubyBox::Session.new
117
+ collaborations = RubyBox::Folder.new(session, {'id' => 1}).collaborations
118
+ collaborations.count.should == 1
119
+ collaborations.first.kind_of?(RubyBox::Collaboration).should == true
120
+ end
121
+ end
122
+ end
@@ -0,0 +1,20 @@
1
+ #encoding: UTF-8
2
+
3
+ require 'ruby-box'
4
+ require 'webmock/rspec'
5
+
6
+ describe '/users/me' do
7
+ before do
8
+ @session = RubyBox::Session.new
9
+ @client = RubyBox::Client.new(@session)
10
+ @me_json = File.read 'spec/fixtures/me.json'
11
+ @me = JSON.load @me_json
12
+ stub_request(:get, /#{RubyBox::API_URL}\/users\/me/).to_return(body: @me_json, :status => 200)
13
+ end
14
+
15
+ it 'should return the currently logged in User' do
16
+ me = @client.me
17
+ me.instance_of?(RubyBox::User).should be_true
18
+ end
19
+
20
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ruby-box
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.2
4
+ version: 1.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Attachments.me
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-05-01 00:00:00.000000000 Z
11
+ date: 2013-05-03 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: multipart-post
@@ -38,6 +38,20 @@ dependencies:
38
38
  - - ! '>='
39
39
  - !ruby/object:Gem::Version
40
40
  version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: json
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ! '>='
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ! '>='
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
41
55
  - !ruby/object:Gem::Dependency
42
56
  name: rspec
43
57
  requirement: !ruby/object:Gem::Requirement
@@ -111,6 +125,7 @@ files:
111
125
  - VERSION
112
126
  - lib/ruby-box.rb
113
127
  - lib/ruby-box/client.rb
128
+ - lib/ruby-box/collaboration.rb
114
129
  - lib/ruby-box/comment.rb
115
130
  - lib/ruby-box/discussion.rb
116
131
  - lib/ruby-box/event.rb
@@ -127,11 +142,13 @@ files:
127
142
  - spec/event_spec.rb
128
143
  - spec/file_spec.rb
129
144
  - spec/fixtures/events.json
145
+ - spec/fixtures/me.json
130
146
  - spec/fixtures/遠志教授.jpg
131
147
  - spec/folder_spec.rb
132
148
  - spec/helper/account.example
133
149
  - spec/helper/account.rb
134
150
  - spec/integration_spec.rb
151
+ - spec/me_spec.rb
135
152
  - spec/spec_helper.rb
136
153
  homepage: http://github.com/attachmentsme/ruby-box
137
154
  licenses: