skydrive 0.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- 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
@@ -0,0 +1,54 @@
|
|
1
|
+
require 'oauth2'
|
2
|
+
module Skydrive
|
3
|
+
# Oauth module
|
4
|
+
module Oauth
|
5
|
+
# Oauth client class
|
6
|
+
class Client
|
7
|
+
attr_accessor :client_id, :client_secret, :oauth_client, :callback_url, :access_token, :scope
|
8
|
+
def initialize(client_id, client_secret, callback_url, scope, opts={})
|
9
|
+
@client_id = client_id
|
10
|
+
@client_secret = client_secret
|
11
|
+
@callback_url = callback_url
|
12
|
+
@scope = scope
|
13
|
+
ssl = opts.delete(:ssl)
|
14
|
+
|
15
|
+
@options = {
|
16
|
+
:site => 'https://login.live.com/',
|
17
|
+
:authorize_url => "oauth20_authorize.srf?response_type=code&scope=#{scope}",
|
18
|
+
:token_url => 'oauth20_token.srf',
|
19
|
+
:parse_json => true}.merge(opts)
|
20
|
+
@options[:connection_opts][:ssl] = ssl if ssl
|
21
|
+
@oauth_client = OAuth2::Client.new(client_id, client_secret, @options)
|
22
|
+
end
|
23
|
+
|
24
|
+
# Step 1: URL for OAuth2 authorization of Microsoft Live
|
25
|
+
# @return [String]
|
26
|
+
def authorize_url
|
27
|
+
oauth_client.auth_code.authorize_url(:redirect_uri => callback_url)
|
28
|
+
end
|
29
|
+
|
30
|
+
# Step 2: Get access token after authorizing user
|
31
|
+
# @param [String] code The value extracted from the callback url param 'code'
|
32
|
+
# @return [OAuth2::AccessToken] the access token
|
33
|
+
def get_access_token code
|
34
|
+
@access_token = oauth_client.auth_code.get_token(code, :redirect_uri => callback_url)
|
35
|
+
end
|
36
|
+
|
37
|
+
# Alternate Step2: Make an access token from already available data
|
38
|
+
# @param [String] token the Access Token value
|
39
|
+
# @param [Hash] opts the options to create the Access Token with
|
40
|
+
# @option opts [String] :refresh_token (nil) the refresh_token value
|
41
|
+
# @option opts [FixNum, String] :expires_in (nil) the number of seconds in which the AccessToken will expire
|
42
|
+
# @option opts [FixNum, String] :expires_at (nil) the epoch time in seconds in which AccessToken will expire
|
43
|
+
# @option opts [Symbol] :mode (:header) the transmission mode of the Access Token parameter value
|
44
|
+
# one of :header, :body or :query
|
45
|
+
# @option opts [String] :header_format ('Bearer %s') the string format to use for the Authorization header
|
46
|
+
# @option opts [String] :param_name ('access_token') the parameter name to use for transmission of the Access Token value in :body or :query transmission mode
|
47
|
+
# @return [OAuth2::AccessToken] the access token
|
48
|
+
def get_access_token_from_hash token, opts={}
|
49
|
+
@access_token = OAuth2::AccessToken.new(@oauth_client, token, opts)
|
50
|
+
end
|
51
|
+
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
@@ -0,0 +1,94 @@
|
|
1
|
+
module Skydrive
|
2
|
+
# The base class for all objects
|
3
|
+
class Object
|
4
|
+
attr_reader :client, :object
|
5
|
+
def initialize client, data
|
6
|
+
@client = client
|
7
|
+
@object = data
|
8
|
+
end
|
9
|
+
|
10
|
+
# ID of the object
|
11
|
+
# @return [String] object id
|
12
|
+
def id
|
13
|
+
object["id"]
|
14
|
+
end
|
15
|
+
|
16
|
+
# Info about the user who uploaded the file.
|
17
|
+
# @return [Skydrive::User]
|
18
|
+
def from
|
19
|
+
Skydrive::User.new(client, object["from"]) if object["from"]
|
20
|
+
end
|
21
|
+
|
22
|
+
# Name of the object
|
23
|
+
# @return [String]
|
24
|
+
def name
|
25
|
+
object["name"]
|
26
|
+
end
|
27
|
+
|
28
|
+
# Desciption of the object
|
29
|
+
# @return [String]
|
30
|
+
def description
|
31
|
+
object["description"]
|
32
|
+
end
|
33
|
+
|
34
|
+
# Type of object
|
35
|
+
# @return [String]
|
36
|
+
def type
|
37
|
+
object["type"]
|
38
|
+
end
|
39
|
+
|
40
|
+
# A URL to view the item on SkyDrive
|
41
|
+
# @return [String]
|
42
|
+
def link
|
43
|
+
object["link"]
|
44
|
+
end
|
45
|
+
|
46
|
+
# The time at which the object was created.
|
47
|
+
# @return [Time]
|
48
|
+
def created_time
|
49
|
+
Time.parse(object["created_time"]) if object["created_time"]
|
50
|
+
end
|
51
|
+
|
52
|
+
# The time at which the object was updated.
|
53
|
+
# @return [Time]
|
54
|
+
def updated_time
|
55
|
+
Time.parse(object["updated_time"]) if object["updated_time"]
|
56
|
+
end
|
57
|
+
|
58
|
+
# The URL to upload file content hosted in SkyDrive.
|
59
|
+
# @return [String]
|
60
|
+
def upload_location
|
61
|
+
object["upload_location"]
|
62
|
+
end
|
63
|
+
|
64
|
+
# The ID of the parent object
|
65
|
+
# @return [String]
|
66
|
+
def parent_id
|
67
|
+
object["parent_id"]
|
68
|
+
end
|
69
|
+
|
70
|
+
# The object that contains permission info.
|
71
|
+
# @return [Hash]
|
72
|
+
def shared_with
|
73
|
+
object["shared_with"]
|
74
|
+
end
|
75
|
+
|
76
|
+
# Get json format object
|
77
|
+
# @return [String]
|
78
|
+
def to_json
|
79
|
+
object.to_json
|
80
|
+
end
|
81
|
+
|
82
|
+
# Get the hash equivalent of the data
|
83
|
+
# @return [Hash]
|
84
|
+
def to_hash
|
85
|
+
object
|
86
|
+
end
|
87
|
+
|
88
|
+
# Delete the object from Skydrive
|
89
|
+
def delete
|
90
|
+
client.delete("/#{id}")
|
91
|
+
end
|
92
|
+
|
93
|
+
end
|
94
|
+
end
|
@@ -0,0 +1,69 @@
|
|
1
|
+
module Skydrive
|
2
|
+
# The basic operations
|
3
|
+
module Operations
|
4
|
+
|
5
|
+
# Your home folder
|
6
|
+
# @return [Skydrive::Folder]
|
7
|
+
def my_skydrive
|
8
|
+
response = get("/me/skydrive")
|
9
|
+
end
|
10
|
+
|
11
|
+
# Your camera_roll folder
|
12
|
+
# @return [Skydrive::Folder]
|
13
|
+
def my_camera_roll
|
14
|
+
response = get("/me/skydrive/camera_roll")
|
15
|
+
end
|
16
|
+
|
17
|
+
# Your documents
|
18
|
+
# @return [Skydrive::Folder]
|
19
|
+
def my_documents
|
20
|
+
response = get("/me/skydrive/my_documents")
|
21
|
+
end
|
22
|
+
|
23
|
+
# Your default album
|
24
|
+
# @return [Skydrive::Photos]
|
25
|
+
def my_photos
|
26
|
+
response = get("/me/skydrive/my_photos")
|
27
|
+
end
|
28
|
+
|
29
|
+
# Your public documents
|
30
|
+
# @return [Skydrive::Folder]
|
31
|
+
def my_public_documents
|
32
|
+
response = get("/me/skydrive/public_documents")
|
33
|
+
end
|
34
|
+
|
35
|
+
# Your shared items
|
36
|
+
# @return [Skydrive::Collection]
|
37
|
+
def my_shared_stuff
|
38
|
+
response = get("/me/skydrive/shared")
|
39
|
+
end
|
40
|
+
|
41
|
+
# Your recent documents
|
42
|
+
# @return [Skydrive::Collection]
|
43
|
+
def recent_documents
|
44
|
+
response = get("/me/skydrive/recent_docs")
|
45
|
+
end
|
46
|
+
|
47
|
+
# Your total and remaining storage quota
|
48
|
+
# @return [Hash] contains keys quota and available
|
49
|
+
def storage_quota
|
50
|
+
response = get("/me/skydrive/quota")
|
51
|
+
end
|
52
|
+
|
53
|
+
# Delete an object with given id
|
54
|
+
def delete_object object_id
|
55
|
+
response = delete("/#{object_id}")
|
56
|
+
end
|
57
|
+
|
58
|
+
# Create a new folder
|
59
|
+
# @param [String] path the path where the new folder should be created
|
60
|
+
# @param [Hash] options the additional parameters to be passed
|
61
|
+
# @option options [String] :name required, the name of the new folder
|
62
|
+
# @option options [String] :description the description about the folder
|
63
|
+
# @return [Skydrive::Folder] the new folder
|
64
|
+
def create_folder path, options={}
|
65
|
+
response = post("/#{path}", options)
|
66
|
+
end
|
67
|
+
|
68
|
+
end
|
69
|
+
end
|
@@ -0,0 +1,53 @@
|
|
1
|
+
module Skydrive
|
2
|
+
# The user object
|
3
|
+
class User < Skydrive::Object
|
4
|
+
# User's home directory
|
5
|
+
# @return [Skydrive::Folder]
|
6
|
+
def skydrive
|
7
|
+
response = get("/#{id}/skydrive")
|
8
|
+
end
|
9
|
+
|
10
|
+
# User's camera_roll folder
|
11
|
+
# @return [Skydrive::Folder]
|
12
|
+
def camera_roll
|
13
|
+
response = get("/#{id}/skydrive/camera_roll")
|
14
|
+
end
|
15
|
+
|
16
|
+
# User's documents
|
17
|
+
# @return [Skydrive::Folder]
|
18
|
+
def documents
|
19
|
+
response = get("/#{id}/skydrive/my_documents")
|
20
|
+
end
|
21
|
+
|
22
|
+
# User's default album
|
23
|
+
# @return [Skydrive::Photos]
|
24
|
+
def photos
|
25
|
+
response = get("/#{id}/skydrive/my_photos")
|
26
|
+
end
|
27
|
+
|
28
|
+
# User's public documents
|
29
|
+
# @return [Skydrive::Folder]
|
30
|
+
def public_documents
|
31
|
+
response = get("/#{id}/skydrive/public_documents")
|
32
|
+
end
|
33
|
+
|
34
|
+
# User's shared items
|
35
|
+
# @return [Skydrive::Collection]
|
36
|
+
def shared_stuff
|
37
|
+
response = get("/#{id}/skydrive/shared")
|
38
|
+
end
|
39
|
+
|
40
|
+
# User's recent documents
|
41
|
+
# @return [Skydrive::Collection]
|
42
|
+
def recent_documents
|
43
|
+
response = get("/#{id}/skydrive/recent_docs")
|
44
|
+
end
|
45
|
+
|
46
|
+
# User's total and remaining storage quota
|
47
|
+
# @return [Hash] contains keys quota and available
|
48
|
+
def storage_quota
|
49
|
+
response = get("/#{id}/skydrive/quota")
|
50
|
+
end
|
51
|
+
|
52
|
+
end
|
53
|
+
end
|
data/skydrive.gemspec
ADDED
@@ -0,0 +1,36 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
require File.expand_path('../lib/skydrive/version', __FILE__)
|
3
|
+
lib = File.expand_path('../lib', __FILE__)
|
4
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
5
|
+
|
6
|
+
Gem::Specification.new do |gem|
|
7
|
+
gem.authors = ["Rony Varghese"]
|
8
|
+
gem.email = ["rony@mobme.in"]
|
9
|
+
gem.description = "Simple ruby client library for Skydrive cloud storage service with OAuth2"
|
10
|
+
gem.summary = "Ruby client library for Microsoft Skydrive"
|
11
|
+
gem.homepage = "https://github.com/ronyv89/skydrive"
|
12
|
+
|
13
|
+
gem.files = `git ls-files`.split($\)
|
14
|
+
gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
|
15
|
+
gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
|
16
|
+
gem.name = "skydrive"
|
17
|
+
gem.require_paths = ["lib"]
|
18
|
+
gem.version = Skydrive::VERSION
|
19
|
+
gem.add_dependency 'httparty', '>= 0.10.2'
|
20
|
+
gem.add_dependency 'activesupport'
|
21
|
+
gem.add_dependency 'httmultiparty'
|
22
|
+
gem.add_dependency 'oauth2'
|
23
|
+
gem.add_development_dependency "rspec"
|
24
|
+
gem.add_development_dependency "rake"
|
25
|
+
gem.add_development_dependency "rb-inotify"
|
26
|
+
gem.add_development_dependency "guard"
|
27
|
+
gem.add_development_dependency "guard-rspec"
|
28
|
+
gem.add_development_dependency "simplecov"
|
29
|
+
gem.add_development_dependency "metric_abc"
|
30
|
+
gem.add_development_dependency "yard"
|
31
|
+
gem.add_development_dependency "ci_reporter"
|
32
|
+
gem.add_development_dependency "simplecov-rcov"
|
33
|
+
gem.add_development_dependency "rdiscount"
|
34
|
+
gem.add_development_dependency "webmock"
|
35
|
+
gem.add_development_dependency "rspec_multi_matchers"
|
36
|
+
end
|
File without changes
|
File without changes
|
@@ -0,0 +1,14 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'active_support/time'
|
3
|
+
describe Skydrive::Client do
|
4
|
+
|
5
|
+
let(:oauth_client) { Skydrive::Oauth::Client.new("client_id", "client_secret", "http://callback_demo", "wl.skydrive_update,wl.offline_access")}
|
6
|
+
let(:access_token) { OAuth2::AccessToken.new(oauth_client, "access_token", {:refresh_token => "refresh_token", :expires_at => 1.hour.since(Time.now).to_i}) }
|
7
|
+
subject { Skydrive::Client.new(access_token)}
|
8
|
+
|
9
|
+
describe '#object' do
|
10
|
+
it "should return a collection when there is 'data' key" do
|
11
|
+
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
@@ -0,0 +1,73 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Skydrive::Collection do
|
4
|
+
|
5
|
+
let(:collection) do
|
6
|
+
YAML.load(%{
|
7
|
+
- id: folder.8c8ce076ca27823f.8C8CE076CA27823F!142
|
8
|
+
from:
|
9
|
+
name: Roberto Tamburello
|
10
|
+
id: 8c8ce076ca27823f
|
11
|
+
name: My Sample Folder in Album 1
|
12
|
+
description: ''
|
13
|
+
parent_id: folder.de57f4126ed7e411
|
14
|
+
upload_location: https://apis.live.net/v5.0/folder.de57f4126ed7e411.DE57F4126ED7E411!126/files/
|
15
|
+
is_embeddable: true
|
16
|
+
count: 3
|
17
|
+
link: https://cid-8c8ce076ca27823f.skydrive.live.com/redir.aspx?page=self&resid=8C8CE076CA27823F!142&parid=8C8CE076CA27823F!126&type=5
|
18
|
+
type: folder
|
19
|
+
shared_with:
|
20
|
+
access: Just me
|
21
|
+
created_time: '2011-04-22T00:36:30+0000'
|
22
|
+
updated_time: '2011-04-22T19:18:12+0000'
|
23
|
+
- id: file.22688711f5410e6c.22688711F5410E6C!942
|
24
|
+
from:
|
25
|
+
name: William Flash
|
26
|
+
id: 22688711f5410e6c
|
27
|
+
name: Processing.docx
|
28
|
+
description:
|
29
|
+
parent_id: folder.22688711f5410e6c.22688711F5410E6C!479
|
30
|
+
size: 12692
|
31
|
+
upload_location: https://apis.live.net/v5.0/file.22688711f5410e6c.22688711F5410E6C!942/content/
|
32
|
+
comments_count: 0
|
33
|
+
comments_enabled: true
|
34
|
+
is_embeddable: false
|
35
|
+
source: http://storage.live.com/s1pEwo9qzyT4_BJZqMNm-aVzgLo-WRsQGzjzFsXjyREuQG5pDYr237vKz3i2pmqFuniYPzsuIZAOCUMB_gdfKCUpLpVcaAMXGrk4T7jOWenRniCv9vex7GWfSvy-XCVBVnU/Processing.docx:Binary
|
36
|
+
link: https://skydrive-df.live.com/redir.aspx?cid=22688711f5410e6c&page=view&resid=22688711F5410E6C!942&parid=22688711F5410E6C!479
|
37
|
+
type: file
|
38
|
+
shared_with:
|
39
|
+
access: Everyone (public)
|
40
|
+
created_time: '2011-10-12T23:18:23+0000'
|
41
|
+
updated_time: '2011-10-12T23:18:23+0000'
|
42
|
+
- id: comment.22688711f5410e6c.22688711f0410e6c!818.22688711F5410E6C!979
|
43
|
+
from:
|
44
|
+
name: Roberto Tamburello
|
45
|
+
id: 8c8ce076ca27823f
|
46
|
+
message: A lighthouse built on some rocks.
|
47
|
+
created_time: '2011-04-21T23:21:28+0000'
|
48
|
+
})
|
49
|
+
end
|
50
|
+
|
51
|
+
subject { Skydrive::Collection.new(skydrive_test_client, collection) }
|
52
|
+
describe "#items" do
|
53
|
+
it "should return an array" do
|
54
|
+
subject.items.should be_a Array
|
55
|
+
end
|
56
|
+
|
57
|
+
it "should return the items in the collection as skydrive objects" do
|
58
|
+
subject.items.should each {|item|
|
59
|
+
item.should be_a Skydrive::Object
|
60
|
+
}
|
61
|
+
end
|
62
|
+
|
63
|
+
it "should resolve objects with no 'type' key in the hash" do
|
64
|
+
subject.items[2].should be_a Skydrive::Comment
|
65
|
+
end
|
66
|
+
end
|
67
|
+
|
68
|
+
describe "#type" do
|
69
|
+
it "should return always return collection" do
|
70
|
+
subject.type.should == "collection"
|
71
|
+
end
|
72
|
+
end
|
73
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Skydrive::Comment do
|
4
|
+
|
5
|
+
let(:comment) do
|
6
|
+
YAML.load(%{
|
7
|
+
id: comment.22688711f5410e6c.22688711f0410e6c!818.22688711F5410E6C!979
|
8
|
+
from:
|
9
|
+
name: Roberto Tamburello
|
10
|
+
id: 8c8ce076ca27823f
|
11
|
+
message: A lighthouse built on some rocks.
|
12
|
+
created_time: '2011-04-21T23:21:28+0000'
|
13
|
+
})
|
14
|
+
end
|
15
|
+
|
16
|
+
subject {skydrive_test_client}
|
17
|
+
|
18
|
+
before :each do
|
19
|
+
stub_request(:get, "https://apis.live.net/v5.0/comment.22688711f5410e6c.22688711f0410e6c!818.22688711F5410E6C!979?access_token=access_token").to_return(:status => 200, :body => comment.to_json, :headers => {})
|
20
|
+
@comment = skydrive_test_client.get("/comment.22688711f5410e6c.22688711f0410e6c!818.22688711F5410E6C!979")
|
21
|
+
end
|
22
|
+
|
23
|
+
it "should return the message associated with the comment" do
|
24
|
+
@comment.message.should eql "A lighthouse built on some rocks."
|
25
|
+
end
|
26
|
+
end
|