boxnet 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore ADDED
@@ -0,0 +1,4 @@
1
+ *.gem
2
+ .bundle
3
+ Gemfile.lock
4
+ pkg/*
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source "http://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in boxnet.gemspec
4
+ gemspec
data/README.rdoc ADDED
@@ -0,0 +1,15 @@
1
+ = Box .Net
2
+
3
+ This is a simple gem that uses the Box.net REST Api.
4
+
5
+ gem install boxnet
6
+
7
+ == Get API Key
8
+
9
+ Create an application and get an API Key. For more information check out Box.net's helpful guide http://developers.box.net/w/page/12923956/ApiOverview
10
+
11
+ == Get Ticket
12
+
13
+ Boxnet.get_ticket
14
+
15
+
data/Rakefile ADDED
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
data/boxnet.gemspec ADDED
@@ -0,0 +1,28 @@
1
+ # -*- encoding: utf-8 -*-
2
+ $:.push File.expand_path("../lib", __FILE__)
3
+ require "boxnet/version"
4
+
5
+ Gem::Specification.new do |s|
6
+ s.name = "boxnet"
7
+ s.version = Boxnet::VERSION
8
+ s.authors = ["Jonathan Birkholz"]
9
+ s.email = ["rookieone@gmail.com"]
10
+ s.homepage = ""
11
+ s.summary = %q{Ruby gem for Box.net REST Api}
12
+ s.description = %q{Ruby gem for Box.net REST Api}
13
+
14
+ s.rubyforge_project = "boxnet"
15
+
16
+ s.add_development_dependency "rspec"
17
+ s.add_development_dependency "httparty"
18
+ s.add_development_dependency "json"
19
+
20
+ s.files = `git ls-files`.split("\n")
21
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
22
+ s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
23
+ s.require_paths = ["lib"]
24
+
25
+ # specify any dependencies here; for example:
26
+ # s.add_development_dependency "rspec"
27
+ # s.add_runtime_dependency "rest-client"
28
+ end
@@ -0,0 +1,3 @@
1
+ module Boxnet
2
+ VERSION = "0.0.1"
3
+ end
data/lib/boxnet.rb ADDED
@@ -0,0 +1,37 @@
1
+ require 'httparty'
2
+ require 'json'
3
+
4
+ class Boxnet
5
+ include HTTParty
6
+ @@API_KEY = nil
7
+ @@URL = "https://www.box.net/api/1.0/rest"
8
+
9
+ def self.API_KEY=(value)
10
+ @@API_KEY = value
11
+ end
12
+
13
+ def self.get_ticket
14
+ get(@@URL + "?api_key=#{@@API_KEY}&action=get_ticket")
15
+ end
16
+
17
+ def self.get_auth_url_for_ticket(ticket)
18
+ "https://www.box.net/api/1.0/auth/#{ticket}"
19
+ end
20
+
21
+ def self.get_auth_token(ticket)
22
+ get(@@URL + "?api_key=#{@@API_KEY}&ticket=#{ticket}&action=get_auth_token")
23
+ end
24
+
25
+ def self.get_account_tree(auth_token, folder_id, options={})
26
+ params = []
27
+ params << "onelevel" if options[:onelevel]
28
+
29
+ if params.empty?
30
+ get(@@URL + "?api_key=#{@@API_KEY}&action=get_account_tree&auth_token=#{auth_token}&folder_id=#{folder_id}")
31
+ else
32
+ params_string = params.join(",")
33
+ get(@@URL + "?api_key=#{@@API_KEY}&action=get_account_tree&auth_token=#{auth_token}&folder_id=#{folder_id}&params=#{params_string}")
34
+ end
35
+ end
36
+
37
+ end
@@ -0,0 +1,74 @@
1
+ require 'spec_helper'
2
+
3
+ describe Boxnet do
4
+ before(:each) do
5
+ Boxnet.API_KEY = ENV["BOXNET_API_KEY"]
6
+ end
7
+
8
+ describe "get ticket" do
9
+ context "no API key" do
10
+ before(:each) do
11
+ Boxnet.API_KEY = ""
12
+ @result = Boxnet.get_ticket
13
+ end
14
+ it { @result.should_not be_nil }
15
+ it { @result["response"]["status"].should == "Wrong input" }
16
+ end
17
+
18
+ context "invalid API key" do
19
+ before(:each) do
20
+ Boxnet.API_KEY = "bad_api_key"
21
+ @result = Boxnet.get_ticket
22
+ end
23
+ it { @result.should_not be_nil }
24
+ it { @result["response"]["status"].should == "application_restricted" }
25
+ end
26
+
27
+ context "valid API key" do
28
+ before(:each) do
29
+ @result = Boxnet.get_ticket
30
+ end
31
+ it { @result.should_not be_nil }
32
+ it { @result["response"]["status"].should == "get_ticket_ok" }
33
+ it { @result["response"]["ticket"].should_not be_nil }
34
+ end
35
+ end
36
+
37
+ describe "get auth token" do
38
+ context "valid ticket" do
39
+ before(:each) do
40
+ ticket = ENV["BOXNET_TICKET"]
41
+ @result = Boxnet.get_auth_token(ticket)
42
+ end
43
+ it { @result.should_not be_nil }
44
+ it { @result["response"]["status"].should == "get_auth_token_ok" }
45
+ it { @result["response"]["auth_token"].should_not be_nil }
46
+ it { @result["response"]["user"].should_not be_nil }
47
+ end
48
+ end
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
+ end
73
+
74
+ end
@@ -0,0 +1,2 @@
1
+ require File.join(File.dirname(__FILE__), '..', 'lib', 'boxnet')
2
+ require 'httparty'
metadata ADDED
@@ -0,0 +1,96 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: boxnet
3
+ version: !ruby/object:Gem::Version
4
+ prerelease:
5
+ version: 0.0.1
6
+ platform: ruby
7
+ authors:
8
+ - Jonathan Birkholz
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+
13
+ date: 2011-11-16 00:00:00 Z
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: rspec
17
+ prerelease: false
18
+ requirement: &id001 !ruby/object:Gem::Requirement
19
+ none: false
20
+ requirements:
21
+ - - ">="
22
+ - !ruby/object:Gem::Version
23
+ version: "0"
24
+ type: :development
25
+ version_requirements: *id001
26
+ - !ruby/object:Gem::Dependency
27
+ name: httparty
28
+ prerelease: false
29
+ requirement: &id002 !ruby/object:Gem::Requirement
30
+ none: false
31
+ requirements:
32
+ - - ">="
33
+ - !ruby/object:Gem::Version
34
+ version: "0"
35
+ type: :development
36
+ version_requirements: *id002
37
+ - !ruby/object:Gem::Dependency
38
+ name: json
39
+ prerelease: false
40
+ requirement: &id003 !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ">="
44
+ - !ruby/object:Gem::Version
45
+ version: "0"
46
+ type: :development
47
+ version_requirements: *id003
48
+ description: Ruby gem for Box.net REST Api
49
+ email:
50
+ - rookieone@gmail.com
51
+ executables: []
52
+
53
+ extensions: []
54
+
55
+ extra_rdoc_files: []
56
+
57
+ files:
58
+ - .gitignore
59
+ - Gemfile
60
+ - README.rdoc
61
+ - Rakefile
62
+ - boxnet.gemspec
63
+ - lib/boxnet.rb
64
+ - lib/boxnet/version.rb
65
+ - spec/boxnet_spec.rb
66
+ - spec/spec_helper.rb
67
+ homepage: ""
68
+ licenses: []
69
+
70
+ post_install_message:
71
+ rdoc_options: []
72
+
73
+ require_paths:
74
+ - lib
75
+ required_ruby_version: !ruby/object:Gem::Requirement
76
+ none: false
77
+ requirements:
78
+ - - ">="
79
+ - !ruby/object:Gem::Version
80
+ version: "0"
81
+ required_rubygems_version: !ruby/object:Gem::Requirement
82
+ none: false
83
+ requirements:
84
+ - - ">="
85
+ - !ruby/object:Gem::Version
86
+ version: "0"
87
+ requirements: []
88
+
89
+ rubyforge_project: boxnet
90
+ rubygems_version: 1.8.8
91
+ signing_key:
92
+ specification_version: 3
93
+ summary: Ruby gem for Box.net REST Api
94
+ test_files:
95
+ - spec/boxnet_spec.rb
96
+ - spec/spec_helper.rb