box-api 0.1.6 → 0.1.7

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore CHANGED
@@ -1 +1,3 @@
1
1
  pkg/
2
+ examples/app_data.yml
3
+ spec/helper/account.yml
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- box-api (0.1.6)
4
+ box-api (0.1.7)
5
5
  httmultiparty (~> 0.3)
6
6
 
7
7
  GEM
data/README.md CHANGED
@@ -8,6 +8,12 @@ You can use the Box.net API to create applications and websites that integrate w
8
8
  * Move, rename and delete files
9
9
  * Share files
10
10
 
11
+ ### Install ###
12
+
13
+ gem install box-api
14
+
15
+ That's it!
16
+
11
17
  ### Usage ###
12
18
 
13
19
  You must first obtain an API key by [registering your Box.net application](http://www.box.net/developers/services).
@@ -1,6 +1,6 @@
1
1
  Gem::Specification.new do |s|
2
2
  s.name = "box-api"
3
- s.version = "0.1.6"
3
+ s.version = "0.1.7"
4
4
  s.platform = Gem::Platform::RUBY
5
5
  s.authors = ["Box.net", "Luke Curley"]
6
6
  s.email = ["luke@box.net"]
@@ -1,6 +1,3 @@
1
- ---
1
+ ---
2
2
  api_key: ezgx2366bod57zqvgk0lhjuy3l367arp
3
- auth_token: !str
4
- str: ouaq0t5r18psa5zcxqo339arfizcn9mr
5
- :@attributes: {}
6
-
3
+ auth_token: yrvp951t1055tpm1g1nxr2u09vx3trj2
@@ -54,7 +54,7 @@ module Box
54
54
 
55
55
  # the user must visit this url to allow the application to access their account
56
56
  def authorize_url(ticket = self.ticket)
57
- "#{ api.url }/auth/#{ ticket }"
57
+ "#{ api.base_url }/auth/#{ ticket }"
58
58
  end
59
59
 
60
60
  # using the ticket, we get the auth_token providing the user has already allowed our application the privilege
@@ -6,6 +6,8 @@ module Box
6
6
  class Api
7
7
  include HTTMultiParty # a slight modification to HTTParty, adding multi-part upload support
8
8
 
9
+ attr_accessor :base_url, :upload_url
10
+
9
11
  def initialize(key, url = 'https://box.net', upload_url = 'https://upload.box.net', version = '1.0')
10
12
  @default_params = { :api_key => key } # add the api_key to every query
11
13
 
@@ -7,6 +7,7 @@ module Box
7
7
 
8
8
  def self.type; 'folder'; end
9
9
 
10
+ # override the existing info method so that we create empty folders/files first
10
11
  def info(refresh = false)
11
12
  return self if @cached_info and not refresh
12
13
 
@@ -50,7 +51,7 @@ module Box
50
51
  # search for items using criteria
51
52
  def find(criteria)
52
53
  recursive = criteria.delete(:recursive)
53
- recursive = true if recursive == nil # default to true
54
+ recursive = false if recursive == nil # default to false for performance reasons
54
55
 
55
56
  tree if recursive # get the full tree
56
57
 
@@ -103,6 +104,7 @@ module Box
103
104
  end
104
105
  end
105
106
 
107
+ # update the cached status of all sub items, as we got the entire tree
106
108
  def force_cached_tree
107
109
  create_sub_items(nil, Box::Folder)
108
110
  create_sub_items(nil, Box::File)
@@ -119,6 +121,7 @@ module Box
119
121
  end
120
122
  end
121
123
 
124
+ # search for any files/folders that match the criteria sent
122
125
  def find!(criteria, recursive)
123
126
  matches = (files + folders).collect do |item| # search over our files and folders
124
127
  match = criteria.all? do |key, value| # make sure all criteria pass
@@ -11,6 +11,7 @@ module Box
11
11
  update_info(info) # merges with the info hash, and renames some fields
12
12
  end
13
13
 
14
+ # return the string representation of this item (file or folder)
14
15
  def self.type; raise "Overwrite this method"; end
15
16
  def self.types; type + 's'; end
16
17
 
@@ -29,6 +30,7 @@ module Box
29
30
 
30
31
  self
31
32
  end
33
+
32
34
  # move the item to the destination folder
33
35
  def move(destination)
34
36
  @api.move(type, id, destination.id)
@@ -69,6 +71,7 @@ module Box
69
71
  self
70
72
  end
71
73
 
74
+ # set the description of the item
72
75
  def description(message)
73
76
  @api.set_description(type, id, message)
74
77
 
@@ -102,10 +105,11 @@ module Box
102
105
  # sub-classes are meant to implement this
103
106
  def get_info(*args); Hash.new; end
104
107
 
108
+ # takes in a hash of info, cleans it, and merges it into the existing info
105
109
  def update_info(info)
106
110
  ninfo = Hash.new
107
111
 
108
- # the api is stupid and some fields are named 'file_id' or 'id' inconsistently, so trim the type off
112
+ # some fields are named 'file_id' or 'id' inconsistently, so trim the type off
109
113
  info.each do |name, value|
110
114
  if name.to_s =~ /^#{ type }_(.+)$/; ninfo[$1] = value
111
115
  else; ninfo[name.to_s] = value; end
@@ -114,11 +118,13 @@ module Box
114
118
  @data.merge!(ninfo) # merge in the updated info
115
119
  end
116
120
 
121
+ # delete the cache for a specific info
117
122
  def delete_info(field)
118
123
  @cached_info = false
119
124
  @data.delete(field)
120
125
  end
121
126
 
127
+ # delete the entire cache
122
128
  def clear_info
123
129
  @cached_info = false
124
130
  @data.clear
@@ -9,7 +9,7 @@ describe Box::File do
9
9
  describe "operations" do
10
10
  before(:all) do
11
11
  @root = get_root
12
- spec = @root.find(:name => 'rspec folder', :type => 'folder', :recursive => false).first
12
+ spec = @root.find(:name => 'rspec folder', :type => 'folder').first
13
13
  spec.delete if spec
14
14
  end
15
15
 
@@ -9,7 +9,7 @@ describe Box::Folder do
9
9
  context "with api" do
10
10
  before(:all) do
11
11
  @root = get_root
12
- spec = @root.find(:name => 'rspec folder', :type => 'folder', :recursive => false).first
12
+ spec = @root.find(:name => 'rspec folder', :type => 'folder').first
13
13
  spec.delete if spec
14
14
  end
15
15
 
@@ -58,27 +58,27 @@ describe Box::Folder do
58
58
  describe "#find" do
59
59
  describe "single result" do
60
60
  it "finds existing item" do
61
- file = @root.find(:name => 'expected.1.swf').first
61
+ file = @root.find(:name => 'expected.1.swf', :recursive => true).first
62
62
  file.id.should == '61679540'
63
63
  file.name.should == 'expected.1.swf'
64
64
  end
65
65
 
66
66
  it "finds non-existant file" do
67
- file = @root.find(:name => 'notfound.png').first
67
+ file = @root.find(:name => 'notfound.png', :recursive => true).first
68
68
  file.should be nil
69
69
  end
70
70
 
71
71
  it "finds specified format" do
72
- folder = @root.find(:name => 'tests', :type => 'folder').first
72
+ folder = @root.find(:name => 'tests', :type => 'folder', :recursive => true).first
73
73
  folder.id.should == '7065552'
74
74
  folder.name.should == 'tests'
75
75
 
76
- file = @root.find(:name => 'tests', :type => 'file').first
76
+ file = @root.find(:name => 'tests', :type => 'file', :recursive => true).first
77
77
  file.should be nil
78
78
  end
79
79
 
80
80
  it "finds specified criteria" do
81
- file = @root.find(:type => 'file', :sha1 => 'f7379ffe883fdc355fbe47e8a4b3073f21ac0f6d').first
81
+ file = @root.find(:type => 'file', :sha1 => 'f7379ffe883fdc355fbe47e8a4b3073f21ac0f6d', :recursive => true).first
82
82
  file.id.should == '61669270'
83
83
  file.name.should == 'file.pdf'
84
84
  end
@@ -89,25 +89,25 @@ describe Box::Folder do
89
89
  end
90
90
 
91
91
  it "finds multiple criteria" do
92
- file = @root.find(:updated => 1304959908, :size => 20372).first
92
+ file = @root.find(:updated => 1304959908, :size => 20372, :recursive => true).first
93
93
  file.id.should == '61679546'
94
94
  file.name.should == 'expected.3.swf'
95
95
  end
96
96
 
97
97
  it "requires both criteria" do
98
- file = @root.find(:updated => 1304, :size => 20372).first
98
+ file = @root.find(:updated => 1304, :size => 20372, :recursive => true).first
99
99
  file.should be nil
100
100
  end
101
101
  end
102
102
 
103
103
  describe "multiple results" do
104
104
  it "finds multiple files" do
105
- items = @root.find(:name => 'expected.1.swf')
105
+ items = @root.find(:name => 'expected.1.swf', :recursive => true)
106
106
  items.should have(2).items
107
107
  end
108
108
 
109
109
  it "finds all files" do
110
- files = @root.find(:type => 'file')
110
+ files = @root.find(:type => 'file', :recursive => true)
111
111
  files.should have(9).items
112
112
  files.first.name.should == 'file.pdf'
113
113
  end
@@ -1,3 +1,3 @@
1
1
  ---
2
2
  api_key: ezgx2366bod57zqvgk0lhjuy3l367arp
3
- auth_token: ouaq0t5r18psa5zcxqo339arfizcn9mr
3
+ auth_token: yrvp951t1055tpm1g1nxr2u09vx3trj2
metadata CHANGED
@@ -2,7 +2,7 @@
2
2
  name: box-api
3
3
  version: !ruby/object:Gem::Version
4
4
  prerelease:
5
- version: 0.1.6
5
+ version: 0.1.7
6
6
  platform: ruby
7
7
  authors:
8
8
  - Box.net
@@ -11,7 +11,7 @@ autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
13
 
14
- date: 2011-07-28 00:00:00 -04:00
14
+ date: 2011-07-29 00:00:00 -04:00
15
15
  default_executable:
16
16
  dependencies:
17
17
  - !ruby/object:Gem::Dependency
@@ -108,7 +108,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
108
108
  requirements:
109
109
  - - ">="
110
110
  - !ruby/object:Gem::Version
111
- hash: 2193464046297207864
111
+ hash: -2887608171974797695
112
112
  segments:
113
113
  - 0
114
114
  version: "0"
@@ -117,7 +117,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
117
117
  requirements:
118
118
  - - ">="
119
119
  - !ruby/object:Gem::Version
120
- hash: 2193464046297207864
120
+ hash: -2887608171974797695
121
121
  segments:
122
122
  - 0
123
123
  version: "0"