class SiteMandala::SiteMandala
Attributes
token[RW]
Public Class Methods
delete(endpoint)
click to toggle source
# File lib/sitemandala/sitemandala.rb, line 49 def self.delete(endpoint) url = generate_url(endpoint) handle_response HTTParty.delete(url, :format => :json) end
generate_url(endpoint)
click to toggle source
# File lib/sitemandala/sitemandala.rb, line 54 def self.generate_url(endpoint) Configuration.ensure! :base_url Configuration.ensure! :token token = Configuration.token base_url = Configuration.base_url base_url+endpoint+"?token="+token end
get(endpoint)
click to toggle source
# File lib/sitemandala/sitemandala.rb, line 29 def self.get(endpoint) url = generate_url(endpoint) handle_response HTTParty.get(url, :format => :json) end
handle_response(response)
click to toggle source
# File lib/sitemandala/sitemandala.rb, line 62 def self.handle_response(response) case response.code when 400 raise BadRequest.new(Hashie::Mash.new response) when 401 data = Hashie::Mash.new(response) when 404 raise NotFound.new when 400...500 raise ClientError.new when 500...600 raise ServerError.new else records = response.parsed_response if records.is_a?(Array) records.map{ |item| Hashie::Mash.new(item) } elsif records.is_a?(Hash) Hashie::Mash.new(records) end end end
patch(endpoint, data)
click to toggle source
# File lib/sitemandala/sitemandala.rb, line 44 def self.patch(endpoint, data) url = generate_url(endpoint) handle_response HTTParty.patch(url, :body => data.to_json, :format => :json) end
post(endpoint, data)
click to toggle source
# File lib/sitemandala/sitemandala.rb, line 34 def self.post(endpoint, data) url = generate_url(endpoint) handle_response HTTParty.post(url, :body => data.to_json, :format => :json) end
put(endpoint, data)
click to toggle source
# File lib/sitemandala/sitemandala.rb, line 39 def self.put(endpoint, data) url = generate_url(endpoint) handle_response HTTParty.put(url, :body => data.to_json, :format => :json) end