Class: Access::Request

Inherits:
Object
  • Object
show all
Includes:
HTTParty
Defined in:
lib/access/request.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#headersObject (readonly)

Returns the value of attribute headers.



5
6
7
# File 'lib/access/request.rb', line 5

def headers
  @headers
end

#return_jsonObject (readonly)

Returns the value of attribute return_json.



5
6
7
# File 'lib/access/request.rb', line 5

def return_json
  @return_json
end

#timeoutObject (readonly)

Returns the value of attribute timeout.



5
6
7
# File 'lib/access/request.rb', line 5

def timeout
  @timeout
end

#urlObject (readonly)

Returns the value of attribute url.



5
6
7
# File 'lib/access/request.rb', line 5

def url
  @url
end

#use_hashifyObject (readonly)

Returns the value of attribute use_hashify.



5
6
7
# File 'lib/access/request.rb', line 5

def use_hashify
  @use_hashify
end

Instance Method Details

#base_setup(path, api_type, options) ⇒ Object



7
8
9
10
11
12
13
14
# File 'lib/access/request.rb', line 7

def base_setup(path, api_type, options)
  @url = set_base(path, api_type, options.delete(:api_environment))
  @headers = set_headers options.delete(:access_token)
  @timeout = options.delete(:access_timeout) || Access.config.access_timeout
  @return_json = should_return_json?(options.delete(:return_json).to_s)
  @use_hashify = hashify_results?(options.delete(:hashify).to_s)
  @debug_output = options.delete(:access_debug_output).to_s || Access.config.access_debug_output
end

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



58
59
60
61
62
63
64
65
66
67
68
69
70
# File 'lib/access/request.rb', line 58

def delete(path, api_type, options={}, &block)
  base_setup(path, api_type, options)
  results = self.class.delete(url, headers: headers, body: options.to_json, timeout: timeout, debug_output: (@debug_output == 'true' ? $stdout : nil))
  if return_json
    use_hashify ? results.hashify : results
  else
    block.call results
  end
rescue Net::ReadTimeout, Net::OpenTimeout
  raise Access::Error::Timeout
rescue EOFError
  raise Access::Error::NoData
end

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



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

def get(path, api_type, options={}, &block)
  base_setup(path, api_type, options)
  results = self.class.get(url, headers: headers, query: options, timeout: timeout, debug_output: (@debug_output == 'true' ? $stdout : nil))
  if return_json
    use_hashify ? results.hashify : results
  else
    block.call results
  end
rescue Net::ReadTimeout, Net::OpenTimeout
  raise Access::Error::Timeout
rescue EOFError
  raise Access::Error::NoData
end

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



44
45
46
47
48
49
50
51
52
53
54
55
56
# File 'lib/access/request.rb', line 44

def post(path, api_type, options={}, &block)
  base_setup(path, api_type, options)
  results = self.class.post(url, headers: headers, body: options.to_json, timeout: timeout, debug_output: (@debug_output == 'true' ? $stdout : nil))
  if return_json
    use_hashify ? results.hashify : results
  else
    block.call results
  end
rescue Net::ReadTimeout, Net::OpenTimeout
  raise Access::Error::Timeout
rescue EOFError
  raise Access::Error::NoData
end

#post_for_filter(path, api_type, filter, options = {}, &block) ⇒ Object



72
73
74
75
76
77
78
79
80
81
82
83
84
# File 'lib/access/request.rb', line 72

def post_for_filter(path, api_type, filter, options={}, &block)
  base_setup(path, api_type, options)
  results = self.class.post(url, headers: headers, body: filter, timeout: timeout, debug_output: (@debug_output == 'true' ? $stdout : nil))
  if return_json
    use_hashify ? results.hashify : results
  else
    block.call results
  end
rescue Net::ReadTimeout, Net::OpenTimeout
  raise Access::Error::Timeout
rescue EOFError
  raise Access::Error::NoData
end

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



30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/access/request.rb', line 30

def put(path, api_type, options={}, &block)
  base_setup(path, api_type, options)
  results = self.class.put(url, headers: headers, body: options.to_json, timeout: timeout, debug_output: (@debug_output == 'true' ? $stdout : nil))
  if return_json
    use_hashify ? results.hashify : results
  else
    block.call results
  end
rescue Net::ReadTimeout, Net::OpenTimeout
  raise Access::Error::Timeout
rescue EOFError
  raise Access::Error::NoData
end