skydrive 0.0.1 → 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # Skydrive
2
2
 
3
- TODO: Write a gem description
3
+ Simple client library for Microsoft Skydrive API with OAuth2 authentication
4
4
 
5
5
  ## Installation
6
6
 
@@ -1,6 +1,6 @@
1
1
  module Skydrive
2
2
  # A user's album in SkyDrive
3
- class Album < Skydrive::Object
3
+ class Album < Skydrive::Folder
4
4
 
5
5
  # The total number of items in the album.
6
6
  # @return [Integer]
@@ -1,6 +1,6 @@
1
1
  module Skydrive
2
2
  # A user's audio file in SkyDrive.
3
- class Audio < Skydrive::Object
3
+ class Audio < Skydrive::File
4
4
 
5
5
  # The size, in bytes, of the audio
6
6
  # @return [Integer]
@@ -20,12 +20,6 @@ module Skydrive
20
20
  object["comments_enabled"]
21
21
  end
22
22
 
23
- # A value that indicates whether this audio can be embedded
24
- # @return [Boolean]
25
- def is_embeddable
26
- object["is_embeddable"]
27
- end
28
-
29
23
  # The URL to use to download the audio from SkyDrive
30
24
  # @return [String]
31
25
  def source
@@ -74,5 +68,18 @@ module Skydrive
74
68
  object["picture"]
75
69
  end
76
70
 
71
+ # The link that can be used to download the audio file
72
+ # @return [String]
73
+ def download_link
74
+ url = client.get("/#{id}/content", :download => true, :suppress_redirects => true)["location"]
75
+ end
76
+
77
+ # Download the audio file
78
+ def download
79
+ uri = URI(download_link)
80
+ response = HTTParty.get("http://#{uri.host}#{uri.path}?#{uri.query}")
81
+ response.parsed_response
82
+ end
83
+
77
84
  end
78
85
  end
@@ -72,6 +72,8 @@ module Skydrive
72
72
  raise Skydrive::Error.new(filtered_response["error"]) if filtered_response["error"]
73
73
  if filtered_response["data"]
74
74
  return Skydrive::Collection.new(self, filtered_response["data"])
75
+ elsif filtered_response["location"]
76
+ return filtered_response
75
77
  elsif filtered_response["id"].match /^comment\..+/
76
78
  return Skydrive::Comment.new(self, filtered_response)
77
79
  else
@@ -83,8 +85,6 @@ module Skydrive
83
85
  else
84
86
  raise Skydrive::Error.new("code" => "http_error_#{response.response.code}", "message" => response.response.message)
85
87
  end
86
-
87
-
88
88
  end
89
89
 
90
90
  end
data/lib/skydrive/file.rb CHANGED
@@ -20,16 +20,24 @@ module Skydrive
20
20
  object["comments_enabled"]
21
21
  end
22
22
 
23
- # A value that indicates whether this file can be embedded
24
- # @return [Boolean]
25
- def is_embeddable
26
- object["is_embeddable"]
27
- end
28
-
29
23
  # The URL to use to download the file from SkyDrive
30
24
  # @return [String]
31
25
  def source
32
26
  object["source"]
33
27
  end
28
+
29
+ # The link that can be used to download the file
30
+ # @return [String]
31
+ def download_link
32
+ url = client.get("/#{id}/content", :download => true, :suppress_redirects => true)["location"]
33
+ end
34
+
35
+ # Download the file
36
+ def download
37
+ uri = URI(download_link)
38
+ response = HTTParty.get("http://#{uri.host}#{uri.path}?#{uri.query}")
39
+ response.parsed_response
40
+ end
41
+
34
42
  end
35
43
  end
@@ -3,11 +3,50 @@ module Skydrive
3
3
  class Folder < Skydrive::Object
4
4
 
5
5
  # Items in the folder
