Class: Google::Client

Inherits:
Object
  • Object
show all
Includes:
HTTParty
Defined in:
lib/gcal_unit/client.rb

Overview

Public : Performs http calls to the Google APIs.

Direct Known Subclasses

Authorization, Calendar, CalendarList, Event

Instance Method Summary collapse

Constructor Details

#initialize(token) ⇒ Client

Public: Initializes a new instance of a client.

token - The user token to make the call.



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

def initialize(token)
  @token = token
end

Instance Method Details

#http_delete(path, options = {}, &block) ⇒ Object

Public: Performs a DELETE request for an http call with the correct queries and headers applied.

path - the url for a DELETE request options - additional options for the DELETE request block - called after the DELETE request is complete

Raises Google::AuthenticationRequiredError if the token is no longer valid

Returns the response



84
85
86
87
88
89
90
91
# File 'lib/gcal_unit/client.rb', line 84

def http_delete(path, options={}, &block)
  apply_api_key options # apply the API key if it is not there
  apply_auth_header options # apply the authorization header if it is not there

  response = self.class.delete path, options, &block
  raise AuthenticationRequiredError.new if response.code == 401
  response
end

#http_get(path, options = {}, &block) ⇒ Object

Public: Performs a GET request for an http call with the correct queries and headers applied.

path - the url for the GET request options - additional options for the GET request block - called after the GET request is complete

Raises Google::AuthenticationRequiredError if the token is no longer valid

Returns the response



24
25
26
27
28
29
30
31
# File 'lib/gcal_unit/client.rb', line 24

def http_get(path, options={}, &block)
  apply_api_key options # apply the API key if it is not there
  apply_auth_header options # apply the authorization header if it is not there

  response = self.class.get path, options, &block
  raise AuthenticationRequiredError.new if response.code == 401
  response
end

#http_post(path, options = {}, &block) ⇒ Object

Public: Performs a POST request for an http call with the correct queries and headers applied.

path - the url for the POST request options - additional options for the POST request block - called after the POST request is complete

Raises Google::AuthenticationRequiredError if the token is no longer valid

Returns the response



43
44
45
46
47
48
49
50
51
52
# File 'lib/gcal_unit/client.rb', line 43

def http_post(path, options={}, &block)
  apply_api_key options # apply the API key if it is not there
  apply_auth_header options # apply the authorization header if it is not there
  apply_content_type_header options
  apply_content_length_header options

  response = self.class.post path, options, &block
  raise AuthenticationRequiredError.new if response.code == 401
  response
end

#http_put(path, options = {}, &block) ⇒ Object

Public: Performs a PUT request for an http call with the correct queries and headers applied.

path - the url for the PUT request options - additional options for the PUT request block - called after the PUT request is complete

Raises Google::AuthenticationRequiredError if the token is no longer valid

Returns the response



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

def http_put(path, options={}, &block)
  apply_api_key options # apply the API key if it is not there
  apply_auth_header options # apply the authorization header if it is not there
  apply_content_type_header options

  response = self.class.put path, options, &block
  raise AuthenticationRequiredError.new if response.code == 401
  response
end