Class: Office365::REST::Request

Inherits:
Object
  • Object
show all
Defined in:
lib/office365/rest/request.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(access_token, debug: false) ⇒ Request

Returns a new instance of Request.



13
14
15
16
# File 'lib/office365/rest/request.rb', line 13

def initialize(access_token, debug: false)
  @access_token = access_token
  @debug = debug
end

Instance Attribute Details

#access_tokenObject

Returns the value of attribute access_token.



11
12
13
# File 'lib/office365/rest/request.rb', line 11

def access_token
  @access_token
end

#debugObject

Returns the value of attribute debug.



11
12
13
# File 'lib/office365/rest/request.rb', line 11

def debug
  @debug
end

Instance Method Details

#get(uri, args: {}) ⇒ Object



18
19
20
21
22
23
24
25
26
27
28
# File 'lib/office365/rest/request.rb', line 18

def get(uri, args: {})
  req_url = URI(uri.start_with?("https") ? uri : (Office365::API_HOST + uri))

  response = Faraday.new(url: [req_url.scheme, "://", req_url.hostname].join, headers: headers) do |faraday|
    faraday.adapter Faraday.default_adapter
    faraday.response :json
    faraday.response :logger, ::Logger.new($stdout), bodies: true if dev_developement?
  end.get(req_url.request_uri, *args)

  parse_respond(response)
end

#patch(uri, args) ⇒ Object



35
36
37
38
39
# File 'lib/office365/rest/request.rb', line 35

def patch(uri, args)
  response = faraday_action(__method__, uri, args)

  parse_respond(response)
end

#post(uri, args) ⇒ Object



30
31
32
33
# File 'lib/office365/rest/request.rb', line 30

def post(uri, args)
  response = faraday_action(__method__, uri, args)
  parse_respond(response)
end