boxrubylib 0.0.1 → 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
data/History.txt CHANGED
@@ -1,4 +1,9 @@
1
+ === 0.0.2 2009-11-30
2
+
3
+ * Support all OpenBox API.
4
+ * The method of generating BoxRestClient instance was changed.
5
+ You must specify API key of your application.
6
+
1
7
  === 0.0.1 2009-10-19
2
8
 
3
- * 1 major enhancement:
4
- * Initial release
9
+ * Initial release.
data/README.rdoc CHANGED
@@ -8,12 +8,14 @@ Ruby library of OpenBox API.
8
8
 
9
9
  == SYNOPSIS:
10
10
 
11
+ See also test case.
12
+
11
13
  require 'rubygems'
12
14
  gem 'boxrubylib'
13
15
  require 'boxrubylib'
14
16
 
15
17
  client = BoxClientLib::BoxRestClient.new()
16
-
18
+
17
19
  == INSTALL:
18
20
 
19
21
  sudo gem install boxrubylib
@@ -2,7 +2,8 @@
2
2
  #Author:: Tomohiko Ariki, Makoto Kobayashi
3
3
  #CopyRights:: Canon Software Inc.
4
4
  #Created date:: 2009/06/10
5
- #Version:: 1.0.0
5
+ #Last Modified:: 2009/11/09
6
+ #Version:: 1.0.1
6
7
  #
7
8
  #This file contains Box.net service class.
8
9
 
@@ -26,16 +27,16 @@ module BoxClientLib
26
27
  @@upload = "upload.box.net"
27
28
  @@apiPath = "/api/1.0/rest"
28
29
  @@header = {
29
- "User-Agent" => "boxclientlib/0.0.1\r\n"
30
+ "User-Agent" => "boxclientlib/0.0.2\r\n"
30
31
  }
31
32
  attr_accessor :apiKey, :userStorageInfo
32
33
 
33
34
  # Constructor.
34
35
  #
35
- # If you want to use your Box.net api key, you can set it after initializing.
36
- def initialize
37
- super
38
- @apiKey = "3kaxmeu3cj0fvm6is2smxgsqhnxa6ajy"
36
+ # You must set Api key
37
+ def initialize(apiKey)
38
+ super()
39
+ @apiKey = apiKey
39
40
  end
40
41
 
41
42
  # Request ticket to receive auth token.
@@ -101,7 +102,12 @@ module BoxClientLib
101
102
  "login" => login,
102
103
  "password" => password
103
104
  }
104
- doc = getRequest(@@server, @useSSL == false ? @@port : @@sslPort, @@apiPath, params, @@header)
105
+ sslFlag = @useSSL
106
+ begin
107
+ doc = getRequest(@@server, @useSSL == false ? @@port : @@sslPort, @@apiPath, params, @@header)
108
+ ensure
109
+ @useSSL = sslFlag
110
+ end
105
111
  return checkError(doc, "successful_register")
106
112
  end
107
113
 
@@ -111,7 +117,7 @@ module BoxClientLib
111
117
  # The login username of the user for which you would like to verify registration.
112
118
  #
113
119
  # [Return value]
114
- # True, if success.
120
+ # True, if user email is available to register.
115
121
  def verifyRegistrationEmail(login)
116
122
  params = {
117
123
  "action" => "verify_registration_email",
@@ -119,7 +125,7 @@ module BoxClientLib
119
125
  "login" => login
120
126
  }
121
127
  doc = getRequest(@@server, @useSSL == false ? @@port : @@sslPort, @@apiPath, params, @@header)
122
- return checkError(doc, "successful_register")
128
+ return checkError(doc, "email_ok")
123
129
  end
124
130
 
125
131
  # Update user's storage information.
@@ -293,7 +299,7 @@ module BoxClientLib
293
299
  "action" => "get_file_info",
294
300
  "api_key" => @apiKey,
295
301
  "auth_token" => @userStorageInfo.authToken,
296
- "fild_id" => fileId
302
+ "file_id" => fileId
297
303
  }
298
304
  doc = getRequest(@@server, @useSSL == false ? @@port : @@sslPort, @@apiPath, params, @@header)
299
305
  checkError(doc, "s_get_file_info")