6
+ # @param [Hash] options Additional parameters
7
+ # @option options [Integer] :limit the maximum number of results to return
8
+ # @option options [Integer] :offset the index of the first item to get
9
+ # @option options [String] :sort_by set the item's sort criteria. Can be 'created, updated, name, size, or default'
10
+ # @option options [String] :sort_order set the item's sort order. Can be 'ascending or descending'
6
11
  # @return [Skydrive::Collection]
7
- def files
12
+ def files options={}
8
13
  response = client.get("/#{id}/files")
9
14
  end
10
15
 
11
-
16
+ # Get all the photos in the folder
17
+ # @param [Hash] options Additional parameters
18
+ # @option options [Integer] :limit the maximum number of results to return
19
+ # @option options [Integer] :offset the index of the first item to get
20
+ # @option options [String] :sort_by set the item's sort criteria. Can be 'created, updated, name, size, or default'
21
+ # @option options [String] :sort_order set the item's sort order. Can be 'ascending or descending'
22
+ # @return [Skydrive::Collection]
23
+ def photos options={}
24
+ response = client.get("/#{id}/photos", options)
25
+ end
26
+
27
+ # Get all the videos in the folder
28
+ # @param [Hash] options Additional parameters
29
+ # @option options [Integer] :limit the maximum number of results to return
30
+ # @option options [Integer] :offset the index of the first item to get
31
+ # @option options [String] :sort_by set the item's sort criteria. Can be 'created, updated, name, size, or default'
32
+ # @option options [String] :sort_order set the item's sort order. Can be 'ascending or descending'
33
+ # @return [Skydrive::Collection]
34
+ def videos options={}
35
+ response = client.get("/#{id}/videos", options)
36
+ end
37
+
38
+ # Delete the folder
39
+ def delete
40
+ client.delete("/#{id}")
41
+ end
42
+
43
+ # Update the folder properties
44
+ # @param [Hash] options
45
+ # @option options [String] :name New name of the folder
46
+ # @option options [String] :description Description for the folder
47
+ # @return [Skydrive::Folder] the updated folder object
48
+ def update options={}
49
+ client.put("/#{id}", options)
50
+ end
12
51
  end
13
52
  end
@@ -1,5 +1,6 @@
1
1
  module Skydrive
2
2
  # The notebook object
3
3
  class Notebook < Skydrive::File
4
+
4
5
  end
5
6
  end
@@ -90,5 +90,11 @@ module Skydrive
90
90
  client.delete("/#{id}")
91
91
  end
92
92
 
93
+ # A value that indicates whether this object can be embedded
94
+ # @return [Boolean]
95
+ def is_embeddable?
96
+ object["is_embeddable"]
97
+ end
98
+
93
99
  end
94
100
  end
@@ -8,56 +8,134 @@ module Skydrive
8
8
  response = get("/me/skydrive")
9
9
  end
10
10
 
11
+ # Get the home folder of a particular user
12
+ # @param [String] user_id ID of the user
13
+ # @return [Skydrive::Folder]
14
+ def user_skydrive user_id
15
+ response = get("/#{user_id}/skydrive")
16
+ end
17
+
11
18
  # Your camera_roll folder
12
19
  # @return [Skydrive::Folder]
13
20
  def my_camera_roll
14
21
  response = get("/me/skydrive/camera_roll")
15
22
  end
16
23
 
24
+ # Get the camera_roll folder of a particular user
25
+ # @param [String] user_id ID of the user
26
+ # @return [Skydrive::Folder]
27
+ def user_camera_roll user_id
28
+ response = get("/#{user_id}/camera_roll")
29
+ end
30
+
17
31
  # Your documents
18
32
  # @return [Skydrive::Folder]
19
33
  def my_documents
20
34
  response = get("/me/skydrive/my_documents")
21
35
  end
22
36
 
37
+ # User's documents
38
+ # @param [String] user_id ID of the user
39
+ # @return [Skydrive::Folder]
40
+ def user_documents user_id
41
+ response = get("/#{user_id}/skydrive/my_documents")
42
+ end
43
+
23
44
  # Your default album
