Class: CF::Badge
Instance Attribute Summary collapse
-
#allow_retake_after ⇒ Object
Returns the value of attribute allow_retake_after.
-
#description ⇒ Object
the description for the badge.
-
#errors ⇒ Object
Contains error message.
-
#max_badge_assignments ⇒ Object
number of badge provided to the worker.
-
#name ⇒ Object
Badge name.
-
#settings ⇒ Object
goldstandard settings.
Class Method Summary collapse
- .create(*args) ⇒ Object
- .destroy(*args) ⇒ Object
-
.list(name = nil) ⇒ Object
list all badges with in the account if name is not provided else it will return list all values of the given badge.
- .show(name) ⇒ Object
- .update(badge_name, update_params) ⇒ Object
Instance Method Summary collapse
-
#initialize(options = {}) ⇒ Badge
constructor
A new instance of Badge.
Constructor Details
#initialize(options = {}) ⇒ Badge
Returns a new instance of Badge.
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 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 63 64 65 |
# File 'lib/cf/badge.rb', line 23 def initialize(={}) .symbolize_keys! #if the form is provided as a file then explicitly add title and raw_html for the form if [:form] && [:form].class != Hash if File.exist?([:form]) file_type = IO.popen(["file", "--brief", "--mime-type", [:form]], in: :close, err: :close).read.chomp if file_type == "text/html" [:form] = {:title => "#{[:name]}_form",:_type => "CustomTaskForm", :raw_html => File.read([:form])} else @errors = ["Wrong type of file for the badge form."] return @errors exit(1) end else @errors = ["Badge form path is not valid."] end end #known_answers of the badge get customize because to if unique identifier doesn't present then array of hashs returns the last hash for Httparty and get all key value merge into one in rest client/ rack [:known_answers] = self.class.customize_known_answers([:known_answers], [:name]) if [:known_answers].present? @settings = @name = [:name] @description = [:description] @allow_retake_after = [:allow_retake_after] request = { :body => { :api_key => CF.api_key, :badge => } } resp = HTTParty.post("#{CF.api_url}#{CF.api_version}/accounts/#{CF.account_name}/badges.json",request) begin self.errors = resp["error"]["message"] if resp.code != 200 return resp rescue self.errors = ["Unexpected error found. Confirm that you are in correct path and form for the badge is provided."] end end |
Instance Attribute Details
#allow_retake_after ⇒ Object
Returns the value of attribute allow_retake_after.
18 19 20 |
# File 'lib/cf/badge.rb', line 18 def allow_retake_after @allow_retake_after end |
#description ⇒ Object
the description for the badge
13 14 15 |
# File 'lib/cf/badge.rb', line 13 def description @description end |
#errors ⇒ Object
Contains error message
21 22 23 |
# File 'lib/cf/badge.rb', line 21 def errors @errors end |
#max_badge_assignments ⇒ Object
number of badge provided to the worker
16 17 18 |
# File 'lib/cf/badge.rb', line 16 def max_badge_assignments @max_badge_assignments end |
#name ⇒ Object
Badge name
10 11 12 |
# File 'lib/cf/badge.rb', line 10 def name @name end |
#settings ⇒ Object
goldstandard settings
7 8 9 |
# File 'lib/cf/badge.rb', line 7 def settings @settings end |
Class Method Details
.create(*args) ⇒ Object
67 68 69 |
# File 'lib/cf/badge.rb', line 67 def self.create(*args) Badge.new(args.first) end |
.destroy(*args) ⇒ Object
97 98 99 100 101 102 103 104 105 106 107 108 |
# File 'lib/cf/badge.rb', line 97 def self.destroy(*args) name = args[0].parameterize = args[1].nil? ? {} : args[1] decendents = check_for_decendents(name) if decendents response = delete("/accounts/#{CF.account_name}/badges/#{name}.json") if .force else response = delete("/accounts/#{CF.account_name}/badges/#{name}.json") end @errors = response['error']['message'] if response['code'] != 200 return response end |
.list(name = nil) ⇒ Object
list all badges with in the account if name is not provided else it will return list all values of the given badge
111 112 113 114 115 |
# File 'lib/cf/badge.rb', line 111 def self.list(name = nil) response = get("/accounts/#{CF.account_name}/badges.json", :name => name) @errors = response['error']['message'] if response['code'] != 200 return response end |
.show(name) ⇒ Object
117 118 119 120 121 |
# File 'lib/cf/badge.rb', line 117 def self.show(name) response = get("/accounts/#{CF.account_name}/badges/#{name.parameterize}.json") @errors = response['error']['message'] if response['code'] != 200 return response end |
.update(badge_name, update_params) ⇒ Object
71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 |
# File 'lib/cf/badge.rb', line 71 def self.update(badge_name, update_params) badge_name = badge_name.parameterize update_params.symbolize_keys! if update_params[:form] && update_params[:form].class != Hash && File.exist?(update_params[:form]) file_type = IO.popen(["file", "--brief", "--mime-type", update_params[:form]], in: :close, err: :close).read.chomp if file_type == "text/html" update_params[:form] = {:title => "#{update_params[:name]}_form",:_type => "CustomTaskForm", :raw_html => File.read(update_params[:form])} else return end end update_params[:known_answers] = customize_known_answers(update_params[:known_answers], update_params[:name]) if update_params[:known_answers].present? request = { :body => { :api_key => CF.api_key, :badge => update_params } } resp = HTTParty.put("#{CF.api_url}#{CF.api_version}/accounts/#{CF.account_name}/badges/#{badge_name}.json",request) return resp end |