@@ -321,8 +327,8 @@ module BoxClientLib
321
327
  "target_id" => targetId,
322
328
  "description" => description
323
329
  }
324
- doc = getRequest(@@server, @useSSL == false ? @@port : @@sslPort, @@apiPath, params)
325
- return checkError(doc, "s_set_desctiption")
330
+ doc = getRequest(@@server, @useSSL == false ? @@port : @@sslPort, @@apiPath, params, @@header)
331
+ return checkError(doc, "s_set_description")
326
332
  end
327
333
 
328
334
  # Upload file (If same file name is already exist target folder, it will be overwritten).
@@ -433,6 +439,7 @@ module BoxClientLib
433
439
  # An message to be included in a notification email.
434
440
  # [emails]
435
441
  # An array of emails for which to notify users about the newly shared file or folder.
442
+ # If you don't want to notify, you can pass this parameter to nil.
436
443
  #
437
444
  # [Return value]
438
445
  # Public name.
@@ -483,7 +490,7 @@ module BoxClientLib
483
490
  # [message]
484
491
  # An message to be included in a notification email.
485
492
  # [emails]
486
- # An array of emails for which to share (and notify) users about the newly shared file or folder.
493
+ # An array of emails for which to share (and notify) users about the newly shared file or folder. Not allowed nil.
487
494
  # [notify]
488
495
  # 1 - notification email will be sent to users, 0 - not notification.
489
496
  #
@@ -517,7 +524,7 @@ module BoxClientLib
517
524
  #
518
525
  # [Return value]
519
526
  # True, if success.
520
- def requestFriends(messsage, emails, options)
527
+ def requestFriends(message, emails, options)
521
528
  params = {
522
529
  "action" => "request_friends",
523
530
  "api_key" => @apiKey,
@@ -562,7 +569,7 @@ module BoxClientLib
562
569
  # [folderId]
563
570
  # The folder ID of the folder to which you will add user to user's storage.
564
571
  # [tags]
565
- # A List of tags to apply to the file when copied into the user's own folder.
572
+ # An array of tags for which to apply to the file or folder.
566
573
  #
567
574
  # [Return value]
568
575
  # True, if success.
@@ -575,7 +582,7 @@ module BoxClientLib
575
582
  "target" => target,
576
583
  "public_name" => publicName,
577
584
  "folder_id" => folderId,
578
- "tags" => tags
585
+ "tags[]" => tags
579
586
  }
580
587
  doc = getRequest(@@server, @useSSL == false ? @@port : @@sslPort, @@apiPath, params, @@header)
581
588
  return checkError(doc, "addtomybox_ok")
@@ -590,7 +597,7 @@ module BoxClientLib
590
597
  # [targetId]
591
598
  # The id of the item you wish to add to tag(s).
592
599
  # [tags]
593
- # A List of tags to apply to the file when copied into the user's own file or folder.
600
+ # An array of tags for which to apply to the file or folder.
594
601
  #
595
602
  # [Return value]
596
603
  # True, if success.
@@ -601,7 +608,7 @@ module BoxClientLib
601
608
  "auth_token" => @userStorageInfo.authToken,
602
609
  "target" => target,
603
610
  "target_id" => targetId,
604
- "tags" => tags
611
+ "tags[]" => tags
605
612
  }
606
613
  doc = getRequest(@@server, @useSSL == false ? @@port : @@sslPort, @@apiPath, params, @@header)
607
614
  return checkError(doc, "addtotag_ok")
@@ -621,12 +628,19 @@ module BoxClientLib
621
628
  checkError(doc, "export_tags_ok")
622
629
  tagList = Array.new
623
630
  doc.elements.each('/response/tags/tag') do |tagElement|
624
- tagList.push(TagInfo.new(tagElment))
631
+ tagList.push(TagInfo.new(tagElement))
625
632
  end
626
633
  return tagList
627
634
  end
628
635
 
629
- # Login to Box.net.
636
+ # Direct login to Box.net.
637
+ # Notice:
638
+ # This method need to authorized API key.
639
+ # If you need to direct login, apply your own API key and authorization it by Box.net.
640
+ # If you do, you can use this methos same like bellow.
641
+ # box = BoxRestClient.new
642
+ # box.apiKey = yourOwnAuthorizedApiKey
643
+ # box.directLogin("login", "password")
630
644
  #
