skydrive 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +19 -0
- data/.rspec +2 -0
- data/Gemfile +18 -0
- data/Guardfile +5 -0
- data/LICENSE +22 -0
- data/README.md +29 -0
- data/Rakefile +2 -0
- data/lib/skydrive.rb +28 -0
- data/lib/skydrive/album.rb +12 -0
- data/lib/skydrive/audio.rb +78 -0
- data/lib/skydrive/client.rb +91 -0
- data/lib/skydrive/collection.rb +31 -0
- data/lib/skydrive/comment.rb +15 -0
- data/lib/skydrive/error.rb +16 -0
- data/lib/skydrive/file.rb +35 -0
- data/lib/skydrive/folder.rb +13 -0
- data/lib/skydrive/notebook.rb +5 -0
- data/lib/skydrive/oauth/client.rb +54 -0
- data/lib/skydrive/object.rb +94 -0
- data/lib/skydrive/operations.rb +69 -0
- data/lib/skydrive/photo.rb +5 -0
- data/lib/skydrive/user.rb +53 -0
- data/lib/skydrive/version.rb +5 -0
- data/lib/skydrive/video.rb +5 -0
- data/skydrive.gemspec +36 -0
- data/spec/skydrive/album_spec.rb +0 -0
- data/spec/skydrive/audio_spec.rb +0 -0
- data/spec/skydrive/client_spec.rb +14 -0
- data/spec/skydrive/collection_spec.rb +73 -0
- data/spec/skydrive/comment_spec.rb +26 -0
- data/spec/skydrive/file_spec.rb +40 -0
- data/spec/skydrive/folder_spec.rb +57 -0
- data/spec/skydrive/oauth/client_spec.rb +70 -0
- data/spec/skydrive/object_spec.rb +82 -0
- data/spec/skydrive/operations_spec.rb +40 -0
- data/spec/skydrive/photo_spec.rb +0 -0
- data/spec/skydrive/user_spec.rb +16 -0
- data/spec/spec_helper.rb +18 -0
- metadata +369 -0
data/.gitignore
ADDED
data/.rspec
ADDED
data/Gemfile
ADDED
data/Guardfile
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2013 Rony Varghese
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
# Skydrive
|
2
|
+
|
3
|
+
TODO: Write a gem description
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
gem 'skydrive'
|
10
|
+
|
11
|
+
And then execute:
|
12
|
+
|
13
|
+
$ bundle
|
14
|
+
|
15
|
+
Or install it yourself as:
|
16
|
+
|
17
|
+
$ gem install skydrive
|
18
|
+
|
19
|
+
## Usage
|
20
|
+
|
21
|
+
TODO: Write usage instructions here
|
22
|
+
|
23
|
+
## Contributing
|
24
|
+
|
25
|
+
1. Fork it
|
26
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
27
|
+
3. Commit your changes (`git commit -am 'Added some feature'`)
|
28
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
29
|
+
5. Create new Pull Request
|
data/Rakefile
ADDED
data/lib/skydrive.rb
ADDED
@@ -0,0 +1,28 @@
|
|
1
|
+
require 'httmultiparty'
|
2
|
+
require 'json'
|
3
|
+
require "skydrive/version"
|
4
|
+
directory = File.expand_path(File.dirname(__FILE__))
|
5
|
+
module Skydrive
|
6
|
+
# Your code goes here...
|
7
|
+
class << self
|
8
|
+
|
9
|
+
attr_accessor :client_id, :client_secret, :api_version, :ssl, :access_token, :locale
|
10
|
+
end
|
11
|
+
require 'active_support/time'
|
12
|
+
require 'skydrive/operations'
|
13
|
+
require 'skydrive/oauth/client'
|
14
|
+
require 'skydrive/collection'
|
15
|
+
require 'skydrive/client'
|
16
|
+
require 'skydrive/object'
|
17
|
+
require 'skydrive/user'
|
18
|
+
|
19
|
+
require 'skydrive/file'
|
20
|
+
require 'skydrive/folder'
|
21
|
+
require 'skydrive/photo'
|
22
|
+
require 'skydrive/album'
|
23
|
+
require 'skydrive/audio'
|
24
|
+
require 'skydrive/error'
|
25
|
+
require 'skydrive/comment'
|
26
|
+
require 'skydrive/notebook'
|
27
|
+
|
28
|
+
end
|
@@ -0,0 +1,78 @@
|
|
1
|
+
module Skydrive
|
2
|
+
# A user's audio file in SkyDrive.
|
3
|
+
class Audio < Skydrive::Object
|
4
|
+
|
5
|
+
# The size, in bytes, of the audio
|
6
|
+
# @return [Integer]
|
7
|
+
def size
|
8
|
+
object["size"]
|
9
|
+
end
|
10
|
+
|
11
|
+
# The number of comments associated with the audio
|
12
|
+
# @return [Integer]
|
13
|
+
def comments_count
|
14
|
+
object["comments_count"]
|
15
|
+
end
|
16
|
+
|
17
|
+
# A value that indicates whether comments are enabled for the audio
|
18
|
+
# @return [Boolean]
|
19
|
+
def comments_enabled
|
20
|
+
object["comments_enabled"]
|
21
|
+
end
|
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
|
+
# The URL to use to download the audio from SkyDrive
|
30
|
+
# @return [String]
|
31
|
+
def source
|
32
|
+
object["source"]
|
33
|
+
end
|
34
|
+
|
35
|
+
# The audio's title
|
36
|
+
# @return [String]
|
37
|
+
def title
|
38
|
+
object["title"]
|
39
|
+
end
|
40
|
+
|
41
|
+
# The audio's artist name
|
42
|
+
# @return [String]
|
43
|
+
def artist
|
44
|
+
object["artist"]
|
45
|
+
end
|
46
|
+
|
47
|
+
# The audio's album name
|
48
|
+
# @return [String]
|
49
|
+
def album
|
50
|
+
object["album"]
|
51
|
+
end
|
52
|
+
|
53
|
+
# The artist name of the audio's album
|
54
|
+
# @return [String]
|
55
|
+
def album_artist
|
56
|
+
object["album_artist"]
|
57
|
+
end
|
58
|
+
|
59
|
+
# The audio's genre
|
60
|
+
# @return [String]
|
61
|
+
def genre
|
62
|
+
object["genre"]
|
63
|
+
end
|
64
|
+
|
65
|
+
# The audio's playing time, in milliseconds
|
66
|
+
# @return [Integer]
|
67
|
+
def duration
|
68
|
+
object["duration"]
|
69
|
+
end
|
70
|
+
|
71
|
+
# A URL to view the audio's picture on SkyDrive
|
72
|
+
# @return [String]
|
73
|
+
def picture
|
74
|
+
object["picture"]
|
75
|
+
end
|
76
|
+
|
77
|
+
end
|
78
|
+
end
|
@@ -0,0 +1,91 @@
|
|
1
|
+
module Skydrive
|
2
|
+
# The client class
|
3
|
+
class Client
|
4
|
+
attr_reader :access_token
|
5
|
+
include HTTMultiParty
|
6
|
+
include Operations
|
7
|
+
base_uri "https://apis.live.net/v5.0/"
|
8
|
+
format :json
|
9
|
+
def initialize access_token
|
10
|
+
@access_token = access_token
|
11
|
+
self.class.default_params :access_token => @access_token.token
|
12
|
+
end
|
13
|
+
|
14
|
+
# Do a 'get' request
|
15
|
+
# @param [String] url the url to get
|
16
|
+
# @param [Hash] options Additonal options to be passed
|
17
|
+
def get url, options={}
|
18
|
+
response = filtered_response(self.class.get(url, {:query => options}))
|
19
|
+
end
|
20
|
+
|
21
|
+
# Do a 'post' request
|
22
|
+
# @param [String] url the url to post
|
23
|
+
# @param [Hash] options Additonal options to be passed
|
24
|
+
def post url, options={}
|
25
|
+
response = filtered_response(self.class.post(url, {:body => options}))
|
26
|
+
end
|
27
|
+
|
28
|
+
# Do a 'move' request
|
29
|
+
# @param [String] url the url to move
|
30
|
+
# @param [Hash] options Additonal options to be passed
|
31
|
+
def move url, options={}
|
32
|
+
response = filtered_response(self.class.move(url, {:body => options}))
|
33
|
+
end
|
34
|
+
|
35
|
+
# Do a 'delete' request
|
36
|
+
# @param [String] url the url to delete
|
37
|
+
def delete url
|
38
|
+
response = filtered_response(self.class.delete(url))
|
39
|
+
end
|
40
|
+
|
41
|
+
# Do a put request
|
42
|
+
# @param [String] url the url to put
|
43
|
+
# @param [Hash] options Additonal options to be passed
|
44
|
+
def put url, options={}
|
45
|
+
response = filtered_response(self.class.put(url, {:body => options}))
|
46
|
+
end
|
47
|
+
|
48
|
+
# Refresh the access token
|
49
|
+
def refresh_access_token!
|
50
|
+
@access_token = access_token.refresh!
|
51
|
+
self.class.default_params :access_token => @access_token.token
|
52
|
+
@access_token
|
53
|
+
end
|
54
|
+
|
55
|
+
# Return a Skdrive::Object sub class
|
56
|
+
def object response
|
57
|
+
if response.is_a? Array
|
58
|
+
return response.collect{ |object| "Skydrive::#{object["type"].capitalize}".constantize.new(self, object)}
|
59
|
+
else
|
60
|
+
return "Skydrive::#{response["type"].capitalize}"
|
61
|
+
end
|
62
|
+
end
|
63
|
+
|
64
|
+
private
|
65
|
+
|
66
|
+
# Filter the response after checking for any errors
|
67
|
+
def filtered_response response
|
68
|
+
raise Skydrive::Error.new({"code" => "no_response_received", "message" => "Request didn't make through or response not received"}) unless response
|
69
|
+
if response.success?
|
70
|
+
filtered_response = response.parsed_response
|
71
|
+
if response.response.code == "200"
|
72
|
+
raise Skydrive::Error.new(filtered_response["error"]) if filtered_response["error"]
|
73
|
+
if filtered_response["data"]
|
74
|
+
return Skydrive::Collection.new(self, filtered_response["data"])
|
75
|
+
elsif filtered_response["id"].match /^comment\..+/
|
76
|
+
return Skydrive::Comment.new(self, filtered_response)
|
77
|
+
else
|
78
|
+
return "Skydrive::#{filtered_response["type"].capitalize}".constantize.new(self, filtered_response)
|
79
|
+
end
|
80
|
+
else
|
81
|
+
return true
|
82
|
+
end
|
83
|
+
else
|
84
|
+
raise Skydrive::Error.new("code" => "http_error_#{response.response.code}", "message" => response.response.message)
|
85
|
+
end
|
86
|
+
|
87
|
+
|
88
|
+
end
|
89
|
+
|
90
|
+
end
|
91
|
+
end
|
@@ -0,0 +1,31 @@
|
|
1
|
+
module Skydrive
|
2
|
+
|
3
|
+
# An object with an array of objects of multiple types
|
4
|
+
class Collection
|
5
|
+
attr_reader :client, :data
|
6
|
+
def initialize client, data
|
7
|
+
@client = client
|
8
|
+
@data = data
|
9
|
+
end
|
10
|
+
|
11
|
+
# Additional type for the collection
|
12
|
+
# @return [String]
|
13
|
+
def type
|
14
|
+
"collection"
|
15
|
+
end
|
16
|
+
|
17
|
+
# Array of items in the collection
|
18
|
+
# @return [Array]
|
19
|
+
def items
|
20
|
+
@items = []
|
21
|
+
@data.each do |object_data|
|
22
|
+
if object_data["type"]
|
23
|
+
@items << "Skydrive::#{object_data["type"].capitalize}".constantize.new(self, object_data)
|
24
|
+
elsif object_data["id"].match /^comment\..+/
|
25
|
+
@items << Skydrive::Comment.new(client, object_data)
|
26
|
+
end
|
27
|
+
end
|
28
|
+
@items
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
module Skydrive
|
2
|
+
# The class that handles the errors
|
3
|
+
class Error < StandardError
|
4
|
+
attr_reader :code, :error_message, :message
|
5
|
+
def initialize error
|
6
|
+
@code = error["code"]
|
7
|
+
@error_message = error["message"]
|
8
|
+
end
|
9
|
+
|
10
|
+
def message
|
11
|
+
"#{code}: #{error_message}"
|
12
|
+
end
|
13
|
+
|
14
|
+
alias :to_s :message
|
15
|
+
end
|
16
|
+
end
|
@@ -0,0 +1,35 @@
|
|
1
|
+
module Skydrive
|
2
|
+
# The file object
|
3
|
+
class File < Skydrive::Object
|
4
|
+
|
5
|
+
# The file size
|
6
|
+
# @return [String]
|
7
|
+
def size
|
8
|
+
object["size"]
|
9
|
+
end
|
10
|
+
|
11
|
+
# The number of comments associated with the file
|
12
|
+
# @return [Integer]
|
13
|
+
def comments_count
|
14
|
+
object["comments_count"]
|
15
|
+
end
|
16
|
+
|
17
|
+
# A value that indicates whether comments are enabled for the file
|
18
|
+
# @return [Boolean]
|
19
|
+
def comments_enabled
|
20
|
+
object["comments_enabled"]
|
21
|
+
end
|
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
|
+
# The URL to use to download the file from SkyDrive
|
30
|
+
# @return [String]
|
31
|
+
def source
|
32
|
+
object["source"]
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|