Class: Crowdskout::Services::AttributeService
- Inherits:
-
BaseService
- Object
- BaseService
- Crowdskout::Services::AttributeService
- Defined in:
- lib/crowdskout/services/attribute_service.rb
Instance Attribute Summary
Attributes inherited from BaseService
Instance Method Summary collapse
-
#create_attribute(new_attribute) ⇒ Attribute
more info - docs.crowdskout.com/api/#create-an-attribute.
-
#delete_attribute(attribute_id) ⇒ boolean
more info - docs.crowdskout.com/api/#delete-an-attribute.
-
#get_attribute(attribute_id, params = {}) ⇒ Attribute
more info - docs.crowdskout.com/api/#get-an-attribute-by-id.
-
#get_attributes(params = {}) ⇒ ResultSet
More info - docs.crowdskout.com/api/#get-all-attributes.
-
#update_attribute(attribute_id, params = {}) ⇒ Attribute
more info - docs.crowdskout.com/api/#update-an-attribute.
Methods inherited from BaseService
Constructor Details
This class inherits a constructor from Crowdskout::Services::BaseService
Instance Method Details
#create_attribute(new_attribute) ⇒ Attribute
more info - docs.crowdskout.com/api/#create-an-attribute
45 46 47 48 49 50 51 52 |
# File 'lib/crowdskout/services/attribute_service.rb', line 45 def create_attribute(new_attribute) raise Exceptions::ServiceException, "Attribute must not be nil" if new_attribute.nil? url = Util::Config.get('endpoints.base_url') + Util::Config.get('endpoints.attribute') url = build_url(url) payload = new_attribute.to_json response = RestClient.post(url, payload, get_headers()) Components::Attribute.create(JSON.parse(response.body)["data"]) end |
#delete_attribute(attribute_id) ⇒ boolean
more info - docs.crowdskout.com/api/#delete-an-attribute
69 70 71 72 73 74 75 |
# File 'lib/crowdskout/services/attribute_service.rb', line 69 def delete_attribute(attribute_id) raise Exceptions::ServiceException, "Attribute ID is required." if attribute_id.nil? url = Util::Config.get('endpoints.base_url') + sprintf(Util::Config.get('endpoints.crud_attribute'), attribute_id) url = build_url(url) response = RestClient.delete(url, get_headers()) response.code == 204 end |
#get_attribute(attribute_id, params = {}) ⇒ Attribute
more info - docs.crowdskout.com/api/#get-an-attribute-by-id
33 34 35 36 37 38 39 40 |
# File 'lib/crowdskout/services/attribute_service.rb', line 33 def get_attribute(attribute_id, params = {}) raise Exceptions::ServiceException, "Attribute ID is required." if attribute_id.nil? url = Util::Config.get('endpoints.base_url') + sprintf(Util::Config.get('endpoints.crud_attribute'), attribute_id) url = build_url(url, params) response = RestClient.get(url, get_headers()) Components::Attribute.create(JSON.parse(response.body)["data"]) end |
#get_attributes(params = {}) ⇒ ResultSet
More info - docs.crowdskout.com/api/#get-all-attributes
14 15 16 17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/crowdskout/services/attribute_service.rb', line 14 def get_attributes(params = {}) url = Util::Config.get('endpoints.base_url') + Util::Config.get('endpoints.attributes') url = build_url(url, params) response = RestClient.get(url, get_headers()) body = JSON.parse(response.body) attributes = [] body['data']['list'].each do |attribute| attributes << Components::Attribute.create(attribute) end if body['data']["total"] > 0 Components::ResultSet.new(attributes, body['messages']) end |
#update_attribute(attribute_id, params = {}) ⇒ Attribute
more info - docs.crowdskout.com/api/#update-an-attribute
58 59 60 61 62 63 64 |
# File 'lib/crowdskout/services/attribute_service.rb', line 58 def update_attribute(attribute_id, params = {}) raise Exceptions::ServiceException, "Attribute ID is required." if attribute_id.nil? url = Util::Config.get('endpoints.base_url') + sprintf(Util::Config.get('endpoints.crud_attribute'), attribute_id) url = build_url(url) response = RestClient.put(url, params, get_headers()) Components::Attribute.create(JSON.parse(response.body)["data"]) end |