Class: ElectricProfile::Client
- Inherits:
-
Object
- Object
- ElectricProfile::Client
- Defined in:
- lib/electric_profile_ruby/client.rb
Instance Attribute Summary collapse
-
#data ⇒ Object
readonly
Returns the value of attribute data.
-
#error ⇒ Object
readonly
Returns the value of attribute error.
-
#successful ⇒ Object
readonly
Returns the value of attribute successful.
Instance Method Summary collapse
- #create_profiler(profiler_attributes) ⇒ Object
- #create_question(question_attributes) ⇒ Object
- #create_reward(reward_attributes) ⇒ Object
- #fetch_profiler(profiler_id) ⇒ Object
- #fetch_profilers(page_size = 99999) ⇒ Object
- #fetch_question(question_id) ⇒ Object
- #fetch_questions(page_size: 99999, categoryIncluded: nil, categoryExcluded: nil) ⇒ Object
- #fetch_respondent_profiler(profiler_id, user_id, locale) ⇒ Object
- #fetch_reward(reward_id) ⇒ Object
-
#initialize ⇒ Client
constructor
A new instance of Client.
- #queue_reward_delivery(reward_id) ⇒ Object
- #update_profiler(profiler_attributes) ⇒ Object
- #update_question(question_attributes) ⇒ Object
- #update_reward(reward_attributes) ⇒ Object
Constructor Details
#initialize ⇒ Client
Returns a new instance of Client.
9 10 11 12 13 14 15 16 17 18 19 20 |
# File 'lib/electric_profile_ruby/client.rb', line 9 def initialize raise ArgumentError, 'Customer token is required' unless @customer_token = ENV['ELECTRIC_PROFILE_CUSTOMER_TOKEN'] raise ArgumentError, 'API URL is required' unless @api_url = ENV['ELECTRIC_PROFILE_API_URL'] @http_headers = { 'Content-Type' => 'application/json', 'Accept' => 'application/json', 'Accept-Charset' => 'utf-8', 'User-Agent' => 'electric_profile_ruby', 'Panel-Services-Auth-Token' => @customer_token } end |
Instance Attribute Details
#data ⇒ Object (readonly)
Returns the value of attribute data.
7 8 9 |
# File 'lib/electric_profile_ruby/client.rb', line 7 def data @data end |
#error ⇒ Object (readonly)
Returns the value of attribute error.
7 8 9 |
# File 'lib/electric_profile_ruby/client.rb', line 7 def error @error end |
#successful ⇒ Object (readonly)
Returns the value of attribute successful.
7 8 9 |
# File 'lib/electric_profile_ruby/client.rb', line 7 def successful @successful end |
Instance Method Details
#create_profiler(profiler_attributes) ⇒ Object
67 68 69 70 71 72 |
# File 'lib/electric_profile_ruby/client.rb', line 67 def create_profiler(profiler_attributes) uri = URI(@api_url + 'profiler') http_request = Net::HTTP::Post.new uri, @http_headers http_request.body = { "data" => profiler_attributes }.to_json perform_request(uri, http_request) end |
#create_question(question_attributes) ⇒ Object
41 42 43 44 45 46 |
# File 'lib/electric_profile_ruby/client.rb', line 41 def create_question(question_attributes) uri = URI(@api_url + 'question') http_request = Net::HTTP::Post.new uri, @http_headers http_request.body = { "data" => question_attributes }.to_json perform_request(uri, http_request) end |
#create_reward(reward_attributes) ⇒ Object
95 96 97 98 99 100 |
# File 'lib/electric_profile_ruby/client.rb', line 95 def create_reward(reward_attributes) uri = URI(@api_url + 'reward') http_request = Net::HTTP::Post.new uri, @http_headers http_request.body = { "data" => reward_attributes }.to_json perform_request(uri, http_request) end |
#fetch_profiler(profiler_id) ⇒ Object
61 62 63 64 65 |
# File 'lib/electric_profile_ruby/client.rb', line 61 def fetch_profiler(profiler_id) uri = URI(@api_url + 'profiler?id=' + profiler_id) http_request = Net::HTTP::Get.new uri, @http_headers perform_request(uri, http_request) end |
#fetch_profilers(page_size = 99999) ⇒ Object
55 56 57 58 59 |
# File 'lib/electric_profile_ruby/client.rb', line 55 def fetch_profilers(page_size = 99999) uri = URI(@api_url + "profiler?PageSize=#{page_size}") http_request = Net::HTTP::Get.new uri, @http_headers perform_request(uri, http_request) end |
#fetch_question(question_id) ⇒ Object
35 36 37 38 39 |
# File 'lib/electric_profile_ruby/client.rb', line 35 def fetch_question(question_id) uri = URI(@api_url + 'question?id=' + question_id) http_request = Net::HTTP::Get.new uri, @http_headers perform_request(uri, http_request) end |
#fetch_questions(page_size: 99999, categoryIncluded: nil, categoryExcluded: nil) ⇒ Object
22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/electric_profile_ruby/client.rb', line 22 def fetch_questions(page_size: 99999, categoryIncluded: nil, categoryExcluded: nil) path_and_query = "question?PageSize=#{page_size}" if categoryIncluded path_and_query += "&categoryIncluded=#{categoryIncluded}" end if categoryExcluded path_and_query += "&categoryExcluded=#{categoryExcluded}" end uri = URI(@api_url + path_and_query) http_request = Net::HTTP::Get.new uri, @http_headers perform_request(uri, http_request) end |
#fetch_respondent_profiler(profiler_id, user_id, locale) ⇒ Object
81 82 83 84 85 86 87 |
# File 'lib/electric_profile_ruby/client.rb', line 81 def fetch_respondent_profiler(profiler_id, user_id, locale) raise ArgumentError, 'Survey token is required' unless survey_token = ENV['ELECTRIC_PROFILE_SURVEY_TOKEN'] @http_headers['Panel-Services-Auth-Token'] = survey_token uri = URI("#{@api_url}respondentProfiler?profilerId=#{profiler_id}&userId=#{user_id}&locale=#{locale}") http_request = Net::HTTP::Get.new uri, @http_headers perform_request(uri, http_request) end |
#fetch_reward(reward_id) ⇒ Object
89 90 91 92 93 |
# File 'lib/electric_profile_ruby/client.rb', line 89 def fetch_reward(reward_id) uri = URI(@api_url + 'reward?id=' + reward_id) http_request = Net::HTTP::Get.new uri, @http_headers perform_request(uri, http_request) end |
#queue_reward_delivery(reward_id) ⇒ Object
109 110 111 112 113 114 |
# File 'lib/electric_profile_ruby/client.rb', line 109 def queue_reward_delivery(reward_id) raise ArgumentError, 'Reward ID is required' unless reward_id uri = URI(@api_url + 'reward/' + reward_id + '/queueDelivery') http_request = Net::HTTP::Put.new uri, @http_headers perform_request(uri, http_request) end |
#update_profiler(profiler_attributes) ⇒ Object
74 75 76 77 78 79 |
# File 'lib/electric_profile_ruby/client.rb', line 74 def update_profiler(profiler_attributes) uri = URI(@api_url + 'profiler') http_request = Net::HTTP::Put.new uri, @http_headers http_request.body = { "data" => profiler_attributes }.to_json perform_request(uri, http_request) end |
#update_question(question_attributes) ⇒ Object
48 49 50 51 52 53 |
# File 'lib/electric_profile_ruby/client.rb', line 48 def update_question(question_attributes) uri = URI(@api_url + 'question') http_request = Net::HTTP::Put.new uri, @http_headers http_request.body = { "data" => question_attributes }.to_json perform_request(uri, http_request) end |
#update_reward(reward_attributes) ⇒ Object
102 103 104 105 106 107 |
# File 'lib/electric_profile_ruby/client.rb', line 102 def update_reward(reward_attributes) uri = URI(@api_url + 'reward') http_request = Net::HTTP::Put.new uri, @http_headers http_request.body = { "data" => reward_attributes }.to_json perform_request(uri, http_request) end |