Class: CollectiveAccess
- Inherits:
-
Object
- Object
- CollectiveAccess
- Includes:
- HTTParty
- Defined in:
- lib/collectiveaccess.rb
Constant Summary collapse
- DEFAULT_REQUEST_OPTS =
{ protocol: 'http', hostname: 'localhost', url_root: '/', script_name: 'service.php', table_name: 'ca_objects', endpoint: 'item', request_body: {}, get_params: {}, url_string: '', verify: false }
Class Method Summary collapse
- .build_simple_uri(opts) ⇒ Object
-
.delete(request_opts = {}) ⇒ Object
HTTP DELETE request.
-
.get(request_opts = {}) ⇒ Object
HTTP GET request.
-
.options(request_opts = {}) ⇒ Object
HTTP OPTIONS request.
-
.post(request_opts = {}) ⇒ Object
HTTP POST request.
-
.put(request_opts = {}) ⇒ Object
HTTP PUT request.
- .set_credentials(user_name, key) ⇒ Object
- .simple(request_opts = {}) ⇒ Object
Class Method Details
.build_simple_uri(opts) ⇒ Object
116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 |
# File 'lib/collectiveaccess.rb', line 116 def self.build_simple_uri(opts) # URI available params: scheme, userinfo, host, port, registry, path, opaque, query and fragment uri_opts = { :host => opts[:hostname], :path => opts[:url_root]+opts[:script_name]+'/simple/'+opts[:endpoint], :query => URI.encode_www_form(opts[:get_params].merge(authToken: stored_auth_token)) } if opts[:protocol] == 'http' url = URI::HTTP.build uri_opts else url = URI::HTTPS.build uri_opts end url.path.gsub! %r{/+}, '/' url end |
.delete(request_opts = {}) ⇒ Object
HTTP DELETE request
55 56 57 |
# File 'lib/collectiveaccess.rb', line 55 def self.delete(request_opts = {}) custom_request :delete, request_opts end |
.get(request_opts = {}) ⇒ Object
HTTP GET request
35 36 37 |
# File 'lib/collectiveaccess.rb', line 35 def self.get(request_opts = {}) custom_request :get, request_opts end |
.options(request_opts = {}) ⇒ Object
HTTP OPTIONS request
45 46 47 |
# File 'lib/collectiveaccess.rb', line 45 def self.(request_opts = {}) custom_request :options, request_opts end |
.post(request_opts = {}) ⇒ Object
HTTP POST request
40 41 42 |
# File 'lib/collectiveaccess.rb', line 40 def self.post(request_opts = {}) custom_request :post, request_opts end |
.put(request_opts = {}) ⇒ Object
HTTP PUT request
50 51 52 |
# File 'lib/collectiveaccess.rb', line 50 def self.put(request_opts = {}) custom_request :put, request_opts end |
.set_credentials(user_name, key) ⇒ Object
30 31 32 |
# File 'lib/collectiveaccess.rb', line 30 def self.set_credentials(user_name, key) @auth = basic_auth user_name, key end |
.simple(request_opts = {}) ⇒ Object
59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 |
# File 'lib/collectiveaccess.rb', line 59 def self.simple(request_opts = {}) opts = request_opts uri = build_simple_uri opts resp = HTTParty.public_send :get, uri # if 401 (access denied), try to re-authenticate if resp.code == 401 delete_stored_auth_token # nuke old token authenticate opts # have to re-build the URI to include the new auth token new_uri = build_simple_uri opts # try again resp = HTTParty.public_send :get, new_uri end resp.parsed_response end |