24
- # @return [Skydrive::Photos]
45
+ # @return [Skydrive::Album]
25
46
  def my_photos
26
47
  response = get("/me/skydrive/my_photos")
27
48
  end
28
49
 
50
+ # User's photos
51
+ # @param [String] user_id ID of the user
52
+ # @return [Skydrive::Folder]
53
+ def user_photos user_id
54
+ response = get("/#{user_id}/skydrive/my_photos")
55
+ end
56
+
29
57
  # Your public documents
30
58
  # @return [Skydrive::Folder]
31
59
  def my_public_documents
32
60
  response = get("/me/skydrive/public_documents")
33
61
  end
34
62
 
63
+ # User's public documents
64
+ # @param [String] user_id ID of the user
65
+ # @return [Skydrive::Folder]
66
+ def user_public_documents user_id
67
+ response = get("/#{user_id}/skydrive/public_documents")
68
+ end
69
+
35
70
  # Your shared items
36
71
  # @return [Skydrive::Collection]
37
72
  def my_shared_stuff
38
73
  response = get("/me/skydrive/shared")
39
74
  end
40
75
 
76
+ # User's shared items
77
+ # @return [Skydrive::Collection]
78
+ def user_shared_stuff
79
+ response = get("/#{id}/skydrive/shared")
80
+ end
81
+
41
82
  # Your recent documents
83
+ # @param [String] user_id ID of the user
42
84
  # @return [Skydrive::Collection]
43
- def recent_documents
85
+ def my_recent_documents
44
86
  response = get("/me/skydrive/recent_docs")
45
87
  end
46
88
 
89
+ # User's recent documents
90
+ # @param [String] user_id ID of the user
91
+ # @return [Skydrive::Collection]
92
+ def user_recent_documents user_id
93
+ response = get("/#{user_id}/skydrive/recent_docs")
94
+ end
95
+
47
96
  # Your total and remaining storage quota
48
97
  # @return [Hash] contains keys quota and available
49
- def storage_quota
98
+ def my_storage_quota
99
+ response = get("/me/skydrive/quota")
100
+ end
101
+
102
+ # User's total and remaining storage quota
103
+ # @return [Hash] contains keys quota and available
104
+ def user_storage_quota
50
105
  response = get("/me/skydrive/quota")
51
106
  end
52
107
 
53
108
  # Delete an object with given id
54
- def delete_object object_id
109
+ # @param [String] object_id the id of the object to be deleted
110
+ def delete_skydrive_object object_id
55
111
  response = delete("/#{object_id}")
56
112
  end
57
113
 
114
+ # Update a skydrive object
115
+ # @param [String] object_id the id of the object to be updated
116
+ # @param [Hash] options The properties to be updated
117
+ # @option options [String] :name The friendly name of the object
118
+ # @option options [String] :description The description text about the object
119
+ def update_skydrive_object object_id, options={}
120
+ response = put("/#{object_id}", options)
121
+ end
122
+
123
+ alias :update_folder :update_skydrive_object
124
+ alias :update_album :update_skydrive_object
125
+ alias :update_file :update_skydrive_object
126
+ alias :update_video :update_skydrive_object
127
+ alias :update_audio :update_skydrive_object
128
+ alias :update_photo :update_skydrive_object
129
+
130
+ alias :delete_folder :delete_skydrive_object
131
+ alias :delete_album :delete_skydrive_object
132
+ alias :delete_file :delete_skydrive_object
133
+ alias :delete_video :delete_skydrive_object
134
+ alias :delete_audio :delete_skydrive_object
135
+ alias :delete_photo :delete_skydrive_object
58
136
  # Create a new folder
59
137
  # @param [String] path the path where the new folder should be created
60
- # @param [Hash] options the additional parameters to be passed
138
+ # @param [Hash] options the details of the new folder
61
139
  # @option options [String] :name required, the name of the new folder
62
140
  # @option options [String] :description the description about the folder
63
141
  # @return [Skydrive::Folder] the new folder
@@ -65,5 +143,14 @@ module Skydrive
65
143
  response = post("/#{path}", options)
66
144
  end
67
145
 
146
+ # Create a new album. Albums can only be created in the path '/me/albums', so no need to pass the path as a parameter
147
+ # @param [Hash] options the details of the new album
148
+ # @option options [String] :name required, the name of the new album
149
+ # @option options [String] :description the description about the album
150
+ # @return [Skydrive::Album] the new album
151
+ def create_album options={}
152
+ response = post("/me/albums", options)
153
+ end
154
+
68
155
  end
69
156
  end
@@ -1,5 +1,17 @@
1
1
  module Skydrive
2
2
  # A user's photo in SkyDrive.
3
- class Photo < Skydrive::Object
3
+ class Photo < Skydrive::File
4
+ # The link that can be used to download the photo
5
+ # @return [String]
6
+ def download_link
7
+ url = client.get("/#{id}/content", :download => true, :suppress_redirects => true)["location"]
8
+ end
9
+
10
+ # Download the photo
11
+ def download
12
+ uri = URI(download_link)
13
+ response = HTTParty.get("http://#{uri.host}#{uri.path}?#{uri.query}")
14
+ response.parsed_response
15
+ end
4
16
  end
5
17
  end
data/lib/skydrive/user.rb CHANGED
@@ -20,7 +20,7 @@ module Skydrive
20
20
  end
21
21
 
22
22
  # User's default album
23
- # @return [Skydrive::Photos]
23
+ # @return [Skydrive::Album]
24
24
  def photos
25
25
  response = get("/#{id}/skydrive/my_photos")
26
26
  end
@@ -1,5 +1,5 @@
1
1
  # Skydrive base module
2
2
  module Skydrive
3
3
  # The gem version
4
- VERSION = "0.0.1"
4
+ VERSION = "0.0.2"
5
5
  end
@@ -1,5 +1,17 @@
1
1
  module Skydrive
2
2
  # A user's video in SkyDrive.
3
- class Video < Skydrive::Object
3
+ class Video < Skydrive::File
4
+ # The link that can be used to download the video file
5
+ # @return [String]
6
+ def download_link
7
+ url = client.get("/#{id}/content", :download => true, :suppress_redirects => true)["location"]
8
+ end
9
+
10
+ # Download the video file
11
+ def download
12
+ uri = URI(download_link)
13
+ response = HTTParty.get("http://#{uri.host}#{uri.path}?#{uri.query}")
14
+ response.parsed_response
15
+ end
4
16
  end
5
17
  end
data/skydrive.gemspec CHANGED
@@ -16,7 +16,7 @@ Gem::Specification.new do |gem|
16
16
  gem.name = "skydrive"
17
17
  gem.require_paths = ["lib"]
18
18
  gem.version = Skydrive::VERSION
19
- gem.add_dependency 'httparty', '>= 0.10.2'
19
+ gem.add_dependency 'httparty', '>= 0.11.0'
20
20
  gem.add_dependency 'activesupport'
21
21
  gem.add_dependency 'httmultiparty'
22
22
  gem.add_dependency 'oauth2'
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: skydrive
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-04-29 00:00:00.000000000 Z
12
+ date: 2013-05-02 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: httparty
@@ -18,7 +18,7 @@ dependencies:
18
18
  requirements:
19
19
  - - ! '>='
20
20
  - !ruby/object:Gem::Version
21
- version: 0.10.2
21
+ version: 0.11.0
22
22
  type: :runtime
23
23
  prerelease: false
24
24
  version_requirements: !ruby/object:Gem::Requirement
@@ -26,7 +26,7 @@ dependencies:
26
26
  requirements:
27
27
  - - ! '>='
28
28
  - !ruby/object:Gem::Version
29
- version: 0.10.2
29
+ version: 0.11.0
30
30
  - !ruby/object:Gem::Dependency
31
31
  name: activesupport
32
32
  requirement: !ruby/object:Gem::Requirement