boxnet 0.0.2 → 0.0.3

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore CHANGED
@@ -2,3 +2,4 @@
2
2
  .bundle
3
3
  Gemfile.lock
4
4
  pkg/*
5
+ env.yml
@@ -1,3 +1,3 @@
1
1
  module Boxnet
2
- VERSION = "0.0.2"
2
+ VERSION = "0.0.3"
3
3
  end
data/lib/boxnet.rb CHANGED
@@ -1,38 +1,46 @@
1
1
  require 'httparty'
2
2
  require 'json'
3
+ require 'result'
4
+ require 'file_node'
5
+ require 'file_tree'
6
+ require 'folder'
7
+ require 'file'
3
8
 
4
- class Boxnet
5
- include HTTParty
6
- @@API_KEY = nil
7
- @@URL = "https://www.box.net/api/1.0/rest"
9
+ module Boxnet
10
+ class Client
11
+ include HTTParty
12
+ @@API_KEY = nil
13
+ @@URL = "https://www.box.net/api/1.0/rest"
8
14
 
9
- def self.API_KEY=(value)
10
- @@API_KEY = value
11
- end
15
+ def self.API_KEY=(value)
16
+ @@API_KEY = value
17
+ end
12
18
 
13
- def self.get_ticket
14
- get(@@URL + "?api_key=#{@@API_KEY}&action=get_ticket")
15
- end
19
+ def self.get_ticket
20
+ get(@@URL + "?api_key=#{@@API_KEY}&action=get_ticket")
21
+ end
16
22
 
17
- def self.get_auth_url_for_ticket(ticket)
18
- "https://www.box.net/api/1.0/auth/#{ticket}"
19
- end
23
+ def self.get_auth_url_for_ticket(ticket)
24
+ "https://www.box.net/api/1.0/auth/#{ticket}"
25
+ end
20
26
 
21
- def self.get_auth_token(ticket)
22
- get(@@URL + "?api_key=#{@@API_KEY}&ticket=#{ticket}&action=get_auth_token")
23
- end
27
+ def self.get_auth_token(ticket)
28
+ get(@@URL + "?api_key=#{@@API_KEY}&ticket=#{ticket}&action=get_auth_token")
29
+ end
24
30
 
25
- def self.get_account_tree(auth_token, folder_id, options={})
26
- params = []
27
- params << "onelevel" if options[:onelevel]
28
- params << "nozip" if options[:nozip]
31
+ def self.get_account_tree(auth_token, folder_id, options={})
32
+ params = []
33
+ params << "onelevel" if options[:onelevel]
34
+ params << "nozip"
29
35
 
30
- if params.empty?
31
- get(@@URL + "?api_key=#{@@API_KEY}&action=get_account_tree&auth_token=#{auth_token}&folder_id=#{folder_id}")
32
- else
33
- params_string = params.join(",")
34
- get(@@URL + "?api_key=#{@@API_KEY}&action=get_account_tree&auth_token=#{auth_token}&folder_id=#{folder_id}&params[]=#{params_string}")
36
+ if params.empty?
37
+ raw_result = get(@@URL + "?api_key=#{@@API_KEY}&action=get_account_tree&auth_token=#{auth_token}&folder_id=#{folder_id}")
38
+ else
39
+ params_string = params.join(",")
40
+ raw_result = get(@@URL + "?api_key=#{@@API_KEY}&action=get_account_tree&auth_token=#{auth_token}&folder_id=#{folder_id}&params[]=#{params_string}")
41
+ end
42
+
43
+ Result.new(raw_result)
35
44
  end
36
45
  end
37
-
38
46
  end
data/lib/file.rb ADDED
@@ -0,0 +1,29 @@
1
+ module Boxnet
2
+ class File < FileNode
3
+ attr :id, :name, :description, :file_count, :sha1, :size
4
+ attr :tags, :shared, :created, :updated, :user_id, :shared_link
5
+ attr :thumbnail, :small_thumbnail, :large_thumbnail, :larger_thumbnail, :preview_thumbnail
6
+
7
+ def initialize(data)
8
+ @id = data["id"]
9
+ @name = data["file_name"]
10
+ @description = data["description"]
11
+ @file_count = data["file_count"]
12
+ @sha1 = data["sha1"]
13
+ @size = data["size"]
14
+ @tags = data["tags"]
15
+ @shared = data["shared"]
16
+ @created = data["created"]
17
+ @updated = data["updated"]
18
+ @user_id = data["user_id"]
19
+ @shared_link = data["shared_link"]
20
+ @thumbnail = data["thumbnail"]
21
+ @small_thumbnail = data["small_thumbnail"]
22
+ @large_thumbnail = data["large_thumbnail"]
23
+ @larger_thumbnail = data["larger_thumbnail"]
24
+ @preview_thumbnail = data["preview_thumbnail"]
25
+ process_node(data)
26
+ end
27
+
28
+ end
29
+ end
data/lib/file_node.rb ADDED
@@ -0,0 +1,26 @@
1
+ module Boxnet
2
+ class FileNode
3
+ attr :files, :folders
4
+
5
+ def process_node(data)
6
+ @files = []
7
+ @folders = []
8
+
9
+ if data["folder"]
10
+ self.folders << Folder.new(data["folder"])
11
+ elsif data["folders"]
12
+ data["folders"]["folder"].each do |folder|
13
+ self.folders << Folder.new(folder)
14
+ end
15
+ end
16
+
17
+ if data["files"]
18
+ data["files"]["file"].each do |file|
19
+ self.files << File.new(file)
20
+ end
21
+ end
22
+ end
23
+
24
+ end
25
+
26
+ end
data/lib/file_tree.rb ADDED
@@ -0,0 +1,10 @@
1
+ module Boxnet
2
+ class FileTree < FileNode
3
+
4
+ def initialize(raw_result)
5
+ tree_data = raw_result["response"]["tree"]
6
+ process_node(tree_data)
7
+ end
8
+
9
+ end
10
+ end
data/lib/folder.rb ADDED
@@ -0,0 +1,22 @@
1
+ module Boxnet
2
+ class Folder < FileNode
3
+ attr :id, :name, :description, :file_count, :user_id
4
+ attr :shared, :shared_link, :permission, :size, :created, :updated
5
+
6
+ def initialize(data)
7
+ @id = data["id"]
8
+ @name = data["name"]
9
+ @description = data["description"]
10
+ @file_count = data["file_count"]
11
+ @user_id = data["user_id"]
12
+ @shared = data["shared"]
13
+ @shared_link = data["shared_link"]
14
+ @permission = data["permission"]
15
+ @size = data["size"]
16
+ @created = data["created"]
17
+ @updated = data["updated"]
18
+ process_node(data)
19
+ end
20
+
21
+ end
22
+ end
data/lib/result.rb ADDED
@@ -0,0 +1,14 @@
1
+ module Boxnet
2
+ class Result
3
+ attr :raw_result, :file_tree
4
+
5
+ def initialize(raw_result)
6
+ @raw_result = raw_result
7
+ @file_tree = Boxnet::FileTree.new(raw_result)
8
+ end
9
+
10
+ def status
11
+ @raw_result["response"]["status"]
12
+ end
13
+ end
14
+ end
data/spec/boxnet_spec.rb CHANGED
@@ -2,43 +2,43 @@ require 'spec_helper'
2
2
 
3
3
  describe Boxnet do
4
4
  before(:each) do
5
- Boxnet.API_KEY = ENV["BOXNET_API_KEY"]
5
+ Boxnet::Client.API_KEY = ENV["BOXNET_API_KEY"]
6
6
  end
7
7
 
8
8
  describe "get ticket" do
9
9
  context "no API key" do
10
10
  before(:each) do
11
11
  Boxnet.API_KEY = ""
12
- @result = Boxnet.get_ticket
12
+ @result = Boxnet::Client.get_ticket
13
13
  end
14
14
  it { @result.should_not be_nil }
15
15
  it { @result["response"]["status"].should == "Wrong input" }
16
16
  end
17
-
17
+
18
18
  context "invalid API key" do
19
19
  before(:each) do
20
20
  Boxnet.API_KEY = "bad_api_key"
21
- @result = Boxnet.get_ticket
21
+ @result = Boxnet::Client.get_ticket
22
22
  end
23
23
  it { @result.should_not be_nil }
24
24
  it { @result["response"]["status"].should == "application_restricted" }
25
25
  end
26
-
26
+
27
27
  context "valid API key" do
28
28
  before(:each) do
29
- @result = Boxnet.get_ticket
29
+ @result = Boxnet::Client.get_ticket
30
30
  end
31
31
  it { @result.should_not be_nil }
32
32
  it { @result["response"]["status"].should == "get_ticket_ok" }
33
33
  it { @result["response"]["ticket"].should_not be_nil }
34
34
  end
35
35
  end
36
-
36
+
37
37
  describe "get auth token" do
38
38
  context "valid ticket" do
39
39
  before(:each) do
40
40
  ticket = ENV["BOXNET_TICKET"]
41
- @result = Boxnet.get_auth_token(ticket)
41
+ @result = Boxnet::Client.get_auth_token(ticket)
42
42
  end
43
43
  it { @result.should_not be_nil }
44
44
  it { @result["response"]["status"].should == "get_auth_token_ok" }
@@ -47,39 +47,4 @@ describe Boxnet do
47
47
  end
48
48
  end
49
49
 
50
- describe "get account tree" do
51
- context "entire tree from root" do
52
- before(:each) do
53
- ticket = ENV["BOXNET_TICKET"]
54
- auth_token = ENV["BOXNET_AUTHTOKEN"]
55
- @result = Boxnet.get_account_tree(auth_token, "0")
56
- end
57
- it { @result.should_not be_nil }
58
- it { @result["response"]["status"].should == "listing_ok" }
59
- it { @result["response"]["tree"].should_not be_nil }
60
- end
61
-
62
- context "get first level from root" do
63
- before(:each) do
64
- ticket = ENV["BOXNET_TICKET"]
65
- auth_token = ENV["BOXNET_AUTHTOKEN"]
66
- @result = Boxnet.get_account_tree(auth_token, "0", :onelevel => true)
67
- end
68
- it { @result.should_not be_nil }
69
- it { @result["response"]["status"].should == "listing_ok" }
70
- it { @result["response"]["tree"].should_not be_nil }
71
- end
72
-
73
- context "get no zip from root" do
74
- before(:each) do
75
- ticket = ENV["BOXNET_TICKET"]
76
- auth_token = ENV["BOXNET_AUTHTOKEN"]
77
- @result = Boxnet.get_account_tree(auth_token, "0", :nozip => true)
78
- end
79
- it { @result.should_not be_nil }
80
- it { @result["response"]["status"].should == "listing_ok" }
81
- it { @result["response"]["tree"].should_not be_nil }
82
- end
83
- end
84
-
85
50
  end
@@ -0,0 +1,19 @@
1
+ require 'spec_helper'
2
+
3
+ describe "get account tree" do
4
+ before(:each) do
5
+ Boxnet::Client.API_KEY = ENV["BOXNET_API_KEY"]
6
+ @auth_token = ENV["BOXNET_AUTHTOKEN"]
7
+ end
8
+
9
+ context "entire tree from root" do
10
+ before(:each) do
11
+ @result = Boxnet::Client.get_account_tree(@auth_token, "0")
12
+ end
13
+ it { @result.should_not be_nil }
14
+ it { @result.status.should == "listing_ok" }
15
+ it { @result.file_tree.should_not be_nil }
16
+ it { @result.file_tree.folders.count.should > 0 }
17
+ it { @result.file_tree.folders.first.folders.first.files.count.should > 0 }
18
+ end
19
+ end
metadata CHANGED
@@ -2,7 +2,7 @@
2
2
  name: boxnet
3
3
  version: !ruby/object:Gem::Version
4
4
  prerelease:
5
- version: 0.0.2
5
+ version: 0.0.3
6
6
  platform: ruby
7
7
  authors:
8
8
  - Jonathan Birkholz
@@ -10,7 +10,7 @@ autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
12
 
13
- date: 2011-11-16 00:00:00 Z
13
+ date: 2011-11-18 00:00:00 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: rspec
@@ -62,7 +62,13 @@ files:
62
62
  - boxnet.gemspec
63
63
  - lib/boxnet.rb
64
64
  - lib/boxnet/version.rb
65
+ - lib/file.rb
66
+ - lib/file_node.rb
67
+ - lib/file_tree.rb
68
+ - lib/folder.rb
69
+ - lib/result.rb
65
70
  - spec/boxnet_spec.rb
71
+ - spec/get_account_file_tree_spec.rb
66
72
  - spec/spec_helper.rb
67
73
  homepage: ""
68
74
  licenses: []
@@ -93,4 +99,5 @@ specification_version: 3
93
99
  summary: Ruby gem for Box.net REST Api
94
100
  test_files:
95
101
  - spec/boxnet_spec.rb
102
+ - spec/get_account_file_tree_spec.rb
96
103
  - spec/spec_helper.rb