631
645
  # [loginName]
632
646
  # Login email address.
@@ -636,23 +650,30 @@ module BoxClientLib
636
650
  # [Return value]
637
651
  # Auth token - if success login. nil - if not success login.
638
652
  def login(loginName, password)
653
+ apiKeyExpression = "<http://"+@@server+@@apiPath+"?action=authorization&api_key=><"+@apiKey+">"
654
+ loginExpression = loginName + "<mailto:&login=" + loginName + ">"
655
+ authToken = nil
656
+
639
657
  sslFlag = @useSSL
640
658
  ticket = getTicket()
641
659
  params = {
642
- "dologin" => 1,
643
- "__login" => 1,
644
- "login" => loginName,
645
- "password" => password
660
+ "action" => "authorization",
661
+ "api_key" => apiKeyExpression,
662
+ "login" => loginExpression,
663
+ "password" => password,
664
+ "method" => nil
646
665
  }
647
666
  @useSSL = true
648
- uri = "/api/1.0/auth/#{ticket}"
649
667
  begin
650
- body = postRequest(@@server, @@sslPort, uri, nil, nil, params, @@header)
668
+ doc = getRequest(@@server, @@sslPort, @@apiPath, params, @@header)
669
+ checkError(doc, "logged")
670
+ @userStorageInfo = UserStorageInfo.new(doc.elements['/response/user'])
671
+ @userStorageInfo.authToken = doc.elements['/response/auth_token'].text
672
+ authToken = @userStorageInfo.authToken
651
673
  ensure
652
674
  @useSSL = sslFlag
653
675
  end
654
- return getAuthToken(ticket) if body
655
- return nil
676
+ return authToken
656
677
  end
657
678
 
658
679
  private
@@ -771,7 +792,7 @@ module BoxClientLib
771
792
  class FolderInfo
772
793
  attr_accessor :userId, :folderId, :folderName, :description, :createDate, :updateDate,
773
794
  :totalFolderSize, :shared, :sharedLinkName, :permissions, :fileList,
774
- :childFolderList, :numOfTags, :tagList;
795
+ :childFolderList, :numOfTags, :tagList
775
796
 
776
797
  # Constructor.
777
798
  #
@@ -781,16 +802,16 @@ module BoxClientLib
781
802
 
782
803
  private
783
804
  def createFolderInfo(folderElement)
784
- @userId = folderElement.attributes['user_id'].to_i;
785
- @folderId = folderElement.attributes['id'].to_i;
786
- @folderName = folderElement.attributes['name'];
787
- @description = folderElement.attributes['description'];
788
- @createDate = folderElement.attributes['created'].to_i;
789
- @updateDate = folderElement.attributes['updated'].to_i;
790
- @totalFolderSize = folderElement.attributes['size'].to_i;
791
- @shared = folderElement.attributes['shared'].to_i;
792
- @sharedLinkName = folderElement.attributes['shared_link'];
793
- @permissions = folderElement.attributes['permissions'];
805
+ @userId = folderElement.attributes['user_id'].to_i
806
+ @folderId = folderElement.attributes['id'].to_i
807
+ @folderName = folderElement.attributes['name']
808
+ @description = folderElement.attributes['description']
809
+ @createDate = folderElement.attributes['created'].to_i
810
+ @updateDate = folderElement.attributes['updated'].to_i
811
+ @totalFolderSize = folderElement.attributes['size'].to_i
812
+ @shared = folderElement.attributes['shared'].to_i
813
+ @sharedLinkName = folderElement.attributes['shared_link']
814
+ @permissions = folderElement.attributes['permissions']
794
815
 
795
816
  if (folderElement.elements['files'] != nil)
796
817
  @fileList = Array.new
@@ -843,7 +864,7 @@ module BoxClientLib
843
864
  attr_accessor :userId, :fileId, :fileName, :description, :sha1, :createDate,
844
865
  :updateDate, :size, :shared, :sharedLinkName, :thumbNail, :smallThumbNail,
845
866
  :largeThumbNail, :largerThumbNail, :previewThumbNail, :permissions,
