ruby-box 1.2.1 → 1.3.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,15 +1,15 @@
1
1
  ---
2
2
  !binary "U0hBMQ==":
3
3
  metadata.gz: !binary |-
4
- Njk0MDYwM2Y2MjVmZDIwZjg3ZGZmZjE3ODEyM2FlNGY0NGI0ZmI4MQ==
4
+ MmFhODFkOWNiMGFhOTkwN2QwNmFlYTY5Y2I2OTk4NGU1NDcwZmM5Mw==
5
5
  data.tar.gz: !binary |-
6
- MmM3NGM4OTBkMzBiYjk2MWZkMGMwOTExNWIyODkwMGM1NjFmOWM4MQ==
6
+ Y2Y1NzM1MjQzZDk5ZDJlZTBhZGRiMWEyMmNiMDBmZTA3YmZkNzhlYw==
7
7
  !binary "U0hBNTEy":
8
8
  metadata.gz: !binary |-
9
- MTE1YjFhYTRkYWFlMTk4YWZkNjkxZDY2ZmU3MWFkNjRmMDk3NTA2MTI1OWE2
10
- MGNjMDljNWYyYTZlOTM2NmFlOGU3NDA5YTgzOWVmMGJmODMzZmQwNzMwZTNm
11
- MWRjMzY1OWJhZTE2MTY4ZjRiYTY4NmI4OWFkMzJlMTgzN2YzMDU=
9
+ OGQxZWNkNzhmMDQ0ZGUzYWEwM2JkMzE5Y2ZiNWFiMWI3MTkyZTk3ZGVkODM5
10
+ Nzk4ZDNlMWI5N2M3ODY3ODE0YzViZWViMDFmOWViN2NhNzdhMGUyZjA4MTBl
11
+ ZWIzY2MzNDgwMTJkNmMwOTJjZTY1ZjBkYzU0OTg1MzNjZGVjMjA=
12
12
  data.tar.gz: !binary |-
13
- NzAwOTc5YWEzMTlmNGY3NjcyNDU0NjZjM2JlNGU3ZDlhNjMyMGNhOTY2ODUz
14
- YWM2NzFhNzY3MTAxZDY2N2IzZTU0MzVlZWE2NjQ5NDBhNTM3NGY2NTA3NTE5
15
- M2JhNjEzZWQ2YjBjMzBjNGJjNzAyNTYzNDY4ZTI5YjhjMmY0N2M=
13
+ MzE4MDEwOWIzZjBiMzhjMjU3NjI5OWNlZjljZGY0N2M5ZDA2Y2I1MDQyODhh
14
+ NGUwOTQyYmI4MGM3ZWRkM2RjNzFhMzhiYzljMmRhZGMwMmNmZGRhYzBiN2Ez
15
+ MzdmZWRmOWQ2NTFjMTZhZGE0NWJkOWJiODA5ZTViNTYwY2YxYzQ=
@@ -1,12 +1,12 @@
1
1
  ruby-box
2
- --------
2
+ ========
3
3
 
