Class: Skydrive::Client

Inherits:
Object
  • Object
show all
Includes:
HTTMultiParty, Operations
Defined in:
lib/skydrive/client.rb

Overview

The client class

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Operations

#create_album, #create_comment, #create_folder, #delete_comment, #delete_skydrive_object, #get_skydrive_object_by_id, #my_camera_roll, #my_documents, #my_photos, #my_public_documents, #my_recent_documents, #my_shared_stuff, #my_skydrive, #my_storage_quota, #object_comments, #update_skydrive_object, #upload, #user_camera_roll, #user_documents, #user_photos, #user_public_documents, #user_recent_documents, #user_shared_stuff, #user_skydrive, #user_storage_quota

Constructor Details

#initialize(access_token) ⇒ Client

Returns a new instance of Client.



9
10
11
12
# File 'lib/skydrive/client.rb', line 9

def initialize access_token
  @access_token = access_token
  self.class.default_params :access_token => @access_token.token
end

Instance Attribute Details

#access_tokenObject (readonly)

Returns the value of attribute access_token.



4
5
6
# File 'lib/skydrive/client.rb', line 4

def access_token
  @access_token
end

Instance Method Details

#delete(url) ⇒ Object

Do a ‘delete’ request

Parameters:

  • url (String)

    the url to delete



37
38
39
# File 'lib/skydrive/client.rb', line 37

def delete url
  response = filtered_response(self.class.delete(url))
end

#get(url, options = {}) ⇒ Object

Do a ‘get’ request

Parameters:

  • url (String)

    the url to get

  • options (Hash) (defaults to: {})

    Additonal options to be passed



17
18
19
# File 'lib/skydrive/client.rb', line 17

def get url, options={}
  response = filtered_response(self.class.get(url, {:query => options}))
end

#meHash

Get the acting user

Returns:

  • (Hash)


50
51
52
# File 'lib/skydrive/client.rb', line 50

def me
  response = JSON.load(self.class.get("/me").parsed_response)
end

#move(url, options = {}) ⇒ Object

Do a ‘move’ request

Parameters:

  • url (String)

    the url to move

  • options (Hash) (defaults to: {})

    Additonal options to be passed



31
32
33
# File 'lib/skydrive/client.rb', line 31

def move url, options={}
  response = filtered_response(self.class.move(url, {:body => options}))
end

#object(response) ⇒ Object

Return a Skdrive::Object sub class



62
63
64
65
66
67
68
# File 'lib/skydrive/client.rb', line 62

def object response
  if response.is_a? Array
    return response.collect{ |object| "Skydrive::#{object["type"].capitalize}".constantize.new(self, object)}
  else
    return "Skydrive::#{response["type"].capitalize}"
  end
end

#post(url, options = {}) ⇒ Object

Do a ‘post’ request

Parameters:

  • url (String)

    the url to post

  • options (Hash) (defaults to: {})

    Additonal options to be passed



24
25
26
# File 'lib/skydrive/client.rb', line 24

def post url, options={}
  response = filtered_response(self.class.post(url, {:body => options}))
end

#put(url, body = nil, options = {}) ⇒ Object

Do a put request

Parameters:

  • url (String)

    the url to put

  • options (Hash) (defaults to: {})

    Additonal options to be passed



44
45
46
# File 'lib/skydrive/client.rb', line 44

def put url, body=nil, options={}
  response = filtered_response(self.class.put(url, { :body => body, :query => options, headers: { 'content-type' => ''} }))
end

#refresh_access_token!Object

Refresh the access token



55
56
57
58
59
# File 'lib/skydrive/client.rb', line 55

def refresh_access_token!
  @access_token = access_token.refresh!
  self.class.default_params :access_token => @access_token.token
  @access_token
end