846
- :tagList;
867
+ :tagList
847
868
 
848
869
  # Constructor.
849
870
  #
@@ -853,22 +874,22 @@ module BoxClientLib
853
874
 
854
875
  private
855
876
  def createFileInfoByAttributes(fileElement)
856
- @userId = fileElement.attributes['user_id'].to_i;
857
- @fileId = fileElement.attributes['id'].to_i;
858
- @fileName = fileElement.attributes['file_name'];
859
- @description = fileElement.attributes['description'];
860
- @sha1 = fileElement.attributes['sha1'];
861
- @createDate = fileElement.attributes['created'].to_i;
862
- @updateDate = fileElement.attributes['updated'].to_i;
863
- @size = fileElement.attributes['size'].to_i;
864
- @shared = fileElement.attributes['shared'].to_i;
865
- @sharedLinkName = fileElement.attributes['shared_link'];
866
- @thumbNail = fileElement.attributes['thumbnail'];
867
- @smallThumbNail = fileElement.attributes['small_thumbnail'];
868
- @largeThumbNail = fileElement.attributes['large_thumbnail'];
869
- @largerThumbNail = fileElement.attributes['larger_thumbnail'];
870
- @previewThumbNail = fileElement.attributes['preview_thumbnail'];
871
- @permissions = fileElement.attributes['permissions'];
877
+ @userId = fileElement.attributes['user_id'].to_i
878
+ @fileId = fileElement.attributes['id'].to_i
879
+ @fileName = fileElement.attributes['file_name']
880
+ @description = fileElement.attributes['description']
881
+ @sha1 = fileElement.attributes['sha1']
882
+ @createDate = fileElement.attributes['created'].to_i
883
+ @updateDate = fileElement.attributes['updated'].to_i
884
+ @size = fileElement.attributes['size'].to_i
885
+ @shared = fileElement.attributes['shared'].to_i
886
+ @sharedLinkName = fileElement.attributes['shared_link']
887
+ @thumbNail = fileElement.attributes['thumbnail']
888
+ @smallThumbNail = fileElement.attributes['small_thumbnail']
889
+ @largeThumbNail = fileElement.attributes['large_thumbnail']
890
+ @largerThumbNail = fileElement.attributes['larger_thumbnail']
891
+ @previewThumbNail = fileElement.attributes['preview_thumbnail']
892
+ @permissions = fileElement.attributes['permissions']
872
893
 
873
894
  if (fileElement.elements['tags'] != nil)
874
895
  @tagList = Array.new
@@ -894,7 +915,7 @@ module BoxClientLib
894
915
  # sharedLinkName - The file's shared(public) name.
895
916
  class FileInfo
896
917
  attr_accessor :userId, :fileId, :fileName, :parentFolderId, :description, :sha1, :createDate,
897
- :updateDate, :size, :shared, :sharedLinkName;
918
+ :updateDate, :size, :shared, :sharedLinkName
898
919
 
899
920
  # Constructor.
900
921
  #
@@ -904,16 +925,16 @@ module BoxClientLib
904
925
 
905
926
  private
906
927
  def createFileInfo(fileElement)
907
- @fileId = fileElement.elements['file_id'].text.to_i;
908
- @fileName = fileElement.elements['file_name'].text;
909
- @parentFolderId = fileElement.elements['folder_id'].text.to_i;
910
- @description = fileElement.elements['description'].text;
911
- @sha1 = fileElement.elements['sha1'].text;
912
- @createDate = fileElement.elements['created'].text.to_i;
913
- @updateDate = fileElement.elements['updated'].text.to_i;
914
- @size = fileElement.elements['size'].text.to_i;
915
- @shared = fileElement.elements['shared'].text.to_i;
916
- @sharedLinkName = fileElement.elements['shared_name'].text;
928
+ @fileId = fileElement.elements['file_id'].text.to_i
929
+ @fileName = fileElement.elements['file_name'].text
930
+ @parentFolderId = fileElement.elements['folder_id'].text.to_i
931
+ @description = fileElement.elements['description'].text
932
+ @sha1 = fileElement.elements['sha1'].text
933
+ @createDate = fileElement.elements['created'].text.to_i
934
+ @updateDate = fileElement.elements['updated'].text.to_i
935
+ @size = fileElement.elements['size'].text.to_i
936
+ @shared = fileElement.elements['shared'].text.to_i
937
+ @sharedLinkName = fileElement.elements['shared_name'].text
917
938
  end