4
4
  Mainted by: [Attachments.me](https://attachments.me)
5
5
 
6
6
  RubyBox provides a simple, chainable, feature-rich client for [Box's 2.0 API](http://developers.box.com/docs/).
7
7
 
8
8
  Authorization
9
- =============
9
+ -------------
10
10
 
11
11
  RubyBox uses Box's OAuth2 Implementaton, Here are the steps involved in authorizing a client:
12
12
 
@@ -49,12 +49,12 @@ client = RubyBox::Client.new(session)
49
49
  ```
50
50
 
51
51
  Usage
52
- -----
52
+ =====
53
53
 
54
54
  Once you've created a client, you can start interacting with the Box API. What follows are some basic examples of RubyBox's usage:
55
55
 
56
56
  Folders
57
- =======
57
+ -------
58
58
 
59
59
  * Listing items in a folder:
60
60
 
@@ -87,7 +87,7 @@ discussion.comments.each {|comment| p comment.message}
87
87
  ```
88
88
 
89
89
  Files
90
- =====
90
+ -----
91
91
 
92
92
  * Fetching a file's meta information.
93
93
 
@@ -127,7 +127,7 @@ end
127
127
  ```
128
128
 
129
129
  Search
130
- ======
130
+ ------
131
131
 
132
132
  You can use RubyBox's search method to return files and folders that match a given query.
133
133
 
@@ -139,7 +139,7 @@ end
139
139
  ```
140
140
 
141
141
  Events
142
- ======
142
+ ------
143
143
 
144
144
  You can use RubyBox's event_response method to return an EventResponse that can be used to process any incoming events.
145
145
 
@@ -155,7 +155,7 @@ end
155
155
 
156
156
 
157
157
  Contributors
158
- ------------
158
+ ============
159
159
 
160
160
  * Benjamin Coe
161
161
  * Larry Kang
@@ -163,7 +163,7 @@ Contributors
163
163
  * Jesse Miller
164
164
 
165
165
  Contributing to ruby-box
166
- -----------------------
166
+ ========================
167
167
 
168
168
  RubyBox does not yet support all of Box's API Version 2.0 functionality, be liberal with your contributions.
169
169
 
@@ -175,7 +175,7 @@ RubyBox does not yet support all of Box's API Version 2.0 functionality, be libe
175
175
  * Submit a pull request
176
176
 
177
177
  Copyright
178
- ---------
178
+ =========
179
179
 
180
180
  Copyright (c) 2012 Attachments.me. See LICENSE.txt for
181
181
  further details.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 1.2.1
1
+ 1.3.0
@@ -4,22 +4,16 @@ module RubyBox
4
4
  has_many :discussions
5
5
  has_many_paginated :items
6
6
 
7
- def files(name=nil, item_limit=100, offset=0)
8
- items(item_limit, offset).select do |item|
9
- item.kind_of? RubyBox::File and (name.nil? or item.name == name)
10
- end
7
+ def files(name=nil, item_limit=100, offset=0, fields=nil)
8
+ items_by_type(RubyBox::File, name, item_limit, offset, fields)
11
9
  end
12
10
 
13
- def folders(name=nil, item_limit=100, offset=0)
14
- items(item_limit, offset).select do |item|
15
- item.kind_of? RubyBox::Folder and (name.nil? or item.name == name)
16
- end
11
+ def folders(name=nil, item_limit=100, offset=0, fields=nil)
12
+ items_by_type(RubyBox::Folder, name, item_limit, offset, fields)
17
13
  end
18
14
 
19
- def collaborations(item_limit=100, offset=0)
20
- items(item_limit, offset).select do |item|
21
- item.kind_of? RubyBox::Collaboration
22
- end
15
+ def collaborations(item_limit=100, offset=0, fields=nil)
16
+ items_by_type(RubyBox::Collaboration, nil, item_limit, offset, fields)
23
17
  end
24
18
 
25
19
  def upload_file(filename, data)
@@ -57,5 +51,19 @@ module RubyBox
57
51
  def update_fields
58
52
  ['name', 'description']
59
53
  end
54
+
55
+ def items_by_type(type, name, item_limit, offset, fields)
56
+
57
+ # allow paramters to be set via
58
+ # a hash rather than a list of arguments.
59
+ if name.is_a?(Hash)
60
+ return items_by_type(type, name[:name], name[:item_limit], name[:offset], name[:fields])
61
+ end
62
+
63
+ items(item_limit, offset, fields).select do |item|
64
+ item.kind_of? type and (name.nil? or item.name == name)
65
+ end
66
+
67
+ end
60
68
  end
61
69
  end
@@ -51,7 +51,7 @@ module RubyBox
51
51
 
52
52
  # Support has many and paginated has many relationships.
53
53
  return many(key) if @@has_many.include?(key)
54
- return paginated(key, args[0] || 100, args[1] || 0) if @@has_many_paginated.include?(key)
54
+ return paginated(key, args[0] || 100, args[1] || 0, args[2]) if @@has_many_paginated.include?(key)
55
55
 
56
56
  # update @raw_item hash if this appears to be a setter.
57
57
  setter = method.to_s.end_with?('=')
@@ -93,10 +93,11 @@ module RubyBox
93
93
  resp['entries'].map {|i| RubyBox::Item.factory(@session, i)}
94
94
  end
95
95
 
96
- def paginated(key, item_limit=100, offset=0)
96
+ def paginated(key, item_limit=100, offset=0, fields=nil)
97
97
  Enumerator.new do |yielder|
98
98
  while true
99
99
  url = "#{RubyBox::API_URL}/#{resource_name}/#{id}/#{key}?limit=#{item_limit}&offset=#{offset}"
100
+ url = "#{url}&fields=#{fields.map(&:to_s).join(',')}" if fields
100
101
  resp = @session.get( url )
101
102
  resp['entries'].each do |entry|
102
103
  yielder.yield(RubyBox::Item.factory(@session, entry))
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = "ruby-box"
8
- s.version = "1.2.1"
8
+ s.version = "1.3.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-15"
12
+ s.date = "2013-06-05"
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 = [
@@ -54,6 +54,18 @@ describe RubyBox::Folder do
54
54
  items[0].kind_of?(RubyBox::Folder).should == true
55
55
  items[1].kind_of?(RubyBox::File).should == true
56
56
  end
57
+
58
+ it "should allow a fields parameter to be set" do
59
+ RubyBox::Session.any_instance.should_receive(:get).with('https://api.box.com/2.0/folders/1/items?limit=100&offset=0&fields=size').and_return({'entries' => []})
60
+ session = RubyBox::Session.new
61
+ RubyBox::Folder.new(session, {'id' => 1}).items(100, 0, [:size]).to_a
62
+ end
63
+
64
+ it "should not have the fields parameter set by default" do
65
+ RubyBox::Session.any_instance.should_receive(:get).with('https://api.box.com/2.0/folders/1/items?limit=100&offset=0').and_return({'entries' => []})
66
+ session = RubyBox::Session.new
67
+ RubyBox::Folder.new(session, {'id' => 1}).items.to_a
68
+ end
57
69
  end
58
70
 
59
71
  describe '#files' do
@@ -80,6 +80,16 @@ describe RubyBox, :skip => true do
80
80
  file.id.should == "2550686921"
81
81
  end
82
82
  end
83
+
84
+ describe '#files' do
85
+ it "allows additional fields to be requested in file listing" do
86
+ folder = RubyBox::Folder.new(@session, {'id' => '318810303'})
87
+ file = folder.files({fields: [:name, :size]}).first
88
+ file.id.should == "2550686921"
89
+ file.name.should == "2513582219_03fb9b67db_b.jpg"
90
+ file.size.should == 593978
91
+ end
92
+ end
83
93
 
84
94
  describe '#create' do
85
95
  it "creates a folder" do
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.2.1
4
+ version: 1.3.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-15 00:00:00.000000000 Z
11
+ date: 2013-06-05 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: multipart-post
@@ -174,4 +174,3 @@ signing_key:
174
174
  specification_version: 4
175
175
  summary: ruby gem for box.com 2.0 api
176
176
  test_files: []
177
- has_rdoc: