Module: OEHClient

Defined in:
lib/oehclient.rb,
lib/oehclient/data.rb,
lib/oehclient/meta.rb,
lib/oehclient/config.rb,
lib/oehclient/helper.rb,
lib/oehclient/version.rb,
lib/oehclient/realtime.rb,
lib/oehclient/exception.rb

Defined Under Namespace

Modules: Config, Data, Exception, Helper, Meta, Realtime

Constant Summary collapse

VERSION =
"2.2.8"

Class Attribute Summary collapse

Class Method Summary collapse

Class Attribute Details

.space_mgrObject

Returns the value of attribute space_mgr.


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

def space_mgr
  @space_mgr
end

.spacesObject

Returns the value of attribute spaces.


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

def spaces
  @spaces
end

Class Method Details

.configure_space {|@space_mgr| ... } ⇒ Object

configure provides the basic interface for passing tenancy configuration to the gem

Yields:


27
28
29
30
31
32
33
34
35
# File 'lib/oehclient.rb', line 27

def configure_space

	# if space_mgr attribute is NIL then return a new instance of the OEHClient::Config::SpaceManager
	#  singleton class
	@space_mgr ||= OEHClient::Config::SpaceManager.instance
	# yield control to the block passed in the configuration
	yield(@space_mgr)

end

.get(url, oauth_consumer = nil, *args) ⇒ Object

wraps the GET method of the RestClient::Resource and manages the response that is returned


38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
# File 'lib/oehclient.rb', line 38

def get(url, oauth_consumer=nil, *args)
	# retrieved the passed options from the SPLAT
	options = (args.length > 0 ? args[0] : Hash.new)
	# if the oauth_consumer is not a proper OAuth::Consumer, then raise the Oeh::Exception::InvalidTokenException
	#  exception to the calling method
	raise OEHClient::Exception::InvalidConsumerException if (!oauth_consumer.nil? && !oauth_consumer.kind_of?(OAuth::Consumer))

	# reset execution processes 
    RestClient.reset_before_execution_procs
	# if this request has an oauth token, sign the RestClient object
	unless (oauth_consumer.nil?)
    	# add the oauth signature
    	RestClient.add_before_execution_proc { |req, params| oauth_consumer.sign! req }
	end

	# force the new hash for the header and params if they are NIL
	header = (options.has_key?(:header) ? options[:header] : OEHClient::Helper::Request.default_JSON_header())
	# merge parameters into the header if they are passed
	header.merge!(:params => options[:params] ) if (options.has_key?(:params))
	#puts("URL: #{url} ; Header: #{header}")
	# send the GET request, manage the returned response, and return the body of the response to the
	#   calling method
	RestClient::Request.execute(method: :get, url: url, headers: header, verify_ssl: OpenSSL::SSL::VERIFY_PEER) { | response, request, result | OEHClient::Helper::Response.handle(response)}

end

.post(url, oauth_consumer = nil, *args) ⇒ Object

post wraps the POST method of the access token and manages the response that is returned


65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
# File 'lib/oehclient.rb', line 65

def post(url, oauth_consumer=nil, *args)

	# retrieved the passed options from the SPLAT
	options = (args.length > 0 ? args[0] : Hash.new)
	# if the oauth_consumer is not a proper OAuth::Consumer, then raise the Oeh::Exception::InvalidTokenException
	#  exception to the calling method
	raise OEHClient::Exception::InvalidConsumerException if (!oauth_consumer.nil? && !oauth_consumer.kind_of?(OAuth::Consumer))

	# reset execution processes 
    RestClient.reset_before_execution_procs
	# if this request has an oauth token, sign the RestClient object
	unless (oauth_consumer.nil?)
    	# add the oauth signature
    	RestClient.add_before_execution_proc { |req, params| oauth_consumer.sign! req }
	end

	# force the new hash for the header and params if they are NIL
	header = (options.has_key?(:header) ? options[:header] : OEHClient::Helper::Request.default_JSON_header())
	# merge parameters into the header if they are passed
	header.merge!(:params => options[:params] ) if (options.has_key?(:params))

	# send the POST request, manage the returned response, and return the body of the response to the
	#   calling method
	RestClient::Request.execute(method: :post, url: url, payload: options[:payload], headers: header, verify_ssl: OpenSSL::SSL::VERIFY_PEER) { | response, request, result | OEHClient::Helper::Response.handle(response)}
end

.put(url, oauth_consumer = nil, *args) ⇒ Object

put wraps the PUT method of the access token and manages the response that is returned


92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
# File 'lib/oehclient.rb', line 92

def put(url, oauth_consumer=nil, *args)
	# retrieved the passed options from the SPLAT
	options = (args.length > 0 ? args[0] : Hash.new)
	# if the oauth_consumer is not a proper OAuth::Consumer, then raise the Oeh::Exception::InvalidTokenException
	#  exception to the calling method
	raise OEHClient::Exception::InvalidConsumerException if (!oauth_consumer.nil? && !oauth_consumer.kind_of?(OAuth::Consumer))

	# reset execution processes 
    RestClient.reset_before_execution_procs
	# if this request has an oauth token, sign the RestClient object
	unless (oauth_consumer.nil?)
    	# add the oauth signature
    	RestClient.add_before_execution_proc { |req, params| oauth_consumer.sign! req }
	end

	# force the new hash for the header and params if they are NIL
	header = (options.has_key?(:header) ? options[:header] : OEHClient::Helper::Request.default_JSON_header())
	# merge parameters into the header if they are passed
	header.merge!(:params => options[:params] ) if (options.has_key?(:params))

	# send the POST request, manage the returned response, and return the body of the response to the
	#   calling method
	RestClient::Request.execute(method: :put, url: url, payload: options[:payload], headers: header, verify_ssl: OpenSSL::SSL::VERIFY_PEER) { | response, request, result | OEHClient::Helper::Response.handle(response)}
end