918
939
  end
919
940
 
@@ -930,7 +951,7 @@ module BoxClientLib
930
951
  # password - Password to open the folder.
931
952
  class CreatedFolderInfo
932
953
  attr_accessor :userId, :folderId, :folderName, :folderPath, :shared, :sharedLinkName,
933
- :parentFolderId, :password;
954
+ :parentFolderId, :password
934
955
 
935
956
  # Constructor.
936
957
  #
@@ -940,14 +961,14 @@ module BoxClientLib
940
961
 
941
962
  private
942
963
  def createCreatedFolderInfo(folderElement)
943
- @userId = folderElement.elements['user_id'].text.to_i;
944
- @folderId = folderElement.elements['folder_id'].text.to_i;
945
- @folderName = folderElement.elements['folder_name'].text;
946
- @folderPath = folderElement.elements['path'].text;
947
- @shared = folderElement.elements['shared'].text.to_i;
948
- @sharedLinkName = folderElement.elements['public_name'].text;
949
- @parentFolderId = folderElement.elements['parent_folder_id'].text.to_i;
950
- @password = folderElement.elements['password'].text;
964
+ @userId = folderElement.elements['user_id'].text.to_i
965
+ @folderId = folderElement.elements['folder_id'].text.to_i
966
+ @folderName = folderElement.elements['folder_name'].text
967
+ @folderPath = folderElement.elements['path'].text
968
+ @shared = folderElement.elements['shared'].text.to_i
969
+ @sharedLinkName = folderElement.elements['public_name'].text
970
+ @parentFolderId = folderElement.elements['parent_folder_id'].text.to_i
971
+ @password = folderElement.elements['password'].text
951
972
  end
952
973
  end
953
974
 
@@ -960,7 +981,7 @@ module BoxClientLib
960
981
  # avatarURL - The friend's avatar URL.
961
982
  # boxList - Box list.
962
983
  class FriendInfo
963
- attr_accessor :friendName, :email, :accepted, :avatarURL, :boxList;
984
+ attr_accessor :friendName, :email, :accepted, :avatarURL, :boxList
964
985
 
965
986
  # Constructor.
966
987
  #
@@ -970,10 +991,10 @@ module BoxClientLib
970
991
 
971
992
  private
972
993
  def createFriendInfo(friendElement)
973
- @friendName = friendElement.elements['name'].text;
974
- @email = friendElement.elements['email'].text;
975
- @accepted = friendElement.elements['accepted'].text;
976
- @avatarURL = friendElement.elements['avatar_url'].text;
994
+ @friendName = friendElement.elements['name'].text
995
+ @email = friendElement.elements['email'].text
996
+ @accepted = friendElement.elements['accepted'].text
997
+ @avatarURL = friendElement.elements['avatar_url'].text
977
998
  @boxList = Array.new
978
999
  fileElement.elements.each('/boxes/box') do |boxElement|
979
1000
  @boxList.push(BoxInfo.new(boxElement))
@@ -987,7 +1008,7 @@ module BoxClientLib
987
1008
  # boxId - The box id.
988
1009
  # URL - The box URL.
989
1010
  class BoxInfo
990
- attr_accessor :boxId, :URL;
1011
+ attr_accessor :boxId, :URL
991
1012
 
992
1013
  # Constructor.
993
1014
  #
@@ -997,8 +1018,8 @@ module BoxClientLib
997
1018
 
998
1019
  private
999
1020
  def createBoxList(boxElement)
1000
- @boxId = boxElement.elements['id'];
1001
- @URL = boxElement.elements['url'];
1021
+ @boxId = boxElement.elements['id']
1022
+ @URL = boxElement.elements['url']
1002
1023
  end
1003
1024
  end
1004
1025
  #Uploaded file information class.
@@ -1011,7 +1032,7 @@ module BoxClientLib
1011
1032
  # status - "upload_ok":File upload is success.
1012
1033
  # others :File upload occues something error(ex. filesize_limit_exceeded).
1013
1034
  class UploadedFileInfo
1014
- attr_accessor :fileName, :fileId, :parentFolderId, :shared, :publicName, :status;
1035
+ attr_accessor :fileName, :fileId, :parentFolderId, :shared, :publicName, :status
1015
1036
 
1016
1037
  # Constructor.
1017
1038
  #
@@ -2,7 +2,8 @@
2
2
  #Author:: Takehiko Watanabe
3
3
  #CopyRights:: Canon Software Inc.
4
4
  #Created date:: 2009/06/10
5
- #Version:: 1.0.0
5
+ #Last Modified:: 2009/11/09
6
+ #Version:: 1.0.1
6
7
  #
7
8
  #This file contains RestClientLib module.
8
9
 
@@ -31,7 +32,7 @@ module RestClientLib
31
32
  def initialize
32
33
  @proxyUrl = nil
33
34
  @proxyPort = nil
34
- @useSSL = false;
35
+ @useSSL = false
35
36
  end
36
37
 
37
38
  # Throw http get request method to the server.
@@ -193,8 +194,8 @@ module RestClientLib
193
194
  end
194
195
  end
195
196
  if ((filename != nil)&&(data != nil))
196
- query += "--" + boundary + "\n";
197
- query += fileToMultiPart(filename, data);
197
+ query += "--" + boundary + "\n"
198
+ query += fileToMultiPart(filename, data)
198
199
  end
199
200
  query += "--" + boundary + "--\n" if (query != nil)
200
201
 
data/lib/boxrubylib.rb CHANGED
@@ -4,5 +4,5 @@ $:.unshift(File.dirname(__FILE__)) unless
4
4
  require 'boxrubylib/boxclientlib'
5
5
 
6
6
  module Boxrubylib
7
- VERSION = '0.0.1'
7
+ VERSION = '0.0.2'
8
8
  end
@@ -1,11 +1,246 @@
1
- require File.dirname(__FILE__) + '/test_helper.rb'
2
-
3
- class TestBoxrubylib < Test::Unit::TestCase
4
-
5
- def setup
6
- end
7
-
8
- def test_truth
9
- assert true
10
- end
11
- end
1
+ require File.dirname(__FILE__) + '/test_helper.rb'
2
+ require "boxrubylib/boxclientlib"
3
+ require "test/unit"
4
+ include BoxClientLib
5
+
6
+ class TestBoxrubylib < Test::Unit::TestCase
7
+
8
+ def setup
9
+ end
10
+
11
+ def showFolderInfo(folder)
12
+ if (folder == nil)
13
+ return
14
+ end
15
+ print("userId = #{folder.userId}\n")
16
+ print("folderId = #{folder.folderId}\n")
17
+ print("folderName = #{folder.folderName}\n")
18
+ print("description = #{folder.description}\n")
19
+ print("createDate = #{folder.createDate}\n")
20
+ print("updateDate = #{folder.updateDate}\n")
21
+ print("totalFolderSize = #{folder.totalFolderSize}\n")
22
+ print("shared = #{folder.shared}\n")
23
+ print("sharedLinkName = #{folder.sharedLinkName}\n")
24
+ print("permissions = #{folder.permissions}\n")
25
+ if (folder.fileList != nil)
26
+ print("--- file list ---\n")
27
+ folder.fileList.each do |file|
28
+ showFileInfo(file)
29
+ end
30
+ print("--- file list end ---\n")
31
+ end
32
+ if (folder.childFolderList != nil)
33
+ print("--- child folder list ---\n")
34
+ folder.childFolderList.each do |childFolder|
35
+ showFolderInfo(childFolder)
36
+ end
37
+ print("--- child folder list end ---\n")
38
+ end
39
+ end
40
+
41
+ def showFileInfo(file)
42
+ print("--- file ---\n")
43
+ print("fileId = #{file.fileId}\n")
44
+ print("fileName = #{file.fileName}\n")
45
+ print("description = #{file.description}\n")
46
+ begin
47
+ print("parentFolderId = #{file.parentFolderId}\n")
48
+ rescue
49
+ end
50
+ print("sha1 = #{file.sha1}\n")
51
+ print("createDate = #{file.createDate}\n")
52
+ print("updateDate = #{file.updateDate}\n")
53
+ print("size = #{file.size}\n")
54
+ print("shared = #{file.shared}\n")
55
+ print("sharedLinkName = #{file.sharedLinkName}\n")
56
+ print("--- file end ---\n")
57
+ end
58
+
59
+ def showUserStorageInfo(usInfo)
60
+ print("loginName = #{usInfo.loginName}\n")
61
+ print("email = #{usInfo.email}\n")
62
+ print("accessId = #{usInfo.accessId}\n")
63
+ print("userId = #{usInfo.userId}\n")
64
+ print("spaceAmount = #{usInfo.spaceAmount}\n")
65
+ print("spaceUsed = #{usInfo.spaceUsed}\n")
66
+ end
67
+
68
+ def showCreatedFolderInfo(folder)
69
+ print("userId = #{folder.userId}\n")
70
+ print("folderId = #{folder.folderId}\n")
71
+ print("folderName = #{folder.folderName}\n")
72
+ print("folderPath = #{folder.folderPath}\n")
73
+ print("shared = #{folder.shared}\n")
74
+ print("sharedLinkName = #{folder.sharedLinkName}\n")
75
+ print("parentFolderId = #{folder.parentFolderId}\n")
76
+ print("password = #{folder.password}\n")
77
+ end
78
+
79
+ def showTagList(taglist)
80
+ print("-- taglist start --\n")
81
+ if (taglist != nil)
82
+ taglist.each do |tag|
83
+ print("tagId = #{tag.tagId}\n")
84
+ print("description = #{tag.description}\n")
85
+ end
86
+ end
87
+ print("--taglist end--\n")
88
+ end
89
+
90
+ def showFriendList(friendlist)
91
+ print("-- friendlist start --\n")
92
+ if (friendlist != nil)
93
+ friendlist.each do |friend|
94
+ print("friendName = #{friend.friendName}\n")
95
+ print("email = #{friend.email}\n")
96
+ print("accepted = #{friend.accepted}\n")
97
+ print("avatarURL = #{friend.avatarURL}\n")
98
+ print("boxList = #{friend.boxList}\n")
99
+ end
100
+ end
101
+ print("--friendlist end--\n")
102
+ end
103
+
104
+ def test_start
105
+ #You need to pass actual parameters bellow if you want to run this test case.
106
+ emailAddress = "your_email@email.ne.jp"
107
+ friendEmailAddress = "your_friend_emai@email.ne.jp"
108
+ password = "your_account_password"
109
+ notRegisteredEmail = "not_registered@email.ne.jp"
110
+ publicName = "public_name"
111
+ apiKey = "your_apprication_api_key"
112
+ filePath = "./test.txt"
113
+ tags = ["tag1", "tag2"]
114
+ emails = [friendEmailAddress]
115
+
116
+ box = BoxRestClient.new(apiKey)
117
+ #login
118
+ ticket = box.getTicket()
119
+ while(true)
120
+ begin
121
+ print("You need to login at \n")
122
+ print("http://www.box.net/api/1.0/auth/#{ticket}\n")
123
+ print("from your Web browser.\n")
124
+ print("If you finish login process, press any key.\n")
125
+ STDIN.gets
126
+ authToken = box.getAuthToken(ticket)
127
+ break
128
+ rescue
129
+ print("Your login isn't success now.\nTry again?[Y/N]\n")
130
+ c = STDIN.gets.chomp
131
+ if ((c != 'y')&&(c != 'Y'))
132
+ break
133
+ end
134
+ end
135
+ end
136
+
137
+ if (authToken == nil)
138
+ exit(1)
139
+ end
140
+
141
+ printf("authtoken = %s\n", box.userStorageInfo.authToken)
142
+ begin
143
+ #Create folder as "tmptest1" on Root folder.
144
+ createdFolder1 = box.createFolder(0, "tmptest1", 1)
145
+
146
+ #Set description "tmptest1" folder.
147
+ box.setDescription("folder", createdFolder1.folderId, "folder description.")
148
+ showCreatedFolderInfo(createdFolder1)
149
+
150
+ #Create folder as "tmptest2" on Root folder.
151
+ createdFolder2 = box.createFolder(0, "tmptest2", 1)
152
+
153
+ #Rename "tmptest2" folder to "renamed".
154
+ box.rename("folder", createdFolder2.folderId, "renamed")
155
+
156
+ #Move "renamed" folder to "tmptest1" folder.
157
+ box.move("folder", createdFolder2.folderId, createdFolder1.folderId)
158
+
159
+ #Get folder information simple mode.
160
+ options = ["simple"]
161
+ folder = box.getFolderInfo(createdFolder1.folderId, options)
162
+ showFolderInfo(folder)
163
+
164
+ f = open(filePath, "r")
165
+ data = f.read
166
+ f.close
167
+
168
+ #File upload to "tmptest1" folder.
169
+ uploadedFileInfo = box.fileUpload("test.txt", data, createdFolder1.folderId, 1, nil, nil)
170
+
171
+ #File copy "test.txt" on "tmptest1" folder as "test2.txt".
172
+ uploadedFileInfo = box.fileNewCopy("test2.txt", data, uploadedFileInfo.fileId, 1, "message", emails)
173
+
174
+ #File over write "test.txt" to "test2.txt".(Only over write data. File name is still "test2.txt".)
175
+ box.fileOverWrite("test.txt", data, uploadedFileInfo.fileId, 1, nil, nil)
176
+
177
+ #File move "test2.txt" to "renamed" folder.
178
+ box.move("file", uploadedFileInfo.fileId, createdFolder2.folderId)
179
+
180
+ #Set description test2.txt as "$$$description$$$"
181
+ box.setDescription("file", uploadedFileInfo.fileId, "$$$description$$$")
182
+ file = box.getFileInfo(uploadedFileInfo.fileId)
183
+
184
+ #"test2.txt" is public shared with password "password".
185
+ box.publicShare("file", uploadedFileInfo.fileId, "password", "This file is public shared!", nil)
186
+
187
+ #Add to tag "tag1" "tag2" to "test2.txt"
188
+ box.addToTag("file", uploadedFileInfo.fileId, tags)
189
+ showFileInfo(file)
190
+
191
+ #"test2.txt" is public unshared.
192
+ box.publicUnshare("file", uploadedFileInfo.fileId)
193
+
194
+ #"test2.txt" is private shared.
195
+ box.privateShare("file", uploadedFileInfo.fileId, "This file is private shared!", emails, 0)
196
+
197
+ #Enabled SSL.
198
+ box.useSSL = true
199
+ data = box.fileDownload(uploadedFileInfo.fileId)
200
+
201
+ f = open(filePath, "w")
202
+ f.write(data)
203
+ f.close
204
+
205
+ #Get folder information about "tmptest1" folder.
206
+ folder = box.getFolderInfo(createdFolder1.folderId, nil)
207
+ showFolderInfo(folder)
208
+
209
+ #Disabled SSL.
210
+ box.useSSL = false
211
+ box.delete("folder", createdFolder1.folderId)
212
+
213
+ #Update user storage information.
214
+ box.updateUserStorageInfo
215
+ showUserStorageInfo(box.userStorageInfo)
216
+
217
+ #Get root folder information.
218
+ options = ["simple", "onelevel"]
219
+ folder = box.getRootFolderInfo(options)
220
+ showFolderInfo(folder)
221
+
222
+ #Request friends.
223
+ options = ["no_email"]
224
+ box.requestFriends("Request friends.", emails, options)
225
+
226
+ #Verify email what is not registered box.net.
227
+ box.verifyRegistrationEmail(notRegisteredEmail)
228
+
229
+ #box.registerNewUser("new@username.ne.jp", "password")
230
+
231
+ #Get tag list.
232
+ taglist = box.exportTag
233
+ showTagList(taglist)
234
+
235
+ #Get friend list.
236
+ friendList = box.getFriends
237
+ showFriendList(friendList)
238
+
239
+ #Get other user's shared file to my box.
240
+ box.addToMyStorage("file", nil, publicName, 0, tags)
241
+ ensure
242
+ #Logout.
243
+ box.logout
244
+ end
245
+ end
246
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: boxrubylib
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tomohiko Ariki
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2009-10-21 00:00:00 +09:00
12
+ date: 2009-11-30 00:00:00 +09:00
13
13
  default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency