Class: SimpleGoogleDrive::Client

Inherits:
SessionBase show all
Defined in:
lib/simple_google_drive/client.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(oauth2_access_token) ⇒ Client

Returns a new instance of Client.



7
8
9
10
11
12
13
14
15
# File 'lib/simple_google_drive/client.rb', line 7

def initialize(oauth2_access_token)

  if oauth2_access_token.is_a?(String)
    @access_token = oauth2_access_token
  else
    raise ArgumentError, "oauth2_access_token doesn't have a valid type"
  end

end

Instance Attribute Details

#access_tokenObject

Returns the value of attribute access_token.



5
6
7
# File 'lib/simple_google_drive/client.rb', line 5

def access_token
  @access_token
end

Instance Method Details

#aboutObject



19
20
21
22
23
24
25
# File 'lib/simple_google_drive/client.rb', line 19

def about
  url = build_url("/about")
  request = build_request(url)
  response = send_request(url, request)

  parse_response(response)
end

#files_copy(file_id, body = nil, params = nil) ⇒ Object



73
74
75
76
77
78
79
# File 'lib/simple_google_drive/client.rb', line 73

def files_copy(file_id, body = nil, params = nil)
  url = build_url("/files/#{file_id}/copy", params)
  request = build_request(url, 'post', body)
  response = send_request(url, request)

  parse_response(response)
end

#files_delete(file_id) ⇒ Object



81
82
83
84
85
86
87
# File 'lib/simple_google_drive/client.rb', line 81

def files_delete(file_id)
  url = build_url("/files/#{file_id}")
  request = build_request(url, 'delete')
  response = send_request(url, request)

  parse_response(response)
end

#files_get(file_id, params = nil) ⇒ Object



27
28
29
30
31
32
33
# File 'lib/simple_google_drive/client.rb', line 27

def files_get(file_id, params = nil)
  url = build_url("/files/#{file_id}", params)
  request = build_request(url)
  response = send_request(url, request)

  parse_response(response)
end

#files_insert(body = {}, params = nil) ⇒ Object



35
36
37
38
39
40
41
# File 'lib/simple_google_drive/client.rb', line 35

def files_insert(body = {}, params = nil)
  url = build_url("/files", params)
  request = build_request(url, 'post', body.to_json)
  response = send_request(url, request)

  parse_response(response)
end

#files_list(params = nil) ⇒ Object



89
90
91
92
93
94
95
# File 'lib/simple_google_drive/client.rb', line 89

def files_list(params = nil)
  url = build_url("/files", params)
  request = build_request(url)
  response = send_request(url, request)

  parse_response(response)
end

#files_patch(file_id, body = nil, params = nil) ⇒ Object



65
66
67
68
69
70
71
# File 'lib/simple_google_drive/client.rb', line 65

def files_patch(file_id, body = nil, params = nil)
  url = build_url("/files/#{file_id}", params)
  request = build_request(url, 'patch', body)
  response = send_request(url, request)

  parse_response(response)
end

#files_touch(file_id) ⇒ Object



97
98
99
100
101
102
103
# File 'lib/simple_google_drive/client.rb', line 97

def files_touch(file_id)
  url = build_url("/files/#{file_id}/touch")
  request = build_request(url, 'post')
  response = send_request(url, request)

  parse_response(response)
end

#files_trash(file_id) ⇒ Object



105
106
107
108
109
110
111
# File 'lib/simple_google_drive/client.rb', line 105

def files_trash(file_id)
  url = build_url("/files/#{file_id}/trash")
  request = build_request(url, 'post')
  response = send_request(url, request)

  parse_response(response)
end

#files_untrash(file_id) ⇒ Object



113
114
115
116
117
118
119
# File 'lib/simple_google_drive/client.rb', line 113

def files_untrash(file_id)
  url = build_url("/files/#{file_id}/untrash")
  request = build_request(url, 'post')
  response = send_request(url, request)

  parse_response(response)
end

#files_upload(file_object, args = {}) ⇒ Object

Raises:

  • (ArgumentError)


43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
# File 'lib/simple_google_drive/client.rb', line 43

def files_upload(file_object, args = {})
  raise ArgumentError, "Invalid upload type. Choose between media, multipart or resumable." if args[:uploadType].nil?

  case args[:uploadType].to_s
    when 'media'
      body = file_object
      content_type = MIME::Types.type_for(file_object.path).first.to_s
    when 'multipart'
      body = build_multipart_body(file_object, args[:body_object])
      content_type = "multipart/related;boundary=simple_google_drive_boundary"
    when 'resumable'
      body = build_resumable_body(file_object, args[:body_object])
      content_type = ""
  end

  url = build_url("/files", args[:parameters], true)
  request = build_request(url, 'post', body, content_type)
  response = send_request(url, request)

  parse_response(response)
end

#files_watch(file_id, body = nil) ⇒ Object



121
122
123
124
125
126
127
# File 'lib/simple_google_drive/client.rb', line 121

def files_watch(file_id, body = nil)
  url = build_url("/files/#{file_id}/watch")
  request = build_request(url, 'post', body.to_json)
  response = send_request(url, request)

  parse_response(response)
end